/* Paper Chain. Warm paper, strips of colored construction paper for the links, big clear letters. */
@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Fredoka"; src: url("/fonts/fredoka-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --paper: #f6f0e4;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #6d645a;          /* 5.6:1 on paper */
  --faint: #a59a8c;
  --line: #e2d8c6;
  --slot: #efe7d8;
  --hit: #2f8a85;            /* right spot: white letters 4.4:1 */
  --near: #c4860f;           /* in the word: the ring */
  --miss: #e6ddcd;
  --accent: #d9483b;
  --strip-1: #d9483b; --strip-2: #b97c0e; --strip-3: #2f8a85; --strip-4: #3f6fb5; --strip-5: #5b8f36; --strip-6: #8a5cb3;
  --tile: clamp(46px, 13.2vw, 60px);
  --letter: clamp(22px, 6.4vw, 28px);
  --key-h: 54px;
  --shadow: 0 1px 0 rgba(43, 38, 32, .08), 0 6px 18px -10px rgba(43, 38, 32, .35);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --body: "Atkinson", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fredoka", "Atkinson", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1a17; --card: #26231f; --ink: #f2ece2; --muted: #b5ab9d; --faint: #7c7366; --line: #3a352e; --slot: #2f2b26;
    --miss: #3a352e; --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -10px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
html.big { --tile: clamp(54px, 15vw, 70px); --letter: clamp(26px, 7.6vw, 34px); --key-h: 62px; font-size: 19px; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--paper); color: var(--ink); font: 400 1rem/1.5 var(--body);
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  background-image: radial-gradient(rgba(120, 100, 70, .045) 1px, transparent 1px); background-size: 6px 6px;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus { outline: none; }
svg { display: block; }
[hidden] { display: none !important; }

/* ---------- Top ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 560px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--paper); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 600 1.45rem/1 var(--display); letter-spacing: .01em; }
.brand__mark { width: 40px; height: 24px; }
.brand__mark rect { fill: none; stroke-width: 4; }
.brand__mark .ring-a { stroke: var(--strip-1); }
.brand__mark .ring-b { stroke: var(--strip-3); }
.top__tools { display: flex; gap: 4px; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; transition: background-color .15s; }
.icon-btn:hover { background: var(--slot); }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .dot { fill: currentColor; }

.status { position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 19; display: flex; justify-content: space-between; align-items: baseline;
  max-width: 560px; margin: 0 auto; padding: 0 18px 10px; background: var(--paper); color: var(--muted); font-size: .95rem; }
.status__points { font-variant-numeric: tabular-nums; }
.status__points b { color: var(--ink); font-size: 1.15rem; display: inline-block; }
.status__points b.bump { animation: bump .45s var(--ease); }
@keyframes bump { 40% { transform: scale(1.25); color: var(--hit); } }

/* ---------- Board ---------- */
.board { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(var(--key-h) * 3 + 64px + env(safe-area-inset-bottom)); }

/* The opener */
.opener { padding: 18px 16px 20px; margin-bottom: 18px; background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  transition: opacity .4s, transform .4s var(--ease); }
.opener__head { text-align: center; margin-bottom: 14px; }
.opener__head h1 { margin: 0; font: 600 1.4rem/1.2 var(--display); }
.opener__head p { margin: 4px 0 0; color: var(--muted); }
.opener.is-done .opener__head p { display: none; }
.grid { display: grid; gap: 6px; justify-content: center; }
.grid__row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 6px; }
.grid__row.is-shake { animation: shake .4s; }
.opener.is-done .grid__row.is-empty { display: none; }
.tile {
  position: relative; display: inline-grid; place-items: center; width: var(--tile); height: var(--tile); border-radius: 10px;
  background: var(--slot); font: 700 var(--letter)/1 var(--body); text-transform: uppercase; color: var(--ink); user-select: none;
}
.tile.is-filled { background: var(--card); box-shadow: inset 0 0 0 2px var(--faint); animation: stamp .14s var(--ease); }
.tile--hit { background: var(--hit) !important; color: #fff; box-shadow: none !important; }
.tile--near { background: var(--card) !important; box-shadow: inset 0 0 0 2px var(--line) !important; }
.tile--near::before { content: ""; position: absolute; inset: 14%; border-radius: 50%; border: 3px solid var(--near); }
.tile--miss { background: var(--miss) !important; color: var(--faint); box-shadow: none !important; }
.grid__row.is-scored .tile { animation: press .38s var(--ease) both; }
.grid__row.is-scored .tile:nth-child(2) { animation-delay: .08s; }
.grid__row.is-scored .tile:nth-child(3) { animation-delay: .16s; }
.grid__row.is-scored .tile:nth-child(4) { animation-delay: .24s; }
.grid__row.is-scored .tile:nth-child(5) { animation-delay: .32s; }
@keyframes stamp { from { transform: scale(1.12); } }
@keyframes press { 0% { transform: scale(1); } 45% { transform: scale(.86) rotate(-2deg); } 100% { transform: none; } }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.opener__help { display: grid; justify-items: center; gap: 10px; margin-top: 14px; }
.opener__help:empty { display: none; }
.clue { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--slot); text-align: center; font-size: 1.02rem; }
.hint-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 999px; box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 700; font-size: .95rem; color: var(--ink); transition: background-color .15s; }
.hint-btn:hover { background: var(--slot); }
.hint-btn span { color: var(--accent); font-variant-numeric: tabular-nums; }
.hint-btn:disabled { opacity: .45; pointer-events: none; }

