/*
 * Shuffle — UI theme.
 *
 * Design palette (Shuffle Final — exact values from design system):
 *   --cream  #efe7d8  warm cream (light surface)
 *   --coal   #1a1714  warm near-black (dark surface)
 *   --paper  #f5f1ea  lightest off-white (light bg)
 *   --ink    #0f0d0b  deepest black (text)
 *   --orange oklch(0.68 0.17 45)  brand orange
 *   --ember  oklch(0.58 0.18 38)  darker orange (hover / light-mode accent)
 *   --muted  #8a8580  neutral mid-grey
 *
 * Body font: JetBrains Mono (OFL-1.1) for data/chat.
 * Logo/brand: "Helvetica Neue", system-ui sans-serif.
 */

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

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --font:            'JetBrains Mono', 'Commit Mono', 'IBM Plex Mono',
                     ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
  --font-ui:         "Helvetica Neue", Helvetica, Arial, ui-sans-serif, system-ui, sans-serif;
  --font-size:       14px;
  --line-height:     1.65;

  /* Dark palette — exact design values */
  --bg:              #1a1714;   /* coal */
  --surface:         #231f1c;
  --surface-2:       #2c2825;
  --text:            #efe7d8;   /* cream */
  --text-muted:      #8a8580;   /* muted */
  --accent:          oklch(0.68 0.17 45);   /* shuffle orange */
  --accent-hover:    oklch(0.62 0.18 42);
  --bubble-self-bg:  oklch(0.68 0.17 45);
  --bubble-self-fg:  #1a1714;
  --bubble-peer-bg:  #2c2825;
  --bubble-peer-fg:  #efe7d8;
  --border:          #2c2825;
  --danger:          #e54040;
  --danger-hover:    #c83030;
  --success:         #30a952;
  --r-sm:            4px;
  --r-md:            6px;
  --r-lg:            8px;
  --col:             760px;
  --gutter:          1.25rem;
}

/* ── Light theme override — exact design values ───────────────────────────── */
[data-theme="light"] {
  --bg:              #efe7d8;   /* cream */
  --surface:         #f5f1ea;   /* paper */
  --surface-2:       #e5ddd0;
  --text:            #1a1714;   /* coal / ink */
  --text-muted:      #8a8580;
  --accent:          oklch(0.55 0.18 38);   /* ember — darker for cream contrast */
  --accent-hover:    oklch(0.47 0.17 35);
  --bubble-self-bg:  oklch(0.55 0.18 38);
  --bubble-self-fg:  #f5f1ea;
  --bubble-peer-bg:  #e5ddd0;
  --bubble-peer-fg:  #1a1714;
  --border:          #d4ccc0;
  --danger:          #c83030;
  --danger-hover:    #a02020;
  --success:         #1e8c3a;
}

/* System dark preference — applied before JS hydrates (no FOUC). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:              #efe7d8;
    --surface:         #f5f1ea;
    --surface-2:       #e5ddd0;
    --text:            #1a1714;
    --text-muted:      #8a8580;
    --accent:          oklch(0.55 0.18 38);
    --accent-hover:    oklch(0.47 0.17 35);
    --bubble-self-bg:  oklch(0.55 0.18 38);
    --bubble-self-fg:  #f5f1ea;
    --bubble-peer-bg:  #e5ddd0;
    --bubble-peer-fg:  #1a1714;
    --border:          #d4ccc0;
    --danger:          #c83030;
    --danger-hover:    #a02020;
    --success:         #1e8c3a;
  }
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "calt" 1, "liga" 0;
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */
.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);   /* single solid background throughout */
  --px: max(var(--gutter), calc((100% - var(--col)) / 2));
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem var(--px);
  padding-top: max(0.6rem, calc(0.6rem + env(safe-area-inset-top, 0px)));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

/* Logo lockup: SVG mark + wordmark side-by-side */
.logo-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
  user-select: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: block;
}

/* Card fill tracks the surface background */
.logo-mark .card-bg {
  fill: var(--bg);
}

.logo-word {
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1;
}

/* Client ID badge */
.client-id-badge {
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.15rem 0.55rem;
  letter-spacing: 0.03em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions { display: flex; gap: 0.4rem; align-items: center; margin-left: auto; flex-shrink: 0; }

/* Square icon button */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 30px;
  height: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  flex-shrink: 0;
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
}
.icon-btn svg { display: block; pointer-events: none; }

/* ── Main content area ────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem var(--px);
  gap: 1rem;
  overflow: hidden;
}

/* Tagline — shown on the idle screen */
.tagline {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

/* Hero lockup — mark + wordmark + tagline rail, idle/landing page */
.hero-lockup {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 22px;
  margin-bottom: 1.25rem;
  user-select: none;
}

.hero-mark {
  width: 96px;
  height: 96px;
  display: block;
  flex-shrink: 0;
}

/* Card fill on the hero mark also tracks the page background */
.hero-mark .card-bg { fill: var(--bg); }

.hero-word {
  font-family: var(--font-ui);
  font-size: 4rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1;
}

.hero-tag {
  margin-left: 18px;
  padding-left: 18px;
  border-left: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
  max-width: 140px;
}

@media (max-width: 520px) {
  .hero-lockup {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
  }
  .hero-tag {
    border-left: none;
    border-top: 1px solid var(--border);
    margin-left: 0;
    padding-left: 0;
    padding-top: 12px;
    max-width: 260px;
    text-align: center;
  }
}

/* Small hint text below status labels */
.status-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.7;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--font-ui);
  padding: 0.6rem 2rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  line-height: 1;
  letter-spacing: -0.01em;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Bordered Shuffle CTA button — light border on dark bg, dark border on light bg */
