/* Sleigh Route - "Fireside" theme. Tokens first, then layout and components. */
:root {
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Nunito Sans", system-ui, sans-serif;
  /* night */
  --bg: #13261d; --night-ink: #fff3df; --night-text: #f6ecda; --night-soft: #d9cbb3; --night-muted: #c3b49a;
  /* paper */
  --surface: #fbf4e6; --surface-2: #f3e8d2; --ink: #2a1f17; --muted: #685947; --line: #e3d4b8; --line-strong: #d2bd96;
  --accent: #c8402f; --accent-hover: #b0341f; --accent-ink: #fff8ee; --focus: #e8b54f;
  --ok: #2f7d4f; --ok-ink: #fff; --gold: #e8b54f;
  --lv-easy: #2f7a4c; --lv-medium: #d39a2c; --lv-hard: #c8402f; --lv-expert: #6a3b8c;
  --chip-on: #2a1f17; --chip-on-ink: #fbf4e6;
  --card-shadow: 0 1px 0 rgb(255 255 255 / .6) inset, 0 6px 18px rgb(0 0 0 / .18);
  --card-shadow-hover: 0 1px 0 rgb(255 255 255 / .6) inset, 0 16px 34px rgb(0 0 0 / .28);
  --btn-shadow: 0 6px 18px rgb(200 64 47 / .35);
  --scrim: rgb(8 18 13 / .72);
  /* board */
  --b-tray: #1f6b45; --b-tray-line: #18573a; --b-well: #17533a; --b-slot: #1b5e40; --b-slot-line: #4f9a73;
  --b-tile: #f6ead2; --b-tile-line: #dccaa7; --b-gate: #15513a; --b-hole: #0d3a28; --b-num: #b9dcc6;
  --b-start: #ff8f73; --b-goal: #ffd27a; --b-groove: #a87543; --b-light: #ffd56b; --b-light-glow: #ff9b3d;
  --b-tree: #23744a; --b-trunk: #7a4d2b; --b-star: #e8b54f;
  --b-gift: #e1a93a; --b-gift-lid: #f0bd4f; --b-ribbon: #c8402f;
  --b-sleigh: #d23b2a; --b-sleigh-trim: #ffd27a; --b-runner: #e8b54f;
  --b-chip-tile: #ead9b8; --b-chip-groove: #a87543;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 16px; }
html.modal-open { overflow: hidden; }
body {
  margin: 0; min-height: 100dvh; color: var(--night-text); font: 400 1rem/1.55 var(--font-body); -webkit-font-smoothing: antialiased; overflow-x: hidden;
  background: radial-gradient(1200px 600px at 80% -10%, #2a4d37 0%, transparent 60%), radial-gradient(900px 500px at -10% 30%, #3a2a17 0%, transparent 55%), var(--bg);
}
img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
a { color: var(--gold); text-underline-offset: .2em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(1200px, 100% - 32px); margin-inline: auto; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0 0 .5em; text-wrap: balance; }
/* Japanese and Chinese: break lines between phrases, not inside words (where supported) */
:lang(ja) :is(h1, h2, h3, p, figcaption), :lang(zh) :is(h1, h2, h3, p, figcaption) { word-break: auto-phrase; line-break: strict; }
:lang(ja) h1, :lang(zh) h1 { line-height: 1.25; }
.nw { white-space: nowrap; }
p { text-wrap: pretty; }
main, header, footer { position: relative; z-index: 1; }
.skip { position: absolute; z-index: 30; left: 16px; top: -60px; padding: .6em 1em; border-radius: 10px; background: var(--surface); color: var(--ink); font-weight: 700; transition: top .2s; }
.skip:focus { top: 12px; }
.noscript { position: relative; z-index: 2; text-align: center; padding: 16px; background: var(--accent); color: #fff; margin: 0; }

/* aurora: a soft glow over the top of the page that fades out before the content */
.aurora { position: absolute; inset: 0 0 auto; height: 760px; z-index: 0; pointer-events: none; overflow: hidden;
  -webkit-mask: linear-gradient(#000 30%, transparent); mask: linear-gradient(#000 30%, transparent); }
.aurora i { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .42; mix-blend-mode: screen; animation: drift 22s ease-in-out infinite alternate; }
.aurora i:nth-child(1) { width: 60vw; height: 240px; left: -6vw; top: 30px; background: #27c99a; rotate: -8deg; }
.aurora i:nth-child(2) { width: 46vw; height: 210px; left: 32vw; top: -30px; background: #3d9e6a; animation-delay: -7s; }
.aurora i:nth-child(3) { width: 34vw; height: 190px; left: 66vw; top: 60px; background: #7656d6; opacity: .32; animation-delay: -14s; }
@keyframes drift { 50% { transform: translate(5vw, 30px) scale(1.12); } 100% { transform: translate(-3vw, 60px) scale(.95); } }
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.snow i { position: absolute; top: -10px; left: var(--x); width: var(--s); height: var(--s); border-radius: 50%; background: #fff7e8;
  animation: fall var(--d) linear var(--delay) infinite; }
@keyframes fall { to { transform: translate(var(--drift), 110vh); } }

/* ---------- buttons, chips, inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: 44px; padding: .6em 1.15em;
  border-radius: 999px; border: 1px solid transparent; cursor: pointer; font-weight: 700; text-decoration: none;
  transition: transform .15s ease, background-color .2s, box-shadow .2s, color .2s, border-color .2s;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn svg { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { cursor: not-allowed; opacity: .75; box-shadow: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--btn-shadow); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-small { min-height: 40px; padding: .4em 1em; font-size: .9rem; }
.btn-solved.is-on { background: var(--ok); color: var(--ok-ink); border-color: transparent; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: .45em; min-height: 44px; padding: .35em 1em; cursor: pointer; white-space: nowrap;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; font-size: .92rem;
  transition: background-color .2s, color .2s, border-color .2s;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chip-n { font-size: .8em; opacity: .75; font-variant-numeric: tabular-nums; }
.chip[data-level]:not([data-level="all"])::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--dot); }
.chip[data-level="easy"] { --dot: var(--lv-easy); } .chip[data-level="medium"] { --dot: var(--lv-medium); }
.chip[data-level="hard"] { --dot: var(--lv-hard); } .chip[data-level="expert"] { --dot: var(--lv-expert); }

.search { position: relative; }
.search input { -webkit-appearance: none; appearance: none; box-sizing: border-box; display: block; font: inherit; font-size: max(16px, 1rem); line-height: 1.2; margin: 0; width: 100%; min-height: 44px; padding: .4em .9em .4em 2.4em; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); outline: none; }
/* Safari/iOS draw search fields natively (own shape, padding, decorations): reset them */
.search input::-webkit-search-decoration, .search input::-webkit-search-results-button { -webkit-appearance: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; margin-left: 6px; cursor: pointer; opacity: .55;
  background: center / 16px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2118' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6 6 18'/%3E%3C/svg%3E"); }
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 0; }
.search svg { position: absolute; left: .85em; top: 50%; translate: 0 -50%; width: 1.05em; height: 1.05em; opacity: .6; pointer-events: none; fill: none; stroke: var(--ink); stroke-width: 2.4; }

.check { display: inline-flex; align-items: center; gap: .55em; min-height: 40px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; transition: background-color .2s, transform .15s; }
.icon-btn:hover { background: var(--line); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* level badge */
.lvl { display: inline-flex; align-items: center; font-size: .76rem; font-weight: 800; letter-spacing: .02em; padding: .2em .65em; border-radius: 99px; color: #fff; background: var(--lv); }
.lvl-easy { --lv: var(--lv-easy); } .lvl-medium { --lv: var(--lv-medium); color: #2b1d00; }
.lvl-hard { --lv: var(--lv-hard); } .lvl-expert { --lv: var(--lv-expert); }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 18px; z-index: 10; }
.brand { display: flex; align-items: center; gap: 16px; font: 800 3rem var(--font-display); color: var(--night-ink); text-decoration: none; letter-spacing: -.01em; }
.brand img { width: 104px; height: 104px; filter: drop-shadow(0 4px 10px rgb(0 0 0 / .35)); transition: transform .3s cubic-bezier(.3,1.4,.5,1); }
.brand:hover img { transform: rotate(-6deg) scale(1.06); }
/* wordmark lockup: bold coral-red "Sleigh" over a glowing gold italic "Route", like the sleigh and the lit groove */
.wordmark { display: grid; line-height: .92; white-space: nowrap; color: #f2553d; text-shadow: 0 2px 0 rgb(90 20 10 / .35); }
.wordmark em { font-style: italic; font-weight: 700; color: #ffcf5a; padding-right: .08em;
  text-shadow: 0 0 14px rgb(255 190 80 / .45), 0 2px 0 rgb(90 50 0 / .3); }
.top-r { display: flex; align-items: center; gap: 6px; }
.nav { display: flex; gap: 4px; }
.nav a { color: #e9dcc4; text-decoration: none; font-weight: 700; padding: .55em .9em; border-radius: 99px; }
.nav a:hover { background: rgb(255 255 255 / .08); }

.lang { position: relative; }
.lang summary { list-style: none; display: inline-flex; align-items: center; gap: .45em; min-height: 44px; padding: .3em .95em; border-radius: 99px; cursor: pointer;
  border: 1px solid rgb(255 255 255 / .22); background: rgb(255 255 255 / .06); color: var(--night-ink); font-weight: 700; }
.lang summary::-webkit-details-marker { display: none; }
.lang summary svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.lang summary::after { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 0 2px 2px 0; rotate: 45deg; translate: 0 -2px; transition: rotate .2s; }
.lang[open] summary::after { rotate: 225deg; translate: 0 2px; }
.lang ul { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; list-style: none; margin: 0; padding: 6px; width: 210px; max-height: min(70vh, 520px); overflow: auto;
  border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgb(0 0 0 / .4); animation: pop-in .2s ease; }
.lang li button { width: 100%; display: flex; justify-content: space-between; gap: 8px; min-height: 40px; padding: .45em .75em; border: 0; border-radius: 10px; background: none; cursor: pointer; font-weight: 600; text-align: left; }
.lang li button:hover { background: var(--surface-2); }
.lang li button[aria-current="true"] { background: var(--surface-2); }
.lang li button[aria-current="true"]::after { content: "✓"; color: var(--ok); font-weight: 800; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 48px; align-items: center; padding-block: 40px 72px; }
.eyebrow { display: inline-flex; gap: .5em; align-items: center; font-weight: 800; letter-spacing: .08em; font-size: .82rem; color: var(--gold); margin: 0; }
.hero h1 { font-size: clamp(2.5rem, 6vw, 4.6rem); font-weight: 800; color: var(--night-ink); letter-spacing: -.02em; margin-top: .3em; }
/* the key word glows sleigh-red, like "Sleigh" in the wordmark */
.hero h1 em { font-style: italic; color: #ff6a50; font-weight: 700; text-shadow: 0 0 22px rgb(255 90 60 / .35); }
.hero .lead { font-size: 1.15rem; color: var(--night-soft); max-width: 34em; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.hero .btn-ghost { background: rgb(255 255 255 / .06); color: var(--night-ink); border-color: rgb(255 255 255 / .22); }
.hero .btn-ghost:hover { background: rgb(255 255 255 / .12); }
.stats { display: flex; gap: 30px; margin: 34px 0 0; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dd { margin: 0; font: 800 1.8rem var(--font-display); color: var(--night-ink); }
.stats dt { color: var(--night-muted); font-size: .9rem; }

.model-card { position: relative; border-radius: 28px; padding: 14px; background: linear-gradient(160deg, #fbf4e6, #f1e3c6); color: var(--ink);
  box-shadow: 0 30px 70px rgb(0 0 0 / .45), 0 0 0 1px rgb(255 255 255 / .4) inset; rotate: 1.2deg; transition: rotate .4s ease; scroll-margin-top: 24px; }
.model-card:hover { rotate: 0deg; }
.model-card .photo { border-radius: 18px; overflow: hidden; background: #e9e2d2; aspect-ratio: 16 / 11; }
.model-card .photo img { width: 100%; height: 100%; object-fit: cover; }
.model-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; align-items: center; padding: 16px 10px 8px; }
.model-body h2 { font-size: 1.35rem; margin: 0; }
.model-body .btn { grid-row: 1; grid-column: 2; }
/* print facts as small chips that never break mid-item */
.specs { grid-column: 1 / -1; list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.specs li { white-space: nowrap; padding: .25em .7em; border-radius: 99px; font-size: .82rem; font-weight: 700; color: #5a4a33;
  background: rgb(255 255 255 / .55); border: 1px solid rgb(120 90 40 / .18); }
.mock { position: absolute; top: 26px; left: 26px; max-width: calc(100% - 52px); background: #2a1f17; color: #ffd27a; font-size: .74rem; font-weight: 800; letter-spacing: .04em; line-height: 1.35; padding: .35em .75em; border-radius: 99px; }
.ribbon-tag { position: absolute; z-index: 1; top: -14px; right: 28px; background: var(--accent); color: #fff; font-weight: 800; font-size: .82rem; padding: .5em .9em; border-radius: 10px; box-shadow: 0 8px 20px rgb(200 64 47 / .45); }

/* ---------- sections ---------- */
section { padding-block: 56px; scroll-margin-top: 8px; }
section:focus { outline: none; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.section-head h2 { font-size: clamp(1.9rem, 4vw, 2.8rem); color: var(--night-ink); margin: 0; }
.section-head p { color: var(--night-soft); margin: .4em 0 0; }

.play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: stretch; }
.paper { background: var(--surface); color: var(--ink); border-radius: 26px; padding: 28px; box-shadow: var(--card-shadow); margin: 0; }
.rules { counter-reset: r; list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; }
.rules li { counter-increment: r; display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 14px; align-items: start; }
.rules li::before { content: counter(r); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #f0dfbd; color: #8a4b1f; font: 800 1.1rem var(--font-display); }
.rules b { display: block; }
.rules span { color: var(--muted); font-size: .95rem; }
.demo { display: grid; gap: 14px; align-content: center; justify-items: center; text-align: center; }
.demo-board { width: min(380px, 100%); aspect-ratio: 1; }
.demo figcaption { color: var(--muted); font-weight: 600; display: grid; }
.demo figcaption > span { grid-area: 1 / 1; }
.demo figcaption > span[aria-hidden="true"] { visibility: hidden; }
/* small round pause/play button floating on the demo board's corner */
.demo-stage { position: relative; width: min(380px, 100%); }
.demo-toggle { position: absolute; right: 5px; bottom: 5px; width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid rgb(255 255 255 / .25); background: rgb(16 35 28 / .55); color: #fff7e8; opacity: .7;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgb(0 0 0 / .25); transition: opacity .2s, transform .15s, background-color .2s; }
.demo-stage:hover .demo-toggle, .demo-toggle:focus-visible, .demo-toggle.is-paused { opacity: 1; }
.demo-toggle:hover { background: rgb(16 35 28 / .8); }
.demo-toggle:active { transform: scale(.92); }
.demo-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.demo-toggle .i-play { display: none; fill: currentColor; stroke: none; }
.demo-toggle.is-paused .i-play { display: block; } .demo-toggle.is-paused .i-pause { display: none; }
@media (hover: none) { .demo-toggle { opacity: .85; } }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- puzzles ---------- */
.puzzles-shell { background: var(--surface); color: var(--ink); border-radius: 32px; padding: 26px; box-shadow: 0 30px 70px rgb(0 0 0 / .35); }
.toolbar { position: relative; top: 10px; z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 14px; margin: -8px -8px 22px; border-radius: 22px;
  background: rgb(251 244 230 / .92); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); border: 1px solid var(--line); }
.toolbar-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.toolbar-row > .chips { min-width: 0; max-width: 100%; }
.toolbar .search { flex: 1 1 220px; max-width: 320px; }
/* desktop/tablet: one grid — levels | search on the first line, status | result count on the second */
@media (min-width: 601px) {
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 16px; }
  .toolbar > .toolbar-row { display: contents; }
  .toolbar #levels { grid-column: 1; grid-row: 1; }
  .toolbar .search { grid-column: 2; grid-row: 1; align-self: start; width: clamp(200px, 24vw, 280px); max-width: none; }
  .toolbar #status { grid-column: 1; grid-row: 2; }
  .toolbar .result-count { grid-column: 2; grid-row: 2; justify-self: end; }
}
.filters-btn { display: none; position: relative; }
.filters-btn .dot { position: absolute; top: 8px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.result-count { font-weight: 700; color: var(--muted); font-size: .9rem; }
.side { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 26px; align-items: start; }

.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(178px, calc(50% - 8px)), 1fr)); }
.card { position: relative; display: grid; gap: 8px; align-content: start; padding: 10px 10px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--card-shadow); content-visibility: auto; contain-intrinsic-size: auto 290px;
  transition: transform .25s cubic-bezier(.2,.7,.3,1), box-shadow .25s, border-color .25s;
  animation: card-in .45s cubic-bezier(.2,.7,.3,1) backwards; animation-delay: calc(var(--n, 0) * 18ms); }
.card:hover { transform: translateY(-3px); box-shadow: var(--card-shadow-hover); border-color: var(--line-strong); }
.card:has(.card-hit:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.card-hit { display: block; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 12px; }
.card-hit::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card-hit:focus-visible { outline: none; }
.card-foot { display: flex; align-items: center; gap: 6px; padding-inline: 4px; min-height: 26px; }
.pid { margin-right: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.done-mark { width: 24px; height: 24px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--ok); }
.done-mark svg { width: 16px; height: 16px; fill: none; stroke: var(--ok-ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.card:not(.is-done) .done-mark { display: none; }
.card.is-done .done-mark { animation: pop .4s cubic-bezier(.3,1.6,.5,1); }
.card.is-done .card-board .board { opacity: .62; }
.counts { list-style: none; margin: 0; padding: 0 4px; display: flex; flex-wrap: wrap; gap: 4px 9px; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.counts li { display: inline-flex; align-items: center; gap: 3px; }
.counts svg { width: 17px; height: 17px; }
.card.skeleton { pointer-events: none; animation: none; }
.card.skeleton .sk-board { aspect-ratio: 1; border-radius: 14px; background: linear-gradient(100deg, var(--surface-2) 40%, #fff9ee 50%, var(--surface-2) 60%) 0 0 / 200% 100%; animation: shimmer 1.4s linear infinite; }
.card.skeleton .sk-line { height: 12px; width: 60%; border-radius: 6px; background: var(--surface-2); }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes pop { from { transform: scale(0); } }
.more { display: flex; justify-content: center; padding: 28px 0 8px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.load-error { text-align: center; padding: 40px 16px; display: grid; gap: 12px; justify-items: center; color: var(--ink); }

.panel { position: sticky; top: 150px; display: grid; gap: 16px; padding: 20px; border-radius: 22px; background: var(--surface-2); border: 1px solid var(--line); }
.panel h3 { font-size: 1.2rem; margin: 0; }
.panel .big { margin: 0; font: 800 2.4rem/1 var(--font-display); }
.panel .big small { font-size: .4em; color: var(--muted); }
.note { font-size: .86rem; color: var(--muted); margin: 0; }
.note.is-off { color: var(--accent); font-weight: 700; }
.file-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btns .btn { min-height: 40px; padding: .4em .9em; font-size: .88rem; }
.progress { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.prog { display: grid; grid-template-columns: 6em minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .9rem; font-weight: 700; }
.prog-bar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.prog-bar span { display: block; height: 100%; width: var(--p); border-radius: inherit; background: var(--lv); transition: width .6s cubic-bezier(.2,.8,.3,1); }
.prog-easy { --lv: var(--lv-easy); } .prog-medium { --lv: var(--lv-medium); } .prog-hard { --lv: var(--lv-hard); } .prog-expert { --lv: var(--lv-expert); }
.prog-n { font-variant-numeric: tabular-nums; } .prog-n small { color: var(--muted); font-weight: 600; }

/* ---------- footer ---------- */
.site-footer { margin-top: 40px; padding-block: 56px 32px; border-top: 1px solid rgb(255 243 223 / .1);
  background: linear-gradient(rgb(0 0 0 / 0), rgb(0 0 0 / .28)); color: var(--night-soft); }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .7fr) minmax(0, 1.6fr); gap: 40px; align-items: start; }
.site-footer h2 { font-size: 1.05rem; color: var(--night-ink); margin: 0 0 12px; }
.f-brand p { margin: 14px 0 0; max-width: 24em; }
.f-links ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.f-links a { color: var(--night-soft); text-decoration: none; font-weight: 700; display: inline-block; padding-block: 6px; }
.f-links a:hover { color: var(--gold); }
.f-share { padding: 0; }
.f-share p { margin: 0 0 14px; }
.share-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.share-pill { display: inline-flex; align-items: center; gap: .45em; min-height: 40px; padding: .4em 1em; border-radius: 99px; cursor: pointer;
  border: 1px solid rgb(255 243 223 / .2); background: rgb(255 255 255 / .05); color: var(--night-ink); font-weight: 700; font-size: .9rem; text-decoration: none;
  transition: background-color .2s, border-color .2s, transform .15s; }
.share-pill:hover { background: rgb(255 255 255 / .12); border-color: rgb(255 243 223 / .4); }
.share-pill:active { transform: scale(.97); }
.share-pill svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.share-main { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.share-main:hover { background: var(--accent-hover); border-color: transparent; }
.footer-bottom { margin-top: 40px; padding-top: 20px; border-top: 1px solid rgb(255 243 223 / .08); display: flex; flex-wrap: wrap; gap: 4px 24px; justify-content: space-between; font-size: .86rem; color: var(--night-muted); }
.footer-bottom p { margin: 0; }
@media (max-width: 860px) { .footer-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .f-share { grid-column: 1 / -1; } }
@media (max-width: 560px) {
  .footer-grid { grid-template-columns: minmax(0, 1fr); gap: 28px; }
  .footer-bottom { flex-direction: column; }
  .site-footer { padding-bottom: calc(84px + env(safe-area-inset-bottom)); } /* room for the back-to-top button */
}

/* ---------- board (SVG) ---------- */
.board { width: 100%; height: auto; overflow: visible; }
.b-tray { fill: var(--b-tray); stroke: var(--b-tray-line); }
.b-well { fill: var(--b-well); }
.b-slot { fill: var(--b-slot); stroke: var(--b-slot-line); stroke-width: .8; stroke-dasharray: 2.4 2.4; }
.b-tile { fill: var(--b-tile); stroke: var(--b-tile-line); stroke-width: .7; }
.b-gate line { stroke: var(--b-gate); stroke-width: 4.6; stroke-linecap: round; }
.b-gate circle { fill: var(--b-hole); }
.b-gate.is-start line { stroke: var(--b-start); } .b-gate.is-goal line { stroke: var(--b-goal); }
.b-num { font: 700 7.4px var(--font-body); fill: var(--b-num); text-anchor: middle; }
.b-num.is-start { fill: var(--b-start); } .b-num.is-goal { fill: var(--b-goal); }
.b-groove { fill: none; stroke: var(--b-groove); stroke-width: 5; stroke-linejoin: round; }
.b-glow { fill: none; stroke: none; }
.b-light { fill: none; stroke: var(--b-light); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1; stroke-dashoffset: 1;
  filter: drop-shadow(0 0 3px var(--b-light)) drop-shadow(0 0 7px var(--b-light-glow)); animation: light var(--dur) cubic-bezier(.45,0,.35,1) .3s forwards; }
.board.is-solved:not(.is-animated) .b-groove { stroke: var(--b-light); }
.board.is-solved .b-tile, .board.is-solved .b-treeicon { transform-box: fill-box; transform-origin: center; animation: tile-in .45s cubic-bezier(.3,1.4,.5,1) backwards; animation-delay: calc(var(--i) * 25ms); }
.board.is-solved .b-groove { animation: fade-in .4s ease .25s backwards; }
.b-token { filter: drop-shadow(0 1px 1.2px rgb(0 0 0 / .35)); }
/* delivery at the gift: starts when the sleigh pulls up (--dur after a .3s lead-in) */
.b-arrive { --t: calc(var(--dur) + .3s); }
.b-ring { fill: none; stroke: var(--b-light); stroke-width: 1.6; opacity: 0; transform-box: fill-box; transform-origin: center; animation: ring .9s cubic-bezier(.2,.7,.3,1) var(--t) forwards; }
.b-spark { fill: var(--b-light); opacity: 0; animation: spark .95s cubic-bezier(.15,.8,.3,1) var(--t) forwards; }
.b-spark.alt { fill: var(--b-star); animation-delay: calc(var(--t) + .08s); }
.b-gift-token { transform-box: fill-box; transform-origin: 50% 100%; animation: gift-hop .8s cubic-bezier(.3,1.5,.5,1) var(--t); }
@keyframes ring { 0% { opacity: .9; transform: scale(.6); } 100% { opacity: 0; transform: scale(2.6); } }
@keyframes spark { 0% { opacity: 0; transform: translate(0, 0) scale(.4) rotate(0); } 25% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--sx), var(--sy)) scale(1.7) rotate(90deg); } }
@keyframes gift-hop { 30% { transform: translateY(-5px) scale(1.18, .9); } 55% { transform: translateY(0) scale(.92, 1.1); } 75% { transform: scale(1.06, .96); } }
@keyframes light { to { stroke-dashoffset: 0; } }
@keyframes tile-in { from { transform: scale(.7); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- viewer ---------- */
dialog { color: var(--ink); }
.viewer { padding: 0; border: 0; max-width: none; max-height: none; background: transparent; overflow: visible; }
.viewer::backdrop { background: var(--scrim); backdrop-filter: blur(6px); }
.viewer[open] { animation: dlg-in .35s cubic-bezier(.2,.8,.3,1); }
.viewer[open]::backdrop { animation: fade-in .3s ease; }
.v-panel { position: relative; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr); gap: 28px; align-items: center;
  width: min(1040px, 100vw - 48px); max-height: calc(100dvh - 48px); overflow: auto; padding: 28px; border-radius: 28px; background: var(--surface); box-shadow: 0 30px 80px rgb(0 0 0 / .35); }
.v-board { max-width: min(560px, 100%); width: 100%; margin-inline: auto; touch-action: pan-y; aspect-ratio: 1; }
.v-info { display: grid; gap: 14px; align-content: center; }
.v-tags { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.v-title { font-size: clamp(1.6rem, 3vw, 2.2rem); margin: 0; }
.v-route { font-weight: 700; font-variant-numeric: tabular-nums; margin: 0; }
.v-trees { color: var(--muted); margin: 0; }
.v-info .counts { font-size: 1rem; gap: 8px 16px; padding: 0; }
.v-info .counts svg { width: 22px; height: 22px; }
.v-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.v-nav { display: flex; gap: 8px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.v-hint { font-size: .82rem; color: var(--muted); text-align: center; }
.v-close { position: absolute; top: 14px; right: 14px; z-index: 2; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(24px) scale(.97); } }

/* ---------- confirm & filter sheet ---------- */
.confirm { padding: 0; border: 0; background: transparent; max-width: min(420px, 100vw - 32px); overflow: visible; }
.confirm::backdrop { background: rgb(0 0 0 / .35); }
.confirm[open] { animation: pop-in .32s cubic-bezier(.3,1.4,.5,1); }
.confirm-panel { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 26px 24px 22px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 24px 60px rgb(0 0 0 / .4); }
.confirm-panel h3 { font-size: 1.45rem; margin: 4px 0 0; }
.confirm-panel p { margin: 0; color: var(--muted); }
.confirm-panel .check { color: var(--muted); font-weight: 600; }
.confirm-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--accent);
  box-shadow: 0 0 0 6px rgb(255 213 107 / .25); animation: glow-pulse 2.4s ease-in-out infinite; }
.confirm-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: 100%; margin-top: 4px; }
.confirm-actions .btn { flex: 1 1 140px; }
@keyframes pop-in { from { opacity: 0; transform: scale(.9) translateY(10px); } }
@keyframes glow-pulse { 50% { box-shadow: 0 0 0 11px rgb(255 213 107 / .1); } }

.sheet { padding: 0; border: 0; margin: auto 0 0; width: 100%; max-width: none; background: transparent; }
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { animation: sheet-in .35s cubic-bezier(.2,.8,.3,1); }
.sheet-panel { display: grid; gap: 18px; padding: 18px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--surface); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { margin: 0; font-size: 1.3rem; }
#sheet-body .toolbar-row { flex-direction: column; align-items: stretch; }
#sheet-body .search { max-width: none; }
.sheet-levels { flex-wrap: wrap; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

/* ---------- delights ---------- */
.burst { position: fixed; z-index: 40; pointer-events: none; }
.burst i { position: absolute; width: 7px; height: 7px; border-radius: 2px; background: #e8b54f; animation: burst .85s cubic-bezier(.1,.7,.3,1) forwards; }
.burst i:nth-child(3n) { background: #c8402f; } .burst i:nth-child(3n+1) { background: #fff; border-radius: 50%; }
@keyframes burst { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); translate: -50% 20px; opacity: 0; z-index: 50; max-width: calc(100vw - 32px);
  padding: .7em 1.2em; border-radius: 12px; background: var(--ink); color: var(--surface); font-weight: 700; transition: .3s; pointer-events: none; }
#toast.on { translate: -50% 0; opacity: 1; }
.to-top { position: fixed; z-index: 8; right: max(16px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); width: 50px; height: 50px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; border: 1px solid rgb(255 255 255 / .25); background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 28px rgb(0 0 0 / .3);
  opacity: 0; transform: translateY(16px) scale(.85); pointer-events: none; transition: opacity .25s, transform .3s cubic-bezier(.3,1.4,.5,1), background-color .2s; }
.to-top.on { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { background: var(--accent-hover); }
.to-top svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.to-top:hover svg { transform: translateY(-2px); }

/* ---------- responsive ---------- */
@media (min-width: 900px) and (min-height: 700px) { .toolbar { position: sticky; } }
@media (max-width: 1020px) {
  .side { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; order: -1; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .panel > .progress { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .hero, .play { grid-template-columns: minmax(0, 1fr); }
  .hero { padding-top: 16px; gap: 36px; }
  .model-card { rotate: 0deg; }
  .nav { display: none; }
}
@media (max-width: 820px) {
  .viewer { margin: 0; inset: 0; width: 100%; height: 100%; }
  .v-panel { grid-template-columns: minmax(0, 1fr); gap: 14px; width: 100vw; height: 100dvh; max-height: none; border-radius: 0; align-content: start;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
  .v-board { max-width: min(520px, 100%, 58dvh); padding-top: 44px; }
  .v-actions .btn { flex: 1 1 140px; }
  .v-hint { display: none; }
  .viewer[open] { animation: sheet-in .38s cubic-bezier(.2,.8,.3,1); }
}
@media (max-width: 600px) {
  .puzzles-shell { padding: 12px; border-radius: 24px; margin-inline: -8px; }
  /* compact sticky bar: levels + a Filters button; status and search move into a bottom sheet */
  .toolbar { position: sticky; top: 0; margin: -4px -4px 14px; padding: 8px; border-radius: 18px; }
  .toolbar-row { flex-wrap: nowrap; gap: 8px; }
  .toolbar .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; flex: 1; }
  .toolbar .chips::-webkit-scrollbar { display: none; }
  .filters-btn { display: inline-flex; flex: none; padding-inline: .9em; }
  .panel { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; }
  .progress { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
  .prog { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; font-size: .85rem; }
  .prog .prog-bar { grid-column: 1 / -1; grid-row: 2; height: 7px; }
  .paper { padding: 20px; }
  .card { padding: 8px 8px 10px; }
  .counts { font-size: .8rem; gap: 2px 7px; }
  .counts svg { width: 15px; height: 15px; }
  .to-top { width: 46px; height: 46px; }
  .top .brand { font-size: 2.25rem; gap: 12px; }
  .top .brand img { width: 76px; height: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .aurora i { animation: none; }
  .b-light { stroke-dashoffset: 0; }
}
