/* AhaClue — "Midnight Broth": cozy-noir, deep teal + ember, late-night warmth.
   Fraunces (serif headline) + Inter (UI) + Noto Serif TC (Chinese). Dark-native,
   mobile-first, colour+glyph verdicts for accessibility. */

:root {
  --bg: #0d1b1e;
  --bg-2: #102327;
  --panel: #14282d;
  --panel-2: #163036;
  --ember: #e8643c;
  --ember-soft: #f08a64;
  --gold: #e8b04c;
  --cream: #f3ece1;
  --muted: #8aa1a3;
  --line: rgba(232,176,76,.16);
  --yes: #4fae6b;
  --yes-bg: rgba(79,174,107,.16);
  --no: #e8643c;
  --no-bg: rgba(232,100,60,.16);
  --irr: #6f8487;
  --irr-bg: rgba(111,132,135,.16);
  --serif: 'Fraunces', 'Noto Serif TC', Georgia, serif;
  --serif-zh: 'Noto Serif TC', 'Fraunces', serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--cream); font-family: var(--sans); min-height: 100%; }
body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(232,100,60,.14), transparent 62%),
    radial-gradient(700px 500px at 90% 110%, rgba(232,176,76,.07), transparent 60%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

/* steam wisps rising behind the card */
.steam { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.steam span {
  position: absolute; bottom: -120px; width: 200px; height: 320px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(232,176,76,.10), transparent);
  filter: blur(14px); animation: rise 14s linear infinite;
}
.steam span:nth-child(1) { left: 12%; animation-delay: 0s; }
.steam span:nth-child(2) { left: 48%; animation-delay: 5s; }
.steam span:nth-child(3) { left: 78%; animation-delay: 9s; }
@keyframes rise { 0% { transform: translateY(0) scale(.8); opacity: 0; }
  20% { opacity: .8; } 100% { transform: translateY(-90vh) scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .steam { display: none; } }

/* top bar */
.topbar {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 9px; }
.logo { color: var(--ember); font-size: 1.5rem; line-height: 1; transform: translateY(2px); }
.wordmark { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; letter-spacing: -.01em; }
.wordmark b { color: var(--ember); font-weight: 600; }
.brand .zh { font-family: var(--serif-zh); color: var(--muted); font-size: .95rem; letter-spacing: .08em; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; background: var(--panel); color: var(--cream);
  border: 1px solid var(--line); font-size: 1rem; cursor: pointer; transition: all .15s;
  display: grid; place-items: center; font-family: var(--serif-zh);
}
.icon-btn:hover { background: var(--panel-2); border-color: rgba(232,100,60,.4); }

/* stage */
.stage {
  position: relative; z-index: 1; flex: 1; min-height: 0; width: 100%; max-width: 640px; margin: 0 auto;
  padding: 16px 18px 14px; display: flex; flex-direction: column; gap: 12px;
}

.card {
  flex: none; max-height: 38vh; overflow: hidden;   /* pinned context, capped < 40% of viewport */
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 20px;
  position: relative; box-shadow: 0 14px 48px rgba(0,0,0,.5);
}
.card-meta, .title { flex: none; }   /* number + title stay pinned; only the surface scrolls */
.card::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(360px 160px at 50% -30%, rgba(232,100,60,.14), transparent);
}
.card-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.meta-right { display: flex; align-items: center; gap: 10px; }
.puzzle-num { font-size: .78rem; letter-spacing: .14em; color: var(--ember); text-transform: uppercase; font-weight: 600; }
.streak-chip { font-size: .85rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.badge {
  font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  border: 1px solid rgba(138,161,163,.35); border-radius: 999px; padding: 3px 9px;
}
.title { font-family: var(--serif); font-weight: 600; font-size: 1.55rem; line-height: 1.18; margin-bottom: 12px; }
.surface { font-family: var(--serif); font-size: 1.3rem; line-height: 1.55; color: #ece3d4;
  min-height: 0; overflow-y: auto; }   /* scrolls inside the capped card; meta + title stay pinned */
:lang(zh) .title, :lang(zh) .surface { font-family: var(--serif-zh); }

/* question log — the scrollable chat area */
.log {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px; padding: 2px;
}
.log:empty::before {
  content: attr(data-empty); display: block; text-align: center; color: var(--muted);
  font-family: var(--serif); font-style: italic; font-size: 1.05rem; padding: 24px 12px;
}
.qa {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px;
  background: rgba(255,255,255,.025); border: 1px solid rgba(255,255,255,.05);
  animation: rise-in .22s ease both;
}
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } }
.qa .qtext { flex: 1; font-family: var(--serif); font-size: 1.12rem; color: #e0d7c8; }
:lang(zh) .qa .qtext { font-family: var(--serif-zh); }
.verdict {
  font-size: .82rem; font-weight: 700; letter-spacing: .02em; padding: 4px 11px; border-radius: 8px;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; animation: pop .3s ease;
}
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.verdict.yes { background: var(--yes-bg); color: #8fe0a3; }
.verdict.no  { background: var(--no-bg); color: var(--ember-soft); }
.verdict.irrelevant { background: var(--irr-bg); color: #b6c6c8; }
.qa .src { font-size: .68rem; color: var(--muted); }
.qa.hint { background: rgba(232,176,76,.09); border-color: rgba(232,176,76,.25); }
.qa.hint .qtext { font-style: italic; color: var(--gold); }
.qa.system { background: var(--no-bg); border-color: rgba(232,100,60,.3); justify-content: center; }
.qa.system .qtext { flex: none; text-align: center; color: var(--ember-soft); font-style: italic; }

/* ask row */
.ask-row { display: flex; gap: 10px; }
.ask-input {
  flex: 1; min-width: 0; background: var(--bg-2); color: var(--cream); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px; font-family: var(--serif); font-size: 1.12rem;
}
:lang(zh) .ask-input { font-family: var(--serif-zh); }
.ask-input:focus { outline: none; border-color: var(--ember); box-shadow: 0 0 0 3px rgba(232,100,60,.18); }
.ask-btn {
  flex: none; white-space: nowrap; background: var(--ember); color: #1a0d08; border: none;
  border-radius: 12px; padding: 0 22px; font-family: var(--sans); font-weight: 700; font-size: .95rem;
  cursor: pointer; transition: all .15s;
}
.ask-btn:hover { background: var(--ember-soft); }
.ask-btn:disabled { opacity: .5; cursor: wait; }
.ask-btn.wide { width: 100%; padding: 14px; }

/* controls */
.controls { display: flex; gap: 10px; }
.ctrl {
  flex: 1; white-space: nowrap; background: transparent; color: var(--cream); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 8px; font-family: var(--sans); font-size: .9rem; cursor: pointer; transition: all .15s;
}
.ctrl:hover { background: rgba(255,255,255,.04); }
.ctrl-primary { border-color: rgba(232,176,76,.45); color: var(--gold); }
.ctrl-primary:hover { background: rgba(232,176,76,.12); }
.ctrl-danger { border-color: rgba(232,100,60,.4); color: var(--ember-soft); }
.ctrl-danger:hover { background: var(--no-bg); }

/* modals */
.modal-wrap {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(4,10,11,.74); backdrop-filter: blur(4px); padding: 18px;
}
.modal-wrap[hidden] { display: none; }
.modal {
  background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.66); animation: rise-in .25s ease both;
}
.modal h2 { font-family: var(--serif); font-size: 1.5rem; margin-bottom: 8px; }
.modal-sub, .onboard-lead { color: var(--muted); font-size: .98rem; margin-bottom: 14px; line-height: 1.5; }
.modal textarea {
  width: 100%; background: var(--bg); color: var(--cream); resize: vertical; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font-family: var(--serif); font-size: 1.1rem; margin-top: 6px;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions.center { justify-content: center; }
.ghost-btn {
  background: transparent; color: var(--gold); border: 1px solid rgba(232,176,76,.4); border-radius: 10px;
  padding: 11px 16px; font-family: var(--sans); font-size: .9rem; cursor: pointer; transition: all .15s;
}
.ghost-btn:hover { background: rgba(232,176,76,.1); }
.feedback { margin-top: 12px; font-family: var(--serif); font-size: 1.05rem; color: var(--gold); min-height: 1.2em; }

/* onboarding */
.onboard { text-align: center; }
.onboard-logo { font-size: 2.4rem; color: var(--ember); margin-bottom: 6px; }
.onboard-demo { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 14px; text-align: left; }
.onboard-foot { color: var(--muted); font-size: .92rem; margin-bottom: 4px; }

/* result */
.result { text-align: center; }
.result-icon { font-size: 2.8rem; margin-bottom: 4px; }
.reveal-label { font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ember); margin-top: 12px; }
.solution { font-family: var(--serif); font-size: 1.22rem; line-height: 1.55; color: #ece3d4; margin-top: 6px; text-align: left; }
:lang(zh) .solution { font-family: var(--serif-zh); }
.share-card {
  margin: 18px 0 2px; padding: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  font-family: var(--sans); font-size: 1rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  text-align: left; color: var(--cream);
}

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 18px; }
.stat { text-align: center; }
.stat-n { display: block; font-family: var(--serif); font-size: 1.7rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.stat-l { font-size: .72rem; color: var(--muted); }
.dist-title { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.dist { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: .82rem; }
.dist-row .bucket { width: 64px; color: var(--muted); white-space: nowrap; }
.dist-row .bar { height: 18px; background: var(--ember); border-radius: 5px; min-width: 18px; display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; color: #1a0d08; font-weight: 700; font-size: .72rem; }

/* footer */
.foot { position: relative; z-index: 1; text-align: center; padding: 16px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); }
.foot a { color: var(--ember-soft); text-decoration: none; }

@media (max-width: 480px) {
  .title { font-size: 1.36rem; } .surface { font-size: 1.18rem; }
  .brand .zh { display: none; }
  .controls { gap: 7px; }
  .ctrl { font-size: .82rem; padding: 11px 4px; }   /* keep labels, just tighten */
  .ask-btn { padding: 0 16px; }
}
