/* Rule Stack – "stacked cards" look. */
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #6b6b70;
  --line: #e3e1da;
  --line-strong: #cfccc2;
  --ink: #18181b;          /* frame of the rule card, primary buttons */
  --on-ink: #ffffff;
  --accent: #18181b;       /* links, active things */
  --accent-text: #ffffff;
  --ok: #1d9e75;
  --ok-soft: #e1f5ee;
  --bad: #d64545;
  --bad-soft: #fbe9e9;
  --warn: #ba7517;
  /* Rule kinds: meaning (purple), letters (blue), length (coral) */
  --k-meaning: #534ab7;  --k-meaning-soft: #eeedfe;  --k-meaning-mid: #afa9ec;
  --k-letters: #185fa5;  --k-letters-soft: #e6f1fb;  --k-letters-mid: #85b7eb;
  --k-length: #993c1d;   --k-length-soft: #faece7;   --k-length-mid: #f0997b;
  --radius: 14px;
  --display: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c1f;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --line: #2e2e33;
    --line-strong: #44444b;
    --ink: #f2f2f4;
    --on-ink: #121214;
    --accent: #f2f2f4;
    --accent-text: #121214;
    --ok: #3ccf8e;
    --ok-soft: #10302a;
    --bad: #f06b6b;
    --bad-soft: #3a1d1d;
    --warn: #ef9f27;
    --k-meaning: #cecbf6;  --k-meaning-soft: #26215c;  --k-meaning-mid: #534ab7;
    --k-letters: #b5d4f4;  --k-letters-soft: #042c53;  --k-letters-mid: #185fa5;
    --k-length: #f5c4b3;   --k-length-soft: #4a1b0c;   --k-length-mid: #993c1d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2, h3, .display { font-family: var(--display); letter-spacing: -.02em; }
