/* Letter Crunch — warm paper theme. Tokens first; components use only tokens. */

:root {
  --bg: #F6F0E4;
  --surface: #FFFDF8;
  --tile: #FFFDF8;
  --tile-edge: #CFC4AB;
  --tile-shadow: rgba(36, 30, 23, .3);
  --ink: #241E17;
  --muted: #5E564A;
  --quiet: #7A7061;
  --line: #DDD3BC;
  --row-line: #D9CFB8;
  --cell: #FBF7EE;
  --empty: #E7DFCD;
  --slot-line: #C2B79E;
  --solved: #1D4E5F;
  --solved-edge: #123C4A;
  --on-solved: #FFFDF8;
  --hint: #E8A33D;
  --hint-ink: #8A5A10;
  --brand: #E04A12;
  --cta: #FF5A1F;
  --cta-edge: #B83A0C;
  --on-cta: #241E17;
  --error: #C8261C;
  --sel: #241E17;
  --on-sel: #FFFDF8;
  --off-bg: #E7DFCD;
  --off-ink: #5E564A;
  --off-edge: #D2C8B1;
  --scrim: rgba(36, 30, 23, .5);
  --font: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130E;
    --surface: #201C16;
    --tile: #2B261E;
    --tile-edge: #0A0805;
    --tile-shadow: rgba(0, 0, 0, .7);
    --ink: #F3ECDD;
    --muted: #B3A992;
    --quiet: #9A907B;
    --line: #383128;
    --row-line: #3A332A;
    --cell: #201C16;
    --empty: #1F1B15;
    --slot-line: #4A4236;
    --solved: #2A7088;
    --solved-edge: #1A4D5E;
    --hint-ink: #E8A33D;
    --brand: #FF6A33;
    --on-cta: #16130E;
    --error: #FF7A6B;
    --sel: #F3ECDD;
    --on-sel: #16130E;
    --off-bg: #2A251D;
    --off-ink: #B3A992;
    --off-edge: #0A0805;
    --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ---------- Page ---------- */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px;
  padding-left: max(32px, env(safe-area-inset-left));
  padding-right: max(32px, env(safe-area-inset-right));
}
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.logo { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.035em; line-height: 1; }
.logo span { color: var(--brand); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; padding: 0;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: grid; place-items: center;
}

/* ---------- Loader ---------- */

.loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; margin-top: 120px;
}
.loader-text { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3.5px solid var(--line);
  border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage {
  margin-top: 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 440px) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}
.col-left { justify-self: end; width: 100%; max-width: 240px; padding-top: 6px; display: flex; flex-direction: column; }
.col-right { justify-self: start; max-width: 300px; padding-top: 20px; }

/* ---------- Answer board ---------- */