/* ---------- The chain ---------- */
.chain { display: grid; justify-items: center; }
.link { position: relative; width: 100%; display: grid; justify-items: center; }
.strip {
  --c: var(--strip-1);
  position: relative; display: flex; align-items: center; justify-content: center; gap: 5px; min-height: calc(var(--tile) + 18px);
  width: 100%; padding: 9px 14px; border-radius: 16px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line);
  transition: background-color .35s, box-shadow .25s, transform .35s var(--ease);
}
.strip.is-locked { opacity: .55; }
.strip.is-open { cursor: pointer; box-shadow: inset 0 0 0 2px var(--faint); }
.strip.is-open:hover, .strip.is-open:focus-visible { box-shadow: inset 0 0 0 2px var(--muted); }
.strip.is-active { box-shadow: inset 0 0 0 3px var(--ink); transform: scale(1.015); }
.strip.is-known { background: var(--c); box-shadow: 0 2px 0 rgba(0, 0, 0, .12), var(--shadow); color: #fff; }
.strip.is-known.is-given { opacity: .92; }
.strip.is-shake { animation: shake .4s; }
.strip.is-new { animation: snap .55s var(--ease); }
@keyframes snap { 0% { transform: scale(.94) rotate(-1.2deg); } 55% { transform: scale(1.03) rotate(.6deg); } 100% { transform: none; } }
.strip .slot {
  display: inline-grid; place-items: center; width: calc(var(--tile) * .72); height: calc(var(--tile) * .86); border-radius: 8px; background: var(--slot);
  font: 700 var(--letter)/1 var(--body); text-transform: uppercase; color: var(--ink);
}
.strip .slot.is-given { color: var(--muted); background: transparent; box-shadow: inset 0 -3px 0 var(--line); }
.strip .slot.is-shown { color: var(--accent); background: transparent; box-shadow: inset 0 -3px 0 var(--accent); }
.strip .slot.is-typed { background: var(--card); box-shadow: inset 0 0 0 2px var(--faint); animation: stamp .14s var(--ease); }
.strip.is-known .slot { background: transparent; color: #fff; box-shadow: none; width: auto; min-width: calc(var(--tile) * .5); }
.strip__note { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }
.strip.is-known .strip__note { color: rgba(255, 255, 255, .9); }
.strip:not(.is-known) .strip__note { color: var(--muted); }
.strip__lock { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--faint); stroke-width: 2; }
.strip.is-known .strip__lock { display: none; }
/* Long words get smaller slots so they still fit a phone. */
.strip[data-len="7"] .slot, .strip[data-len="8"] .slot { width: calc(var(--tile) * .6); font-size: calc(var(--letter) * .9); }

/* Between two links: two little rings, and the phrase once both words are known. */
.joint { position: relative; display: grid; place-items: center; height: 34px; width: 100%; }
.joint svg { width: 34px; height: 34px; }
.joint svg rect { fill: none; stroke: var(--line); stroke-width: 3.5; transition: stroke .35s; }
.joint.is-known svg rect:first-child { stroke: var(--ca); }
.joint.is-known svg rect:last-child { stroke: var(--cb); }
.joint__phrase { position: absolute; left: calc(50% + 26px); font-size: .9rem; color: var(--muted); font-style: italic; white-space: nowrap; animation: fade .4s; }
@keyframes fade { from { opacity: 0; transform: translateX(-4px); } }

/* Hints under the word you're on */
.tools { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.chain.is-done .tools { display: none; }

/* ---------- Keyboard ---------- */
.keys { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; gap: 7px; padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); transition: transform .35s var(--ease); }
.keys.is-gone { transform: translateY(110%); }
.keys__row { display: flex; gap: 6px; justify-content: center; max-width: 520px; width: 100%; margin: 0 auto; }
.keys button {
  flex: 1 1 0; min-width: 0; height: var(--key-h); border-radius: 8px; background: var(--card); box-shadow: 0 1px 0 rgba(0, 0, 0, .14), inset 0 0 0 1px var(--line);
  font: 700 1.12rem/1 var(--body); text-transform: uppercase; color: var(--ink); user-select: none; -webkit-user-select: none;
  transition: background-color .15s, transform .08s;
}
.keys button:active { transform: translateY(1px); background: var(--slot); }
.keys__wide { flex: 1.55 1 0 !important; font-size: .82rem !important; letter-spacing: .03em; }
.keys__wide svg { width: 24px; height: 24px; margin: 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.keys__half { flex: .5 1 0; }
.keys button.k-hit { background: var(--hit); color: #fff; box-shadow: none; }
.keys button.k-near { box-shadow: inset 0 0 0 3px var(--near); }
.keys button.k-miss { background: var(--miss); color: var(--faint); box-shadow: none; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; top: calc(110px + env(safe-area-inset-top)); z-index: 40; transform: translate(-50%, -10px); opacity: 0;
  padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); font-weight: 700; pointer-events: none;
  transition: opacity .2s, transform .25s var(--ease); max-width: calc(100% - 32px); text-align: center; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 24px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-weight: 700; font-size: 1.05rem; transition: transform .1s, opacity .15s; }
.btn:active { transform: translateY(1px); }
.btn--ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }

/* ---------- Sheets ---------- */
.sheet { width: min(100% - 24px, 460px); max-height: min(88vh, 760px); margin: auto; padding: 26px 22px 24px; border: 0; border-radius: 22px;
  background: var(--card); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45); overflow: auto; }
