/* ===========================================================================
   Convince the Duck — player UI

   Chat-first layout. The conversation is a single scrolling thread; the duck's
   reply streams directly into the last bubble in that thread, so nothing ever
   jumps from one part of the page to another.

   Visual direction: light Zro surface, near-black ink, restrained blue accent
   (#1b4fa4), yellow duck + gold egg, JetBrains Mono.
   =========================================================================== */

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('JetBrains Mono'), local('JetBrainsMono-Regular');
}

:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --surface-2: #eceef2;
  --ink: #0b0d10;
  --ink-dim: #5b616b;
  --ink-faint: #8b909a;
  --rule: #e2e5ea;
  --rule-strong: #cfd4db;
  --accent: #1b4fa4;
  --accent-soft: #eaf0fa;
  --duck: #f5c542;
  --egg: #f0c14b;
  --ok: #1b6b3a;
  --danger: #a4231b;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Lock the app to the viewport. The chat thread is the only scroller; the page
     itself never grows as the conversation gets longer. */
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
button { font-family: inherit; }

/* ---- Header ------------------------------------------------------------- */
.topbar {
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  height: 68px;
  flex: none;
  background: var(--bg);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  display: block;
  width: 31px;
  height: 31px;
  object-fit: contain;
}
.brand-tag {
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--ink-dim);
  border-left: 1px solid var(--rule-strong);
  padding-left: 12px;
}
.spacer { flex: 1; }
.online-count {
  color: var(--ink-dim);
  font-size: 11px;
  white-space: nowrap;
}
.online-count::before {
  content: '●';
  color: var(--ok);
  font-size: 8px;
  margin-right: 7px;
  vertical-align: 1px;
}

.linkbtn {
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 4px;
  text-decoration: none;
  font-family: inherit;
}
.linkbtn:hover { color: var(--ink); }

.btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.06s ease;
  white-space: nowrap;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }

/* ---- a11y --------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- Layout ------------------------------------------------------------- */
.layout {
  flex: 1 1 0;
  display: grid;
  grid-template-columns: minmax(340px, 0.85fr) minmax(420px, 1.15fr);
  gap: 32px;
  padding: 28px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  overflow: hidden;
}

.left {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ---- Hero + character --------------------------------------------------- */
.hero { text-align: center; }
.hero h1 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 44px);
  line-height: 1.02;
  letter-spacing: -0.035em;
  font-weight: 700;
}
.subhead {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-size: 14px;
}

.character {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* Explicit height so the child can be sized against it rather than its own
     intrinsic height. Without this the duck overflows into the stats cards. */
  height: 100%;
}
#duck-container {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  min-height: 0;
  max-height: 100%;
}
#duck-container svg {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}
/* Restrained life: subtle breathing and a slow blink. Disabled wholesale by the
   prefers-reduced-motion block near the end of this file. */
#duck-container #duck {
  animation: duck-breathe 4.5s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center bottom;
}
#duck-container #eyes {
  animation: duck-blink 6s steps(1) infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes duck-breathe {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(-2px) scaleY(1.012); }
}
@keyframes duck-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.08); }
}
.duck-caption {
  position: absolute;
  right: 6%;
  top: 14%;
  max-width: 130px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: left;
  transform: rotate(-4deg);
}
.duck-caption::after {
  content: '';
  display: block;
  width: 54px;
  height: 28px;
  margin: 2px 0 0 6px;
  border-left: 1.5px solid var(--ink-faint);
  border-bottom: 1.5px solid var(--ink-faint);
  border-bottom-left-radius: 22px;
  transform: rotate(-8deg);
  transform-origin: top left;
}

