/* ============================================
   streaming-LLM — Cyberpunk / eth2030 Theme
   ============================================ */

:root {
  --bg: #0a0a1e;
  --surface: #12122a;
  --purple: #8c8dfc;
  --teal: #2de2e6;
  --pink: #ff6b9d;
  --dim: #9090b8;
  --text: #e0e0ff;
  --font-mono: "JetBrains Mono", monospace;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(140, 141, 252, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140, 141, 252, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  line-height: 1.6;
}

/* CRT scanline overlay */
.scanline-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

/* ---- Layout ---- */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- Header ---- */

.header {
  flex-shrink: 0;
  padding: 12px 0;
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid rgba(140, 141, 252, 0.15);
  border-radius: 8px;
  padding: 10px 16px;
  box-shadow:
    0 0 12px rgba(140, 141, 252, 0.08),
    inset 0 1px 0 rgba(140, 141, 252, 0.05);
}

/* Terminal dots */
.terminal-dots {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot-red {
  background: #ff5f57;
}

.dot-yellow {
  background: #febc2e;
}

.dot-green {
  background: #28c840;
}

/* Title with glitch */
.title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--purple);
  text-shadow:
    0 0 6px rgba(140, 141, 252, 0.6),
    0 0 20px rgba(140, 141, 252, 0.3);
  position: relative;
  animation: glitch 4s infinite;
}

.title::before,
.title::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  overflow: hidden;
}

.title::before {
  color: var(--teal);
  z-index: -1;
  animation: glitch-top 4s infinite;
}

.title::after {
  color: var(--pink);
  z-index: -2;
  animation: glitch-bottom 4s infinite;
}

@keyframes glitch {
  0%, 92%, 100% {
    transform: none;
  }
  93% {
    transform: translate(-2px, 1px);
  }
  94% {
    transform: translate(2px, -1px);
  }
  95% {
    transform: translate(-1px, 0);
  }
}

@keyframes glitch-top {
  0%, 92%, 100% {
    clip-path: inset(0 0 65% 0);
    transform: none;
  }
  93% {
    clip-path: inset(0 0 65% 0);
    transform: translate(3px, 0);
  }
  94% {
    clip-path: inset(0 0 65% 0);
    transform: translate(-3px, 0);
  }
  95% {
    clip-path: inset(0 0 65% 0);
    transform: translate(1px, 0);
  }
}

@keyframes glitch-bottom {
  0%, 92%, 100% {
    clip-path: inset(65% 0 0 0);
    transform: none;
  }
  93% {
    clip-path: inset(65% 0 0 0);
    transform: translate(-3px, 0);
  }
  94% {
    clip-path: inset(65% 0 0 0);
    transform: translate(3px, 0);
  }
  95% {
    clip-path: inset(65% 0 0 0);
    transform: translate(-1px, 0);
  }
}

/* Cost counter */
.cost-counter {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cost-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.cost-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--teal);
  text-shadow:
    0 0 6px rgba(45, 226, 230, 0.5),
    0 0 20px rgba(45, 226, 230, 0.2);
  font-variant-numeric: tabular-nums;
}

/* Wallet button */
.wallet-section {
  flex-shrink: 0;
}

.wallet-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid var(--purple);
  border-radius: 4px;
  background: transparent;
  color: var(--purple);
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.wallet-btn:hover {
  background: rgba(140, 141, 252, 0.1);
  box-shadow:
    0 0 10px rgba(140, 141, 252, 0.2),
    0 0 25px rgba(140, 141, 252, 0.08);
}

.wallet-btn.connected {
  border-color: var(--teal);
  color: var(--teal);
}

.wallet-btn.connected:hover {
  background: rgba(45, 226, 230, 0.1);
  box-shadow:
    0 0 10px rgba(45, 226, 230, 0.2),
    0 0 25px rgba(45, 226, 230, 0.08);
}

.wallet-icon {
  font-size: 13px;
  line-height: 1;
}

.wallet-btn.connected .wallet-icon {
  color: var(--teal);
  text-shadow: 0 0 6px rgba(45, 226, 230, 0.5);
}

