/* KROOKED shell styles. Flat, chunky, hard shadows. No blur, no gradients, no rounded web cards.
   Portrait (SPEC 14): everything lives in the app box, a 9:16..9:21 column centred in the visible viewport.
   --u is 1% of the app width: sizes everywhere are in u, so layouts scale with the screen (box = 100u wide). */

@font-face { font-family: 'Permanent Marker'; src: url('../assets/fonts/permanent-marker.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'Sedgwick Ave Display'; src: url('../assets/fonts/sedgwick-ave-display.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'Press Start 2P'; src: url('../assets/fonts/press-start-2p.woff2') format('woff2'); font-display: block; }

:root {
  --purple: #3b2bb8; --purple-light: #5a4be0; --gold: #8a5a14; --lime: #c8e62a;
  --white: #f4f4f0; --outline: #0a1030; --panel: rgba(10, 24, 60, 0.55); --danger: #ff3b30;
  --display: 'Permanent Marker', 'Sedgwick Ave Display', cursive;
  --pixel: 'Press Start 2P', monospace;
  /* --app-* are set by js/ui/viewport.js to the really visible rectangle (not hidden by browser bars) */
  --app-x: 0px; --app-y: 0px; --app-w: 100vw; --app-h: 100vh;
  --u: calc(var(--app-w) / 100);
  --ol: var(--outline);
}

@supports (height: 100dvh) { :root { --app-w: 100dvw; --app-h: 100dvh; } }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #000; color: var(--white); position: fixed; inset: 0;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  font-family: var(--pixel);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; }

#app { touch-action: none; overscroll-behavior: none; position: fixed; left: var(--app-x); top: var(--app-y); width: var(--app-w); height: var(--app-h); overflow: hidden; background: #000; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#input-root { position: absolute; inset: 0; z-index: 5; touch-action: none; overscroll-behavior: none; }
.layer { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* hard outline text: eight hard offsets, no blur */
.outlined {
  text-shadow:
    calc(var(--u) * .35) 0 0 var(--ol), calc(var(--u) * -.35) 0 0 var(--ol),
    0 calc(var(--u) * .35) 0 var(--ol), 0 calc(var(--u) * -.35) 0 var(--ol),
    calc(var(--u) * .35) calc(var(--u) * .35) 0 var(--ol), calc(var(--u) * -.35) calc(var(--u) * -.35) 0 var(--ol),
    calc(var(--u) * .35) calc(var(--u) * -.35) 0 var(--ol), calc(var(--u) * -.35) calc(var(--u) * .35) 0 var(--ol),
    calc(var(--u) * .8) calc(var(--u) * .8) 0 var(--ol);
}

/* -------------------------------------------------------------- title */
.title { z-index: 20; background: #0b1a6e; }
.title canvas.bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.title .stack {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: calc(var(--u) * 5) 0 calc(var(--u) * 4);
}
/* cover art: a tilted sticker with a hard drop shadow, upper half */
.title .cover {
  width: calc(var(--u) * 74); height: calc(var(--u) * 74); flex: none; transform: rotate(-3deg); image-rendering: auto;
  border: calc(var(--u) * 1.2) solid var(--white); outline: calc(var(--u) * .6) solid var(--outline);
  box-shadow: calc(var(--u) * 2.4) calc(var(--u) * 2.4) 0 var(--outline);
  animation: coverbob 1.8s steps(2, jump-none) infinite;
}
@keyframes coverbob { 0% { transform: translateY(0) rotate(-3deg); } 100% { transform: translateY(calc(var(--u) * -1.2)) rotate(-2deg); } }
.title .logo-wrap { text-align: center; white-space: nowrap; transform: rotate(-4deg); }
.title .logo { font-family: var(--display); font-size: calc(var(--u) * 17); line-height: 1; color: var(--white); letter-spacing: calc(var(--u) * .3); }
.title .logo span {
  display: inline-block; --d: 0;
  -webkit-text-stroke: calc(var(--u) * 1.1) var(--outline); paint-order: stroke fill;
  text-shadow:
    calc(var(--u) * .9) calc(var(--u) * .9) 0 var(--purple),
    calc(var(--u) * 1.8) calc(var(--u) * 1.8) 0 var(--purple),
    calc(var(--u) * 2.7) calc(var(--u) * 2.7) 0 var(--outline);
  animation: wob .9s steps(2, jump-none) infinite; animation-delay: calc(var(--d) * -.13s);
}
.title .logo span:nth-child(3), .title .logo span:nth-child(6) { color: var(--lime); }
@keyframes wob { 0% { transform: translateY(calc(var(--u) * -1)) rotate(-3deg); } 100% { transform: translateY(calc(var(--u) * 1)) rotate(3deg); } }
.title .sub {
  font-family: var(--pixel); font-size: calc(var(--u) * 2.6); margin-top: calc(var(--u) * 3.5); color: var(--lime);
  letter-spacing: calc(var(--u) * .3);
}
.title .press { text-align: center; font-size: calc(var(--u) * 3.6); color: var(--white); animation: blink 1s steps(1) infinite; }
.title .press b { background: var(--outline); padding: calc(var(--u) * 1.6) calc(var(--u) * 2.6); display: inline-block; box-shadow: calc(var(--u) * .8) calc(var(--u) * .8) 0 #000; font-weight: normal; border: calc(var(--u) * .5) solid var(--white); }
.title .foot { display: flex; flex-direction: column; align-items: center; gap: calc(var(--u) * 1.6); }
.title .best { text-align: center; font-size: calc(var(--u) * 2.5); color: #9fb4ff; min-height: calc(var(--u) * 2.6); }
.title .ver { font-size: calc(var(--u) * 2); color: #5a6fd0; }
@keyframes blink { 0%, 100% { opacity: 1; } 55% { opacity: 0; } }

/* -------------------------------------------------------------- HUD */
.hud { z-index: 10; pointer-events: none; font-family: var(--pixel); }
.hud .score { position: absolute; left: calc(calc(var(--u) * 3) + env(safe-area-inset-left)); top: calc(calc(var(--u) * 2.2) + env(safe-area-inset-top)); }
.hud .score .lbl { font-size: max(calc(var(--u) * 2.5), 9px); color: #cfe0ff; }
.hud .score .val { font-family: var(--display); font-size: calc(var(--u) * 9); line-height: 1.05; color: var(--white); letter-spacing: calc(var(--u) * .3); }
.hud .score .best { font-size: max(calc(var(--u) * 2.5), 9px); color: var(--lime); margin-top: calc(var(--u) * .6); }
.hud .beat { display: flex; gap: calc(var(--u) * 1.1); align-items: center; height: calc(var(--u) * 3); margin-top: calc(var(--u) * 1); }
.hud .beat i { display: block; width: calc(var(--u) * 1.6); height: calc(var(--u) * 1.6); flex: none; background: rgba(244, 244, 240, .45); box-shadow: 0 0 0 calc(var(--u) * .35) var(--outline, #0a1030); }
.hud .beat i:nth-child(2), .hud .beat i:nth-child(4) { width: calc(var(--u) * 2.4); height: calc(var(--u) * 2.4); background: rgba(200, 230, 42, .5); }
.hud .beat[data-b="0"] i:nth-child(1), .hud .beat[data-b="2"] i:nth-child(3) { background: #fff; }
.hud .beat[data-b="1"] i:nth-child(2), .hud .beat[data-b="3"] i:nth-child(4) { background: var(--lime); }
.hud .beat[data-p="0"] i { opacity: .85; }
.hud .beat[data-p="1"] i { opacity: .9; }
.hud .beat[data-p="2"] i { opacity: .95; }
.hud .beat[data-p="3"] i, .hud .beat[data-p="4"] i { opacity: 1; }
/* buttons (SPEC 26): one column up the right edge, 5u in from it, listed from the thumb up. Its foot is 72u above the bottom:
   20u clear of the right stick's home ring (base top 52u), so a thumb flicking up from the stick has room.
   In a short box (9:16 is 178u tall) the column reaches up beside the trick line, so there the line is narrower (.hud .line). */
.hud .btns { position: absolute; z-index: 1; right: calc(var(--u) * 5); bottom: calc(var(--u) * 72); display: flex; flex-direction: column-reverse; align-items: center; gap: calc(var(--u) * 1.5); pointer-events: none; }
.hud .btn {
  pointer-events: auto; width: max(calc(var(--u) * 8.4), 36px); height: max(calc(var(--u) * 8.4), 36px); background: rgba(10, 24, 60, .82);
  border: calc(var(--u) * .6) solid var(--white); box-shadow: calc(var(--u) * .7) calc(var(--u) * .7) 0 #000; display: flex; align-items: center; justify-content: center; padding: 0;
}
.hud .btn.on { background: var(--purple); }
.hud .btn.off { opacity: .45; }
.hud .btn.rec { border-color: var(--danger); color: var(--danger); font-size: max(calc(var(--u) * 2.6), 9px); animation: blink 1s steps(1) infinite; }
.hud .btn:active { background: var(--purple); transform: translate(calc(var(--u) * .4), calc(var(--u) * .4)); box-shadow: calc(var(--u) * .3) calc(var(--u) * .3) 0 #000; }
.hud .btn svg { width: 55%; height: 55%; display: block; shape-rendering: crispEdges; }
.hud .line {
  position: absolute; left: 50%; top: calc(calc(var(--u) * 26) + env(safe-area-inset-top)); transform: translateX(-50%);
  /* 92u wide; 66u in a box under 190u tall, where the button column stands beside it (wide again from 194u) */
  width: clamp(calc(var(--u) * 66), calc(var(--u) * 66 + (var(--app-h) - var(--u) * 190) * 6.5), calc(var(--u) * 92)); text-align: center; font-family: var(--display); font-size: calc(var(--u) * 5.6); line-height: 1.12; color: var(--white);
  overflow-wrap: anywhere; text-wrap: balance;
}
.hud .line .l2 { font-size: calc(var(--u) * 6.8); color: var(--lime); }
.hud .line.land { color: var(--lime); }
.hud .line.land .l2 { color: var(--white); }
.hud .line.bail { color: var(--danger); font-size: calc(var(--u) * 10); }
.hud .charge { position: absolute; left: 50%; bottom: calc(calc(var(--u) * 34) + env(safe-area-inset-bottom)); transform: translateX(-50%); width: calc(var(--u) * 24); height: calc(var(--u) * 3); background: rgba(10, 24, 60, .82); border: calc(var(--u) * .5) solid var(--white); box-shadow: calc(var(--u) * .5) calc(var(--u) * .5) 0 #000; }
.hud .charge .fill { height: 100%; width: 0; background: var(--purpleLight, #5a4be0); }
.hud .charge.full .fill { background: var(--lime); animation: blink .3s steps(1) infinite; }
.hud .lap { position: absolute; left: 50%; top: calc(calc(var(--u) * 50) + env(safe-area-inset-top)); transform: translateX(-50%); text-align: center; white-space: nowrap; font-family: var(--display); font-size: calc(var(--u) * 6.4); color: var(--white); animation: blink 1s steps(1) infinite; }
.hud .lap .l2 { font-size: calc(var(--u) * 10); color: var(--lime); }
.hud .line.pop { animation: pop .18s steps(3) 1; }
.hud .line.fade { opacity: .5; }
@keyframes pop { 0% { transform: translateX(-50%) scale(1.4); } 100% { transform: translateX(-50%) scale(1); } }

/* how-to card */
.howto {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: calc(var(--u) * 90); pointer-events: auto;
  background: rgba(10, 24, 60, .92); border: calc(var(--u) * .8) solid var(--white); box-shadow: calc(var(--u) * 1.4) calc(var(--u) * 1.4) 0 #000; z-index: 3;
}
.howto .hh { background: var(--purple); font-family: var(--display); font-size: calc(var(--u) * 8); padding: calc(var(--u) * 1.6) calc(var(--u) * 3); color: var(--white); border-bottom: calc(var(--u) * .5) solid var(--outline); }
.howto ul { list-style: none; padding: calc(var(--u) * 3) calc(var(--u) * 3.4) calc(var(--u) * 2); }
.howto li { font-size: calc(var(--u) * 3.3); line-height: 1.7; margin-bottom: calc(var(--u) * 1.6); color: var(--white); }
.howto li b { color: var(--lime); font-weight: normal; display: block; }
.howto li i { color: var(--lime); font-style: normal; }
.howto .ok { padding: 0 calc(var(--u) * 3.4) calc(var(--u) * 3); text-align: center; font-size: calc(var(--u) * 3); color: #9fb4ff; animation: blink 1s steps(1) infinite; }

/* -------------------------------------------------------------- pause */
.pause { z-index: 30; background: rgba(4, 8, 24, .78); overflow: hidden; }
.pause .panel { position: absolute; left: 6%; top: 50%; transform: translateY(-50%); width: 88%; display: flex; flex-direction: column; }   /* the menu alone (SPEC 26): mid-screen, a thumb's reach from the pause button */
.pause .hdr {
  height: calc(var(--u) * 14); background: var(--purple); display: flex; align-items: center; padding-left: calc(var(--u) * 4);
  font-family: var(--display); font-size: calc(var(--u) * 9.5); line-height: 1; box-shadow: 0 calc(var(--u) * .8) 0 var(--outline);
}
.pause .rows { margin-top: calc(var(--u) * 1.4); background: var(--panel); border-top: calc(var(--u) * .4) solid rgba(255,255,255,.18); }
.pause .row {
  display: flex; align-items: center; justify-content: center; width: 100%; height: calc(var(--u) * 9.6);
  border-bottom: calc(var(--u) * .35) solid rgba(190, 205, 255, .32); font-family: var(--display); font-size: calc(var(--u) * 5.6); line-height: 1; color: var(--white);
  white-space: nowrap; overflow: hidden;
}
.pause .row.sel { color: var(--lime); }
/* -------------------------------------------------------------- help (SPEC 26): AYUDA in the pause menu */
.help { z-index: 31; background: rgba(4, 8, 24, .9); overflow: hidden; display: flex; flex-direction: column; gap: calc(var(--u) * 1.6);
  padding: calc(calc(var(--u) * 3) + env(safe-area-inset-top)) calc(var(--u) * 3) calc(calc(var(--u) * 3) + env(safe-area-inset-bottom)); }
.help .hdr {
  flex: none; height: calc(var(--u) * 11); background: var(--purple); display: flex; align-items: center; padding-left: calc(var(--u) * 4);
  font-family: var(--display); font-size: calc(var(--u) * 8); line-height: 1; box-shadow: 0 calc(var(--u) * .8) 0 var(--outline);
}
.help .tabs { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: calc(var(--u) * 1.4); margin-top: calc(var(--u) * .8); }
.help .tab {
  height: calc(var(--u) * 8.4); background: var(--outline); border: calc(var(--u) * .5) solid #5a6fd0; box-shadow: calc(var(--u) * .7) calc(var(--u) * .7) 0 #000;
  font-family: var(--display); font-size: calc(var(--u) * 4.6); line-height: 1; color: var(--white); white-space: nowrap;
}
.help .tab.sel { background: var(--purple); border-color: var(--lime); color: var(--lime); }
.help .body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.help .page {
  background: rgba(10, 24, 60, .85); border: calc(var(--u) * .6) solid var(--white); box-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #000;
  padding: calc(var(--u) * 1.8) calc(var(--u) * 2.4) calc(var(--u) * 1.8); overflow: hidden;
}
.help .row {
  flex: none; display: flex; align-items: center; justify-content: center; width: 100%; height: calc(var(--u) * 8.4); background: var(--panel);
  border: calc(var(--u) * .35) solid rgba(190, 205, 255, .32); font-family: var(--display); font-size: calc(var(--u) * 5.6); line-height: 1; color: var(--lime);
}
.help h3 { font-family: var(--display); font-weight: normal; font-size: calc(var(--u) * 5); color: var(--lime); margin-bottom: calc(var(--u) * 1); line-height: 1; white-space: nowrap; }
.help .lead { font-size: calc(var(--u) * 1.9); color: var(--white); line-height: 1.6; margin-bottom: calc(var(--u) * .4); }
.help .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 calc(var(--u) * 2.4); }
.help .col { min-width: 0; }
.help .ct { font-size: calc(var(--u) * 2.3); color: var(--white); background: rgba(90, 75, 224, .55); padding: calc(var(--u) * .9) calc(var(--u) * 1); margin: calc(var(--u) * 1) 0 calc(var(--u) * .5); white-space: nowrap; }
.help .trk { display: flex; align-items: center; gap: calc(var(--u) * 1.4); height: calc(var(--u) * 13); border-top: calc(var(--u) * .3) solid rgba(190, 205, 255, .25); min-width: 0; }
.help .col .trk:first-of-type, .help .keys .trk:first-child { border-top: 0; }
.help .trk > div:last-child { min-width: 0; }
.help .trk svg { width: calc(var(--u) * 9); height: calc(var(--u) * 9); flex: none; display: block; shape-rendering: crispEdges; background: rgba(0,0,0,.35); }
.help .trk .nm { font-size: calc(var(--u) * 2.4); color: var(--white); white-space: nowrap; }
.help .trk .hn { font-size: calc(var(--u) * 1.85); color: #9fb4ff; margin-top: calc(var(--u) * .9); line-height: 1.4; white-space: nowrap; }
.help .note { font-size: calc(var(--u) * 2.1); color: var(--lime); margin-top: calc(var(--u) * 1.8); line-height: 1.7; }
/* grinds: three cards a row, each a picture (one cell of assets/help/grinds.png, 8 cells of 112x100) over the left-stick diagram and the name */
.help .cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: calc(var(--u) * 1.6); }
.help .gc { min-width: 0; }
.help .pic {
  width: 100%; aspect-ratio: 112 / 100; background: #9fc4e8 url('../assets/help/grinds.png') 0 0 / 800% 100% no-repeat;
  image-rendering: pixelated; border: calc(var(--u) * .4) solid var(--white);
}
.help .gc .trk { height: calc(var(--u) * 7.4); border-top: 0; gap: calc(var(--u) * 1.1); }
.help .gc .trk svg { width: calc(var(--u) * 6.4); height: calc(var(--u) * 6.4); }
.help .gc .trk .nm { font-size: calc(var(--u) * 1.95); }
.help .gc .trk .hn { font-size: calc(var(--u) * 1.75); margin-top: calc(var(--u) * .7); }
/* SPEC 31: how to get out of a grind: one line under the grinds, and on the controls page both sticks drawn side by side */
.help .out { font-size: calc(var(--u) * 1.9); color: var(--lime); margin-top: calc(var(--u) * .6); line-height: 1.2; white-space: nowrap; }
.help .trk svg.duo { width: calc(var(--u) * 13.5); }
.help .outs .trk { border-top: 0; height: calc(var(--u) * 11.6); }
/* controls: the HUD buttons with what they do */
.help .keys .trk { height: calc(var(--u) * 9.4); }
.help .keys .ic {
  flex: none; width: calc(var(--u) * 7.6); height: calc(var(--u) * 7.6); background: rgba(10, 24, 60, .82); border: calc(var(--u) * .5) solid var(--white);
  display: flex; align-items: center; justify-content: center;
}
.help .keys .ic svg { width: 55%; height: 55%; background: none; }

/* clip panel (SPEC 25): the pause panel's header and rows (same look, its own class), with the recording playing under them */
.clip { z-index: 30; background: rgba(4, 8, 24, .78); overflow: hidden; }
.clip .panel { position: absolute; left: 6%; top: calc(var(--u) * 5); width: 88%; display: flex; flex-direction: column; }
.clip .hdr {
  height: calc(var(--u) * 14); background: var(--purple); display: flex; align-items: center; padding-left: calc(var(--u) * 4);
  font-family: var(--display); font-size: calc(var(--u) * 9.5); line-height: 1; box-shadow: 0 calc(var(--u) * .8) 0 var(--outline);
}
.clip .rows { margin-top: calc(var(--u) * 1.4); background: var(--panel); border-top: calc(var(--u) * .4) solid rgba(255,255,255,.18); }
.clip .row {
  display: flex; align-items: center; justify-content: center; width: 100%; height: calc(var(--u) * 8.4);
  border-bottom: calc(var(--u) * .35) solid rgba(190, 205, 255, .32); font-family: var(--display); font-size: calc(var(--u) * 5.6); line-height: 1; color: var(--white);
  white-space: nowrap; overflow: hidden;
}
.clip .row.sel { color: var(--lime); }
.clip .prev { display: block; align-self: center; width: calc(var(--u) * 46); margin-top: calc(var(--u) * 3); border: calc(var(--u) * .6) solid var(--white); box-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #000; background: #000; image-rendering: pixelated; }
.clip .msg { align-self: center; margin-top: calc(var(--u) * 2.4); font-size: calc(var(--u) * 2.3); color: var(--lime); text-align: center; line-height: 1.6; }

/* -------------------------------------------------------------- playground select (after PRESS START) */
.select { z-index: 20; background: #0b1a6e; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--u) * 5); }
.select .hdr { font-family: var(--display); font-size: calc(var(--u) * 11); line-height: 1; color: var(--white); transform: rotate(-3deg); }
.select .cards { width: 86%; display: flex; flex-direction: column; gap: calc(var(--u) * 4); }
.select .card {
  display: block; width: 100%; text-align: left; padding: calc(var(--u) * 3.2) calc(var(--u) * 3.6); background: var(--outline); color: var(--white);
  border: calc(var(--u) * .6) solid #5a6fd0; box-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #000;
}
.select .card.sel { border-color: var(--lime); background: var(--purple); transform: translate(calc(var(--u) * -.6), calc(var(--u) * -.6)); box-shadow: calc(var(--u) * 1.6) calc(var(--u) * 1.6) 0 #000; }
.select .card .nm { font-family: var(--display); font-size: calc(var(--u) * 8.4); line-height: 1; white-space: nowrap; }
.select .card.sel .nm { color: var(--lime); }
.select .card .bl { font-size: calc(var(--u) * 2.2); line-height: 1.7; color: #9fb4ff; margin-top: calc(var(--u) * 2); }
.select .card .bs { font-size: calc(var(--u) * 2.1); color: var(--white); margin-top: calc(var(--u) * 1.6); min-height: calc(var(--u) * 2.2); }
.select .hint { font-size: calc(var(--u) * 2.2); color: #9fb4ff; text-align: center; line-height: 1.8; }

/* -------------------------------------------------------------- rotate overlay */
/* shown on a touch device held in landscape: the game is portrait only */
.rotate {
  position: fixed; inset: 0; z-index: 100; display: none; background: #0b1a6e; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 4vmin; gap: 4vmin;
}
.rotate .big { font-family: var(--display); font-size: min(12vw, 15vh); color: var(--white); line-height: 1.05; }
.rotate .small { font-family: var(--pixel); font-size: min(3.2vw, 3.6vh); color: var(--lime); line-height: 1.6; }
.rotate svg { width: min(30vw, 30vh); height: min(30vw, 30vh); shape-rendering: crispEdges; animation: tilt 1.2s steps(2, jump-none) infinite; }
@keyframes tilt { 0% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }
@media (orientation: landscape) and (pointer: coarse) { .rotate { display: flex; } }
.rotate.force { display: flex; }