.screen { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--muted); margin: 0; font-size: .95rem; }
.center { text-align: center; }
.eyebrow { font-family: var(--display); font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
kbd { font: inherit; font-size: .85em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-family: var(--display); font-weight: 700; font-size: 1rem;
  padding: 13px 16px; border-radius: 12px; cursor: pointer; width: 100%;
  transition: transform .08s ease, background .15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  appearance: none; border: none; background: transparent; color: var(--muted);
  font-size: 1.2rem; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-title { font-family: var(--display); font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; }
.streak { font-family: var(--display); font-weight: 700; font-size: 1.05rem; white-space: nowrap; }

/* ---------- Home ---------- */
.home-tools { display: flex; justify-content: flex-end; gap: 6px; }
.home-tools .icon-btn { font-size: 1rem; font-weight: 700; color: var(--text); background: var(--surface); border: 1px solid var(--line); font-family: var(--display); }
.home-head { text-align: center; padding: 4px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.logo { width: 76px; height: 76px; animation: logoIn .7s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-14px) scale(.9); } to { opacity: 1; transform: none; } }
.home-head h1 { margin: 0; font-size: 2.4rem; font-weight: 700; line-height: 1; }
.tagline { margin: 0; color: var(--muted); }
.mode-card { position: relative; overflow: hidden; }
.mode-card .k-strip { display: flex; gap: 4px; }
.mode-card .k-strip i { height: 6px; flex: 1; border-radius: 99px; background: var(--line); }
.mode-card .k-strip i:nth-child(3n+1) { background: var(--k-meaning-mid); }
.mode-card .k-strip i:nth-child(3n+2) { background: var(--k-letters-mid); }
.mode-card .k-strip i:nth-child(3n) { background: var(--k-length-mid); }
.footer-links { text-align: center; font-size: .85rem; margin: 8px 0 0; }
.footer-links a { color: var(--muted); }

/* ---------- Screens with a back button ---------- */
.screen-head { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; }
.screen-head h2 { margin: 0; text-align: center; font-size: 1.25rem; }

/* ---------- Game HUD ---------- */
.hud {
  position: sticky; top: 0; z-index: 6; background: var(--bg);
  margin: -4px -16px 0; padding: 4px 16px 8px; display: flex; flex-direction: column; gap: 8px;
}
.game-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.game-top .score-pill { justify-self: end; }
.top-left { display: flex; }
.sound-btn svg { width: 20px; height: 20px; }
.game-title { text-align: center; font-family: var(--display); font-weight: 700; }
.score-pill {
  font-family: var(--display); background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.score-pill.bump { animation: bump .45s ease-out; }
@keyframes bump { 30% { transform: scale(1.18); background: var(--ok-soft); border-color: var(--ok); } }
.timer { display: flex; align-items: center; gap: 10px; }
.timer-bar { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timer-bar > div { height: 100%; width: 100%; background: var(--ink); border-radius: 99px; transition: background .3s; }
.timer.low .timer-bar > div { background: var(--bad); }
.timer-text { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3em; text-align: right; }
.timer.low .timer-text { color: var(--bad); }
.rs-status-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .88rem; }
.lives { display: flex; gap: 3px; }
.heart { width: 18px; height: 18px; color: var(--bad); }
.heart.lost { color: var(--line); }
.heart.pop { animation: heartLost .6s ease-out; }
@keyframes heartLost { 0% { transform: scale(1.4); color: var(--bad); } 100% { transform: scale(1); } }
.dots { display: flex; gap: 4px; }
.dot { width: 14px; height: 8px; border-radius: 99px; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.now { background: var(--ink); }
.round-text { font-family: var(--display); font-weight: 700; }

/* ---------- Intro ---------- */
.intro { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 28px 8px; text-align: center; }
.intro .logo { width: 64px; height: 64px; }
.ready-title { font-family: var(--display); font-weight: 700; font-size: 1.6rem; letter-spacing: -.02em; }
.intro ul { text-align: left; margin: 0; padding-left: 20px; color: var(--muted); font-size: .95rem; display: flex; flex-direction: column; gap: 4px; max-width: 380px; }
.intro .best { font-family: var(--display); font-weight: 700; margin: 0; }
.intro .btn { max-width: 260px; }

/* ---------- The rule stack (the puzzle) ---------- */
.stack { position: relative; padding-top: 16px; }
/* two cards peeking out from behind – the "stack" */
.stack::before, .stack::after {
  content: ''; position: absolute; height: 40px; border-radius: 14px; transition: transform .35s;
}
.stack::before { left: 22px; right: 22px; top: 0; background: var(--k-meaning-mid); opacity: .55; }
.stack::after { left: 11px; right: 11px; top: 7px; background: var(--k-letters-mid); opacity: .75; }
.rules {
  position: relative; z-index: 1; list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: 16px; overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.rule {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 12px; border-top: 1px solid var(--line); transition: background .2s;
}
.rule:first-child { border-top: none; }
.rule .kind {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  font-family: var(--display); font-size: .82rem; font-weight: 700;
}
.k-meaning .kind { background: var(--k-meaning-soft); color: var(--k-meaning); }
.k-letters .kind { background: var(--k-letters-soft); color: var(--k-letters); }
.k-length .kind { background: var(--k-length-soft); color: var(--k-length); }
.k-meaning-t { color: var(--k-meaning); } .k-letters-t { color: var(--k-letters); } .k-length-t { color: var(--k-length); }
.rule .txt { font-family: var(--display); font-size: 1.05rem; font-weight: 600; line-height: 1.25; }
.rule .state {
  width: 24px; height: 24px; border-radius: 99px;
  border: 2px solid var(--line); display: grid; place-items: center; color: transparent; font-size: .78rem; font-weight: 700;
  transition: background .15s, border-color .15s, transform .15s;
}
.rule.ok .state { background: var(--ok); border-color: var(--ok); color: #fff; transform: scale(1.08); }
.rule.ok .txt { color: var(--ok); }
.rule.bad { background: var(--bad-soft); }
.rule.bad .state { border-color: var(--bad); }
.rule .new {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; font-size: .6rem; font-weight: 700; letter-spacing: .08em;
  background: var(--text); color: var(--bg); vertical-align: 2px;
}
.rule.enter { animation: ruleIn .5s cubic-bezier(.2, .9, .3, 1.2); }
.k-meaning.enter { --flash: var(--k-meaning-soft); }
.k-letters.enter { --flash: var(--k-letters-soft); }
.k-length.enter { --flash: var(--k-length-soft); }
@keyframes ruleIn {
  0% { opacity: 0; transform: translateY(18px); background: var(--flash); }
  60% { opacity: 1; transform: none; background: var(--flash); }
  100% { background: transparent; }
}
.rule.dropped { color: var(--muted); animation: ruleOut 1.1s ease-in forwards; overflow: hidden; }
.rule.dropped .txt { text-decoration: line-through; }
.rule.dropped .kind { opacity: .4; }
.rule.dropped .state { opacity: 0; }
@keyframes ruleOut {
  0%, 45% { max-height: 90px; opacity: .7; }
  100% { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; transform: translateY(-14px); }
}
/* Solved: the card turns green and gets pressed onto the stack */
.stack.win .rules { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.stack.win { animation: press .5s ease-out; }
.stack.win::before, .stack.win::after { transform: translateY(6px); }
@keyframes press { 30% { transform: translateY(5px) scale(.985); } 100% { transform: none; } }
.stack.lose .rules { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.stack.lose { animation: shake .4s; }

/* ---------- Your answer ---------- */
.answer-zone { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.answer {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 2.5px solid var(--ink); border-radius: 16px; padding: 5px 5px 5px 16px;
  transition: box-shadow .15s;
}
.answer:focus-within { box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink) 14%, transparent); }
.answer input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--text);
  font-family: var(--display); font-size: 1.6rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 6px 0;
}
.answer input::placeholder { color: var(--muted); opacity: .6; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 1.2rem; }
.go {
  flex: none; width: 48px; height: 48px; border: none; border-radius: 12px; cursor: pointer;
  background: var(--ink); color: var(--on-ink); font-family: var(--display); font-size: 1.4rem; font-weight: 700;
  display: grid; place-items: center; touch-action: manipulation;
}
.go:active { transform: scale(.95); }
.answer-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 32px; padding: 0 4px; }
.rs-word { font-size: .85rem; color: var(--muted); }
.rs-word.yes { color: var(--ok); font-weight: 600; }
.skip {
  appearance: none; margin-left: auto; border: 1.5px solid var(--line-strong); background: transparent; color: var(--text);
  font-family: var(--display); font-weight: 700; font-size: .88rem; padding: 5px 12px; border-radius: 99px; cursor: pointer;
  touch-action: manipulation;
}
.skip span { color: var(--bad); font-weight: 600; margin-left: 2px; }
.skip:active { transform: scale(.96); }
.hint { font-size: .85rem; color: var(--bad); }
.hint:empty { display: none; }
.rs-msg { text-align: center; font-weight: 600; }
.answer-zone.demo { pointer-events: none; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Round log (quiet, so it doesn't compete with the rules) ---------- */
.log-head { margin-top: 10px; }
.log-head:has(+ .rs-log:empty) { display: none; }
.rs-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rs-log li { border-top: 1px solid var(--line); padding: 9px 2px; font-size: .88rem; display: flex; flex-direction: column; gap: 3px; }
.rs-log li:first-child { border-top: none; }
.rs-log .top { display: flex; justify-content: space-between; gap: 8px; font-family: var(--display); font-weight: 700; }
.rs-log .top .w { text-transform: uppercase; letter-spacing: .04em; }
.rs-log .top span:last-child { color: var(--muted); font-weight: 600; }
.rs-log li.fail .top span:first-child { color: var(--bad); }
.rs-log .rules-line { color: var(--muted); font-size: .8rem; }
.rs-log .ex { color: var(--muted); font-size: .82rem; }
.rs-log .ex b { color: var(--text); font-weight: 600; }
.rs-log li.fresh { animation: slidein .35s ease-out; }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
#rs-log-final { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2px 12px; }

/* ---------- Result ---------- */
.result-head { text-align: center; padding: 12px 0 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.result-title { font-family: var(--display); font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.result-score { font-family: var(--display); font-size: 3.4rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.result-score small { font-size: 1rem; color: var(--muted); letter-spacing: 0; }
.result-head .dots .dot { width: 24px; height: 10px; }
.new-best { font-family: var(--display); font-weight: 700; color: var(--warn); }
.challenge { display: flex; flex-direction: column; gap: 8px; }
.challenge .eyebrow { text-align: center; }
.challenge .stack { pointer-events: none; }
.challenge .found { text-align: center; font-size: .9rem; color: var(--muted); margin: 0; }
.challenge .found b { font-family: var(--display); color: var(--text); text-transform: uppercase; letter-spacing: .05em; }
.share-row { display: flex; gap: 12px; align-items: center; }
.share-row .btn { flex: 1; }
.streak.big { font-size: 1.4rem; }
.share-preview {
  margin: 0; padding: 12px; background: var(--surface); border: 1px dashed var(--line); border-radius: 12px;
  font-family: inherit; font-size: .88rem; white-space: pre-wrap; word-break: break-word; color: var(--muted);
}
.result-actions { display: flex; flex-direction: column; gap: 8px; }

/* Confetti for a solved daily */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i {
  position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall var(--d, 1.6s) cubic-bezier(.3, .6, .5, 1) var(--delay, 0s) forwards;
}
@keyframes fall {
  to { transform: translate(var(--dx, 0), 105vh) rotate(var(--r, 540deg)); }
}

/* ---------- Tutorial ---------- */
.tut { position: relative; padding-left: 56px; }
.tut p { margin: 0; }
.tut ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .93rem; display: flex; flex-direction: column; gap: 4px; }
.tut-step {
  position: absolute; left: 14px; top: 14px; width: 30px; height: 30px; border-radius: 99px;
  background: var(--ink); color: var(--on-ink); display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: .9rem;
}
.tut .stack { margin-left: -42px; pointer-events: none; }
.tut .answer-zone { margin-left: -42px; }
.tut .answer input { font-size: 1.3rem; }

/* ---------- Statistics ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-family: var(--display); font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }

/* ---------- Misc ---------- */
.loading { text-align: center; padding: 80px 0; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--on-ink); padding: 10px 16px; border-radius: 99px; font-family: var(--display); font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20;
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  #app { max-width: 540px; padding-top: 32px; }
  .home-head h1 { font-size: 2.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .confetti { display: none; }
}
#rs-fits { white-space: nowrap; font-size: .82rem; }
#rs-play, #rs-over { display: flex; flex-direction: column; gap: 14px; }
#rs-over .challenge { margin-top: 6px; }
