:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --line: #e3e5ea;
  --line-strong: #c9ccd4;
  --ink: #1b1d22;
  --ink-soft: #4b4f58;
  --muted: #7a7f8a;
  --primary: #2f6df6;
  --primary-dark: #1f56cf;
  --primary-soft: #e8f0ff;
  --good: #2e9e5b;
  --good-soft: #e6f6ec;
  --bad: #d9453d;
  --bad-soft: #fdecea;
  --skip: #8a8f9a;
  --skip-soft: #eef0f3;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417;
    --panel: #1b1c21;
    --panel-2: #23252c;
    --line: #2d3038;
    --line-strong: #3f434d;
    --ink: #f1f2f5;
    --ink-soft: #c3c6ce;
    --muted: #8b8f99;
    --primary: #5b8dff;
    --primary-dark: #4577e6;
    --primary-soft: #1f2a44;
    --good: #4cc27a;
    --good-soft: #17301f;
    --bad: #f0685f;
    --bad-soft: #3a1f1d;
    --skip: #9aa0ab;
    --skip-soft: #2a2d35;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
[hidden] { display: none !important; }

/* header */
.site-header {
  width: min(560px, calc(100% - 32px));
  min-height: 52px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--primary); color: #fff; }
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { font-weight: 700; font-size: 1.05rem; }
.header-actions { display: flex; gap: 6px; }
.icon-button {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-button svg { width: 18px; height: 18px; }
.icon-button:hover { border-color: var(--line-strong); color: var(--ink); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* card */
main { width: min(560px, calc(100% - 32px)); margin: 0 auto; padding: 14px 0 16px; flex: 1; }
.game-card { text-align: left; }
.puzzle-chip { margin: 0 0 4px; color: var(--muted); font-size: .82rem; font-weight: 500; }
.game-card h1 { font-size: 1.35rem; }
.challenge-note { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }
.game-card.finished .challenge-note { display: none; }

/* player */
.player {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.play-button {
  flex: none;
  width: 44px; height: 44px;
  position: relative;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: background .12s, transform .08s;
}
.play-button:hover { background: var(--primary-dark); }
.play-button:active { transform: scale(.96); }
.play-button:disabled { cursor: not-allowed; opacity: .5; }
.play-icon {
  position: absolute; top: 50%; left: 50%;
  width: 0; height: 0;
  border-left: 16px solid #fff;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  transform: translate(-40%, -50%);
}
.playing .play-icon { width: 16px; height: 18px; border: 0; border-left: 5px solid #fff; border-right: 5px solid #fff; transform: translate(-50%, -50%); }
.play-track { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.play-track span { display: block; width: 0; height: 100%; border-radius: 4px; background: var(--primary); }
.clip-readout { flex: none; min-width: 34px; text-align: right; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.clip-readout strong { font-weight: 600; color: var(--ink-soft); }

/* optional unlock bar (only shown when clip lengths differ) */
.unlock-bar { margin-top: 10px; }
.unlock-track { display: flex; gap: 4px; height: 6px; }
.unlock-seg { flex: 1 1 0; border-radius: 3px; background: var(--line); }
.unlock-seg.unlocked { background: var(--primary-soft); }
.unlock-seg.current { background: var(--primary); }
.unlock-labels { display: flex; gap: 4px; margin-top: 4px; color: var(--muted); font-size: .72rem; }
.unlock-labels span { flex: 1 1 0; text-align: right; }
.unlock-labels span.current { color: var(--ink-soft); font-weight: 600; }

/* guesses */
.guess-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.guess-item {
  min-height: 38px;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 0;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: .95rem;
}
.guess-mark { align-self: stretch; display: grid; place-items: center; border-right: 1px dashed var(--line-strong); font-size: .85rem; font-weight: 600; color: var(--muted); }
.guess-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guess-meta { color: var(--muted); font-size: .75rem; }
.guess-item.current { border: 1px solid var(--primary); background: var(--primary-soft); color: var(--ink-soft); }
.guess-item.current .guess-mark { border-right-style: solid; border-right-color: var(--primary); color: var(--primary); }
.guess-item.wrong, .guess-item.skip, .guess-item.correct { border-style: solid; color: var(--ink); }
.guess-item.wrong { border-color: var(--bad); background: var(--bad-soft); }
.guess-item.wrong .guess-mark { background: var(--bad); border-right-color: var(--bad); color: #fff; }
.guess-item.skip { border-color: var(--skip); background: var(--skip-soft); color: var(--ink-soft); }
.guess-item.skip .guess-mark { background: var(--skip); border-right-color: var(--skip); color: #fff; }
.guess-item.correct { border-color: var(--good); background: var(--good-soft); }
.guess-item.correct .guess-mark { background: var(--good); border-right-color: var(--good); color: #fff; }
.guess-item.correct .guess-text { color: var(--good); font-weight: 600; }

/* status + form */
.status-line { min-height: 20px; margin: 8px 0 6px; color: var(--muted); font-size: .88rem; }
.status-line.error { color: var(--bad); }
.status-line.success { color: var(--good); }
.guess-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.guess-row input {
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
}
.guess-row input::placeholder { color: var(--muted); }
.guess-row input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.guess-row input:disabled { opacity: .5; }
.submit-button {
  min-width: 100px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 600;
  cursor: pointer;
}
.submit-button:hover { background: var(--primary-dark); }
.submit-button:disabled, .text-button:disabled { cursor: not-allowed; opacity: .45; }
.secondary-actions { display: flex; justify-content: space-between; gap: 16px; margin-top: 6px; }
.text-button { padding: 4px 0; border: 0; background: transparent; color: var(--muted); font-size: .88rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--ink); }
.text-button.danger:hover { color: var(--bad); }
.text-button span { color: var(--ink-soft); }

/* demo note */
.demo-note { margin-top: 12px; padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--muted); font-size: .88rem; }
.demo-note strong { display: block; margin-bottom: 2px; color: var(--ink-soft); }
.demo-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.demo-chip { padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel); color: var(--ink-soft); font-size: .85rem; cursor: pointer; }
.demo-chip:hover { border-color: var(--primary); color: var(--ink); }
.demo-chip:disabled { opacity: .4; cursor: not-allowed; }

/* result */
.result-panel { margin-top: 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); text-align: center; }
.result-panel.won { border-color: var(--good); }
.result-panel.lost { border-color: var(--bad); }
.result-kicker { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--skip-soft); color: var(--ink-soft); }
.result-panel.won .result-kicker { background: var(--good-soft); color: var(--good); }
.result-panel.lost .result-kicker { background: var(--bad-soft); color: var(--bad); }
.result-panel h2 { margin: 6px 0 2px; font-size: 1.4rem; }
.result-copy { margin: 0; color: var(--ink-soft); }
.result-credit { margin: 4px 0 0; color: var(--muted); font-size: .76rem; }
.result-credit a { color: var(--ink-soft); }
.result-actions { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 10px; }
.share-button { height: 40px; padding: 0 22px; border: 0; border-radius: 8px; background: var(--good); color: #fff; font-weight: 600; cursor: pointer; }
.share-button:hover { filter: brightness(.95); }
.share-feedback { min-height: 18px; color: var(--good); font-size: .82rem; }
.result-streak { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.result-streak strong { color: var(--ink); }
.next-puzzle { display: flex; flex-direction: row; align-items: baseline; justify-content: center; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.next-puzzle span { color: var(--muted); font-size: .78rem; }
.next-puzzle strong { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* footer */
footer { width: min(560px, calc(100% - 32px)); min-height: 44px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
footer a { color: var(--muted); text-underline-offset: 3px; }
footer a:hover { color: var(--ink); }

/* modals */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 45%); }
.modal-card { position: relative; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 16px 40px rgb(0 0 0 / 18%); }
.modal-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: 0; border-radius: 8px; background: var(--panel-2); color: var(--ink-soft); cursor: pointer; }
.modal-close:hover { color: var(--ink); }
.modal-card h2 { margin: 0 0 14px; font-size: 1.25rem; }
.help-steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--ink-soft); font-size: .95rem; }
.help-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.help-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-box { width: 14px; height: 14px; border-radius: 3px; }
.legend-box.good { background: var(--good); }
.legend-box.bad { background: var(--bad); }
.legend-box.skip { background: var(--skip); }
.modal-primary { width: 100%; height: 44px; margin-top: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { padding: 10px 4px; border-radius: 8px; background: var(--panel-2); text-align: center; }
.stat strong { display: block; font-size: 1.5rem; font-weight: 650; line-height: 1.1; }
.stat span { display: block; margin-top: 4px; font-size: .72rem; color: var(--muted); }
.dist-title { margin: 18px 0 8px; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.distribution { display: grid; gap: 5px; }
.dist-row { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-size: .85rem; color: var(--muted); }
.dist-bar { min-width: 24px; height: 20px; padding: 0 6px; display: flex; align-items: center; justify-content: flex-end; border-radius: 4px; background: var(--skip-soft); color: var(--ink-soft); font-size: .8rem; }
.dist-row.highlight .dist-bar { background: var(--good); color: #fff; }
.dist-row.loss .dist-bar { background: var(--bad-soft); color: var(--bad); }
.modal-next { margin-top: 18px; }

/* privacy page */
.legal-page { max-width: 560px; padding: 32px 0 60px; }
.legal-page .eyebrow { margin: 0; color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.legal-page h1 { margin: 6px 0 16px; font-size: 1.6rem; }
.legal-page p { color: var(--ink-soft); font-size: .95rem; line-height: 1.65; }
.legal-back { display: inline-block; margin-top: 16px; color: var(--primary); font-size: .9rem; text-underline-offset: 3px; }

@media (max-width: 480px) {
  .guess-row { grid-template-columns: 1fr; }
  .submit-button { height: 44px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  footer { gap: 8px; padding: 8px 0; font-size: .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