.board { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.clue { margin: 0; max-width: 240px; text-align: center; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; text-wrap: balance; }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.r { display: flex; gap: 3px; padding: 3px; border-radius: 10px; border: 1.5px solid var(--row-line); transition: background-color .25s, border-color .25s; }
.r.ok { background: var(--solved); border-color: var(--solved); }
.c {
  width: 36px; height: 28px; border-radius: 6px; background: var(--cell);
  display: grid; place-items: center; font-size: 16px; font-weight: 800; color: var(--ink);
}
.c.hn { background: var(--hint); color: #241E17; }
.c.ok { background: var(--solved); color: var(--on-solved); }
.c.new { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }

/* ---------- Play column ---------- */

.play { min-width: 0; display: flex; flex-direction: column; align-items: center; }
.slots { display: flex; gap: 10px; }
.sl {
  width: 62px; height: 66px; border-radius: 14px; padding: 0;
  border: 2px dashed var(--slot-line); background: transparent;
  display: grid; place-items: center; font-size: 28px; font-weight: 800; color: var(--ink);
}
.sl.f { border: 2px solid transparent; background: var(--tile); box-shadow: 0 3px 0 var(--tile-edge); }
.sl.x { border: 2px solid var(--error); background: var(--tile); box-shadow: 0 3px 0 var(--error); }
.slots.shake { animation: shake .36s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.status { margin: 10px 0 0; min-height: 20px; text-align: center; font-size: 14px; font-weight: 700; color: var(--muted); }
.status.error { color: var(--error); }
.status.hint { color: var(--hint-ink); }

.grid {
  margin-top: 14px; width: 100%;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
}
.t {
  aspect-ratio: 1; border-radius: 16px; border: 0; padding: 0;
  background: var(--tile); color: var(--ink);
  font-size: 32px; font-weight: 800;
  display: grid; place-items: center;
  box-shadow: 0 5px 0 var(--tile-edge), 0 10px 18px -10px var(--tile-shadow);
  transition: transform .08s ease, background-color .12s;
  touch-action: manipulation;
  user-select: none;
}
.t:active:not(:disabled) { transform: translateY(2px); }
.t.s { background: var(--sel); color: var(--on-sel); box-shadow: 0 1px 0 var(--tile-edge); transform: translateY(4px); }
.t.e { background: var(--empty); box-shadow: none; color: transparent; }

.actions { margin-top: 22px; width: 100%; display: flex; gap: 8px; }
.tool {
  width: 68px; height: 56px; flex: none; padding: 0; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 3px 0 var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.tool svg { width: 20px; height: 20px; color: var(--ink); }
.tool.hint svg { color: var(--hint-ink); }
.tool:disabled { opacity: .5; }
.submit {
  flex: 1; height: 56px; border-radius: 14px; border: 0;
  background: var(--cta); color: var(--on-cta);
  font-size: 17px; font-weight: 800; box-shadow: 0 4px 0 var(--cta-edge);
}
.submit:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--cta-edge); }
.submit:disabled { background: var(--off-bg); color: var(--off-ink); box-shadow: 0 4px 0 var(--off-edge); }
.submit.wide { width: 100%; flex: none; }

.give-up svg { color: var(--error) !important; }
.give-up-msg { margin: 20px 0 20px; font-size: 15px; color: var(--muted); line-height: 1.5; }
.give-up-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.give-up-confirm { background: var(--error); color: var(--surface); box-shadow: 0 4px 0 color-mix(in srgb, var(--error) 70%, black); }
.give-up-confirm:active:not(:disabled) { box-shadow: 0 2px 0 color-mix(in srgb, var(--error) 70%, black); }
.keep-playing {
  height: 56px; border-radius: 14px; font-size: 17px; font-weight: 800;
  background: transparent; color: var(--ink);
  border: 2px solid var(--line); box-shadow: none;
}
.keep-playing:active:not(:disabled) { background: var(--off-bg); }
.keep-playing:disabled { opacity: .5; }
.give-up-confirm.loading::after {
  content: ''; display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}

.done { margin-top: 22px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.done .submit { width: 100%; flex: none; }
.next { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); text-align: center; }
.countdown { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }

/* ---------- Side column ---------- */

.kbd-tips { margin: 0; font-size: 13px; line-height: 2; font-weight: 600; color: var(--muted); }
kbd {
  font-family: inherit; font-size: 12px; font-weight: 700; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 6px; padding: 1px 6px;
}

/* ---------- Dialogs ---------- */

dialog.sheet {
  width: min(480px, calc(100% - 32px));
  border: 0; border-radius: 24px; padding: 32px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .55);
}
dialog.sheet::backdrop { background: var(--scrim); }
dialog.sheet[open] { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2:focus { outline: none; }
.sheet h2 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.mini-word { display: flex; gap: 6px; margin: 22px 0; }
.mini-word span {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-size: 20px; font-weight: 800; background: var(--sel); color: var(--on-sel);
}
.how { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.how li { display: flex; gap: 16px; align-items: center; }
.how p { margin: 0; font-size: 16px; line-height: 1.45; font-weight: 500; }
.how-ico { flex: none; width: 40px; height: 40px; border-radius: 20px; background: var(--bg); display: grid; place-items: center; }
.how-note { margin: 22px 0; font-size: 14px; font-weight: 600; color: var(--muted); }

.win { max-width: 400px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.win:not([open]) { display: none; }
.win-title { font-size: 54px !important; letter-spacing: -0.04em !important; line-height: 1; color: var(--brand); }
.win-sub { margin: 10px 0 24px; font-size: 16px; font-weight: 600; color: var(--muted); }
.win-words { display: flex; flex-direction: column; gap: 6px; }
.win-word { display: flex; gap: 5px; justify-content: center; }
.win-word span {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  background: var(--solved); color: var(--on-solved); font-size: 19px; font-weight: 800;
  box-shadow: 0 2px 0 var(--solved-edge);
}
.win-stats { margin: 24px 0; font-size: 16px; font-weight: 600; color: var(--muted); }
.win-stats b, .win-sub b { color: var(--ink); }
.win .next { margin-top: 14px; }
.link-btn { margin-top: 6px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 15px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--sel); color: var(--on-sel); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 700; z-index: 10;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .stage { grid-template-columns: minmax(0, 440px); justify-content: center; gap: 24px; }
  .col-left { justify-self: center; }
  .col-right { display: none; }
}

@media (max-width: 600px) {
  .page { padding: 12px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .logo { font-size: 26px; }
  .stage { margin-top: 12px; gap: 12px; }
  .clue { font-size: 20px; max-width: 320px; }
  .board { gap: 10px; }
  .rows { gap: 5px; }
  .c { height: 22px; font-size: 15px; }
  .sl { width: min(56px, calc((100vw - 72px) / 5)); height: 58px; font-size: 24px; border-radius: 12px; }
  .slots { gap: 8px; }
  .status { margin-top: 4px; min-height: 16px; font-size: 13px; }
  .grid, .actions, .done { width: min(100%, 304px); }
  .grid { margin-top: 10px; gap: 7px; }
  .t { font-size: 26px; border-radius: 14px; }
  .actions { margin-top: 16px; }
  .done { margin-top: 12px; gap: 6px; }
  .tool { width: 60px; }
  dialog.sheet { padding: 24px; }
  .win-title { font-size: 46px !important; }
}

/* Touch devices have no keyboard shortcuts to advertise. */
@media (hover: none) { .kbd-tips { display: none; } }

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