/* Block Puzzle styles. Self-contained (system fonts, no external requests). Light and dark via prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f4efe6;
  --ink: #16223b;
  --ink-2: #3b4661;
  --muted: #5b6475;
  --line: #e5ddcf;
  --btn: #16223b;
  --btn-ink: #ffffff;
  --focus: #16223b;
  --accent: #e8542f;
  --deep: #a8361a;
  --board: #e7e0d3;
  --slot: #d9d0c0;
  --slot-hi: #cfc5b3;
  --bad: #c0392b;
  --shadow: 0 1px 2px rgba(22, 34, 59, 0.06), 0 10px 28px rgba(22, 34, 59, 0.08);
  --t0: #f0715a; --t1: #f4b13e; --t2: #6cc56a; --t3: #36b5a6;
  --t4: #4fa3f0; --t5: #6f7cf2; --t6: #b17ae8; --t7: #ef7fb4;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Board size: as wide as the phone allows, but short enough that the board and the pieces fit on screen together. */
  --bsz: clamp(240px, min(100vw - 32px, (100vh - 214px) / 1.29), 520px);
  --bsz: clamp(240px, min(100vw - 32px, (100svh - 214px) / 1.29), 520px);
  --pad: calc(var(--bsz) * 0.016);
  --gap: calc(var(--bsz) * 0.008);
  --cell: calc((var(--bsz) - 2 * var(--pad) - 7 * var(--gap)) / 8);
  --tc: calc(var(--bsz) / 8 * 0.46);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --surface: #172033;
    --surface-2: #1d2841;
    --ink: #eef1f7;
    --ink-2: #c9d0dd;
    --muted: #9aa4b6;
    --line: #2b3752;
    --btn: #eef1f7;
    --btn-ink: #0f1522;
    --focus: #f3d38a;
    --deep: #ffab8a;
    --board: #18213a;
    --slot: #232e4b;
    --slot-hi: #2c3a5d;
    --bad: #ff8f84;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.6 var(--font); overflow-x: hidden; }
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
a:hover { color: var(--deep); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only, .vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 50; background: var(--btn); color: var(--btn-ink); padding: 10px 14px; border-radius: 10px; }
.skip:focus { top: 10px; }
kbd { font: 600 0.82em/1 ui-monospace, Menlo, Consolas, monospace; padding: 2px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font: 650 1rem/1.15 var(--font); cursor: pointer; text-decoration: none; text-align: center;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { border-color: var(--ink-2); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn-primary { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 44px; padding: 7px 14px; font-size: 0.94rem; border-radius: 12px; }
.btn.confirm { border-color: var(--accent); color: var(--deep); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid transparent;
  background: transparent; color: var(--ink); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.icon-btn:hover { border-color: var(--line); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] .off, .icon-btn[aria-pressed="false"] .on { display: none; }
.icon-btn[aria-pressed="false"] { color: var(--muted); }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1080px; margin: 0 auto; padding: 4px 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 650; font-size: 0.98rem; min-height: 44px; }
.brand svg { width: 24px; height: 24px; color: var(--accent); }
.brand b { font-weight: 650; color: var(--muted); }
.tools { display: flex; gap: 2px; }

/* Game layout: one column on phones; board on the left and everything else on the right on wider screens. */
.game { width: calc(var(--bsz) + 32px); max-width: 100%; margin: 0 auto; padding: 0 16px; display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 8px; }
.intro { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 12px; }
.intro h1 { margin: 0; font: 800 clamp(1.35rem, 5.4vw, 1.7rem)/1.15 var(--display); letter-spacing: -0.01em; }
.tagline { flex-basis: 100%; margin: 0; font-size: 0.86rem; line-height: 1.4; color: var(--muted); }
.modes { display: inline-flex; padding: 3px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); }
.modes label { position: relative; cursor: pointer; }
.modes label::after { content: ""; position: absolute; inset: -4px 0; } /* 46 px tall tap area */
.modes input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.modes span { display: grid; place-items: center; min-height: 38px; padding: 0 14px; border-radius: 10px; font-weight: 650; font-size: 0.92rem; color: var(--ink-2); }
.modes input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(22, 34, 59, 0.16); }
.modes input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
@media (prefers-color-scheme: dark) { .modes input:checked + span { background: #3a4868; color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); } }

.challenge { display: grid; gap: 8px; padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--accent); box-shadow: var(--shadow); }
.challenge p { margin: 0; font-size: 0.95rem; line-height: 1.4; }
.challenge-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.hud { display: flex; align-items: flex-start; gap: 18px; min-height: 44px; }
.stat { display: grid; line-height: 1.1; }
.stat .k { font-size: 0.74rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat output, .stat .v { font: 800 1.2rem/1.15 var(--display); font-variant-numeric: tabular-nums; }
.stat-score output { font-size: 1.65rem; }
.stat-score output.bump { animation: bump 0.28s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }
.stat output { display: inline-block; transform-origin: left 70%; }
.combo { margin-left: auto; align-self: center; display: grid; justify-items: end; gap: 3px; }
.combo span:first-child { font: 800 0.95rem/1 var(--display); color: var(--deep); }
.pips { display: flex; gap: 4px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.pips i.used { background: var(--line); }

/* Board */
.board-wrap { position: relative; width: var(--bsz); height: var(--bsz); justify-self: center; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: var(--gap); padding: var(--pad);
  width: 100%; height: 100%; border-radius: calc(var(--bsz) * 0.03); background: var(--board);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.board:focus-visible { outline-offset: 4px; }
.cell { border-radius: 22%; background: var(--slot); position: relative; }
.t0 { --c: var(--t0); } .t1 { --c: var(--t1); } .t2 { --c: var(--t2); } .t3 { --c: var(--t3); }
.t4 { --c: var(--t4); } .t5 { --c: var(--t5); } .t6 { --c: var(--t6); } .t7 { --c: var(--t7); }
.tile, .cell.f, .cell.gh {
  background: var(--c);
  box-shadow: inset 0 calc(var(--cell) * -0.08) 0 rgba(0, 0, 0, 0.16), inset 0 calc(var(--cell) * 0.06) 0 rgba(255, 255, 255, 0.32);
}
.cell.gh { opacity: 0.5; }
.cell.gh.hl { opacity: 0.9; }
.cell.f.hl { filter: brightness(1.12) saturate(1.1); box-shadow: inset 0 calc(var(--cell) * -0.08) 0 rgba(0, 0, 0, 0.12), inset 0 0 0 calc(var(--cell) * 0.08) rgba(255, 255, 255, 0.75); }
.cell.bad { background: transparent; box-shadow: inset 0 0 0 2px var(--bad); }
.cell.cur::after { content: ""; position: absolute; inset: -3px; border-radius: 26%; border: 2px dashed var(--ink-2); }
.cell.pop { animation: pop 0.22s ease-out; }
@keyframes pop { 0% { transform: scale(0.82); } 60% { transform: scale(1.06); } }
.cell.clr { background: var(--c); animation: clr 0.38s ease-in forwards; animation-delay: var(--d, 0ms); z-index: 1; }
@keyframes clr { 0% { transform: scale(1); filter: brightness(1.4); } 35% { transform: scale(1.08); filter: brightness(1.6); } 100% { transform: scale(0.15) rotate(12deg); opacity: 0; } }

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.hint { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); margin: 0; display: flex; align-items: center; gap: 8px; white-space: nowrap;
  padding: 8px 14px; border-radius: 999px; background: var(--surface); color: var(--ink-2); font-weight: 650; font-size: 0.92rem; box-shadow: var(--shadow); pointer-events: none;
  animation: nudge 1.6s ease-in-out 0.6s infinite; }
.hint svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
@keyframes nudge { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -6px); } }
.pts { position: absolute; transform: translate(-50%, -50%); font: 800 1.35rem/1 var(--display); color: var(--ink); white-space: nowrap;
  text-shadow: 0 1px 0 var(--bg), 0 0 8px var(--bg); animation: rise 0.9s ease-out forwards; }
.pts.big { font-size: 1.7rem; color: var(--deep); }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 100% { opacity: 0; transform: translate(-50%, -150%); } }