.btn-shuffle {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--text);
  padding: 0.65rem 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
  opacity: 0.9;
  transition: opacity 0.12s, border-color 0.12s;
}
.btn-shuffle:hover:not(:disabled) {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
}
.btn-shuffle:active { transform: scale(0.98); }

/* Logo mark inside the button — sized to match text height */
.btn-shuffle-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.btn-shuffle-icon .logo-mark {
  width: 20px;
  height: 20px;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-sm { padding: 0.38rem 0.85rem; font-size: 0.8rem; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Status / label text ──────────────────────────────────────────────────── */
.status-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  letter-spacing: 0.01em;
}

/* ── Auto-search row ──────────────────────────────────────────────────────── */
.auto-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font);
}
.auto-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}
.auto-row input[type="number"] {
  width: 44px;
  padding: 0.2rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  text-align: center;
}

.countdown-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-family: var(--font);
}

/* ── Chat layout ──────────────────────────────────────────────────────────── */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.chat-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem var(--px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.chat-bar-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem var(--px);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  scroll-behavior: smooth;
}

.msg {
  max-width: 70%;
  padding: 0.5rem 0.85rem;
  border-radius: var(--r-md);
  font-size: 0.85rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  font-family: var(--font);
}
.msg-self {
  align-self: flex-end;
  background: var(--bubble-self-bg);
  color: var(--bubble-self-fg);
  border-bottom-right-radius: 2px;
}
.msg-peer {
  align-self: flex-start;
  background: var(--bubble-peer-bg);
  color: var(--bubble-peer-fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}
.msg-system {
  align-self: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.25rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  letter-spacing: 0.02em;
}

.input-row {
  display: flex;
  gap: 0.45rem;
  padding: 0.6rem var(--px);
  padding-bottom: max(0.6rem, calc(0.6rem + env(safe-area-inset-bottom, 0px)));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.chat-input {
  flex: 1;
  padding: 0.5rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: max(0.85rem, 16px);
  resize: none;
  line-height: 1.45;
  max-height: 120px;
  outline: none;
  transition: border-color 0.12s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

/* ── Ended screen ─────────────────────────────────────────────────────────── */
.ended-icon   { font-size: 2rem; }
.ended-title  {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── Settings / debug panel ───────────────────────────────────────────────── */
.debug-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
}

.debug-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  font-family: var(--font);
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.debug-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.debug-section {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.debug-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}

.debug-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.debug-row-col {
  flex-direction: column;
  align-items: flex-start;
}

.debug-label {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 72px;
  font-size: 0.78rem;
}

.debug-value {
  color: var(--text);
  word-break: break-all;
  font-size: 0.8rem;
}

.debug-mono {
  font-family: var(--font);
  font-size: 0.76rem;
}

.debug-select {
  flex: 1;
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  appearance: auto;
}
.debug-select:focus { outline: none; border-color: var(--accent); }

.debug-input {
  width: 100%;
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.78rem;
}
.debug-input:focus { outline: none; border-color: var(--accent); }

.debug-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--r-sm);
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: var(--font);
}
.debug-badge-ok {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}
.debug-badge-pending {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.debug-url-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.2rem;
}
.debug-url-item {
  font-size: 0.72rem;
  color: var(--text-muted);
  word-break: break-all;
}

.debug-toggle-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  cursor: pointer;
}
.debug-toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  margin-top: 3px;
  flex-shrink: 0;
  cursor: pointer;
}
.debug-toggle-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text);
}
.debug-toggle-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  line-height: 1.45;
}

/* ── Signal strength bars (chat bar) ─────────────────────────────────────── */
.signal-btn {
  background: none;
  border: none;
  padding: 0 0.3rem;
  cursor: default;
  display: flex;
  align-items: center;
  opacity: 0.75;
  flex-shrink: 0;
}
.signal-btn:hover { opacity: 1; }

.bar-wrap {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.bar {
  width: 3px;
  border-radius: 1px;
  transition: background 0.4s;
}
.bar-1 { height: 4px; }
.bar-2 { height: 7px; }
.bar-3 { height: 10px; }
.bar-4 { height: 14px; }

/* ── Safe area (iPhone notch / home indicator) ────────────────────────────── */
.main {
  padding-bottom: calc(2.5rem + env(safe-area-inset-bottom, 0px));
}

/* ── Icon button — fix <a> variant ───────────────────────────────────────── */
a.icon-btn {
  text-decoration: none;
  color: var(--text-muted);
}
a.icon-btn:hover {
  color: var(--text);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-indicator {
  align-self: flex-start;
  padding: 0.45rem 0.75rem;
  background: var(--bubble-peer-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-bottom-left-radius: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 44px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.1s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

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

/* ── Scrollbars (WebKit) ──────────────────────────────────────────────────── */
::-webkit-scrollbar         { width: 5px; height: 5px; }
::-webkit-scrollbar-track   { background: transparent; }
::-webkit-scrollbar-thumb   { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Text selection ───────────────────────────────────────────────────────── */
::selection {
  background: oklch(0.68 0.17 45 / 0.3);
  color: inherit;
}
