@font-face {
  font-family: 'Pixelify';
  src: url(../assets/fonts/pixelify.woff2) format('woff2');
  font-weight: 400 700;
  font-display: block;
}

:root {
  --bg: #2b1d3f;
  --bg2: #321f4a;
  --well: #1a1229;
  --panel: #1f152f;
  --line: #4b3568;
  --outline: #140b21;
  --ink: #fff4fb;
  --muted: #c4b0dc;
  --dim: #ab98c8;
  --pink: #ff9ec7;
  --pink-deep: #ff6fa8;
  --mint: #8ee8b0;
  --lav: #c9a8ff;
  --yellow: #ffe066;
  --aqua: #7fe3f0;
  --radius: 6px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pixelify', ui-rounded, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "clig" 0; /* the pixel font's fi/fl ligatures render wrong */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
}
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 50% -10%, rgba(255, 158, 199, .16), transparent 55%),
    linear-gradient(45deg, var(--bg2) 25%, transparent 25%, transparent 75%, var(--bg2) 75%),
    linear-gradient(45deg, var(--bg2) 25%, transparent 25%, transparent 75%, var(--bg2) 75%);
  background-size: 100% 100%, 32px 32px, 32px 32px;
  background-position: 0 0, 0 0, 16px 16px;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, button { -webkit-user-select: none; user-select: none; }
input[type=text], input:not([type]) { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
svg { fill: currentColor; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px);
  display: none; flex-direction: column;
}
.screen.active { display: flex; animation: screen-in .28s steps(6) both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  font-size: 18px; font-weight: 600; letter-spacing: .02em;
  color: var(--outline);
  background: #fff4fb;
  border: 3px solid var(--outline);
  border-radius: var(--radius);
  box-shadow: inset 0 -4px 0 rgba(20, 11, 33, .18), 0 4px 0 var(--outline);
  transition: transform .06s, box-shadow .06s;
  touch-action: manipulation;
}
.btn:active, .btn.pressed { transform: translateY(3px); box-shadow: inset 0 -2px 0 rgba(20, 11, 33, .18), 0 1px 0 var(--outline); }
.btn.pink { background: var(--pink); }
.btn.mint { background: var(--mint); }
.btn.lav { background: var(--lav); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); box-shadow: 0 4px 0 var(--outline); }
.btn.small { min-height: 44px; padding: 6px 14px; font-size: 16px; }
.btn.danger { color: #ff9aa8; border-color: #6b3050; }
.btn:focus-visible, .icon-btn:focus-visible, .round:focus-visible, .pill:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.icon-btn {
  width: 48px; height: 48px; display: grid; place-items: center;
  background: var(--panel); color: var(--pink);
  border: 3px solid var(--outline); border-radius: var(--radius);
  box-shadow: 0 3px 0 var(--outline), inset 0 0 0 2px var(--line);
  touch-action: manipulation;
}
.icon-btn svg { width: 24px; height: 24px; shape-rendering: crispEdges; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--outline), inset 0 0 0 2px var(--line); }
.icon-btn.small { width: calc(44px * var(--ui, 1)); height: calc(44px * var(--ui, 1)); }

/* ---------- Title ---------- */
#title { align-items: center; justify-content: space-between; overflow: hidden; }
.title-top { width: 100%; max-width: 520px; display: flex; justify-content: space-between; }
.logo { text-align: center; margin-top: 2vh; }
.logo-small {
  font-size: clamp(22px, 6vw, 34px); color: var(--pink); font-weight: 700;
  text-shadow: 3px 3px 0 var(--outline);
  transform: rotate(-4deg); display: inline-block;
}
.logo-big { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 4px; }
.logo-word { display: flex; gap: clamp(2px, .8vw, 5px); }
.logo-big .ch {
  display: grid; place-items: center;
  width: clamp(34px, 10.4vw, 58px); height: clamp(38px, 11.6vw, 64px);
  font-size: clamp(28px, 8.6vw, 48px); font-weight: 700; color: var(--outline);
  background: var(--c);
  border: 3px solid var(--outline); border-radius: 4px;
  box-shadow: inset 4px 4px 0 rgba(255, 255, 255, .45), inset -4px -4px 0 rgba(0, 0, 0, .18), 0 4px 0 var(--outline);
  animation: letter-hop 2.6s steps(2) infinite;
  animation-delay: calc(var(--i) * 90ms);
}
@keyframes letter-hop { 0%, 86%, 100% { transform: translateY(0); } 90% { transform: translateY(-6px); } }
.logo-sub { margin-top: 14px; color: var(--muted); font-size: 16px; }
.logo-sub b { color: var(--ink); font-weight: 600; }
.heart { color: var(--pink); display: inline-block; animation: beat 1.2s steps(2) infinite; }
@keyframes beat { 50% { transform: scale(1.25); } }