.over { position: absolute; inset: 0; display: grid; place-items: center; padding: 14px; border-radius: calc(var(--bsz) * 0.03);
  background: color-mix(in srgb, var(--bg) 72%, transparent); animation: fade 0.3s ease-out; }
@keyframes fade { from { opacity: 0; } }
.over-card { width: min(100%, 320px); padding: 18px 18px 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; }
.over-kicker { margin: 0; font-weight: 650; color: var(--muted); font-size: 0.92rem; }
.over-card h2 { margin: 4px 0 2px; font: 800 2.6rem/1.05 var(--display); font-variant-numeric: tabular-nums; }
.over-best, .over-vs, .over-stats { margin: 4px 0 0; font-size: 0.95rem; line-height: 1.4; }
.over-best.new { color: var(--deep); font-weight: 750; }
.over-vs { font-weight: 650; }
.over-stats { color: var(--muted); font-size: 0.86rem; }
.over-btns { display: grid; gap: 8px; margin-top: 12px; }

/* Tray */
.tray { display: grid; grid-template-columns: repeat(3, 1fr); width: var(--bsz); justify-self: center; height: calc(var(--tc) * 5 + 14px); touch-action: none; }
.slot {
  display: grid; place-items: center; padding: 0; border: 0; border-radius: 14px; background: transparent; color: inherit; cursor: grab;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.slot:disabled { cursor: default; }
.slot.sel { background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--accent); }
.slot:focus-visible { outline-offset: -3px; }
.mini { display: grid; gap: calc(var(--tc) * 0.12); transition: opacity 0.15s, transform 0.15s; }
.mini i { width: var(--tc); height: var(--tc); border-radius: 22%; }
.mini i.tile { --cell: var(--tc); }
.slot.nofit .mini { opacity: 0.32; filter: grayscale(0.8); }
.slot.lifted .mini { opacity: 0.18; transform: scale(0.9); }
.slot.deal .mini { animation: deal 0.32s ease-out backwards; animation-delay: var(--d, 0ms); }
@keyframes deal { from { opacity: 0; transform: translateY(18px) scale(0.85); } }
.slot.shake .mini { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* The piece you're dragging */
.float { position: fixed; left: 0; top: 0; z-index: 40; display: grid; gap: var(--gap); pointer-events: none; will-change: transform;
  filter: drop-shadow(0 10px 14px rgba(22, 34, 59, 0.28)); }
.float i { width: var(--cell); height: var(--cell); border-radius: 22%; }
.float.back { transition: transform 0.18s ease-in, opacity 0.18s ease-in; opacity: 0; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.status { flex: 1 1 100%; margin: 0; font-size: 0.9rem; line-height: 1.45; color: var(--muted); min-height: 1.3em; }
.help { margin: 0; font-size: 0.86rem; line-height: 1.5; color: var(--muted); }

@media (min-width: 760px) {
  :root {
    --bsz: clamp(260px, (100vh - 120px) / 1.29, 520px);
    --bsz: clamp(260px, (100svh - 120px) / 1.29, 520px);
  }
  .game { width: auto; max-width: 1080px; padding: 8px 24px 0; column-gap: 40px; justify-content: center;
    grid-template-columns: var(--bsz) minmax(260px, 340px); grid-template-rows: auto auto auto auto 1fr auto; }
  .game > * { grid-column: 2; }
  .board-wrap { grid-column: 1; grid-row: 1 / 6; align-self: start; }
  .tray { grid-column: 1; grid-row: 6; }
  .intro { padding-top: 6px; }
  .intro h1 { font-size: 2.3rem; flex-basis: 100%; }
  .tagline { margin: 4px 0 12px; font-size: 0.95rem; }
  .modes { order: 3; }
  .hud { margin-top: 6px; }
  .stat-score output { font-size: 2.2rem; }
  .actions { align-self: start; }
  .help { align-self: start; }
}

/* Content */
.prose { max-width: 720px; margin: 28px auto 0; padding: 0 16px; }
.prose h2 { font: 800 1.45rem/1.25 var(--display); margin: 32px 0 10px; }
.prose h3 { font-size: 1.04rem; margin: 20px 0 4px; }
.prose p, .prose li { color: var(--ink-2); }
.prose ul { padding-left: 1.2em; }
.prose li { margin: 6px 0; }
.points { width: 100%; border-collapse: collapse; font-size: 0.96rem; }
.points th, .points td { text-align: left; vertical-align: top; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.points th { width: 38%; font-weight: 650; color: var(--ink); }
.points td { color: var(--ink-2); }

.more-toys { max-width: 1080px; margin: 12px auto 0; padding: 28px 16px 0; }
.more-toys h2 { font: 800 1.3rem/1.2 var(--display); margin: 0 0 12px; }
.more-toys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.more-toys a { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: center; column-gap: 14px; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); text-decoration: none; color: var(--ink); }
.more-toys a:hover { border-color: var(--accent); color: var(--ink); }
.more-toys img { grid-row: 1 / 3; display: block; width: 112px; height: 63px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.more-toys b { align-self: end; font-weight: 750; }
.more-toys span { align-self: start; font-size: 0.88rem; line-height: 1.35; color: var(--muted); }

.foot { max-width: 1080px; margin: 20px auto 0; padding: 24px 16px 40px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; color: var(--muted); font-size: 0.92rem; }
.foot p { margin: 0; }
.foot a { color: var(--ink-2); display: inline-block; padding: 12px 0; }

.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 60; transform: translate(-50%, calc(100% + 40px)); max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: 14px; background: var(--btn); color: var(--btn-ink); font-weight: 600; font-size: 0.95rem; box-shadow: var(--shadow);
  transition: transform 0.25s ease, visibility 0s 0.25s; pointer-events: none; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); pointer-events: auto; visibility: visible; transition: transform 0.25s ease; }
.toast input { display: block; width: min(80vw, 420px); margin-top: 8px; padding: 8px; border-radius: 8px; border: 0; font: 500 0.9rem/1.2 ui-monospace, Menlo, monospace; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .cell.clr { animation: none; opacity: 0; }
  .hint { animation: none; }
}