.sheet::backdrop { background: rgba(28, 24, 18, .45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.sheet[open] { animation: rise .32s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } }
.sheet h2 { margin: 0 0 14px; font: 600 1.45rem/1.2 var(--display); }
.sheet__close { position: absolute; right: 12px; top: 12px; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.sheet__close:hover { background: var(--slot); }
.sheet__close svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.sheet .btn { width: 100%; margin-top: 18px; }
.sheet--small { text-align: center; }
.sheet--small p { margin: 0; color: var(--muted); }
.sheet__row { display: flex; gap: 10px; margin-top: 18px; }
.sheet__row .btn { margin-top: 0; }
/* How to play: three short steps, each with a little picture. */
.how { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; counter-reset: step; }
.how__step { counter-increment: step; }
.how__step:nth-child(1) { --n: var(--strip-1); }
.how__step:nth-child(2) { --n: var(--strip-3); }
.how__step:nth-child(3) { --n: var(--strip-4); }
.how__step h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 2px; font: 600 1.12rem/1.25 var(--display); }
.how__step h3::before { content: counter(step); display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--n); color: #fff; font: 700 .88rem/1 var(--body); }
.how__step p { margin: 0; padding-left: 36px; color: var(--muted); }
.how__tiles { display: flex; gap: 5px; margin: 10px 0 0 36px; }
.how__tiles .tile { --tile: 40px; --letter: 20px; border-radius: 8px; }
.how__tiles .tile--near::before { border-width: 2.5px; }
.how__key { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 8px 0 0 36px; padding: 0; color: var(--muted); font-size: .88rem; }
.how__key li { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; flex: none; border-radius: 4px; }
.sw--hit { background: var(--hit); }
.sw--near { border-radius: 50%; box-shadow: inset 0 0 0 3px var(--near); }
.sw--miss { background: var(--miss); box-shadow: inset 0 0 0 1px var(--line); }
.how__chain { display: flex; align-items: center; margin: 10px 0 0 36px; }
.mini { display: inline-flex; align-items: center; gap: 3px; height: 32px; padding: 0 10px; border-radius: 9px; background: var(--c); color: #fff;
  font: 700 .82rem/1 var(--body); text-transform: uppercase; letter-spacing: .14em; box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.mini--blank { background: var(--card); color: var(--muted); letter-spacing: 0; box-shadow: inset 0 0 0 2px var(--line); padding: 0 9px; }
.mini--blank i { width: 9px; height: 15px; margin-left: 1px; border-radius: 3px; background: var(--slot); }
.mini__link { width: 24px; height: 14px; flex: none; margin: 0 -3px; position: relative; z-index: 1; }
.mini__link rect { fill: none; stroke-width: 2.5; }
.mini__link rect:first-child { stroke: var(--a); }
.mini__link rect:last-child { stroke: var(--b); }
.how__step p.how__eg { margin-top: 6px; font-size: .9rem; }
.how__more { margin-top: 18px; border-top: 1px solid var(--line); }
.how__more summary { display: flex; align-items: center; justify-content: space-between; padding: 12px 2px 0; color: var(--muted); font-weight: 700;
  font-size: .92rem; cursor: pointer; list-style: none; -webkit-tap-highlight-color: transparent; }
.how__more summary::-webkit-details-marker { display: none; }
.how__more summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border: solid currentColor; border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg); transition: transform .2s; }
.how__more[open] summary::after { transform: translateY(2px) rotate(-135deg); }
.how__points { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: .92rem; }
.how__points td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.how__points td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }
.how__note { margin: 10px 0 0; color: var(--muted); font-size: .9rem; }