.friends { display: flex; justify-content: center; align-items: flex-end; gap: 0; height: clamp(56px, 15vw, 88px); width: 100%; max-width: 560px; }
.friends img { flex: 1 1 0; min-width: 0; max-height: 100%; height: auto; object-fit: contain; width: 0; image-rendering: auto; animation: friend-hop 1.8s steps(3) infinite; animation-delay: calc(var(--i) * 160ms); filter: drop-shadow(0 3px 0 rgba(0,0,0,.25)); }
.friends img:nth-child(4) { flex-grow: 1.25; max-height: 118%; }
@keyframes friend-hop { 0%, 70%, 100% { transform: translateY(0); } 80% { transform: translateY(-10px); } }

.menu { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 380px; margin-bottom: 1vh; }
.mode-btn { flex-direction: column; gap: 0; min-height: 66px; }
.mode-name { font-size: 24px; font-weight: 700; line-height: 1.1; }
.mode-desc { font-size: 14px; font-weight: 500; opacity: .75; }
.menu .ghost { align-self: center; }

.a2hs {
  position: static; width: 100%; flex: none;
  margin: 8px auto 0; max-width: 420px;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 3px solid var(--line); border-radius: var(--radius);
}
.a2hs .x { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--muted); width: 36px; height: 36px; }

/* Short landscape phones: logo and menu side by side */
@media (orientation: landscape) and (max-height: 540px) {
  #title { display: none; }
  #title.active { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr auto; column-gap: 24px; align-items: center; justify-items: center; }
  #title .title-top { grid-column: 1 / 3; max-width: none; }
  #title .logo { grid-column: 1; grid-row: 2; margin-top: 0; align-self: start; }
  #title .friends { grid-column: 1; grid-row: 3; height: 56px; max-width: 420px; }
  #title .menu { grid-column: 2; grid-row: 2 / 4; gap: 10px; margin: 0; }
  #title .mode-btn { min-height: 54px; }
  #title .logo-big .ch { width: 34px; height: 38px; font-size: 26px; }
  #title .logo-sub { margin-top: 8px; font-size: 14px; }
  .title-top { position: absolute; z-index: 2; top: calc(var(--safe-t) + 8px); left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px); width: auto; pointer-events: none; }
  .title-top .icon-btn { pointer-events: auto; }
  #title .menu { margin-top: 44px; max-width: 340px; }
  .a2hs { display: none !important; }
}

