:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background: #030913;
  color: #ecffff;
  --cyan: #5ce9df;
  --amber: #ffc55c;
  --pink: #ef5d9d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; }
body {
  min-height: 100dvh;
  background: radial-gradient(circle at 50% -10%, #17324d 0, #07121f 36%, #030913 80%);
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  touch-action: manipulation;
}
button, a { font: inherit; }
button { color: inherit; }
.game-shell { width: min(100%, 980px); margin: 0 auto; display: grid; gap: 8px; }
.topbar { min-height: 56px; display: grid; grid-template-columns: 72px 1fr 56px; gap: 8px; align-items: center; }
.back-link, .icon-button, .hud button {
  min-width: 56px; min-height: 56px; display: grid; place-items: center; border-radius: 16px;
  border: 1px solid #4ce6df55; background: #071a2bcc; color: #eaffff; text-decoration: none;
}
.identity { text-align: center; min-width: 0; }
.identity span { display: block; color: #85aaa9; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
.identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(.9rem, 3.5vw, 1.2rem); }
.stage {
  position: relative; width: 100%; aspect-ratio: 5 / 3; overflow: hidden; border-radius: 20px;
  border: 1px solid #65f0e455; background: #050d18; box-shadow: 0 20px 60px #000a, inset 0 0 40px #54f0dd12;
}
canvas { width: 100%; height: 100%; display: block; object-fit: contain; touch-action: none; }
.screen { position: absolute; inset: 0; display: none; place-items: center; padding: 18px; background: #020812cf; backdrop-filter: blur(7px); z-index: 6; overflow-y: auto; }
.screen-visible { display: grid; }
.card { width: min(100%, 620px); max-height: 100%; overflow-y: auto; padding: clamp(18px, 4vw, 34px); border: 1px solid #69e8de70; border-radius: 22px; background: linear-gradient(145deg, #0a2032f2, #090f20f2); text-align: center; box-shadow: 0 18px 70px #000c; }
.card h1, .card h2, .card p { margin-top: 0; }
.card h1 { margin-bottom: 12px; font-size: clamp(2rem, 8vw, 4.2rem); line-height: .9; letter-spacing: -.04em; }
.card h1 span { display: block; color: var(--cyan); }
.card h2 { margin-bottom: 12px; font-size: clamp(1.55rem, 5vw, 2.6rem); }
.card p { color: #c9dddd; line-height: 1.55; }
.kicker { margin-bottom: 10px !important; color: var(--amber) !important; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: .72rem; }
.primary-button, .text-button {
  min-height: 56px; min-width: 190px; border-radius: 18px; border: 0; padding: 12px 22px; cursor: pointer; font-weight: 900;
}
.primary-button { background: linear-gradient(135deg, var(--cyan), #80f0c0); color: #032126; box-shadow: 0 8px 24px #5ce9df44; }
.text-button { background: transparent; color: #b9efeb; text-decoration: underline; }
.as-link { display: inline-grid; place-items: center; }
.controls-hint { margin: 14px 0 0 !important; font-size: .78rem; color: #8eb1b4 !important; }
.compact-card { width: min(100%, 430px); }
.ending-time { display: grid; margin: 14px auto; }
.ending-time strong { font-size: clamp(2rem, 8vw, 4rem); color: var(--amber); }
.ending-time small { color: #98b8b8; text-transform: uppercase; letter-spacing: .12em; }
.hud { position: absolute; inset: 10px 10px auto; z-index: 4; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) 56px; gap: 6px; pointer-events: none; }
.hud[hidden] { display: none; }
.hud > div { min-height: 48px; display: grid; place-content: center; padding: 5px 9px; border-radius: 12px; background: #04101de3; border: 1px solid #6ce9df35; text-align: center; }
.hud small { font-size: .56rem; color: #82a9a8; text-transform: uppercase; }
.hud strong { font-size: clamp(.72rem, 2.2vw, 1rem); white-space: nowrap; }
.hud button { min-height: 48px; pointer-events: auto; }
.toast { position: absolute; z-index: 5; left: 50%; bottom: 12px; translate: -50% 0; width: min(calc(100% - 24px), 520px); padding: 12px 18px; border-radius: 16px; border: 1px solid #ffc55c88; background: #071521f2; text-align: center; box-shadow: 0 12px 40px #000b; }
.toast[hidden] { display: none; }
.toast strong, .toast span, .toast small { display: block; }
.toast strong { color: var(--amber); }
.toast span { margin: 3px 0; font-size: .88rem; }
.toast small { color: #8fb3b4; }
.boss-toast { border-color: #ef5d9d99; }
.boss-hud { position: absolute; z-index: 4; left: 50%; top: 70px; translate: -50% 0; min-width: 250px; padding: 7px 16px; border: 1px solid #ef5d9d77; background: #100818e8; border-radius: 14px; text-align: center; }
.boss-hud[hidden] { display: none; }
.boss-hud span { display: block; color: #f3a4c5; font-size: .65rem; letter-spacing: .13em; }
.boss-hud strong { color: var(--cyan); letter-spacing: .25em; }
.touch-controls { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(120px, 1fr); gap: 14px; min-height: 150px; align-items: stretch; user-select: none; -webkit-user-select: none; }
.joystick-control { min-height: 150px; display: grid; place-items: center; align-content: center; gap: 4px; touch-action: none; border-radius: 24px; background: #071522b8; border: 1px solid #65f0e438; }
.joystick-base { position: relative; width: 112px; height: 112px; border-radius: 50%; border: 2px solid #65f0e466; background: radial-gradient(circle, #65f0e418 0 18%, transparent 20%), #0a2134; box-shadow: inset 0 0 24px #0009; }
.joystick-knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; display: grid; place-items: center; border-radius: 50%; color: #082326; background: var(--cyan); box-shadow: 0 5px 20px #5ce9df55; transform: translate(0, 0); transition: transform 90ms ease-out; }
.joystick-control[data-active="true"] .joystick-knob { transition: none; }
.joystick-control small { color: #8fb7b6; }
.action-button { min-height: 112px; min-width: 112px; align-self: center; justify-self: center; aspect-ratio: 1; border-radius: 50%; border: 2px solid #ffc55c99; background: radial-gradient(circle at 38% 30%, #fff1a8, var(--amber) 45%, #d87537 100%); color: #321706; box-shadow: 0 9px 28px #ffc55c44; touch-action: none; }
.action-button span, .action-button b { display: block; }
.action-button span { font-size: 2.1rem; }
.action-button b { text-transform: uppercase; letter-spacing: .08em; }
.action-button:active { transform: scale(.94); }
footer { padding: 4px 10px; text-align: center; color: #708d91; font-size: .72rem; }
footer p { margin: 5px 0; }
footer strong { color: #a8cdca; }
.qa-panel { position: fixed; z-index: 20; right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, minmax(56px, auto)); gap: 5px; padding: 7px; border-radius: 14px; border: 1px solid #ffc55c99; background: #060b14ed; }
.qa-panel[hidden] { display: none; }
.qa-panel strong { grid-row: span 2; display: grid; place-items: center; padding: 6px; color: var(--amber); }
.qa-panel button { min-width: 56px; min-height: 56px; padding: 4px; border: 1px solid #62e7dc66; border-radius: 10px; background: #10273a; color: #eaffff; font-size: .7rem; }

@media (pointer: fine) and (min-width: 900px) {
  .touch-controls { display: none; }
}

@media (max-width: 520px) {
  body { padding-top: max(4px, env(safe-area-inset-top)); }
  .game-shell { gap: 5px; }
  .topbar { min-height: 56px; grid-template-columns: 62px 1fr 56px; }
  .back-link, .icon-button { min-height: 56px; border-radius: 14px; }
  .stage { height: 330px; aspect-ratio: auto; border-radius: 14px; }
  .screen { padding: 10px; }
  .card { padding: 12px 16px; border-radius: 16px; }
  .card h1 { font-size: clamp(1.8rem, 10vw, 3rem); }
  .card p { font-size: .85rem; line-height: 1.4; }
  .title-card p:not(.kicker) { line-height: 1.28; }
  .title-card .controls-hint { display: none; }
  .hud { inset: 5px 5px auto; gap: 3px; grid-template-columns: repeat(4, minmax(0, 1fr)) 56px; }
  .hud > div { min-height: 56px; padding: 3px; border-radius: 9px; }
  .hud button { min-width: 56px; min-height: 56px; border-radius: 9px; }
  .boss-hud { top: 66px; min-width: 210px; padding: 4px 10px; }
  .touch-controls { min-height: 146px; gap: 8px; }
  .joystick-control { min-height: 146px; }
  footer { display: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  body { padding-top: max(4px, env(safe-area-inset-top)); }
  .game-shell { width: min(100%, 880px); grid-template-columns: minmax(0, 1fr) 190px; grid-template-rows: 48px minmax(0, 1fr); gap: 5px 10px; }
  .topbar { grid-column: 1 / -1; min-height: 56px; }
  .back-link, .icon-button { min-height: 56px; }
  .stage { grid-column: 1; height: 100%; max-height: calc(100dvh - 70px); }
  .touch-controls { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; grid-template-rows: 1fr 104px; min-height: 0; }
  .joystick-control { min-height: 0; }
  .joystick-base { width: 104px; height: 104px; }
  .action-button { min-width: 88px; min-height: 88px; width: 88px; }
  footer { display: none; }
  .card { padding: 12px 18px; }
  .card h1 { font-size: 2.4rem; }
  .card p { font-size: .78rem; line-height: 1.3; }
  .primary-button, .text-button { min-height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
