:root {
  color-scheme: dark;
  --ink: #fff9df;
  --purple: #251547;
  --purple-deep: #100a24;
  --pink: #f06292;
  --gold: #ffd166;
  --cyan: #72e4e8;
  --shadow: 0 18px 60px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(115deg, transparent 48%, rgba(255,255,255,.025) 49%, transparent 50%) 0 0 / 38px 38px,
    radial-gradient(circle at 50% 10%, #542d6b 0, var(--purple-deep) 60%);
  user-select: none;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid var(--cyan); outline-offset: 3px; }
#app { width: 100%; height: 100%; display: grid; place-items: center; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
#game-shell { position: relative; width: min(100%, calc((100vh - 16px) * 16 / 9)); aspect-ratio: 16 / 9; overflow: hidden; border-radius: clamp(8px, 1.5vw, 22px); background: #201834; box-shadow: var(--shadow); }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }

#hud { position: absolute; z-index: 4; inset: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; padding: clamp(7px, 1.2vw, 18px); pointer-events: none; }
.hud-panel { background: rgba(18,10,40,.82); border: 2px solid rgba(255,255,255,.25); border-radius: 14px; padding: 8px 14px; backdrop-filter: blur(8px); text-shadow: 0 2px 2px #000; }
.stage-label { display: flex; flex-direction: column; justify-self: start; font-size: clamp(10px, 1.1vw, 15px); }
.stage-label strong { font-size: clamp(12px, 1.4vw, 20px); }
.stage-label em { margin-top: 3px; color: var(--cyan); font-size: clamp(9px, 1vw, 13px); font-style: normal; font-weight: 800; }
.timer { min-width: 110px; text-align: center; font-size: clamp(26px, 4.2vw, 58px); line-height: .95; font-weight: 900; color: var(--gold); }
.timer.warning { color: #ff6868; animation: pulse .65s infinite alternate; }
.timer.hit { animation: hit .25s; }
.pause-panel { justify-self: end; width: fit-content; padding: 5px; display: flex; align-items: center; pointer-events: auto; }
.icon-button, .close-button { color: var(--ink); background: #50306d; border: 2px solid rgba(255,255,255,.4); border-radius: 10px; cursor: pointer; min-width: 42px; min-height: 42px; }

.screen { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: clamp(18px, 5vw, 70px); background:
  radial-gradient(circle at 18% 20%, rgba(240,98,146,.18), transparent 25%),
  radial-gradient(circle at 82% 78%, rgba(114,228,232,.14), transparent 30%),
  linear-gradient(135deg, rgba(20,10,43,.97), rgba(61,29,70,.94)); overflow-y: auto; }
.screen:empty { display: none; }
.card { width: min(680px, 100%); text-align: center; }
.eyebrow { color: var(--cyan); text-transform: uppercase; letter-spacing: .18em; font-weight: 800; font-size: clamp(12px, 1.4vw, 17px); }
h1 { margin: 0 0 8px; font-size: clamp(48px, 9vw, 112px); line-height: .82; text-transform: uppercase; letter-spacing: -.06em; color: var(--gold); text-shadow: 5px 5px 0 var(--pink), 10px 10px 0 #542d6b; transform: rotate(-2deg); }
h2 { margin: 8px 0 12px; font-size: clamp(30px, 5vw, 64px); line-height: 1; }
.subtitle { font-size: clamp(15px, 2vw, 23px); max-width: 580px; margin: 20px auto; }
.menu { display: grid; gap: 12px; width: min(340px, 100%); margin: 26px auto; }
.primary-button, .secondary-button { border: 0; border-radius: 999px; padding: 13px 26px; min-height: 52px; cursor: pointer; font-weight: 900; letter-spacing: .03em; }
.primary-button { background: var(--gold); color: #26142d; box-shadow: 0 6px 0 #b57832; }
.secondary-button { color: var(--ink); background: transparent; border: 2px solid rgba(255,255,255,.55); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #b57832; }
.portrait { position: relative; width: clamp(100px, 15vw, 170px); aspect-ratio: 1; margin: 12px auto; border-radius: 50%; display: grid; place-items: center; font-size: clamp(44px, 7vw, 80px); background: repeating-radial-gradient(circle, var(--accent, #e76f51) 0 9px, color-mix(in srgb, var(--accent) 78%, #291434) 10px 18px); border: 7px solid var(--ink); box-shadow: 10px 8px 0 rgba(0,0,0,.25); }
.portrait::after { content: ""; position: absolute; inset: 39%; border-radius: 50%; background: var(--ink); border: 4px solid rgba(20,10,43,.7); }
.portrait span { position: relative; z-index: 1; filter: drop-shadow(2px 3px 0 #24152f); }
.intro-card { max-width: 760px; }
.stage-name { display: inline-block; margin: 0 0 8px; padding: 6px 16px; color: var(--gold); border: 1px solid rgba(255,209,102,.5); border-radius: 99px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 9px; margin: 20px 0; }
.stat { padding: 12px; border-radius: 12px; background: rgba(255,255,255,.1); }
.stat strong { display: block; font-size: 1.5em; color: var(--gold); }
.results-table { width: 100%; border-collapse: collapse; margin: 18px 0; }
.results-table th, .results-table td { padding: 8px; border-bottom: 1px solid rgba(255,255,255,.18); text-align: left; }
.content-note { opacity: .72; font-size: 12px; }

.joystick { position: absolute; z-index: 6; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: 126px; height: 126px; touch-action: none; }
.joystick-ring { position: absolute; inset: 7px; border-radius: 50%; background: rgba(18,10,40,.55); border: 3px solid rgba(255,255,255,.5); }
.joystick-knob { position: absolute; width: 54px; height: 54px; border-radius: 50%; background: rgba(255,209,102,.9); left: 50%; top: 50%; transform: translate(-50%,-50%); box-shadow: 0 4px 12px #0008; }

.video-popover { position: fixed; z-index: 20; inset: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 12px; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: #080510; }
.video-topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.video-topbar h2 { margin: 0; font-size: clamp(20px, 3vw, 34px); }
.video-frame-wrap { min-height: 0; display: grid; place-items: center; }
.video-frame-wrap iframe { width: min(100%, calc(100vh * 16 / 9)); height: min(100%, calc(100vw * 9 / 16)); aspect-ratio: 16 / 9; border: 0; background: #000; }
.video-popover > .primary-button { justify-self: center; min-width: 220px; }

.debug-panel { position: absolute; z-index: 10; left: 12px; bottom: 12px; display: grid; gap: 5px; padding: 10px; background: #000d; font: 12px monospace; }
.debug-panel button { cursor: pointer; }
.privacy-shortcuts {
  position: fixed;
  z-index: 14;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  background: rgba(16,10,36,.86);
  backdrop-filter: blur(9px);
  font-size: 12px;
}
.privacy-shortcuts a,
.privacy-shortcuts button {
  color: var(--ink);
}
.privacy-shortcuts a { text-underline-offset: 3px; }
.privacy-shortcuts button {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.cookie-banner {
  position: fixed;
  z-index: 30;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  width: min(980px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px;
  border: 2px solid rgba(255,209,102,.72);
  border-radius: 18px;
  background: rgba(24,14,49,.98);
  box-shadow: 0 18px 70px rgba(0,0,0,.65);
  backdrop-filter: blur(14px);
}
.cookie-copy h2 {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.1;
}
.cookie-copy p {
  max-width: 670px;
  margin: 0;
  line-height: 1.5;
}
.cookie-copy a {
  color: var(--cyan);
  text-underline-offset: 3px;
}
.cookie-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.cookie-actions .primary-button,
.cookie-actions .secondary-button {
  min-height: 46px;
  padding: 10px 18px;
  white-space: nowrap;
}

.legal-page {
  min-height: 100%;
  height: auto;
  overflow: auto;
  user-select: text;
}
.legal-shell {
  width: min(860px, calc(100% - 32px));
  margin: 0 auto;
  padding: 54px 0 120px;
}
.legal-back {
  display: inline-flex;
  margin-bottom: 28px;
  color: var(--cyan);
  font-weight: 800;
  text-underline-offset: 4px;
}
.legal-card {
  padding: clamp(24px, 5vw, 56px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 24px;
  background: rgba(16,10,36,.86);
  box-shadow: var(--shadow);
}
.legal-card h1 {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: clamp(42px, 8vw, 76px);
  line-height: .95;
  transform: none;
  text-transform: none;
  text-shadow: 4px 4px 0 #542d6b;
}
.legal-card h2 {
  margin: 34px 0 10px;
  color: var(--cyan);
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.2;
}
.legal-card h3 {
  margin: 24px 0 8px;
  color: var(--gold);
  font-size: 19px;
}
.legal-card p,
.legal-card li {
  line-height: 1.7;
}
.legal-card a {
  color: var(--cyan);
  text-underline-offset: 3px;
}
.legal-card table {
  width: 100%;
  margin: 18px 0;
  border-collapse: collapse;
}
.legal-card th,
.legal-card td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(255,255,255,.16);
  text-align: left;
  vertical-align: top;
}
.legal-card th { color: var(--gold); }
.legal-note {
  padding: 14px 16px;
  border-left: 4px solid var(--gold);
  background: rgba(255,209,102,.1);
}
.legal-updated {
  color: rgba(255,249,223,.72);
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes pulse { to { transform: scale(1.08); } }
@keyframes hit { 50% { transform: scale(1.25); background: #9c2525; } }
@media (pointer: coarse), (max-width: 760px) { .joystick:not(.hidden) { display: block; } }
@media (max-width: 760px) {
  .cookie-banner {
    grid-template-columns: 1fr;
    gap: 14px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
  .cookie-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .cookie-actions .primary-button,
  .cookie-actions .secondary-button {
    white-space: normal;
  }
  .privacy-shortcuts { font-size: 11px; }
  .legal-card {
    overflow-x: auto;
  }
}
@media (max-width: 480px) {
  .cookie-actions { grid-template-columns: 1fr; }
}
@media (orientation: portrait) and (max-width: 600px) { #app { align-items: center; } #game-shell { width: 100%; } .stage-label strong { display: none; } .timer { min-width: 74px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; } }