/* ---------- Game ---------- */
#game { padding-left: calc(var(--safe-l) + 8px); padding-right: calc(var(--safe-r) + 8px); gap: 6px; }
.hud { display: flex; align-items: center; gap: 8px; flex: none; }
.hud-stat:nth-child(2) { flex: 1.5; }
.hud-stat {
  flex: 1; min-width: 0; text-align: center;
  background: var(--panel); border: 3px solid var(--outline); border-radius: var(--radius);
  box-shadow: inset 0 0 0 2px var(--line);
  padding: 3px 4px 4px;
}
.hud-stat label, .panel label, .minis label { display: block; font-size: calc(12px * var(--ui, 1)); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; line-height: 1.1; }
.hud-stat output { display: block; font-size: calc(19px * var(--ui, 1)); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-stat output.bump { animation: bump .25s steps(3); color: var(--yellow); }
@keyframes bump { 40% { transform: scale(1.18); } }

.target { flex: none; display: flex; align-items: center; gap: 8px; font-size: calc(13px * var(--ui, 1)); color: var(--muted); padding: 0 2px; }
.target-bar { flex: 1; height: 10px; background: var(--panel); border: 2px solid var(--outline); border-radius: 3px; overflow: hidden; }
.target-bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--pink) 0 6px, var(--pink-deep) 6px 12px); transition: width .3s steps(6); }
.target.won .target-bar i { background: repeating-linear-gradient(90deg, var(--yellow) 0 6px, #ffc93c 6px 12px); }
.target span { white-space: nowrap; }

.playfield { flex: 1; min-height: 0; display: flex; justify-content: center; align-items: flex-start; gap: 6px; }
.side { display: flex; flex-direction: column; gap: 8px; width: var(--side-w, 64px); flex: none; }
.panel {
  background: var(--panel); border: 3px solid var(--outline); border-radius: var(--radius);
  box-shadow: inset 0 0 0 2px var(--line);
  padding: 4px 3px 3px; text-align: center;
}
.panel canvas { display: block; margin: 2px auto 0; }
#hold-panel.denied { animation: shake-x .2s steps(4); }
@keyframes shake-x { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.mascot { position: relative; display: grid; place-items: center; }
.mascot img { width: 100%; height: auto; animation: bob 1.2s steps(2) infinite; filter: drop-shadow(0 3px 0 rgba(0,0,0,.3)); }
.mascot.cheer img { animation: cheer .5s steps(3) infinite; }
.mascot.nervous img { animation: bob .45s steps(2) infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes cheer { 50% { transform: translateY(-9px) rotate(-4deg); } }
.minis { display: flex; flex-direction: column; gap: 6px; text-align: center; }
.minis output { display: block; font-size: calc(16px * var(--ui, 1)); font-weight: 600; font-variant-numeric: tabular-nums; }

.well { position: relative; flex: none; }
.well canvas { display: block; }
.well.danger::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; top: var(--peek, 0px);
  border-radius: 4px; pointer-events: none;
  box-shadow: 0 0 0 3px rgba(255, 111, 168, .9), 0 0 18px rgba(255, 111, 168, .6);
  animation: danger-pulse .8s steps(2) infinite;
}
@keyframes danger-pulse { 50% { opacity: .35; } }
.well.shake { animation: well-shake .18s steps(3); }
.well.shake-big { animation: well-shake-big .35s steps(5); }
@keyframes well-shake { 33% { transform: translateY(3px); } 66% { transform: translateY(-1px); } }
@keyframes well-shake-big { 20% { transform: translate(-4px, 4px); } 40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, 2px); } 80% { transform: translate(2px, -1px); } }

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.pop {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  font-weight: 700; text-align: center; white-space: nowrap;
  color: var(--ink); font-size: calc(var(--cell) * 1.05);
  text-shadow: 3px 3px 0 var(--outline), -1px -1px 0 var(--outline), 1px -1px 0 var(--outline), -1px 1px 0 var(--outline);
  animation: pop-up 1.1s steps(10) forwards;
}
.pop.big { font-size: calc(var(--cell) * 1.6); color: var(--yellow); }
.pop.pink { color: var(--pink); }
.pop.mint { color: var(--mint); }
.pop.aqua { color: var(--aqua); }
.pop small { display: block; font-size: .55em; color: var(--ink); }
@keyframes pop-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -110%); }
}
.mascot.visit img { animation: visit .35s steps(4), cheer .5s steps(3) .35s infinite; }
@keyframes visit { from { transform: scale(.55) translateY(20%); } 60% { transform: scale(1.12); } }
.mascot .bubble {
  position: absolute; z-index: 3; left: 50%; bottom: 88%;
  transform: translateX(-50%);
  padding: 3px 7px; font-size: max(12px, calc(var(--cell) * .55)); font-weight: 700; color: var(--outline);
  background: #fff; border: 3px solid var(--outline); border-radius: 6px;
  white-space: nowrap; pointer-events: none;
  animation: bubble 1.5s steps(10) forwards;
}
.mascot .bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--outline); border-bottom: 0; }
@keyframes bubble { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.6); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 20%, 85% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -6px); } }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--cell) * 3.6); font-weight: 700; color: var(--yellow);
  text-shadow: 4px 4px 0 var(--outline);
  pointer-events: none;
}
.countdown span { animation: count .7s steps(7) forwards; }
@keyframes count { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(.8); } }

