:root {
  --ink: #0d0a07;
  --ink-2: #17110b;
  --ink-3: #231a10;
  --paper: #f2dfb8;
  --paper-2: #e6cf9f;
  --paper-dim: #b9a585;
  --muted: #8c7b62;
  --amber: #ffb347;
  --hot: #ff2d78;
  --lime: #c6ff00;
  --sepia: #6b4a26;
  --display: "Fraunces", Georgia, serif;
  --mono: "Space Mono", ui-monospace, Menlo, monospace;
  --hand: "Gochi Hand", "Comic Sans MS", cursive;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; overflow: hidden; overscroll-behavior: none;
  background-image: radial-gradient(ellipse at 50% 30%, #2a1d10 0%, var(--ink) 70%);
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.grain {
  position: fixed; inset: -50%; pointer-events: none; z-index: 50; opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain { 0%,100% { transform: translate(0,0); } 33% { transform: translate(-3%,2%); } 66% { transform: translate(2%,-3%); } }
@media (prefers-reduced-motion: reduce) { .grain { animation: none; } }

.screen {
  position: fixed; inset: 0; display: none; flex-direction: column; align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  height: 100dvh;
}
.screen.is-on { display: flex; }

/* buttons: hand-cut paper */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 22px; border: 0; background: none; color: var(--paper);
  font-family: var(--hand); font-size: 22px; text-decoration: none; letter-spacing: .02em; z-index: 0;
}
.btn::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border: 2px solid var(--paper);
  border-radius: 14px 18px 12px 20px / 18px 12px 20px 14px; filter: url(#sketch);
}
.btn--hot { color: var(--ink); }
.btn--hot::before { background: var(--amber); border-color: var(--amber); }
.btn--big { font-size: 26px; min-height: 58px; padding: 10px 30px; }
.btn--ghost::before { border-style: dashed; opacity: .6; }
.btn:active { transform: translateY(1px) rotate(-.5deg); }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* START */
#start { justify-content: center; gap: 10px; text-align: center; overflow-y: auto; }
.back { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 16px; color: var(--paper-dim); font-size: 13px; text-decoration: none; letter-spacing: .1em; }
.start__pot img { width: 112px; height: 112px; border-radius: 50%; border: 3px solid var(--paper); filter: sepia(.35) url(#sketch); }
.title { margin: 6px 0 0; font-family: var(--display); font-weight: 900; font-size: clamp(56px, 18vw, 96px); line-height: .85; letter-spacing: -.02em; display: flex; flex-direction: column; }
.title span:nth-child(1) { transform: rotate(-3deg); }
.title span:nth-child(2) { color: var(--amber); transform: rotate(2deg) translateX(14px); }
.tag { margin: 6px 0 12px; font-family: var(--hand); font-size: 22px; color: var(--paper-2); }
.start__btns { display: flex; flex-direction: column; gap: 12px; width: min(300px, 100%); }
.best { min-height: 1.5em; margin: 6px 0 0; color: var(--paper-dim); font-size: 13px; }
.how { max-width: 420px; text-align: left; color: var(--paper-dim); font-size: 13px; }
.how summary { cursor: pointer; text-align: center; font-family: var(--hand); font-size: 19px; color: var(--paper); list-style: none; }
.how summary::-webkit-details-marker { display: none; }
.how summary::after { content: " +"; }
.how[open] summary::after { content: " -"; }
.how ol { padding-left: 20px; }
.how li { margin: 6px 0; }
.loading { font-size: 12px; color: var(--muted); min-height: 1.5em; margin: 0; }

/* PLAY */
#play { gap: 8px; touch-action: none; user-select: none; -webkit-user-select: none; }
.hud { width: min(520px, 100%); display: grid; grid-template-columns: 44px 1fr 1fr 1fr 44px; align-items: center; gap: 8px; }
.hud__quit { width: 44px; height: 44px; border: 0; background: none; font-size: 30px; color: var(--paper-dim); }
.hud__timer, .hud__score, .hud__count { display: flex; align-items: center; justify-content: center; gap: 6px; font-family: var(--display); font-weight: 700; font-size: 22px; }
.hud small { font-family: var(--mono); font-weight: 400; font-size: 11px; color: var(--paper-dim); margin-left: 2px; }
.hud__timer svg { width: 34px; height: 34px; transform: rotate(-90deg); }
.dial-bg { fill: none; stroke: var(--ink-3); stroke-width: 5; }
.dial { fill: none; stroke: var(--amber); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 100.53; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear, stroke .3s; }
.hud__timer.is-hot .dial { stroke: var(--hot); }
.hud__timer.is-hot #time { color: var(--hot); animation: boil .5s ease-in-out infinite alternate; }
@keyframes boil { to { transform: scale(1.12); } }

.current { min-height: 52px; font-family: var(--display); font-weight: 900; font-size: 38px; letter-spacing: .08em; text-transform: uppercase; display: flex; align-items: center; }
.current.is-good { color: var(--lime); }
.current.is-dupe { color: var(--paper-dim); }
.current.is-bad { color: var(--hot); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
.pop { position: fixed; z-index: 30; pointer-events: none; font-family: var(--hand); font-size: 30px; color: var(--lime); animation: pop .9s ease-out forwards; }
.pop.is-secret { color: var(--amber); }
@keyframes pop { from { opacity: 1; transform: translate(-50%, 0) scale(.8); } to { opacity: 0; transform: translate(-50%, -70px) scale(1.2); } }

.board-wrap { position: relative; flex: 1 1 auto; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }
.board {
  --size: min(calc(100vw - 32px), calc(100dvh - 250px), 520px);
  --n: 5;
  width: var(--size); height: var(--size); display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  gap: calc(var(--size) * .025); padding: calc(var(--size) * .03); position: relative;
}
.board::before { /* the pot: a hand-drawn cutting board */
  content: ""; position: absolute; inset: 0; background: var(--ink-3); border: 3px solid var(--sepia);
  border-radius: 22px 30px 20px 28px / 28px 20px 30px 22px; filter: url(#sketch);
}
.tile {
  position: relative; display: flex; align-items: center; justify-content: center; color: var(--ink);
  font-family: var(--display); font-weight: 900; font-size: calc(var(--size) * .5 / var(--n)); line-height: 1; text-transform: uppercase;
  transform: rotate(var(--rot, 0deg)); transition: transform .12s;
}
.tile::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--paper); border: 2px solid var(--sepia);
  border-radius: var(--shape, 16px); filter: url(#sketch); box-shadow: 0 3px 0 var(--sepia);
}
.tile.is-qu { font-size: calc(var(--size) * .375 / var(--n)); }
.tile.is-special::after { content: "\2605"; position: absolute; top: 4%; right: 8%; font-size: calc(var(--size) * .035); color: var(--hot); }
.tile.is-on { transform: rotate(0deg) scale(1.06); color: var(--ink); }
.tile.is-on::before { background: var(--amber); border-color: var(--ink); }
.board.is-good .tile.is-on::before { background: var(--lime); }
.board.is-bad .tile.is-on::before { background: var(--hot); }
.board.is-shuffling .tile { animation: stir .45s ease-in-out; }
@keyframes stir { 50% { transform: rotate(180deg) scale(.6); opacity: .4; } }
.stir { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.stir polyline { fill: none; stroke: var(--hot); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .75; filter: url(#sketch); }

.found { width: min(520px, 100%); height: 76px; overflow-y: auto; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; }
.chip { font-size: 12px; padding: 2px 9px; border: 1px solid var(--line, rgba(242,223,184,.25)); border-radius: 12px; color: var(--paper-2); text-transform: uppercase; letter-spacing: .06em; }
.chip.is-secret { border-color: var(--amber); color: var(--amber); }
.chip.is-special { border-color: var(--hot); }
.chip.is-new { animation: chipIn .3s; }
@keyframes chipIn { from { transform: scale(1.4); } }

/* PLATE */
#plate { padding-left: 0; padding-right: 0; }
.plate__scroll { width: 100%; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px 40px; display: flex; flex-direction: column; align-items: center; }
.plate__scroll > * { width: min(560px, 100%); }
.plate__h { font-family: var(--display); font-weight: 900; font-size: 52px; margin: 8px 0 6px; text-align: center; transform: rotate(-2deg); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stats b { display: block; font-family: var(--display); font-size: 30px; color: var(--amber); text-transform: uppercase; overflow-wrap: anywhere; }
.stats small { color: var(--paper-dim); font-size: 12px; }
.missed { color: var(--paper-dim); font-size: 13px; text-align: center; }
.missed b { color: var(--paper); text-transform: uppercase; }
.words { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.words .chip { cursor: pointer; font-size: 13px; padding: 5px 11px; }
.words .chip.is-off { opacity: .35; text-decoration: line-through; }
.plate__sub { font-family: var(--hand); font-weight: 400; font-size: 26px; margin: 22px 0 6px; text-align: center; }
.hint { color: var(--paper-dim); font-size: 12px; text-align: center; margin: 6px 0 0; }
.flavors { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.flavor { font-family: var(--hand); font-size: 19px; padding: 6px 14px; min-height: 44px; border: 2px solid var(--paper-dim); border-radius: 18px 14px 20px 12px / 12px 20px 14px 18px; background: none; color: var(--paper-2); }
.flavor[aria-checked="true"] { background: var(--paper); color: var(--ink); border-color: var(--paper); }

.sheet {
  position: relative; margin: 20px 0 8px; padding: 22px 20px 26px; color: var(--ink); z-index: 0;
  transform: rotate(-.6deg);
}
.sheet::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, rgba(107,74,38,.18) 27px 28px);
  border-radius: 6px 10px 4px 12px; filter: url(#sketch); box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.sheet__title { margin: 0; font-family: var(--display); font-weight: 900; font-size: 34px; line-height: 1; }
.sheet__style { margin: 4px 0 12px; font-family: var(--hand); font-size: 18px; color: var(--sepia); }
.sheet__body { font-family: var(--hand); font-size: 19px; line-height: 28px; }
.sheet__body h4 { margin: 14px 0 0; font-family: var(--mono); font-size: 11px; letter-spacing: .15em; text-transform: uppercase; color: var(--sepia); }
.sheet__body p { margin: 0; }
.sheet__body mark { background: none; color: var(--hot); font-weight: 700; }

.cook { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 16px; text-align: center; }
.cook__msg { margin: 0; font-family: var(--hand); font-size: 20px; color: var(--paper-2); min-height: 1.2em; }
.cook audio { width: 100%; }
.cook__after { display: flex; gap: 10px; }
.pot-anim { display: flex; gap: 8px; height: 40px; align-items: flex-end; }
.pot-anim span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--paper); animation: bubble 1.2s ease-in infinite; }
.pot-anim span:nth-child(2) { animation-delay: .3s; }
.pot-anim span:nth-child(3) { animation-delay: .6s; }
@keyframes bubble { from { transform: translateY(0) scale(.6); opacity: 1; } to { transform: translateY(-30px) scale(1.2); opacity: 0; } }
.again { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 26px; }
[hidden] { display: none !important; }
button.chip { background: none; font-family: var(--mono); }
.stats b.is-word { font-size: clamp(18px, 6vw, 28px); line-height: 1.2; padding-top: 6px; }
.stats { grid-template-columns: repeat(2, 1fr); }
.stats > div:last-child { grid-column: 1 / -1; }
.stats b.is-word { overflow-wrap: normal; }
.next { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 14px 0 18px; }
.next .btn { width: min(320px, 100%); }
.next small { font-size: 15px; opacity: .7; }
.words--plain .chip { cursor: default; }
.songbox { border-top: 2px dashed rgba(242,223,184,.2); margin-top: 18px; padding-top: 4px; }

/* shake to mix */
.board.is-lidded .tile::before { background: var(--paper-2); }
.board.is-lidded .tile { animation: idle 1.8s ease-in-out infinite; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes idle { 50% { transform: rotate(calc(var(--rot, 0deg) * -1.5)) translateY(-3%); } }
.board.is-mixing .tile { transition: transform .07s linear; }
.board.is-mixing { animation: potshake .14s linear infinite; }
@keyframes potshake { 25% { transform: translate(-1.5%, .8%) rotate(-1deg); } 75% { transform: translate(1.5%, -.8%) rotate(1deg); } }
.board.is-landing .tile { animation: land .45s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes land { from { transform: translateY(-60%) scale(1.35) rotate(25deg); opacity: 0; } }
.mixer {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  text-align: center; padding: 16px; pointer-events: none;
}
.mixer > * { pointer-events: auto; }
.mixer__msg {
  margin: 0; max-width: 300px; font-family: var(--hand); font-size: 30px; line-height: 1.15; color: var(--paper);
  text-shadow: 0 2px 0 var(--ink), 0 0 18px var(--ink), 0 0 30px var(--ink);
  animation: wobble 1.2s ease-in-out infinite;
}
@keyframes wobble { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@media (prefers-reduced-motion: reduce) { .board.is-mixing, .mixer__msg, .board.is-lidded .tile { animation: none; } }

/* how to play */
.how-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(13,10,7,.78); backdrop-filter: blur(3px); }
.how-card {
  position: relative; z-index: 0; width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 22px 20px 20px; color: var(--ink); transform: rotate(-.6deg);
}
.how-card::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, rgba(107,74,38,.15) 27px 28px);
  border-radius: 8px 12px 6px 14px; filter: url(#sketch); box-shadow: 0 14px 40px rgba(0,0,0,.6);
}
.how-card__h { margin: 0 0 6px; font-family: var(--display); font-weight: 900; font-size: 40px; line-height: 1; }
.how-steps { margin: 0; padding-left: 22px; font-family: var(--hand); font-size: 17px; line-height: 1.3; }
.how-steps li { margin: 7px 0; }
.how-steps b { font-family: var(--display); font-size: 17px; }
.how-steps .star { color: var(--hot); }
.how-card__btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.how-card .btn:not(.btn--hot) { color: var(--ink); }
.how-card .btn:not(.btn--hot)::before { border-color: var(--ink); }
#how-open { font-size: 20px; min-height: 44px; }

/* demo */
.demo-cap {
  position: absolute; z-index: 20; left: 16px; right: 16px; top: max(70px, calc(env(safe-area-inset-top) + 60px)); margin: 0 auto; max-width: 460px;
  padding: 10px 14px; text-align: center; font-family: var(--hand); font-size: 20px; line-height: 1.25; color: var(--ink);
  background: var(--amber); border-radius: 14px 18px 12px 20px / 18px 12px 20px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.demo-skip { display: none; position: absolute; z-index: 21; bottom: max(16px, env(safe-area-inset-bottom)); right: 16px; border: 0; background: none; color: var(--paper-dim); font-size: 14px; min-height: 44px; padding: 0 8px; }
#play.is-demo .demo-skip { display: block; }
#play.is-demo .hud__quit { visibility: hidden; }
#play.is-demo .mixer__msg { display: none; }
.finger {
  position: fixed; z-index: 40; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; pointer-events: none;
  border: 3px solid var(--ink); background: rgba(242,223,184,.55); box-shadow: 0 6px 14px rgba(0,0,0,.45);
  transition: left .32s ease, top .32s ease, transform .15s;
}
.finger.is-down { transform: scale(.8); background: rgba(255,179,71,.75); }
.demo-done { margin: -4px 0 6px; text-align: center; font-family: var(--hand); font-size: 22px; color: var(--amber); }
.how-card:focus { outline: none; }

/* levels + leaderboard */
.btn__sub { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .75; margin-left: 4px; }
.start__links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.start__links .btn { font-size: 19px; min-height: 44px; padding: 8px 16px; }
.level-tag { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); }
.level-result { margin: -4px 0 8px; text-align: center; font-family: var(--hand); font-size: 22px; color: var(--hot); }
.level-result.is-pass { color: var(--lime); }
.lb-post { margin: 4px 0 8px; text-align: center; }
.lb-post__h { margin: 0 0 8px; font-family: var(--hand); font-size: 20px; }
.lb-post__row { display: flex; gap: 8px; justify-content: center; }
.lb-post input {
  flex: 1 1 auto; max-width: 220px; min-height: 48px; padding: 8px 12px; font: 16px var(--mono); color: var(--ink);
  background: var(--paper); border: 2px solid var(--paper); border-radius: 12px;
}
.lb-post__msg { margin: 8px 0 0; font-family: var(--hand); font-size: 18px; color: var(--amber); min-height: 1.2em; }
.lb-tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.lb-tab { flex: 1; min-height: 40px; border: 2px solid var(--ink); border-radius: 12px; background: none; color: var(--ink); font-family: var(--hand); font-size: 17px; }
.lb-tab[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.lb-list { margin: 0; padding: 0; list-style: none; counter-reset: lb; }
.lb-list li { counter-increment: lb; display: grid; grid-template-columns: 28px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed rgba(107,74,38,.35); }
.lb-list li::before { content: counter(lb); grid-row: 1 / 3; font-family: var(--display); font-weight: 900; font-size: 20px; color: var(--sepia); }
.lb-list li.lb-empty { display: block; font-family: var(--hand); font-size: 18px; border: 0; }
.lb-list li.lb-empty::before { content: none; }
.lb-list li.is-me { background: rgba(255,179,71,.35); border-radius: 8px; }
.lb-nick { font-family: var(--display); font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.lb-list b { grid-row: 1 / 3; grid-column: 3; font-family: var(--display); font-size: 22px; }
.lb-list small { grid-column: 2; font-size: 11px; color: var(--sepia); }
.lb-note { font-size: 11px; color: var(--sepia); margin: 10px 0 0; }
.start__btns .btn { flex-direction: column; gap: 0; line-height: 1.1; padding-top: 8px; padding-bottom: 8px; }
.start__btns .btn__sub { margin: 2px 0 0; }

/* site menu: the HUD has its own menu button, so hide the floating one while playing */
.hud__menu { width: 44px; height: 44px; border: 0; background: none; color: var(--paper-dim); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.hud__menu span { display: grid; gap: 4px; }
.hud__menu i { display: block; width: 20px; height: 2px; border-radius: 2px; background: currentColor; }
body:has(#play.is-on) .cm-btn { display: none; }
