/* Swarm Doctrine — one stylesheet. Arcade night sky, chunky buttons, big thumbs; a sleeker title screen. */

:root {
    --bg: #0d0826;
    --bg-2: #1a0f45;
    --panel: #1d1450;
    --panel-hover: #281c68;
    --panel-solid: #1a1248;
    --panel-glass: #150e3de6;
    --border: #ffffff1f;
    --border-soft: #ffffff12;
    --accent: #ffd23f;
    --accent-deep: #d69a00;
    --accent-2: #37e2d5;
    --accent-2-deep: #169c93;
    --on-accent: #2b1a00;
    --text: #fbf8ff;
    --text-2: #cfc6f5;
    --text-3: #978cc7;
    --focus: #ffe98a;
    --danger: #ff5d7a;
    --player-color: #00f7ff;
    --radius: 18px;
    --radius-lg: 26px;
    --tap: 48px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --display: 'Fredoka', 'Nunito', system-ui, sans-serif;
    --sky: radial-gradient(circle at 15% 10%, #ff4fd833, transparent 40%), radial-gradient(circle at 85% 20%, #37e2d52e, transparent 45%), radial-gradient(circle at 50% 100%, #6a4bff40, transparent 55%), linear-gradient(180deg, var(--bg-2), var(--bg));
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 600 16px/1.45 var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent-2); }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--display); }
h2 { font-weight: 700; font-size: clamp(28px, 4vw, 40px); line-height: 1.1; letter-spacing: 0.2px; color: var(--text); text-shadow: 0 3px 0 #00000055; }
h2:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.hidden { display: none !important; }

@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-10px) rotate(8deg); } }
@keyframes glow { 0%, 100% { box-shadow: 0 6px 0 var(--accent-deep), 0 0 0 0 #ffd23f66; } 50% { box-shadow: 0 6px 0 var(--accent-deep), 0 0 32px 4px #ffd23f55; } }
@keyframes shimmer { to { background-position: 200% 0; } }

/* Screens ----------------------------------------------------------------- */

.screen { position: fixed; inset: 0; overflow-y: auto; overscroll-behavior: contain; height: 100dvh; }
.screen-page { background: var(--sky); padding: 0 calc(16px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(16px + var(--safe-left)); }
.screen-page:not(.hidden) .page > *:not(.page-head) { animation: pop-in .35s cubic-bezier(.2, .9, .3, 1.3) both; }
.screen-page:not(.hidden) .page > *:nth-child(3) { animation-delay: .04s; }
.screen-page:not(.hidden) .page > *:nth-child(4) { animation-delay: .08s; }
.screen-page:not(.hidden) .page > *:nth-child(5) { animation-delay: .12s; }
.page { width: min(960px, 100%); margin: 0 auto; display: grid; gap: 16px; }
.page-narrow { width: min(640px, 100%); }
.page-head { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: center; margin: 0 calc(-16px - var(--safe-left)) 4px; padding: calc(12px + var(--safe-top)) 16px 14px; background: linear-gradient(180deg, #1a0f45f2 70%, #1a0f4500); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.page-head .btn-back { grid-row: 1 / 3; }
.page-head .eyebrow { grid-column: 2; }
.page-head h2 { grid-column: 2; font-size: clamp(26px, 4vw, 36px); }
.page-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.eyebrow, .card-eyebrow { display: block; font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.card-eyebrow { color: var(--text-3); }
.note { color: var(--text-2); font-size: 14px; font-weight: 600; }
.section-title { font: 700 14px var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); margin-top: 8px; }

/* Home: the arcade sky, sharpened. A faint arena grid, a vector mark and
   chamfered HUD buttons keep it a game without looking like a toy. */
.screen-home { --home-font: 'Chakra Petch', var(--display); overflow: hidden; display: grid; place-items: center;
    background: radial-gradient(ellipse at 50% 42%, #2a1a7055, transparent 60%), radial-gradient(ellipse at 50% 120%, #37e2d51f, transparent 55%), linear-gradient(180deg, #120a36, #07041a); }
.screen-home::before { content: ''; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(#00f7ff0d 1px, transparent 1px), linear-gradient(90deg, #00f7ff0d 1px, transparent 1px); background-size: 64px 64px; background-position: center;
    -webkit-mask-image: radial-gradient(ellipse at 50% 45%, #000 20%, transparent 75%); mask-image: radial-gradient(ellipse at 50% 45%, #000 20%, transparent 75%); }
.screen-home::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 50%, transparent 55%, #05021299 100%); }
#swarm-preview { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0.55; }
.home-hero > * { max-width: 100%; }
.home-hero { position: relative; z-index: 2; width: min(400px, 100%); padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom)); display: grid; justify-items: center; text-align: center; }
.home-mark { width: 72px; height: 68px; color: var(--accent-2); filter: drop-shadow(0 0 14px #37e2d599); margin-bottom: 22px; animation: float 5s ease-in-out infinite; }
.home-title { display: grid; font-family: var(--home-font); font-weight: 700; line-height: 0.9; text-transform: uppercase; }
.home-title span { font-size: clamp(50px, 14vw, 78px); letter-spacing: 0.08em; margin-right: -0.08em; color: var(--text); text-shadow: 0 0 30px #6a4bff66; }
.home-title em { font-style: normal; font-weight: 600; font-size: clamp(22px, 6.2vw, 34px); letter-spacing: 0.42em; margin-right: -0.42em; margin-top: 10px;
    background: linear-gradient(90deg, var(--accent-2), #8f7bff 50%, #ff6bd6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.home-tagline { display: flex; align-items: center; gap: 12px; color: var(--text-3); font: 600 12px var(--home-font); letter-spacing: 0.2em; text-transform: uppercase; white-space: nowrap; margin: 22px 0 34px; }
.home-tagline::before, .home-tagline::after { content: ''; width: 28px; height: 1px; background: linear-gradient(90deg, transparent, var(--text-3)); }
.home-tagline::after { transform: scaleX(-1); }
.home-actions { display: grid; gap: 12px; width: 100%; }
.screen-home .btn-big { --cut: 14px; min-height: 60px; border-radius: 0; font: 700 18px var(--home-font); letter-spacing: 0.18em; text-transform: uppercase; box-shadow: none; text-shadow: none;
    clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut)); transition: filter .15s, transform .08s; }
.screen-home .btn-big svg { width: 20px; height: 20px; flex: none; }
.screen-home .btn-big:active { transform: scale(0.985); box-shadow: none; }
.screen-home .btn-primary { background: linear-gradient(135deg, #ffe27a, var(--accent) 45%, #ffae2b); color: #1d1200; filter: drop-shadow(0 0 18px #ffc83d55); }
.screen-home .btn-primary:hover { filter: drop-shadow(0 0 26px #ffc83d88) brightness(1.05); }
.screen-home .btn-secondary { background: linear-gradient(135deg, #37e2d5, #37e2d566); color: #bdfbf6; isolation: isolate; }
/* A chamfered outline: the gradient shows through a 1.5px gap around an inner panel with the same cut. */
.screen-home .btn-secondary::before { content: ''; position: absolute; inset: 1.5px; z-index: -1; background: linear-gradient(135deg, #133a4a, #0e1238);
    clip-path: polygon(calc(var(--cut) - 0.6px) 0, 100% 0, 100% calc(100% - var(--cut) + 0.6px), calc(100% - var(--cut) + 0.6px) 100%, 0 100%, 0 calc(var(--cut) - 0.6px)); transition: background .15s; }
.screen-home .btn-secondary:hover { filter: none; }
.screen-home .btn-secondary:hover::before { background: linear-gradient(135deg, #1a4d5e, #151a4a); }
#btn-play { animation: none; }
.home-links { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 26px; }
.home-link { min-height: var(--tap); padding: 0 6px; border: 0; background: none; color: var(--text-2); font: 600 13px var(--home-font); letter-spacing: 0.2em; text-transform: uppercase; cursor: pointer; transition: color .15s; }
.home-link:hover, .home-link:focus-visible { color: var(--accent-2); }
.home-link-sep { width: 4px; height: 4px; transform: rotate(45deg); background: var(--text-3); }
.home-record { margin-top: 12px; color: var(--accent); font: 600 12px var(--home-font); letter-spacing: 0.18em; text-transform: uppercase; min-height: 1.4em; }

/* Buttons ----------------------------------------------------------------- */

.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 54px; padding: 12px 22px; border: 0; border-radius: 16px; background: var(--panel-hover); color: var(--text); text-decoration: none; font: 700 17px var(--display); letter-spacing: 0.3px; box-shadow: 0 5px 0 #0f0930, inset 0 1px 0 #ffffff1a; transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #0f0930; }
.btn-primary { background: linear-gradient(180deg, #ffe06a, var(--accent)); color: var(--on-accent); box-shadow: 0 6px 0 var(--accent-deep), 0 14px 26px #ffb80033; text-shadow: 0 1px 0 #fff6; }
.btn-primary:active { box-shadow: 0 2px 0 var(--accent-deep); }
.btn-secondary { background: linear-gradient(180deg, #6cf3e9, var(--accent-2)); color: #06302d; box-shadow: 0 6px 0 var(--accent-2-deep), 0 14px 26px #37e2d522; }
.btn-secondary:active { box-shadow: 0 2px 0 var(--accent-2-deep); }
.btn-big { width: 100%; min-height: 64px; font-size: 22px; border-radius: 20px; }
#btn-play { animation: glow 2.4s ease-in-out infinite; }
#btn-play:active { animation: none; }
.btn-wide { width: 100%; }
.btn-danger { background: #3a1030; color: #ff9fb3; box-shadow: 0 5px 0 #1f0718; }
.btn-quiet { background: none; box-shadow: none; color: var(--text-2); }
.btn-quiet:active { transform: none; }
.btn-back, .pill, .chip { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; min-height: var(--tap); padding: 0 18px; border-radius: 999px; border: 0; background: var(--panel-hover); color: var(--text); font: 700 15px var(--display); box-shadow: 0 4px 0 #0f0930, inset 0 1px 0 #ffffff1a; transition: transform .08s, box-shadow .08s, filter .15s; }
.btn-back:hover, .pill:hover, .chip:hover { filter: brightness(1.15); }
.btn-back:active, .pill:active, .chip:active { transform: translateY(3px); box-shadow: 0 1px 0 #0f0930; }
.btn-back { width: var(--tap); padding: 0; font-size: 0; }
.btn-back::before { content: '←'; font-size: 22px; line-height: 1; }
.pill { background: #ffffff14; box-shadow: 0 3px 0 #0006; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card-grid-3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.card-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { --tint: var(--accent-2); position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr; grid-auto-rows: min-content; column-gap: 14px; row-gap: 2px; align-items: center; min-height: 92px; padding: 16px 18px; text-align: left; background: linear-gradient(135deg, color-mix(in srgb, var(--tint) 22%, var(--panel)), var(--panel) 70%); border: 2px solid color-mix(in srgb, var(--tint) 35%, transparent); border-radius: var(--radius); color: var(--text); box-shadow: 0 6px 0 #0f0930, 0 12px 24px #0005; transition: transform .1s, box-shadow .1s, border-color .15s; }
.card > :not(.card-icon):not(.team-symbol) { grid-column: 2; }
.card > .card-icon, .card > .team-symbol { grid-column: 1; grid-row: 1 / span 3; }
.card:hover { border-color: var(--tint); transform: translateY(-2px); box-shadow: 0 8px 0 #0f0930, 0 16px 30px color-mix(in srgb, var(--tint) 30%, transparent); }
.card:active { transform: translateY(4px); box-shadow: 0 2px 0 #0f0930; }
.card strong { font: 700 20px/1.15 var(--display); letter-spacing: 0.2px; }
.card p { color: var(--text-2); font-size: 14px; line-height: 1.4; font-weight: 600; }
.card-icon { width: 56px; height: 56px; display: grid; place-items: center; font-size: 30px; border-radius: 16px; background: color-mix(in srgb, var(--tint) 30%, #0000); box-shadow: inset 0 -3px 0 #0003, 0 0 0 2px color-mix(in srgb, var(--tint) 45%, transparent); }
.card.done { --tint: #4cf0a8; }
.card.done .card-eyebrow { color: #4cf0a8; }
.card.done .card-eyebrow::after { content: ' ★'; }
.card.choice[aria-pressed="true"] { border-color: var(--tint); box-shadow: 0 6px 0 #0f0930, 0 0 0 3px color-mix(in srgb, var(--tint) 45%, transparent), 0 12px 30px color-mix(in srgb, var(--tint) 35%, transparent); }
.card.choice[aria-pressed="true"]::after { content: '✓'; position: absolute; top: 10px; right: 12px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--tint); color: #120a33; font-weight: 900; font-size: 15px; }
.team-card { --tint: var(--team); }
.team-symbol { width: 56px; height: 56px; display: grid; place-items: center; font: 30px var(--display); color: var(--team); border-radius: 16px; background: color-mix(in srgb, var(--team) 20%, #0000); box-shadow: 0 0 0 2px color-mix(in srgb, var(--team) 50%, transparent), 0 0 20px color-mix(in srgb, var(--team) 30%, transparent); line-height: 1; }
.upgrade-card { min-height: 130px; text-align: left; }
#lesson-grid .card { grid-template-columns: 1fr; }
#lesson-grid .card > * { grid-column: 1; }

/* Guide */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 10px; }
.steps li { counter-increment: step; padding: 16px 16px 16px 66px; position: relative; background: var(--panel); border-radius: var(--radius); box-shadow: 0 5px 0 #0f0930; }
.steps li::before { content: counter(step); position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--on-accent); font: 700 18px var(--display); box-shadow: 0 3px 0 var(--accent-deep); }
.steps strong { display: block; font: 700 19px var(--display); margin-bottom: 2px; }
.steps p, .rule-list li, .controls dd { color: var(--text-2); font-size: 15px; line-height: 1.55; }
.controls { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 0; padding: 16px; background: var(--panel); border-radius: var(--radius); }
.controls dt { font: 700 16px var(--display); color: var(--accent); }
.controls dd { margin: 0; }
.rule-list { margin: 0; padding: 16px 16px 16px 34px; display: grid; gap: 8px; background: var(--panel); border-radius: var(--radius); }

/* Online lobby */
.online-setup { display: grid; gap: 12px; padding: 16px; background: var(--panel); border-radius: var(--radius); }
.online-field { display: grid; gap: 6px; }
.online-field > span { font: 700 13px var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); }
.online-field .field { min-height: var(--tap); font: 700 17px var(--font); color: var(--text); }
.segmented-wrap { flex-wrap: wrap; border-radius: 18px; }
.online-status { font-weight: 700; color: var(--text-2); }
.online-status[data-state="online"]::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: #4cf0a8; box-shadow: 0 0 8px #4cf0a8; }
.online-players { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.online-player { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; background: var(--panel); border-radius: var(--radius); box-shadow: 0 5px 0 #0f0930; }
.online-player strong { font: 700 18px var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-player .btn { min-height: 44px; padding: 8px 16px; font-size: 15px; }
.online-player .btn:disabled { opacity: 0.5; }
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: #4cf0a8; box-shadow: 0 0 8px #4cf0a8; }
.online-player.busy .online-dot { background: #ffb13b; box-shadow: none; }

/* Field guide */
.page-guide { width: min(820px, 100%); gap: 12px; }
.page-guide > * { min-width: 0; }
.guide-chapters { display: flex; gap: 6px; overflow-x: auto; padding: 2px; margin: 0 -2px; scrollbar-width: none; min-width: 0; }
@media (min-width: 760px) { .guide-chapters { flex-wrap: wrap; overflow: visible; } }
.guide-chapters::-webkit-scrollbar { display: none; }
.guide-chapters .pill { flex: none; min-height: 38px; padding: 0 14px; font-size: 14px; background: #ffffff10; box-shadow: none; }
.guide-chapters .pill.active { background: var(--accent); color: var(--on-accent); }
.guide-device { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 10px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: #0d0826; box-shadow: inset 0 2px 4px #0006; }
.segment { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; background: none; color: var(--text-2); font: 700 14px var(--display); cursor: pointer; }
.segment[aria-pressed="true"] { background: var(--panel-hover); color: var(--text); box-shadow: 0 2px 0 #0f0930; }
.guide-progress { height: 6px; border-radius: 999px; background: #ffffff14; overflow: hidden; }
#guide-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .25s ease; }
.guide-card { margin: 0; overflow: hidden; background: var(--panel); border-radius: var(--radius-lg); box-shadow: 0 6px 0 #0f0930, 0 16px 30px #0005; }
.guide-media { display: grid; place-items: center; background: #0d0826; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.guide-media img { display: block; width: 100%; height: auto; -webkit-user-drag: none; }
/* Portrait pictures: keep picture, caption and buttons on one screen. */
#guide-screen[data-device="phone"] .guide-media img { width: auto; max-width: 100%; max-height: max(220px, calc(100dvh - 430px - var(--safe-top) - var(--safe-bottom))); aspect-ratio: 3 / 4; }
.guide-card figcaption { display: grid; gap: 4px; padding: 14px 18px 18px; }
.guide-card strong { font: 700 21px/1.25 var(--display); }
.guide-card p { color: var(--text-2); font-size: 16px; line-height: 1.5; }
@media (max-width: 440px) { .home-tagline { font-size: 11px; letter-spacing: 0.12em; gap: 8px; } .home-tagline::before, .home-tagline::after { width: 14px; } }
@media (max-width: 480px) { .guide-card figcaption { padding: 12px 14px 14px; } .guide-card strong { font-size: 19px; } .guide-card p { font-size: 15px; line-height: 1.45; } }
.guide-nav { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.guide-nav .btn { white-space: nowrap; padding-inline: 12px; }
.guide-nav .btn:disabled { opacity: 0.4; }
.timeline { width: 100%; display: grid; gap: 12px; padding: 36px 18px 20px; }
.timeline-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; }
.timeline-row b { font: 700 14px var(--display); color: var(--text-2); }
.timeline-track { position: relative; height: 36px; border-radius: 10px; background: #0d0826; }
.timeline-bar { position: absolute; top: 3px; bottom: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 8px; font: 700 12px var(--display); white-space: nowrap; color: #120a33; }
.timeline-bar span { padding: 0 4px; overflow: hidden; text-overflow: ellipsis; }
.timeline-bar.locked { background: repeating-linear-gradient(135deg, #4a3f86, #4a3f86 6px, #3a2f78 6px, #3a2f78 12px); color: var(--text); }
.timeline-bar.charging { background: linear-gradient(90deg, #37e2d555, #37e2d5); }
.timeline-bar.frozen { background: #b6edff; }
.timeline-cast { position: absolute; top: -18px; bottom: -4px; border-left: 2px dashed #fff; }
.timeline-cast span { position: absolute; top: -4px; left: 4px; font: 700 12px var(--display); white-space: nowrap; }
.timeline-axis { display: flex; justify-content: space-between; margin-left: 74px; color: var(--text-3); font-size: 12px; font-weight: 700; }

/* Settings */
.settings { display: grid; gap: 16px; }
.settings-group { border: 0; border-radius: var(--radius); padding: 10px 18px 14px; margin: 0; background: var(--panel); box-shadow: 0 5px 0 #0f0930; }
.settings-group legend { float: left; width: 100%; padding: 6px 0 4px; font: 700 14px var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); }
.setting-row { clear: both; display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 1.4fr) 4ch; align-items: center; gap: 12px; min-height: 52px; border-top: 1px solid var(--border-soft); }
.setting-row label { font-weight: 700; }
.setting-row label small { color: var(--text-3); font-weight: 600; }
.setting-row select { min-height: 42px; border-radius: 12px; border: 0; background: var(--panel-hover); padding: 0 12px; grid-column: 2 / 4; font-weight: 700; box-shadow: 0 3px 0 #0f0930; }
.setting-row input[type=range] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.setting-row output { color: var(--accent); font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.field { grid-column: 2 / -1; width: 100%; min-height: var(--tap); padding: 0 12px; border-radius: 12px; border: 0; background: var(--panel-hover); }
details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
.switch { appearance: none; justify-self: end; grid-column: 3; width: 54px; height: 32px; border-radius: 999px; background: #3a2f78; position: relative; cursor: pointer; transition: background .18s; box-shadow: inset 0 2px 4px #0006; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px #0006; transition: transform .2s cubic-bezier(.3, 1.5, .5, 1); }
.switch:checked { background: #4cf0a8; }
.switch:checked::after { transform: translateX(22px); }

/* Game screen -------------------------------------------------------------- */

.screen-game { overflow: hidden; background: radial-gradient(ellipse at 50% 45%, #22185a, #0b0624 75%); user-select: none; -webkit-user-select: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud-top { position: fixed; z-index: 30; top: calc(10px + var(--safe-top)); left: calc(10px + var(--safe-left)); right: calc(10px + var(--safe-right)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-top > .chip { justify-self: start; }
.hud-chips { justify-self: end; display: flex; gap: 8px; }
.hud-top .chip { background: #1d1450d9; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.chip-icon { width: var(--tap); padding: 0; }
#btn-pause::before { content: ''; width: 5px; height: 16px; border-radius: 2px; background: currentColor; box-shadow: 9px 0 0 currentColor; margin-right: 9px; }
.chip[aria-expanded="true"] { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 0 var(--accent-deep); }
.hud-status { pointer-events: none; display: grid; justify-items: center; padding: 6px 18px 8px; background: #1d1450d9; border-radius: 18px; box-shadow: 0 4px 0 #0f0930; font-variant-numeric: tabular-nums; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#hud-timer { font: 700 18px var(--display); color: var(--text); line-height: 1.2; }
.hud-sub { font-size: 13px; font-weight: 800; color: var(--accent); }
.hud-sub b { color: var(--text); font-weight: 800; }
.hud-combo { position: fixed; z-index: 29; top: calc(70px + var(--safe-top)); left: 50%; transform: translateX(-50%) rotate(-3deg); padding: 4px 14px; font: 700 18px var(--display); color: var(--on-accent); background: linear-gradient(180deg, #ffe06a, var(--accent)); border-radius: 999px; box-shadow: 0 4px 0 var(--accent-deep); pointer-events: none; }
.rival-status { position: fixed; z-index: 28; top: calc(104px + var(--safe-top)); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: var(--text-3); pointer-events: none; white-space: nowrap; }

.coach { position: fixed; z-index: 60; top: calc(68px + var(--safe-top)); right: calc(10px + var(--safe-right)); width: min(330px, calc(100vw - 20px)); max-height: min(340px, 50dvh); overflow: auto; padding: 14px 16px; display: grid; gap: 4px; background: var(--panel-solid); border: 2px solid #ffd23f55; border-radius: var(--radius); box-shadow: 0 6px 0 #0f0930, 0 18px 40px #0008; animation: pop-in .25s cubic-bezier(.2, .9, .3, 1.3); }
.coach strong { font: 700 18px var(--display); }
.coach p { color: var(--text-2); font-size: 14px; }
.coach .eyebrow:empty, .coach p:empty, .checklist:empty { display: none; }
.checklist { list-style: none; margin: 6px 0 0; padding: 8px 0 0; border-top: 1px solid var(--border-soft); display: grid; gap: 4px; font-size: 14px; color: var(--text-2); }
.checklist .done { color: #4cf0a8; }

.scrim { position: fixed; inset: 0; z-index: 70; background: #0806188c; }
.sheet { position: fixed; z-index: 80; left: 0; right: 0; bottom: 0; max-height: min(72dvh, calc(100dvh - 72px)); overflow: auto; padding: 10px 18px calc(18px + var(--safe-bottom)); background: var(--panel-solid); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: 0 -10px 40px #0008; display: grid; gap: 16px; align-content: start; animation: pop-in .25s ease-out; }
.sheet::before { content: ''; justify-self: center; width: 44px; height: 5px; border-radius: 3px; background: #ffffff33; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head strong { font: 700 22px var(--display); }
.sheet-section { display: grid; gap: 6px; padding: 14px; background: var(--panel); border-radius: var(--radius); }
.sheet-section h3 { font: 700 13px var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-2); }
.big-number { font: 700 36px var(--display); color: var(--accent); }
.meter { height: 10px; border-radius: 5px; background: #0f0930; overflow: hidden; box-shadow: inset 0 2px 3px #0008; }
.meter > div { height: 100%; width: 0; border-radius: 5px; background: var(--player-color); transition: width .3s; box-shadow: inset 0 -3px 0 #0003; }
.fleet-bars { display: grid; gap: 10px; }
.fleet-bar { display: grid; grid-template-columns: 1fr auto; gap: 4px; font-size: 14px; font-weight: 800; }
.fleet-bar .fleet-name, .fleet-bar .fleet-count { color: var(--team); font-variant-numeric: tabular-nums; }
.fleet-bar .meter { grid-column: 1 / -1; }
.fleet-bar .meter > div { background: var(--team); }

/* Round arcade buttons, bottom-centre on desktop, thumb corners on phones. */
.ability-bar { position: fixed; z-index: 35; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-bottom)); display: flex; gap: 22px; pointer-events: none; }
.ability { pointer-events: auto; position: relative; overflow: hidden; width: 104px; height: 104px; padding: 0; display: grid; justify-items: center; align-content: center; gap: 0; border: 0; border-radius: 50%; color: #fff; background: radial-gradient(circle at 50% 30%, #3b2c8f, #1d1450); box-shadow: 0 6px 0 #0f0930, 0 12px 30px #0008, inset 0 0 0 3px #ffffff22; transition: transform .08s, box-shadow .08s; }
#slot-freeze { animation: pop-in .4s cubic-bezier(.2, .9, .3, 1.6); background: radial-gradient(circle at 50% 30%, #7ff7ee, #1aa9c9); box-shadow: 0 6px 0 #0c6a80, 0 12px 30px #37e2d544, inset 0 0 0 3px #ffffff33; }
.ability:active, .ability.active { transform: translateY(4px) scale(0.97); }
#slot-freeze.aiming { box-shadow: 0 2px 0 #0c6a80, 0 0 0 6px #7ff7ee66, 0 0 40px #7ff7ee88, inset 0 0 0 3px #fff8; transform: translateY(4px); }
.ability.locked { filter: grayscale(1) brightness(0.6); }
.ability-key { position: absolute; top: 14px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #fffc; }
.ability-icon { font-size: 34px; line-height: 1; color: #fff; text-shadow: 0 2px 0 #0004; }
.ability-label { font: 700 15px var(--display); letter-spacing: 0.3px; text-shadow: 0 2px 0 #0004; }
.ability-status { position: absolute; bottom: 12px; left: 6px; right: 6px; text-align: center; font-size: 11px; font-weight: 800; color: #fff; min-height: 14px; text-shadow: 0 1px 2px #0008; }
.ability-status:empty { display: none; }
.ability-cooldown { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: #0f0930aa; pointer-events: none; }
.ability.cooling .ability-icon { opacity: 0.6; }

/* Dialogs ------------------------------------------------------------------ */

.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: calc(20px + var(--safe-top)) calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left)); background: #0806189e; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); overflow: auto; }
.dialog { width: min(420px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; display: grid; gap: 12px; padding: 28px 24px 24px; text-align: center; background: linear-gradient(180deg, #2a1d70, var(--panel-solid)); border: 2px solid #ffffff1f; border-radius: var(--radius-lg); box-shadow: 0 10px 0 #0f0930, 0 30px 80px #000a; animation: pop-in .3s cubic-bezier(.2, .9, .3, 1.4); }
.dialog h2 { font-size: clamp(30px, 6vw, 40px); }
.dialog-wide { width: min(780px, 100%); }
.dialog .note, .dialog p { color: var(--text-2); }
.dialog p:empty { display: none; }
.callout { padding: 12px 14px; border-radius: 14px; background: #ffd23f1f; border: 2px dashed #ffd23f66; color: var(--text) !important; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; margin: 8px 0; }
.stat { display: flex; flex-direction: column-reverse; padding: 10px 4px; background: #0f0930aa; border-radius: 14px; }
.stat dt { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.stat dd { margin: 0; font: 700 26px var(--display); color: var(--accent); }

.toast { position: fixed; z-index: 200; left: 50%; bottom: calc(140px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 16px; background: var(--panel-hover); box-shadow: 0 5px 0 #0f0930, 0 10px 30px #0008; font-size: 14px; font-weight: 700; animation: pop-in .25s ease-out; }
.busy { position: fixed; z-index: 190; inset: 0; display: grid; place-items: center; background: #080618aa; color: var(--text); font: 700 20px var(--display); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--bg); }

/* Layouts ------------------------------------------------------------------ */

@media (min-width: 900px) {
    .card-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .card-grid-4 .card { grid-template-columns: 1fr; justify-items: start; }
    .card-grid-4 .card > * { grid-column: 1; grid-row: auto; }
}
@media (min-width: 960px) {
    .sheet { top: 0; left: auto; width: min(400px, 42vw); max-height: none; border-radius: var(--radius-lg) 0 0 var(--radius-lg); padding-top: calc(16px + var(--safe-top)); }
    .sheet::before { display: none; }
    body.details-open .hud-chips { margin-right: min(400px, 42vw); }
}
/* Phones: app-style stacked lists and thumb-reach controls. */
@media (max-width: 720px) {
    .card-grid, .card-grid-4 { grid-template-columns: 1fr; gap: 12px; }
    .card { min-height: 84px; padding: 14px 16px; }
    .dialog { padding: 24px 18px 20px; }
    .stat dd { font-size: 22px; }
    .chip-label { display: none; }
    .hud-chips .chip { width: var(--tap); padding: 0; font-size: 18px; }
    .ability-bar { left: calc(14px + var(--safe-left)); right: calc(14px + var(--safe-right)); transform: none; justify-content: flex-end; bottom: calc(14px + var(--safe-bottom)); }
    .ability { width: 92px; height: 92px; }
    .ability-key { display: none; }
    .setting-row { grid-template-columns: 1fr auto; padding: 6px 0; }
    .setting-row input[type=range] { grid-column: 1 / -1; grid-row: 2; }
    .setting-row output { grid-column: 2; grid-row: 1; }
    .setting-row select { grid-column: 2; }
    .switch { grid-column: 2; }
    .page-actions .btn { flex: 1 1 100%; }
}
/* Landscape phones: keep the arena clear. */
@media (max-height: 500px) {
    .home-logo { display: none; }
    .home-title { font-size: 44px; }
    .home-tagline { margin: 10px 0 14px; }
    .btn-big { min-height: 52px; font-size: 18px; }
    .home-record { display: none; }
    .ability-bar { left: auto; right: calc(12px + var(--safe-right)); transform: none; bottom: calc(10px + var(--safe-bottom)); flex-direction: column; gap: 12px; }
    .ability { width: 74px; height: 74px; }
    .ability-icon { font-size: 24px; }
    .ability-label { font-size: 12px; }
    .ability-key { display: none; }
    .rival-status { top: calc(66px + var(--safe-top)); }
}
@media (hover: none) {
    .card:hover { transform: none; }
    .ability-key { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