/* Payment prompt in chat */
.payment-prompt {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.payment-prompt .payment-info {
  color: var(--pink);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.payment-prompt .payment-detail {
  color: var(--dim);
  font-size: 12px;
  line-height: 1.5;
}

.payment-prompt .payment-link {
  color: var(--purple);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

.payment-prompt .payment-link:hover {
  color: var(--teal);
  text-shadow: 0 0 6px rgba(45, 226, 230, 0.3);
}

.payment-connect-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 8px 16px;
  border: 1px solid var(--purple);
  border-radius: 4px;
  background: rgba(140, 141, 252, 0.1);
  color: var(--purple);
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: flex-start;
  margin-top: 4px;
}

.payment-connect-btn:hover {
  background: rgba(140, 141, 252, 0.2);
  box-shadow: 0 0 10px rgba(140, 141, 252, 0.2);
}

/* ---- Settings gear button ---- */

.settings-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid rgba(140, 141, 252, 0.2);
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  color: var(--dim);
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.settings-btn:hover {
  color: var(--purple);
  border-color: var(--purple);
  background: rgba(140, 141, 252, 0.08);
}

.settings-btn.active {
  color: var(--purple);
  border-color: var(--purple);
  background: rgba(140, 141, 252, 0.12);
  box-shadow: 0 0 8px rgba(140, 141, 252, 0.15);
}

.settings-icon {
  display: block;
  transition: transform 0.3s ease;
}

.settings-btn.active .settings-icon {
  transform: rotate(90deg);
}

.settings-key-indicators {
  display: flex;
  gap: 3px;
}

.key-indicator {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--teal);
  background: rgba(45, 226, 230, 0.1);
  border: 1px solid rgba(45, 226, 230, 0.25);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.3;
}

/* ---- Settings Panel ---- */

.settings-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease;
  opacity: 0;
}

.settings-panel.open {
  max-height: 600px;
  opacity: 1;
}

.settings-inner {
  background: var(--surface);
  border: 1px solid rgba(140, 141, 252, 0.2);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--purple);
  margin-bottom: 10px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.settings-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--dim);
  text-transform: uppercase;
}

.settings-key-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.settings-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid rgba(140, 141, 252, 0.2);
  border-radius: 4px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.2s ease;
}

.settings-input::placeholder {
  color: rgba(144, 144, 184, 0.5);
}

.settings-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 6px rgba(140, 141, 252, 0.12);
}

.settings-toggle-vis {
  background: transparent;
  border: 1px solid rgba(140, 141, 252, 0.15);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--dim);
  transition: color 0.2s ease, border-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-toggle-vis:hover {
  color: var(--purple);
  border-color: var(--purple);
}

.settings-toggle-vis.visible {
  color: var(--teal);
  border-color: rgba(45, 226, 230, 0.3);
}

.settings-link {
  font-size: 11px;
  color: var(--purple);
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: color 0.2s ease;
}

.settings-link:hover {
  color: var(--teal);
  text-shadow: 0 0 6px rgba(45, 226, 230, 0.3);
}

.settings-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.settings-action-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 7px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid;
}

.settings-save-btn {
  background: rgba(140, 141, 252, 0.12);
  border-color: var(--purple);
  color: var(--purple);
}

.settings-save-btn:hover {
  background: rgba(140, 141, 252, 0.22);
  box-shadow: 0 0 10px rgba(140, 141, 252, 0.2);
}

.settings-clear-btn {
  background: transparent;
  border-color: rgba(255, 107, 157, 0.3);
  color: var(--pink);
}

.settings-clear-btn:hover {
  background: rgba(255, 107, 157, 0.08);
  box-shadow: 0 0 10px rgba(255, 107, 157, 0.15);
}

.settings-wallet-connect-btn {
  background: transparent;
  border-color: var(--purple);
  color: var(--purple);
  align-self: flex-start;
}

.settings-wallet-connect-btn:hover {
  background: rgba(140, 141, 252, 0.1);
}

.settings-wallet-connect-btn.connected {
  border-color: var(--teal);
  color: var(--teal);
}

.settings-wallet-connect-btn.connected:hover {
  background: rgba(45, 226, 230, 0.1);
}