/* ---- Stats -------------------------------------------------------------- */
.stats {
  display: grid;
  /* Full-width cards stacked, so the four latest-attempt metrics have room. */
  grid-template-columns: 1fr;
  gap: 12px;
  min-width: 0;
  flex: none;
}
.stat-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--bg);
  min-width: 0;
}
.stat-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}
.stat-row {
  display: flex;
  gap: 16px;
  align-items: baseline;
  min-width: 0;
  /* Allow metrics to wrap onto a second line rather than overflow. */
  flex-wrap: wrap;
  row-gap: 10px;
}
/* Two plain metrics (attempts, cost) sized to match the full-width card. */
.stat-row.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 26px; }
/* Four metrics with units, across the full-width card. */
.stat-row.four { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 26px; }
.stat-block { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat-num {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  /* Never let a number (or its unit) spill outside the card. */
  max-width: 100%;
  overflow-wrap: anywhere;
}
.stat-privacy {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-num.sm { font-size: 24px; }
/* The latest-attempt metrics carry units, so they run smaller to fit four-up. */
.stat-row.four .stat-num {
  font-size: 23px;
  white-space: nowrap;
}
.stat-row.four .stat-label { font-size: 11px; white-space: nowrap; }
/* Cost values can be wide; size them down so three metrics fit side by side. */
#round-cost {
  font-size: 24px;
  white-space: nowrap;
}
.stat-label {
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* ---- Chat shell --------------------------------------------------------- */
.chat-shell {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  flex: none;
  flex-wrap: wrap;
  row-gap: 8px;
}
.chat-who { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  flex: none;
  background-size: cover;
  background-position: center;
}
.avatar svg { display: block; width: 40px; height: 40px; }
.chat-name { font-weight: 700; font-size: 15px; }
.chat-mood { font-size: 12px; color: var(--ink-dim); display: flex; align-items: center; gap: 6px; }
.mood-chip {
  display: inline-block;
  border: 1px solid var(--rule-strong);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--ink);
}
.mood-chip[data-mood='curious'], .mood-chip[data-mood='considering'] {
  background: var(--accent-soft); border-color: #b9cee9; color: var(--accent);
}
.mood-chip[data-mood='tempted'] { background: #fdf3da; border-color: #e8cf8f; }
.mood-chip[data-mood='won'] { background: #e6f4ec; border-color: #b6ddc5; color: var(--ok); }

/* Header actions: speed readout + an always-available restart. */
.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* Small, honest speed readout: "Reply started in 0.4s". */
.speed-chip {
  font-size: 11px;
  color: var(--ink-dim);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.speed-chip[hidden] { display: none; }

.new-duck-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.new-duck-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.difficulty-select {
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.difficulty-select:hover { border-color: var(--accent); }

/* ---- Thread (the only scroller) ----------------------------------------- */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}
.thread::-webkit-scrollbar { width: 9px; }
.thread::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 5px; }

.row { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
.row.duck { justify-content: flex-start; }
.row.player { justify-content: flex-end; }

.bubble-wrap { display: flex; flex-direction: column; gap: 3px; max-width: min(76%, 560px); }
.row.player .bubble-wrap { align-items: flex-end; }

.bubble {
  padding: 11px 15px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
}
.row.duck .bubble {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 5px;
}
.row.player .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.bubble.pending {
  color: var(--ink-dim);
  font-style: italic;
}
.meta-line {
  font-size: 11px;
  color: var(--ink-faint);
  padding: 0 4px;
}
.role-label { font-size: 11px; color: var(--ink-faint); padding: 0 4px; }

.cursor {
  display: inline-block;
  width: 7px; height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.new-reply {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(11, 13, 16, 0.22);
  z-index: 3;
}
.new-reply[hidden] { display: none; }

/* ---- Result card (lives inside the thread) ------------------------------ */
.result-card {
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  background: var(--accent-soft);
  align-self: stretch;
}
.result-card .kicker {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 700;
}
.result-card h2 {
  margin: 0 0 6px;
  font-size: clamp(18px, 2.2vw, 23px);
  letter-spacing: -0.02em;
}
.result-card .meta { color: var(--ink-dim); font-size: 13px; }
.result-card .claim {
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  margin-top: 6px;
}
.result-card .challenge { margin: 10px 0 0; color: var(--ink-dim); font-size: 13px; }
.result-card .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 16px;
}
.result-card .actions .btn { font-size: 13px; padding: 9px 15px; border-radius: 10px; }

/* ---- Suggestions -------------------------------------------------------- */
.suggest {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.suggest[hidden] { display: none; }
.suggest-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  width: 100%;
  margin-bottom: 2px;
  font-weight: 700;
}
.chip {
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip-ico { font-size: 13px; }

/* ---- Composer ----------------------------------------------------------- */
.composer {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.composer[hidden] { display: none; }
textarea#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  padding: 13px 15px;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  min-height: 56px;
  max-height: 22dvh;
  background: var(--bg);
  color: var(--ink);
}
textarea#input::placeholder { color: var(--ink-faint); }
textarea#input:focus { border-color: var(--accent); outline: none; }
textarea#input:disabled { opacity: 0.5; }
.composer .btn.primary { min-width: 190px; font-size: 15px; }
.send-arrow { display: none; }
.composer-hint {
  font-size: 11px;
  color: var(--ink-dim);
  padding: 0 2px;
}

/* ---- Footer ------------------------------------------------------------- */
.footbar {
  border-top: 1px solid var(--rule);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: none;
  background: var(--bg);
}
.foot-note {
  font-size: 11px;
  color: var(--ink-dim);
  display: inline-flex;
  align-items: flex-start;
  gap: 7px;
  max-width: 480px;
}
.foot-ico { flex: none; }
.foot-brand { margin-left: auto; font-size: 12px; color: var(--ink-dim); }
.foot-brand strong { color: var(--ink); }

.badge-mock {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-live {
  display: inline-block;
  border: 1px solid var(--ok);
  color: var(--ok);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
}

/* ---- Overlays / toast --------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 16, 0.42);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.overlay[hidden] { display: none; }
.overlay .panel {
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(11, 13, 16, 0.24);
}
.overlay .panel h3 { margin: 0 0 10px; }
.overlay .panel p { color: var(--ink-dim); font-size: 14px; }
.overlay-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.tutorial-steps { margin: 14px 0; padding-left: 25px; color: var(--ink-dim); font-size: 14px; line-height: 1.55; }
.tutorial-steps li { padding-left: 5px; margin: 9px 0; }
.tutorial-steps li::marker { color: #1b4fa4; font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); }

/* ---- Motion ------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .cursor { animation: none; opacity: 1; }
}

/* ---- Tablet ------------------------------------------------------------- */
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 18px;
    padding: 20px;
  }
  .left {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
  }
  .hero { text-align: left; flex: 1 1 300px; }
  .character { flex: 0 0 170px; }
  #duck-container svg { width: 160px; }
  .duck-caption { display: none; }
  .stats { flex: 1 1 100%; }
  .chat-shell { min-height: 56dvh; }
}

/* ---- Mobile ------------------------------------------------------------- */
@media (max-width: 720px) {
  .topbar { padding: 0 12px; height: 54px; gap: 8px; }
  .brand-mark { width: 26px; height: 26px; }
  .brand-tag { display: block; font-size: 8px; line-height: 1.35; letter-spacing: .12em; }
  .badge-mock, .badge-live { font-size: 9px; padding: 3px 7px; white-space: nowrap; }
  .badge-long { display: none; }
  .linkbtn { font-size: 12px; }

  /* Chat-first: the page itself does not scroll; the thread is the scroller. */
  body { height: 100dvh; overflow: hidden; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 10px 12px 0;
    gap: 8px;
    overflow: hidden;
  }

  .left { flex-direction: column; align-items: stretch; gap: 8px; }
  .hero { text-align: left; flex: none; }
  .hero h1 { font-size: clamp(17px, 5.4vw, 22px); }
  .subhead { font-size: 11px; margin-top: 3px; }
  /* The illustration is a desktop flourish; on a phone the chat is the point. */
  .character { display: none; }

  .stats { grid-template-columns: 1fr; gap: 8px; flex: none; }
  .stat-card { padding: 11px 12px; }
  .stat-row { gap: 10px 14px; flex-wrap: wrap; row-gap: 10px; }
  /* Two metrics per line on phones so units like "87 tok/s" never break apart. */
  .stat-row.two { gap: 8px 14px; }
  .stat-row.four { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .stat-row.four > .stat-block { flex: none; }
  .stat-num { font-size: 20px; }
  .stat-row.four .stat-num { font-size: 19px; }
  .stat-title { font-size: 11px; margin-bottom: 7px; }
  .stat-label { font-size: 10px; overflow-wrap: normal; word-break: keep-all; hyphens: none; }
  .stat-privacy { font-size: 10px; }

  /* The chat thread owns the remaining height; the composer stays put below. */
  .right { min-height: 0; }
  .chat-shell { min-height: 0; }
  .chat-head { padding: 9px 12px; gap: 8px; }
  .avatar, .avatar svg { width: 30px; height: 30px; }
  .chat-name { font-size: 14px; }
  .chat-mood { font-size: 11px; }
  .speed-chip { display: none; }
  .new-duck-btn { padding: 5px 9px; font-size: 11px; }
  .chat-actions { gap: 6px; }
  .difficulty-select {
    padding: 5px 8px;
    font-size: 11px;
    max-width: 108px;
    /* Keep the control on one line; the label shortens via the option text. */
    text-overflow: ellipsis;
  }
  .thread { padding: 12px; gap: 10px; }
  .bubble-wrap { max-width: 86%; }
  .bubble { font-size: 15px; }

  .suggest { gap: 6px; }
  .suggest-label { margin-bottom: 0; }
  .chip { padding: 8px 11px; font-size: 12px; }

  textarea#input { font-size: 16px; /* prevents iOS zoom */ min-height: 50px; }
  .composer .btn.primary { min-width: 0; padding: 12px 16px; border-radius: 12px; }
  .send-label { display: none; }
  .send-arrow { display: inline; font-size: 18px; }
  .composer-hint { display: none; }

  .footbar { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .foot-note { font-size: 10px; }
  .foot-brand { display: none; }
}