/* The finish */
.finish__big { margin: 6px 0 4px; font: 600 1.55rem/1.25 var(--display); text-align: center; text-wrap: balance; }
.finish__big b { color: var(--hit); }
.finish__sub { margin: 0; text-align: center; color: var(--muted); }
.finish__parts { list-style: none; margin: 16px 0 0; padding: 0; border-top: 1px solid var(--line); }
.finish__parts li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .98rem; }
.finish__parts li b { font-variant-numeric: tabular-nums; }
.finish__actions .btn { background: var(--hit); color: #fff; }
.stats__title { margin-top: 26px !important; font-size: 1.15rem !important; }
[data-finish][hidden] + .stats__title { margin-top: 0 !important; font-size: 1.45rem !important; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tiles div { padding: 10px 4px; border-radius: 12px; background: var(--slot); text-align: center; }
.tiles b { display: block; font: 700 1.35rem/1.1 var(--body); font-variant-numeric: tabular-nums; }
.tiles span { font-size: .78rem; color: var(--muted); }
.spark { margin-top: 18px; }
.spark__label { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.spark__bars { display: flex; align-items: flex-end; gap: 2px; height: 70px; border-bottom: 1px solid var(--line); }
.spark__bars span { flex: 1; min-width: 3px; border-radius: 4px 4px 0 0; background: var(--hit); }
.spark__bars span.is-today { background: var(--accent); }
.spark__bars span.is-none { background: transparent; }
.spark__empty { color: var(--muted); font-size: .95rem; }
.next { margin: 16px 0 0; text-align: center; color: var(--muted); }

/* ---------- Done for the day (under the chain, once the score sheet is closed) ---------- */
.board:has(.chain.is-done) { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.done { margin: 26px 0 0; padding: 22px 20px 20px; border-radius: 22px; background: var(--card); box-shadow: 0 1px 0 rgba(0, 0, 0, .06), inset 0 0 0 1px var(--line); text-align: center; }
.done__title { margin: 0; font: 600 1.25rem/1.25 var(--display); }
.done__score { margin: 4px 0 0; color: var(--muted); }
.done__score b { font: 600 1.6rem/1.2 var(--display); color: var(--hit); font-variant-numeric: tabular-nums; }
.done__actions { display: grid; gap: 10px; margin-top: 16px; }
.done__actions .btn { width: 100%; }
.done__actions .btn:not(.btn--ghost) { background: var(--hit); color: #fff; }
.done .next { margin-top: 14px; }
.next b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { max-width: 520px; margin: 40px auto; padding: 0 16px; text-align: center; }

/* A finished chain waves. */
.chain.is-wave .strip { animation: wave .7s var(--ease) both; animation-delay: calc(var(--i) * 55ms); }
@keyframes wave { 40% { transform: translateY(-7px) rotate(-.8deg); } }

@media (min-width: 700px) {
  .board { padding-top: 10px; }
}
@media (max-width: 560px) {
  .sheet { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 24px 24px 0 0;
    padding: 24px 20px calc(18px + env(safe-area-inset-bottom)); }
  .sheet[open] { animation: up .36s var(--ease); }
  .sheet .btn { margin-top: 16px; }
}
@keyframes up { from { transform: translateY(100%); } }
/* Short screens (an iPhone SE, or any phone with the keyboard bars showing): How to play still fits without scrolling. */
@media (max-height: 620px) {
  .sheet { padding-top: 18px; }
  .sheet h2 { margin-bottom: 8px; font-size: 1.3rem; }
  .how { gap: 11px; }
  .how__tiles .tile { --tile: 34px; --letter: 17px; }
  .how__tiles, .how__chain { margin-top: 7px; }
  .how__key { margin-top: 6px; }
  .mini { height: 28px; }
  .how__more { margin-top: 12px; }
  .how__more summary { padding-top: 9px; }
  .sheet .btn { margin-top: 12px; min-height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