.settings-status {
  font-size: 11px;
  letter-spacing: 0.5px;
  min-height: 16px;
  margin-top: 4px;
}

.settings-status.success {
  color: var(--teal);
}

.settings-status.cleared {
  color: var(--pink);
}

.settings-divider {
  height: 1px;
  background: rgba(140, 141, 252, 0.12);
}

.settings-divider-thin {
  height: 1px;
  background: rgba(140, 141, 252, 0.08);
  margin: 6px 0;
}

.settings-wallet-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.settings-wallet-address {
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.settings-hint {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.5;
  margin-bottom: 4px;
}

/* ---- Chat area ---- */

.chat-area {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Messages */
.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid rgba(140, 141, 252, 0.08);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.message-content {
  color: var(--text);
  line-height: 1.7;
}

.message-user {
  align-self: flex-end;
  border-left: 3px solid var(--teal);
}

.message-user .message-label {
  color: var(--teal);
}

.message-assistant {
  align-self: flex-start;
  border-left: 3px solid var(--purple);
}

.message-assistant .message-label {
  color: var(--purple);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--purple);
  opacity: 0.4;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ---- Input area ---- */

.input-area {
  flex-shrink: 0;
  padding: 12px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Provider selector */
.provider-selector {
  display: flex;
  gap: 4px;
}

.provider-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid rgba(140, 141, 252, 0.2);
  border-radius: 4px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  transition: all 0.2s ease;
}

.provider-btn:hover {
  border-color: var(--purple);
  color: var(--text);
}

.provider-btn.active {
  background: rgba(140, 141, 252, 0.12);
  border-color: var(--purple);
  color: var(--purple);
  box-shadow: 0 0 8px rgba(140, 141, 252, 0.15);
}

/* Model selector */
.model-select {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid rgba(140, 141, 252, 0.2);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  min-width: 200px;
  transition: border-color 0.2s ease;
}

.model-select:focus {
  border-color: var(--purple);
}

.model-select option {
  background: var(--surface);
  color: var(--text);
}

/* Input row */
.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid rgba(140, 141, 252, 0.15);
  border-radius: 6px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  line-height: 1.5;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.message-input::placeholder {
  color: var(--dim);
}

.message-input:focus {
  border-color: var(--purple);
  box-shadow:
    0 0 8px rgba(140, 141, 252, 0.15),
    0 0 20px rgba(140, 141, 252, 0.05);
}

/* Send button */
.send-btn {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 24px;
  background: var(--purple);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  box-shadow:
    0 0 14px rgba(140, 141, 252, 0.5),
    0 0 30px rgba(140, 141, 252, 0.2);
  transform: translateY(-1px);
}

.send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Custom scrollbar ---- */

.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: var(--bg);
}

.chat-area::-webkit-scrollbar-thumb {
  background: var(--purple);
  border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
  background: rgba(140, 141, 252, 0.8);
}

/* Firefox scrollbar */
.chat-area {
  scrollbar-width: thin;
  scrollbar-color: var(--purple) var(--bg);
}

/* ---- Footer ---- */

.footer {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 0 12px;
  font-size: 11px;
  letter-spacing: 1px;
}

.footer a {
  color: var(--dim);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--purple);
  text-shadow: 0 0 6px rgba(140, 141, 252, 0.3);
}

.footer-sep {
  color: rgba(140, 141, 252, 0.2);
  margin: 0 8px;
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  .title,
  .title::before,
  .title::after {
    animation: none;
  }

  .typing-dot {
    animation: none;
    opacity: 0.6;
  }

  .send-btn:hover:not(:disabled) {
    transform: none;
  }
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  .app-container {
    padding: 0 8px;
  }

  .header-bar {
    padding: 8px 12px;
    gap: 10px;
  }

  .title {
    font-size: 14px;
  }

  .cost-value {
    font-size: 13px;
  }

  .wallet-btn {
    font-size: 10px;
    padding: 5px 10px;
  }

  .settings-btn {
    padding: 4px 6px;
  }

  .settings-inner {
    padding: 12px 14px;
  }

  .message {
    max-width: 95%;
  }

  .input-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .model-select {
    min-width: unset;
    width: 100%;
  }

  .provider-selector {
    justify-content: center;
  }
}