/* ---------- Pad ---------- */
.pad { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 0; }
.pad.lefty { flex-direction: row-reverse; }
.dpad { position: relative; width: var(--dpad, 156px); height: var(--dpad, 156px); touch-action: none; flex: none; }
.dpad-cross { position: absolute; inset: 0; display: grid; grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr; filter: drop-shadow(0 4px 0 var(--outline)); }
.d { background: #3d2c58; position: relative; }
.d.up { grid-area: 1 / 2; border-radius: 6px 6px 0 0; }
.d.left { grid-area: 2 / 1; border-radius: 6px 0 0 6px; }
.d.mid { grid-area: 2 / 2; }
.d.right { grid-area: 2 / 3; border-radius: 0 6px 6px 0; }
.d.down { grid-area: 3 / 2; border-radius: 0 0 6px 6px; }
.d { outline: 3px solid var(--outline); outline-offset: -1px; }
.d.mid { outline: none; box-shadow: 0 -3px 0 #3d2c58, 0 3px 0 #3d2c58; }
.d.mid::after { content: ''; position: absolute; inset: 30%; border-radius: 50%; background: #2c1f40; }
.d i { position: absolute; inset: 0; margin: auto; width: 0; height: 0; border: 9px solid transparent; }
.d.up i { border-bottom: 12px solid var(--muted); border-top: 0; transform: translateY(-2px); }
.d.down i { border-top: 12px solid var(--muted); border-bottom: 0; }
.d.left i { border-right: 12px solid var(--muted); border-left: 0; }
.d.right i { border-left: 12px solid var(--muted); border-right: 0; }
.d.on { background: #5a4180; }
.d.on i { filter: brightness(1.4); }
.d.up.on i { border-bottom-color: var(--pink); }
.d.on:not(.up) i { border-top-color: var(--pink); border-left-color: var(--pink); border-right-color: var(--pink); }
.d.down i { border-left-color: transparent !important; border-right-color: transparent !important; }
.d.left i, .d.right i { border-top-color: transparent !important; border-bottom-color: transparent !important; }
.d.up i { border-left-color: transparent !important; border-right-color: transparent !important; }

.pad-mid { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.pill {
  min-width: calc(68px * var(--ui, 1)); height: calc(44px * var(--ui, 1)); padding: 0 12px;
  font-size: calc(14px * var(--ui, 1)); font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); background: #3d2c58;
  border: 3px solid var(--outline); border-radius: 22px;
  box-shadow: 0 3px 0 var(--outline);
  touch-action: none;
}
.pill.on, .pill:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--outline); color: var(--pink); }
.pill:disabled { opacity: .4; }

.ab { position: relative; width: calc(var(--btn, 72px) * 2.15); height: calc(var(--btn, 72px) * 1.55); flex: none; }
.round {
  position: absolute; width: var(--btn, 72px); height: var(--btn, 72px);
  border-radius: 50%; border: 3px solid var(--outline);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .2), inset 0 4px 0 rgba(255, 255, 255, .35), 0 4px 0 var(--outline);
  display: grid; place-items: center; padding: 0;
  touch-action: none;
}
.round span { font-size: calc(var(--btn, 72px) * .36); font-weight: 700; color: var(--outline); line-height: 1; }
.round em { position: absolute; bottom: calc(var(--btn, 72px) * .1); font-style: normal; font-size: calc(var(--btn, 72px) * .2); color: rgba(20, 11, 33, .6); line-height: 1; }
.round.a { right: 0; top: 0; background: var(--pink); }
.round.b { left: 0; bottom: 0; background: var(--lav); }
.pad.lefty .round.a { right: auto; left: 0; }
.pad.lefty .round.b { left: auto; right: 0; }
.round.on { transform: translateY(3px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2), inset 0 4px 0 rgba(255, 255, 255, .35), 0 1px 0 var(--outline); filter: brightness(1.08); }

/* Landscape / wide: pads on either side of the board */
#game.wide.active { display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: auto 1fr; column-gap: 16px; row-gap: 8px; }
#game.wide .hud { grid-column: 1; grid-row: 1; align-self: start; justify-self: center; width: 100%; max-width: calc(300px * var(--ui, 1)); display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; }
#game.wide .hud .icon-btn { grid-row: 1; grid-column: 1; }
#game.wide .hud .hud-stat:nth-child(2) { grid-row: 1; grid-column: 2 / 4; }
#game.wide .hud .hud-stat:nth-child(3) { grid-row: 2; grid-column: 1 / 3; }
#game.wide .hud .hud-stat:nth-child(4) { grid-row: 2; grid-column: 3; }
#game.wide .target { grid-column: 3; grid-row: 1; align-self: start; max-width: 300px; width: 100%; justify-self: center; }
#game.wide .playfield { grid-column: 2; grid-row: 1 / 3; }
#game.wide .pad { display: contents; }
#game.wide .dpad { grid-column: 1; grid-row: 2; align-self: center; justify-self: center; }
#game.wide .ab { grid-column: 3; grid-row: 2; align-self: center; justify-self: center; transform: translateY(calc(var(--btn, 72px) * -0.3)); }
#game.wide .pad-mid { grid-column: 3; grid-row: 2; align-self: center; justify-self: center; transform: translateY(calc(var(--btn, 72px) * 1.45)); }
#game.wide .pad.lefty .dpad { grid-column: 3; }
#game.wide .pad.lefty .ab, #game.wide .pad.lefty .pad-mid { grid-column: 1; }
#game.swipe .pad { display: none; }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(14, 8, 24, .66); z-index: 10; animation: fade .2s steps(4); }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; inset: 0; z-index: 11; display: flex; align-items: flex-end; justify-content: center; padding: 12px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px); pointer-events: none; }
.sheet.full { align-items: stretch; padding-top: calc(var(--safe-t) + 12px); }
.sheet-card {
  position: relative; pointer-events: auto;
  width: 100%; max-width: 420px;
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 24px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: #2a1d3e; border: 3px solid var(--outline); border-radius: 10px;
  box-shadow: inset 0 0 0 3px var(--line), 0 6px 0 var(--outline);
  padding: 20px 18px 18px; text-align: center;
  animation: sheet-in .26s steps(6) both;
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet-card.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; text-align: left; max-width: 520px; overscroll-behavior: contain; }
.sheet-head { position: sticky; top: -20px; margin: -20px -18px 8px; padding: 16px 18px 12px; display: flex; justify-content: space-between; align-items: center; background: #2a1d3e; border-bottom: 3px solid var(--line); z-index: 2; border-radius: 10px 10px 0 0; }
.sheet-card h2 { margin: 0 0 6px; font-size: 30px; color: var(--pink); text-shadow: 3px 3px 0 var(--outline); }
.sheet-head h2 { margin: 0; font-size: 26px; }
.sheet-card h3 { margin: 20px 0 8px; font-size: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.sheet-pet { width: 88px; height: 88px; margin: -12px auto 2px; display: block; filter: drop-shadow(0 4px 0 rgba(0,0,0,.35)); animation: bob 1.2s steps(2) infinite; }
.sheet-pet.sleepy { animation-duration: 2.4s; }
.sheet-note { margin: 0 0 12px; color: var(--muted); font-size: 16px; line-height: 1.35; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions > .btn { flex: 1; }
.sheet-actions .go { flex: 1.6; font-size: 22px; min-height: 56px; }
.sheet-actions.col { flex-direction: column; }
.row2 { display: flex; gap: 10px; }
.row2 .btn { flex: 1; }
.hint { color: var(--dim); font-size: 14px; margin: -2px 0 8px; line-height: 1.3; }
.credit { text-align: center; color: var(--dim); margin: 26px 0 4px; font-size: 14px; }

/* speed picker */
.speed { margin: 8px 0 4px; }
.speed-top { display: flex; align-items: center; justify-content: center; gap: 12px; }
.speed-btn { width: 56px; height: 56px; font-size: 30px; font-weight: 700; padding: 0; }
.speed-val { min-width: 118px; }
.speed-num { font-size: 46px; font-weight: 700; line-height: 1; color: var(--ink); text-shadow: 3px 3px 0 var(--outline); font-variant-numeric: tabular-nums; }
.speed-name { font-size: 15px; color: var(--pink); margin-top: 2px; }
.speed-bar { display: flex; gap: 2px; margin: 12px 0 8px; height: 14px; }
.speed-bar i { flex: 1; background: #3d2c58; border-radius: 2px; }
.speed-bar i.on { background: var(--c); }
.speed-presets { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 4px 12px; font-size: 14px; font-weight: 600;
  background: #3d2c58; color: var(--muted); border: 2px solid var(--outline); border-radius: 18px;
  touch-action: manipulation;
}
.chip.on { background: var(--pink); color: var(--outline); }
.speed-sub { font-size: 13px; color: var(--dim); margin-top: 6px; }

/* toggles, segments, sliders, fields */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; font-size: 17px; text-align: left; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { flex: none; width: 52px; height: 30px; border-radius: 15px; background: #3d2c58; border: 3px solid var(--outline); position: relative; transition: background .1s; }
.toggle i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .12s steps(3); }
.toggle input:checked + i { background: var(--mint); }
.toggle input:checked + i::after { transform: translateX(22px); background: #fff; }
.toggle input:focus-visible + i { outline: 3px solid var(--yellow); outline-offset: 2px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: #1f152f; padding: 4px; border: 3px solid var(--outline); border-radius: 8px; margin-bottom: 6px; }
.seg button { flex: 1 0 auto; min-height: 44px; background: none; border: 0; border-radius: 5px; font-size: 15px; font-weight: 600; color: var(--muted); padding: 4px 6px; touch-action: manipulation; }
.seg button.on { background: var(--pink); color: var(--outline); box-shadow: 0 2px 0 var(--outline); }
.slider { margin: 8px 0 10px; }
.slider label { display: flex; justify-content: space-between; font-size: 16px; margin-bottom: 4px; }
.slider output { color: var(--pink); font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 10px; background: #1f152f; border: 2px solid var(--outline); border-radius: 5px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; background: var(--pink); border: 3px solid var(--outline); border-radius: 50%; }
input[type=range]::-moz-range-track { height: 10px; background: #1f152f; border: 2px solid var(--outline); border-radius: 5px; }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; background: var(--pink); border: 3px solid var(--outline); border-radius: 50%; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; font-size: 17px; }
.field input { width: 55%; min-height: 44px; font: inherit; font-size: 18px; color: var(--ink); background: #1f152f; border: 3px solid var(--outline); border-radius: 6px; padding: 6px 10px; touch-action: manipulation; }
.field input:focus { outline: 3px solid var(--pink); }

/* game over */
.over-tip { margin: 12px 0 0; padding: 8px 10px; font-size: 15px; line-height: 1.35; color: var(--ink); background: #1f152f; border: 2px dashed var(--line); border-radius: 6px; text-align: left; }
.over-tip:empty { display: none; }
.wide-btn { width: 100%; margin-top: 4px; }
.over-msg { color: var(--ink); font-size: 18px; margin: 0 0 6px; line-height: 1.3; min-height: 1em; }
.big-number { font-size: 48px; font-weight: 700; color: var(--yellow); text-shadow: 3px 3px 0 var(--outline); line-height: 1.1; margin: 4px 0 10px; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat-grid div { background: #1f152f; border: 2px solid var(--outline); border-radius: 6px; padding: 6px 4px; }
.stat-grid label { display: block; font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.stat-grid b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat-grid .best b { color: var(--yellow); }
.new-best { display: inline-block; margin-bottom: 4px; padding: 3px 10px; font-size: 15px; font-weight: 700; color: var(--outline); background: var(--yellow); border: 2px solid var(--outline); border-radius: 4px; animation: beat .6s steps(2) infinite; }

/* stats screen */
.best-cards { display: grid; gap: 10px; }
.best-card { display: flex; gap: 12px; align-items: center; background: #1f152f; border: 3px solid var(--outline); border-radius: 8px; padding: 10px 12px; }
.best-card img { width: 56px; height: 56px; flex: none; }
.best-card h4 { margin: 0; font-size: 18px; color: var(--pink); }
.best-card p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.best-card .val { margin-left: auto; font-size: 24px; font-weight: 700; color: var(--yellow); text-align: right; font-variant-numeric: tabular-nums; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding: 6px; background: #1f152f; border: 3px solid var(--outline); border-radius: 8px; }
.chart i { flex: 1; background: var(--lav); border-radius: 2px 2px 0 0; min-height: 3px; }
.chart i.top { background: var(--yellow); }
.chart-empty { color: var(--dim); font-size: 15px; padding: 12px; text-align: center; background: #1f152f; border: 3px solid var(--outline); border-radius: 8px; }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.totals div { background: #1f152f; border: 2px solid var(--outline); border-radius: 6px; padding: 8px; }
.totals label { display: block; font-size: 12px; color: var(--dim); text-transform: uppercase; }
.totals b { font-size: 20px; }

.howto ul { margin: 0; padding-left: 0; list-style: none; }
.howto li { padding: 7px 0; border-bottom: 2px dashed var(--line); font-size: 16px; line-height: 1.35; }
.howto li b { color: var(--pink); }
.howto .tips li::before { content: '\2665'; color: var(--pink); margin-right: 8px; }

/* confetti & toast */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti i { position: absolute; top: -24px; width: 10px; height: 10px; background: var(--c); animation: fall var(--t, 2.4s) linear forwards; animation-delay: var(--d, 0s); }
.confetti i.h { background: none; width: auto; height: auto; color: var(--c); font-size: 20px; font-style: normal; }
.confetti img { position: absolute; top: calc(var(--safe-t) - 90px); width: 72px; animation: parade 2.8s steps(14) forwards; animation-delay: var(--d, 0s); }
@keyframes fall { to { transform: translate(var(--x, 0), 110vh) rotate(720deg); } }
@keyframes parade { 0% { transform: translateY(0); } 25%, 75% { transform: translateY(120px); } 100% { transform: translateY(0); } }
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 14px); z-index: 30;
  transform: translate(-50%, -140%);
  padding: 10px 16px; font-size: 16px; font-weight: 600; color: var(--outline);
  background: var(--yellow); border: 3px solid var(--outline); border-radius: 8px; box-shadow: 0 4px 0 var(--outline);
  transition: transform .25s steps(5), visibility 0s .25s; white-space: nowrap; pointer-events: none;
  visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform .25s steps(5); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  /* Feedback text must still appear: show it, hold, then fade, with no movement. */
  .pop, .mascot .bubble { animation: rm-hold 1.2s linear forwards !important; }
  .countdown span { animation: rm-hold .55s linear forwards !important; }
  .coach-demo * { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pause-vol { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; margin-top: 4px; }
.pause-vol .slider { margin: 4px 0; }
.pause-vol .slider label { font-size: 14px; }
.mission {
  position: relative; flex: none; align-self: center;
  width: max-content; max-width: 100%;
  padding: 6px 10px; font-size: max(13px, calc(var(--cell) * .6)); font-weight: 600; color: var(--outline); text-align: center;
  background: var(--yellow); border: 3px solid var(--outline); border-radius: 6px; box-shadow: 0 3px 0 var(--outline);
  pointer-events: none; z-index: 2;
}
.mission small { font-size: .8em; opacity: .65; margin-right: 4px; }
.mission.done { background: var(--mint); }
.mission.bump { animation: bump .3s steps(3); }
@keyframes rm-hold { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
@media (hover: hover) {
  .btn:hover { filter: brightness(1.05); }
  .chip:hover, .seg button:hover { color: var(--ink); }
}

/* ---------- Coach (tutorial) ---------- */
.sheet-card.coach { padding-top: 16px; }
.coach-skip { position: absolute; z-index: 2; top: 6px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 16px; padding: 8px; min-height: 44px; }
.coach-demo { position: relative; height: 190px; margin: 6px auto 12px; width: 260px; }
.cd-well { position: absolute; left: 70px; top: 0; width: 120px; height: 180px; background: var(--well); border: 4px solid var(--outline); box-shadow: inset 0 0 0 2px var(--line); border-radius: 4px; overflow: hidden; }
.cd-hold { position: absolute; left: 0; top: 0; width: 60px; height: 56px; background: var(--panel); border: 3px solid var(--outline); border-radius: 6px; font-size: 11px; color: var(--dim); text-align: center; padding-top: 3px; text-transform: uppercase; }
.cd-piece { position: absolute; left: 36px; top: 18px; width: 48px; height: 32px; }
.cd-piece i { position: absolute; width: 16px; height: 16px; background: var(--lav); border: 2px solid var(--outline); box-shadow: inset 3px 3px 0 rgba(255,255,255,.45), inset -3px -3px 0 rgba(0,0,0,.18); }
.cd-piece i:nth-child(1) { left: 16px; top: 0; } .cd-piece i:nth-child(2) { left: 0; top: 16px; } .cd-piece i:nth-child(3) { left: 16px; top: 16px; } .cd-piece i:nth-child(4) { left: 32px; top: 16px; }
.cd-stack { position: absolute; left: 0; right: 0; bottom: 0; height: 32px;
  background-image:
    linear-gradient(135deg, rgba(255,255,255,.45) 0 22%, transparent 22% 78%, rgba(0,0,0,.2) 78%),
    linear-gradient(90deg, #86e39a 0 25%, transparent 25% 38%, #6fdcf0 38% 62%, #ffab5c 62% 100%);
  background-size: 16px 16px, 100% 100%;
  box-shadow: inset 0 0 0 2px var(--outline); }
.cd-finger { position: absolute; font-size: 38px; left: 110px; top: 110px; filter: drop-shadow(0 3px 0 rgba(0,0,0,.4)); }
.cd-keys { position: absolute; right: 0; top: 40px; display: flex; flex-direction: column; gap: 4px; width: 56px; }
.cd-keys b { display: none; height: 38px; border-radius: 8px; background: #3d2c58; border: 3px solid var(--outline); color: var(--ink); font-size: 16px; place-items: center; }
.coach-demo.slide .k-l, .coach-demo.slide .k-r, .coach-demo.spin .k-a, .coach-demo.spin .k-b, .coach-demo.drop .k-d, .coach-demo.drop .k-u, .coach-demo.hold .k-h { display: grid; }
.coach-demo.spin .k-a { background: var(--pink); color: var(--outline); border-radius: 50%; width: 44px; height: 44px; animation: key-press 1.2s steps(2) infinite; }
.coach-demo.spin .k-b { background: var(--lav); color: var(--outline); border-radius: 50%; width: 44px; height: 44px; }
.coach-demo.slide .k-l { animation: key-press 2.4s steps(2) infinite; }
.coach-demo.slide .k-r { animation: key-press 2.4s steps(2) 1.2s infinite; }
.coach-demo.drop .k-u { animation: key-press 2s steps(2) 1s infinite; }
.coach-demo.hold .k-h { font-size: 13px; animation: key-press 2s steps(2) infinite; }
@keyframes key-press { 0%, 40% { background-color: #5a4180; transform: translateY(2px); } 50%, 100% { transform: none; } }
.coach-demo.slide .cd-piece { animation: demo-slide 2.4s steps(1) infinite; }
.coach-demo.slide .cd-finger { animation: finger-slide 2.4s steps(8) infinite; }
@keyframes demo-slide { 0% { transform: translateX(0); } 12% { transform: translateX(-16px); } 24%, 50% { transform: translateX(-32px); } 62% { transform: translateX(-16px); } 74% { transform: translateX(0); } 86%, 100% { transform: translateX(16px); } }
@keyframes finger-slide { 0% { transform: translateX(0); } 25%, 50% { transform: translateX(-34px); } 90%, 100% { transform: translateX(20px); } }
.coach-demo.spin .cd-piece { animation: demo-spin 2.4s steps(1) infinite; transform-origin: 24px 24px; }
.coach-demo.spin .cd-finger { animation: finger-tap 1.2s steps(2) infinite; }
@keyframes demo-spin { 0% { transform: rotate(0); } 25% { transform: rotate(90deg); } 50% { transform: rotate(180deg); } 75% { transform: rotate(270deg); } }
@keyframes finger-tap { 0%, 40% { transform: translateY(0) scale(1); } 50%, 100% { transform: translateY(6px) scale(.9); } }
.coach-demo.drop .cd-piece { animation: demo-drop 2s steps(1) infinite; }
.coach-demo.drop .cd-finger { animation: finger-flick 2s steps(6) infinite; }
@keyframes demo-drop { 0%, 49% { transform: translateY(0); } 50%, 90% { transform: translateY(98px); } 100% { transform: translateY(0); } }
@keyframes finger-flick { 0%, 30% { transform: translateY(-50px); opacity: 1; } 50% { transform: translateY(10px); opacity: 1; } 60%, 100% { transform: translateY(10px); opacity: 0; } }
.coach-demo.hold .cd-piece { animation: demo-hold 2s steps(1) infinite; }
.coach-demo.hold .cd-finger { animation: finger-up 2s steps(6) infinite; }
@keyframes demo-hold { 0%, 49% { transform: translate(0, 0); } 50%, 100% { transform: translate(-96px, 2px) scale(.6); } }
@keyframes finger-up { 0%, 20% { transform: translateY(20px); opacity: 1; } 45% { transform: translateY(-50px); opacity: 1; } 55%, 100% { opacity: 0; } }
.coach-dots { display: flex; justify-content: center; gap: 8px; margin: 4px 0 14px; }
.coach-dots i { width: 10px; height: 10px; border-radius: 2px; background: #3d2c58; border: 2px solid var(--outline); }
.coach-dots i.on { background: var(--pink); }
.coach .go { width: 100%; }

/* ---------- Short screens (placed last so they override) ---------- */
@media (orientation: portrait) and (max-height: 640px) {
  #title { overflow-y: auto; touch-action: pan-y; justify-content: flex-start; gap: 10px; }
  .logo { margin-top: 0; }
  .logo-big .ch { width: 34px; height: 38px; font-size: 27px; }
  .logo-small { font-size: 22px; }
  .logo-sub { margin-top: 8px; font-size: 14px; }
  .friends { height: 48px; }
  .menu { gap: 10px; }
  .mode-btn { min-height: 56px; }
  .mode-name { font-size: 21px; }
  .a2hs { font-size: 13px; padding: 6px 10px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .sheet, .sheet.full { align-items: center; padding-top: calc(var(--safe-t) + 8px); padding-bottom: calc(var(--safe-b) + 8px); }
  .sheet-card { max-height: calc(100dvh - 16px); overflow-y: auto; touch-action: pan-y; padding-top: 14px; overscroll-behavior: contain; }
  .sheet-pet { display: none; }
  .sheet-card h2 { font-size: 24px; }
  .sheet-actions { position: sticky; bottom: -18px; margin: 12px -18px -18px; padding: 10px 18px 12px; background: #2a1d3e; border-top: 2px solid var(--line); z-index: 2; }
  .speed-num { font-size: 36px; }
  .speed-btn { width: 48px; height: 48px; }
  .speed-bar { margin: 8px 0 6px; }
  .big-number { font-size: 36px; margin: 0 0 6px; }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .coach-demo { height: 150px; transform: scale(.8); margin: -10px auto 0; }
  .sheet-card.coach { max-width: 460px; }
}

#game.wide .mission { grid-column: 3; grid-row: 1; align-self: end; justify-self: center; }
.over-friends { display: flex; justify-content: center; height: 64px; margin: -6px 0 4px; }
.over-friends img { height: 100%; flex: 1 1 0; min-width: 0; object-fit: contain; animation: friend-hop .9s steps(3) infinite; animation-delay: calc(var(--i) * 90ms); }
@media (max-height: 700px) {
  .sheet-pet { width: 64px; height: 64px; margin-top: -8px; }
  .pause-vol { display: none; }
  .sheet-card { padding-top: 14px; }
  .sheet-card h2 { font-size: 26px; }
}
@media (max-width: 380px) {
  .sheet-actions .btn { font-size: 16px; padding: 10px 8px; white-space: nowrap; }
  .sheet-actions .go { font-size: 18px; }
}
/* Tablets: scale the title up so it doesn't float tiny in the middle */
@media (min-width: 700px) and (min-height: 800px) {
  #title .logo, #title .friends, #title .menu, #title .a2hs { zoom: 1.45; }
  #title .icon-btn { zoom: 1.3; }
}

button, input, output { font-variant-ligatures: none; font-feature-settings: "liga" 0, "clig" 0; }
@media (max-height: 600px) {
  #sheet-pause .speed-presets, #sheet-pause .speed-sub { display: none; }
  #sheet-pause .sheet-pet { display: none; }
  .sheet-actions { margin-top: 12px; }
}

#game.sprint .minis > div:first-child { display: none; }
@media (max-width: 359px) { .pill { min-width: 56px; font-size: 12px; padding: 0 8px; } }

.pad.tall { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; align-items: end; column-gap: 8px; }
.pad.tall .dpad { grid-column: 1; grid-row: 1 / 3; align-self: center; }
.pad.tall .pad-mid { grid-column: 3; grid-row: 1; flex-direction: row; justify-self: center; margin-bottom: 8px; }
.pad.tall .ab { grid-column: 3; grid-row: 2; }
.pad.tall.lefty .dpad { grid-column: 3; }
.pad.tall.lefty .pad-mid, .pad.tall.lefty .ab { grid-column: 1; }

.pause-vol:has(#pause-music[hidden]) { grid-template-columns: 1fr; }
html.big-ui .sheet-card { font-size: 1.08em; }
html.big-ui .toggle, html.big-ui .field, html.big-ui .slider label, html.big-ui .howto li, html.big-ui .sheet-note { font-size: 19px; }
html.big-ui .hint, html.big-ui .speed-sub, html.big-ui .mode-desc { font-size: 16px; }
