@font-face { font-family: 'Bangers'; font-weight: 400; font-display: block; src: url('assets/fonts/Bangers-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Bebas Neue'; font-weight: 400; font-display: swap; src: url('assets/fonts/BebasNeue-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('assets/fonts/Inter-SemiBold.ttf') format('truetype'); }
@font-face { font-family: 'Inter'; font-weight: 700; font-display: swap; src: url('assets/fonts/Inter-Bold.ttf') format('truetype'); }

:root {
  --ink: #3b1d0d;
  --ink-soft: #6b3a1e;
  --cream: #fff5e4;
  --sand: #f6d8ae;
  --sun: #ffb43c;
  --terra: #d6703a;
  --clay: #b3552b;
  --teal: #1ea393;
  --teal-deep: #0e6b62;
  --berry: #e2453b;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --display: 'Bangers', 'Impact', system-ui, sans-serif;
  --label: 'Bebas Neue', 'Arial Narrow', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: #e59a5d; color: var(--ink);
  font-family: var(--body); font-weight: 600;
  overscroll-behavior: none; touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#stage, #gizmo { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#stage { touch-action: none; outline: none; }
#gizmo { pointer-events: none; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; top: 0; pointer-events: none;
  padding: calc(var(--safe-t) + 10px) 0 0 calc(var(--safe-l) + 12px);
}
.hud-card {
  display: grid; gap: 2px; padding: 6px 12px 7px 12px; border-radius: 16px;
  background: rgba(59, 29, 13, 0.34); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  color: var(--cream); text-shadow: 0 2px 0 rgba(59, 29, 13, 0.45);
}
.hud-row { display: flex; align-items: center; gap: 10px; }
.hud-score { display: grid; line-height: 0.9; }
.hud-score small { font: 400 13px/1 var(--label); letter-spacing: 0.14em; opacity: 0.85; }
.hud-score strong { font: 400 38px/0.95 var(--display); letter-spacing: 0.03em; min-width: 2ch; }
.hud-score strong.bump { animation: bump 0.36s ease-out; }
.mult {
  font: 400 24px/1 var(--display); color: var(--ink); padding: 4px 9px 3px; border-radius: 11px;
  background: linear-gradient(180deg, #ffe07a, var(--sun)); box-shadow: 0 3px 0 #c9771a; transform: rotate(-6deg);
  text-shadow: none;
}
.mult.bump { animation: multpop 0.42s cubic-bezier(.2, 1.6, .4, 1); }
.hud-sub { gap: 12px; }
.lives { display: flex; gap: 3px; }
.glyph polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.glyph .g-edge { stroke: currentColor; stroke-width: 15; opacity: 0.35; }
.glyph .g-body { stroke: currentColor; stroke-width: 10; }
.btn .glyph { width: 30px; height: 20px; }
.lives svg { width: 26px; height: 18px; transition: opacity 0.25s, transform 0.25s; }
.lives .g-edge { stroke: #5a2610; opacity: 1; }
.lives .g-body { stroke: var(--sun); }
.lives svg.gone { opacity: 0.3; transform: scale(0.8) rotate(-20deg); }
.lives svg.gone .g-body { stroke: #5a2d17; }
.lives svg.lost { animation: lifelost 0.6s ease-out; }
.lives svg.gain { animation: lifegain 0.6s ease-out; }
.leg { font: 400 17px/1 var(--label); letter-spacing: 0.12em; opacity: 0.92; }

/* ---------- callouts ---------- */
#callouts { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.callout {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font: 400 clamp(34px, 8vmin, 64px)/1 var(--display); letter-spacing: 0.04em; white-space: nowrap;
  color: var(--cream); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink); animation: callout 1.15s ease-out forwards;
}
.callout.small { font-size: clamp(22px, 5vmin, 36px); top: 50%; text-shadow: 0 3px 0 var(--ink); }
.callout.good { color: #bff7e3; }
.callout.gold { color: #ffe27a; }
.callout.bad { color: #ffc0b0; }
.popup {
  position: absolute; transform: translate(-50%, -100%);
  font: 400 clamp(26px, 6vmin, 44px)/1 var(--display); color: #ffe27a; white-space: nowrap;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink);
  animation: floatup 1.1s ease-out forwards;
}
.popup em { font-style: normal; color: var(--cream); font-size: 0.7em; margin-left: 4px; }

#hurt {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(226, 69, 59, 0) 45%, rgba(226, 69, 59, 0.55) 100%);
}
#hurt.on { animation: hurt 0.55s ease-out; }

/* ---------- coach ---------- */
#coach {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%);
  width: min(92vw, 420px); display: flex; align-items: center; gap: 12px; pointer-events: none;
  padding: 10px 16px; border-radius: 18px; background: rgba(255, 245, 228, 0.9); color: var(--ink);
  box-shadow: 0 6px 0 rgba(59, 29, 13, 0.25); font-size: 14px; line-height: 1.35;
}
#coach p { margin: 0; }
#coach b { color: var(--teal-deep); }
.coach-hand { width: 52px; height: 52px; flex: none; overflow: visible; }
.coach-finger { fill: #fff; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; animation: coachdrag 2.2s ease-in-out infinite; }
.coach-dot { fill: var(--teal); opacity: 0.5; animation: coachdot 2.2s ease-in-out infinite; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden;
  padding: calc(var(--safe-t) + 60px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
}
.keyart {
  background:
    linear-gradient(180deg, rgba(255, 219, 170, 0.35) 0%, rgba(214, 112, 58, 0.55) 55%, rgba(59, 29, 13, 0.82) 100%),
    url('assets/keyart.jpg') center 30% / cover no-repeat, #d9824b;
}
#screen-loading { z-index: 30; transition: opacity 0.45s; }
#screen-loading.fade { opacity: 0; pointer-events: none; }
.loading-card { display: grid; justify-items: center; gap: 18px; margin-top: 30vh; }
#loading-note { margin: 0; color: var(--cream); font: 400 20px var(--label); letter-spacing: 0.12em; text-shadow: 0 2px 0 var(--ink); }
.loader { width: 180px; height: 12px; border-radius: 99px; background: rgba(59, 29, 13, 0.45); overflow: hidden; }
.loader i { display: block; height: 100%; width: 40%; border-radius: 99px; background: var(--sun); animation: loading 1.1s ease-in-out infinite; }

.logo { margin: 0; display: grid; justify-items: center; line-height: 0.82; font-weight: 400; transform: rotate(-4deg); }
.logo span {
  font: 400 clamp(58px, 17vmin, 120px)/0.84 var(--display); letter-spacing: 0.03em; color: var(--sun);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 7px 0 var(--ink);
}
.logo span + span { color: var(--cream); margin-left: 1.2em; }

#screen-title { place-items: end center; background: linear-gradient(180deg, rgba(59, 29, 13, 0) 35%, rgba(59, 29, 13, 0.55) 100%); }
.title-card { display: grid; justify-items: center; gap: 14px; width: min(100%, 440px); padding-bottom: 4vh; }
.tagline { margin: 0 0 6px; color: var(--cream); text-align: center; font-size: 15px; text-shadow: 0 2px 0 rgba(59, 29, 13, 0.6); }
.best-line { margin: 2px 0 0; color: var(--cream); font: 400 20px/1 var(--label); letter-spacing: 0.14em; text-shadow: 0 2px 0 var(--ink); }
.best-line b { font: 400 26px var(--display); color: var(--sun); margin-left: 6px; letter-spacing: 0.04em; }

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; color: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 16px; touch-action: manipulation;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, filter 0.15s;
}
.btn svg { width: 22px; height: 22px; fill: currentColor; }
.btn:active { transform: translateY(4px); }
.btn:focus-visible { outline: 3px solid var(--cream); outline-offset: 3px; }
.btn-go {
  min-width: 220px; min-height: 64px; font: 400 36px/1 var(--display); letter-spacing: 0.06em;
  color: var(--cream); background: linear-gradient(180deg, #2fc4b2, var(--teal)); box-shadow: 0 6px 0 var(--teal-deep), 0 10px 20px rgba(0, 0, 0, 0.2);
  text-shadow: 0 3px 0 var(--teal-deep);
}
.btn-go:active { box-shadow: 0 2px 0 var(--teal-deep); }
.btn-soft { background: var(--cream); color: var(--ink); box-shadow: 0 5px 0 #c98f5c; font-weight: 700; font-size: 15px; }
.btn-soft:active { box-shadow: 0 1px 0 #c98f5c; }
.btn-icon { width: 52px; padding: 0; }
.btn-small { min-height: 42px; width: 46px; padding: 0; }
.btn-small svg { fill: none; stroke: currentColor; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; gap: 12px; }
#btn-sound .wave { fill: none; stroke: currentColor; stroke-width: 3.4; stroke-linecap: round; }
#btn-sound .ico-off { display: none; }
#btn-sound[aria-pressed='false'] .ico-on { display: none; }
#btn-sound[aria-pressed='false'] .ico-off { display: block; }

.panel {
  width: min(100%, 400px); max-height: 100%; overflow: auto; border-radius: 26px; padding: 20px 20px 22px;
  background: rgba(255, 245, 228, 0.95); box-shadow: 0 10px 0 rgba(59, 29, 13, 0.35), 0 20px 40px rgba(0, 0, 0, 0.25);
  display: grid; gap: 12px; justify-items: center; text-align: center; animation: panelin 0.42s cubic-bezier(.2, 1.4, .4, 1);
}
.panel h2 { margin: 0; font: 400 44px/1 var(--display); letter-spacing: 0.05em; color: var(--terra); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); }
.result-numbers { display: flex; align-items: center; gap: 14px; }
.num-block { display: grid; line-height: 1; }
.num-block small { font: 400 16px/1 var(--label); letter-spacing: 0.16em; color: var(--ink-soft); }
.num-block strong { font: 400 56px/1 var(--display); color: var(--ink); letter-spacing: 0.02em; }
.num-dot { font: 400 44px/1 var(--display); color: var(--terra); }
.record { margin: -4px 0 0; padding: 4px 12px; border-radius: 99px; font: 400 22px/1.1 var(--display); letter-spacing: 0.08em; color: var(--ink); background: var(--sun); animation: record 1s ease-in-out infinite alternate; }
.stat-list { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-list li { display: grid; gap: 2px; padding: 8px 6px; border-radius: 14px; background: rgba(214, 112, 58, 0.12); }
.stat-list span { font-size: 12px; color: var(--ink-soft); }
.stat-list b { font: 400 26px/1 var(--display); letter-spacing: 0.04em; }
.unlock-note { margin: 0; padding: 8px 12px; border-radius: 14px; background: rgba(30, 163, 147, 0.16); color: var(--teal-deep); font-size: 14px; }
.result-panel .btn-go { width: 100%; }
.result-panel .btn-soft { width: 100%; }

.panel-head { width: 100%; display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; }
.skins-panel { width: min(100%, 520px); }
.skins-panel h2 { font-size: 34px; }
.skin-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.skin {
  appearance: none; border: 3px solid transparent; border-radius: 18px; padding: 10px 8px 10px; cursor: pointer;
  background: #fff; color: var(--ink); font: inherit; display: grid; gap: 4px; justify-items: center;
  box-shadow: 0 4px 0 #e2b58a; transition: transform 0.1s;
}
.skin:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.skin:active { transform: translateY(3px); }
.skin svg { width: 96px; height: 60px; }
.skin .name { font-weight: 700; font-size: 14px; }
.skin .req { font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 4px; }
.skin .req svg { width: 12px; height: 12px; fill: currentColor; }
.skin.selected { border-color: var(--teal); background: #e9fbf6; }
.skin.selected .req { color: var(--teal-deep); }
.skin.locked { background: #f1e2cf; cursor: default; }
.skin.locked > svg { filter: grayscale(1) brightness(0.55) opacity(0.6); }
.skins-hint { margin: 0; font-size: 13px; color: var(--ink-soft); }

#fatal { z-index: 50; background: #3b1d0d; color: var(--cream); text-align: center; }

/* host pause freezes every CSS animation too */
.is-paused *, .is-paused *::before, .is-paused *::after { animation-play-state: paused !important; }

@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.25); color: #ffe27a; } 100% { transform: scale(1); } }
@keyframes multpop { 0% { transform: rotate(-6deg) scale(0.4); } 100% { transform: rotate(-6deg) scale(1); } }
@keyframes lifelost { 0% { transform: scale(1.4); fill: var(--berry); } 100% { transform: scale(0.8) rotate(-20deg); } }
@keyframes lifegain { 0% { transform: scale(0.2); } 60% { transform: scale(1.4); } 100% { transform: scale(1); } }
@keyframes callout {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); opacity: 0; }
  14% { transform: translate(-50%, -50%) scale(1.12) rotate(2deg); opacity: 1; }
  24% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  78% { transform: translate(-50%, -62%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(0.92); opacity: 0; }
}
@keyframes floatup {
  0% { transform: translate(-50%, -60%) scale(0.5); opacity: 0; }
  18% { transform: translate(-50%, -110%) scale(1.15); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -260%) scale(1); opacity: 0; }
}
@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes loading { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }
@keyframes panelin { 0% { transform: translateY(40px) scale(0.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes record { from { transform: rotate(-3deg) scale(1); } to { transform: rotate(3deg) scale(1.06); } }
@keyframes coachdrag {
  0%, 10% { transform: translate(0, 0) scale(1); }
  18% { transform: translate(0, 2px) scale(0.92); }
  45% { transform: translate(-16px, 2px) scale(0.92); }
  72% { transform: translate(14px, 2px) scale(0.92); }
  80%, 100% { transform: translate(14px, -4px) scale(1); }
}
@keyframes coachdot { 0%, 12% { opacity: 0.2; } 50% { opacity: 0.7; } 100% { opacity: 0.2; } }

@media (orientation: landscape) and (max-height: 500px) {
  .screen { padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px); }
  .logo span { font-size: clamp(44px, 15vh, 80px); }
  .title-card { gap: 8px; padding-bottom: 2vh; }
  .loading-card { margin-top: 10vh; }
  /* panels stay clear of the host mute button (top-right) by keeping their width inside it */
  .panel { width: min(100%, 580px, calc(100vw - 2 * (138px + var(--safe-r)))); padding: 12px 16px 14px; gap: 8px; }
  .panel h2 { font-size: 34px; }
  .result-panel {
    grid-template-columns: 1fr 1.3fr; column-gap: 14px; align-items: center;
    grid-template-areas: "title title" "nums stats" "record stats" "unlock unlock" "again skins";
  }
  .result-panel h2 { grid-area: title; }
  .result-numbers { grid-area: nums; justify-self: center; }
  .record { grid-area: record; justify-self: center; margin: 0; }
  .stat-list { grid-area: stats; gap: 6px; }
  .stat-list li { padding: 5px 6px; }
  .stat-list b { font-size: 22px; }
  .unlock-note { grid-area: unlock; padding: 5px 10px; }
  .result-panel #btn-again { grid-area: again; min-height: 52px; min-width: 0; font-size: 28px; }
  .result-panel #btn-skins-2 { grid-area: skins; min-height: 52px; }
  .num-block strong { font-size: 44px; }
  .skins-panel { width: min(100%, 640px, calc(100vw - 2 * (138px + var(--safe-r)))); }
  .skin-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .skin { padding: 6px 6px 8px; gap: 2px; }
  .skin svg { width: 76px; height: 46px; }
  .hud-score strong { font-size: 32px; }
  #coach { left: auto; right: calc(var(--safe-r) + 12px); transform: none; bottom: calc(var(--safe-b) + 10px); width: min(46vw, 360px); padding: 6px 12px; font-size: 13px; }
  .coach-hand { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .callout, .popup { animation-duration: 0.9s; }
  .coach-finger, .coach-dot, .record { animation: none; }
}
