/* Top Corner */
:root {
  --ink: #fbfdff;
  --muted: #c4d0e3;
  --panel: rgba(9, 20, 46, 0.9);
  --accent: #ffd21f;
  --accent-ink: #1d1400;
  --good: #46d17c;
  --bad: #ff5a4a;
  --focus: #5fd4ff;
  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  --bottom: max(14px, env(safe-area-inset-bottom));
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1b3d;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#game { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* device-specific prompts: body[data-device] = touch | mouse | keyboard | gamepad */
.pad-only, .touch-only, .kbd-only { display: none; }
body[data-device="gamepad"] .pad-only { display: inline; }
body[data-device="touch"] .touch-only { display: inline; }
body[data-device="keyboard"] .kbd-only, body[data-device="mouse"] .kbd-only { display: inline; }
.glyph {
  display: none; font-size: 0.8em; font-weight: 800; margin-left: 6px; padding: 0 6px; border-radius: 9px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
}
body[data-device="gamepad"] .glyph.pad-only { display: inline-block; }
body[data-device="keyboard"] .glyph.kbd-only, body[data-device="mouse"] .glyph.kbd-only { display: inline-block; }

/* -------------------------------------------------------------- HUD ---- */
#hud { position: fixed; inset: 0; pointer-events: none; display: none; }
body[data-state="play"] #hud, body[data-state="pause"] #hud { display: block; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter-r) 0 var(--gutter);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.chip { background: rgba(5, 14, 34, 0.6); border-radius: 12px; padding: 6px 12px; font-weight: 800; font-size: clamp(13px, 2.6vw, 17px); justify-self: start; }
.hud-btns { display: flex; gap: 8px; justify-content: flex-end; }
.icon-btn { pointer-events: auto; min-width: 42px; height: 42px; border-radius: 21px; background: rgba(5, 14, 34, 0.6); font-size: 18px; padding: 0 10px; }
.icon-btn.off { opacity: 0.5; }

.scoreboard { background: rgba(5, 14, 34, 0.72); border-radius: 14px; padding: 6px 14px; font-weight: 800; text-align: center; font-size: clamp(14px, 2.8vw, 20px); }
.scoreboard .sb-row { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.scoreboard .sb-name { min-width: 3.5em; text-align: left; font-size: 0.8em; color: var(--muted); }
.scoreboard .sb-goals { min-width: 1.4em; text-align: right; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); display: inline-block; }
.dot.g { background: var(--good); border-color: var(--good); }
.dot.m { background: var(--bad); border-color: var(--bad); }
.dot.next { border-color: var(--accent); box-shadow: 0 0 6px var(--accent); }
.scoreboard .sd { font-size: 0.65em; color: var(--accent); letter-spacing: 0.08em; }

#banner {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%) scale(0.6);
  text-align: center; opacity: 0; transition: opacity 0.18s, transform 0.25s cubic-bezier(.2, 1.6, .4, 1);
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.55); white-space: nowrap;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner .b-main { font-size: clamp(34px, 9vw, 88px); font-weight: 900; letter-spacing: 0.02em; font-style: italic; -webkit-text-stroke: 2px rgba(5, 14, 34, 0.75); paint-order: stroke fill; }
#banner .b-sub { font-size: clamp(14px, 3vw, 22px); font-weight: 800; color: #fff; text-shadow: 0 0 6px #000, 0 2px 4px #000; }
#banner.good .b-main { color: var(--accent); }
#banner.bad .b-main { color: #ffffff; }

#toast {
  position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 84px); transform: translateX(-50%);
  background: rgba(5, 14, 34, 0.85); border-radius: 12px; padding: 8px 14px; font-weight: 700;
  opacity: 0; transition: opacity 0.25s; white-space: nowrap;
}
#toast.show { opacity: 1; }
#hint {
  position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 54px); transform: translateX(-50%);
  font-size: clamp(11px, 2.2vw, 14px); color: var(--muted); text-shadow: 0 1px 2px #000; white-space: nowrap; max-width: 60vw; overflow: hidden; text-overflow: ellipsis;
}
#replay-tag {
  position: absolute; left: var(--gutter); top: 62px; background: var(--bad); color: #fff; font-weight: 900;
  border-radius: 8px; padding: 4px 10px; letter-spacing: 0.1em; animation: blink 1s steps(2) infinite;
}
#replay-tag small { font-weight: 600; letter-spacing: 0; opacity: 0.85; }
@keyframes blink { 50% { opacity: 0.6; } }

/* shot types: a 3×2 grid at the bottom centre (+ chip / dip) */
#shot-types {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 4px);
  display: none; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 6px; pointer-events: auto; max-width: 70vw;
}
body[data-phase="aim"] #shot-types, body[data-phase="charge"] #shot-types, body[data-phase="intro"] #shot-types { display: flex; }
.st-grid {
  display: grid; grid-template-columns: repeat(3, minmax(86px, 1fr)); gap: 5px;
  background: rgba(5, 14, 34, 0.55); padding: 5px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.st-btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; position: relative;
  background: rgba(10, 22, 48, 0.9); border-radius: 10px; padding: 8px 10px; min-height: 40px;
  font-weight: 900; font-size: clamp(12px, 2.3vw, 16px); letter-spacing: 0.02em; border: 2px solid rgba(255, 255, 255, 0.18); text-transform: uppercase; white-space: nowrap;
}
.st-btn.big { font-size: clamp(13px, 2.6vw, 18px); }
.st-btn.on { border-color: #fff; background: var(--accent); color: var(--accent-ink); }
.st-btn.foot { background: #2346a8; border-color: rgba(255, 255, 255, 0.35); font-size: clamp(11px, 2vw, 14px); }
.st-btn.extra { grid-column: 1 / -1; padding: 2px 12px; min-height: 26px; font-size: 12px; }
.st-btn .glyph { position: absolute; right: 3px; top: 2px; font-size: 9px; padding: 0 4px; margin: 0; opacity: 0.8; }
body[data-device="gamepad"] .st-btn .glyph.pad-only, body[data-device="keyboard"] .st-btn .glyph.kbd-only, body[data-device="mouse"] .st-btn .glyph.kbd-only { display: inline-block; }
@media (max-height: 460px) {
  .st-btn { min-height: 28px; padding: 3px 7px; font-size: 12px; }
  .st-btn.big { font-size: 13px; }
  .st-grid { grid-template-columns: repeat(3, minmax(70px, 1fr)); gap: 4px; padding: 4px; }
  .chip { font-size: 12px; padding: 4px 9px; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #hint { display: none; }
}
.st-head { width: 100%; text-align: center; }

/* power meter (with its green sweet zone) + shoot button (bottom right) */
#shoot-ui {
  position: absolute; right: var(--gutter-r); bottom: var(--bottom);
  display: none; align-items: flex-end; gap: 12px; pointer-events: auto;
}
body[data-phase="aim"] #shoot-ui, body[data-phase="charge"] #shoot-ui, body[data-phase="strike"] #shoot-ui, body[data-phase="intro"] #shoot-ui { display: flex; }
#btn-shoot {
  width: clamp(88px, 18vmin, 128px); height: clamp(88px, 18vmin, 128px); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe766, #f2a900); color: var(--accent-ink);
  font-weight: 900; font-size: clamp(15px, 3vmin, 20px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none;
}
#btn-shoot:active, #btn-shoot.held { transform: scale(0.95); }
#btn-shoot .glyph { background: rgba(0, 0, 0, 0.25); margin: 2px 0 0; }
#meter {
  position: relative; width: 28px; height: clamp(120px, 34vmin, 220px);
  background: rgba(5, 14, 34, 0.7); border: 2px solid rgba(255, 255, 255, 0.6); border-radius: 13px; overflow: hidden;
}
#meter .m-red { position: absolute; left: 0; right: 0; top: 0; height: 13%; background: repeating-linear-gradient(45deg, #ff5a4a, #ff5a4a 5px, #c22 5px, #c22 10px); opacity: 0.85; }
#meter .m-zone { position: absolute; left: 0; right: 0; background: rgba(70, 209, 124, 0.35); border-top: 2px solid #46d17c; border-bottom: 2px solid #46d17c; }
#meter .m-fill { position: absolute; left: 4px; right: 4px; bottom: 0; height: 0; border-radius: 8px; background: linear-gradient(0deg, #ffffff, #ffd21f 70%, #ff7a1a); opacity: 0.92; }

/* keeper: side-steps (bottom left), dive pad (bottom right), dive indicator */
#keep-ui { position: absolute; right: var(--gutter-r); bottom: var(--bottom); display: none; pointer-events: auto; flex-direction: column; align-items: flex-end; gap: 5px; }
body[data-phase="keep"] #keep-ui { display: flex; }
.dive-head { font-weight: 900; font-size: 13px; letter-spacing: 0.12em; text-shadow: 0 1px 3px #000; align-self: center; }
.dive-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; background: rgba(255, 255, 255, 0.85); padding: 5px; border-radius: 12px; }
.dc {
  min-width: clamp(64px, 10.5vw, 100px); min-height: clamp(34px, 8.5vmin, 52px); border-radius: 9px; position: relative;
  font-weight: 900; font-size: clamp(11px, 2vw, 15px); text-transform: uppercase; color: #fff; touch-action: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}
.dc.side { background: #f08a1c; }
.dc.mid { background: #2356d6; }
.dc b { font-size: 1.05em; }
.dc i { position: absolute; right: 4px; bottom: 1px; font-style: normal; font-size: 9px; opacity: 0.85; display: none; }
body[data-device="keyboard"] .dc i, body[data-device="mouse"] .dc i { display: block; }
.dc.aim { outline: 3px solid #5fd4ff; outline-offset: 1px; }
.dc.pick { outline: 3px solid #fff; background: #1aa94f; }
#keep-left { position: absolute; left: var(--gutter); bottom: var(--bottom); display: none; gap: 8px; pointer-events: auto; }
body[data-phase="keep"] #keep-left { display: flex; }
.shuffle {
  width: clamp(54px, 11vmin, 74px); height: clamp(54px, 11vmin, 74px); border-radius: 14px; background: rgba(5, 14, 34, 0.7);
  font-size: 26px; touch-action: none; position: relative; border: 2px solid rgba(255, 255, 255, 0.25);
}
.shuffle:active { background: rgba(95, 212, 255, 0.4); }
.shuffle .glyph { position: absolute; bottom: 2px; right: 3px; font-size: 9px; }
#dive-ready {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 22px); display: none;
  flex-direction: column; align-items: center; gap: 3px; font-weight: 900; font-size: 13px; letter-spacing: 0.1em; text-shadow: 0 1px 3px #000;
}
body[data-phase="keep"] #dive-ready { display: flex; }
#dive-ready .dr-bar { width: 150px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.35); }
#dive-ready[data-s="ready"] .dr-bar { background: #46d17c; }
#dive-ready[data-s="now"] { color: #ffd21f; transform: translateX(-50%) scale(1.15); }
#dive-ready[data-s="now"] .dr-bar { background: #ffd21f; box-shadow: 0 0 10px #ffd21f; }
#dive-ready[data-s="set"] .dr-bar { background: #5fd4ff; }
#dive-ready[data-s="gone"] { opacity: 0.5; }
#btn-fp {
  position: absolute; right: var(--gutter-r); top: calc(max(10px, env(safe-area-inset-top)) + 50px); display: none; pointer-events: auto;
  background: rgba(5, 14, 34, 0.7); border-radius: 12px; padding: 6px 10px; font-weight: 800; font-size: 12px; text-transform: uppercase;
}
body[data-phase="keep"] #btn-fp { display: block; }
#btn-fp.on { background: rgba(95, 212, 255, 0.45); }

/* how-to card */
#howto { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5, 14, 34, 0.55); pointer-events: auto; padding: 12px; }
.howto-card { background: var(--panel); border-radius: 18px; padding: 16px 20px; max-width: min(560px, 100%); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.howto-card h2 { font-size: 20px; font-weight: 900; text-align: center; }
.howto-card ul { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 15px; line-height: 1.35; }
.howto-card button { background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 10px; font-weight: 900; }

.seg { display: inline-flex; background: rgba(5, 14, 34, 0.66); border-radius: 12px; overflow: hidden; }
.seg button { padding: 8px 12px; font-weight: 800; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------ menus ---- */
#overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter-r) var(--bottom) var(--gutter);
  background: radial-gradient(ellipse at center, rgba(5, 14, 34, 0.35), rgba(5, 14, 34, 0.75));
  overflow-y: auto; touch-action: pan-y;
}
body[data-state="play"] #overlay { display: none; }
.panel {
  background: var(--panel); border-radius: 20px; padding: 18px 20px; width: min(560px, 100%);
  max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); touch-action: pan-y;
}
.panel.wide { width: min(900px, 100%); }
.panel h2 { font-size: clamp(20px, 4vw, 28px); font-weight: 900; text-align: center; }
.logo { text-align: center; font-size: clamp(38px, 9vw, 70px); font-weight: 900; font-style: italic; letter-spacing: 0.04em; line-height: 1; }
.logo span { color: var(--accent); }
.tagline { text-align: center; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 0.9em; text-align: center; }
.panel button, a.btn {
  background: rgba(255, 255, 255, 0.1); border-radius: 12px; padding: 10px 14px; font-weight: 800; text-align: center;
  border: 2px solid transparent; outline: none;
}
.panel button.primary { background: var(--accent); color: var(--accent-ink); }
.panel button.subtle { background: transparent; color: var(--muted); font-weight: 600; }
.panel button.danger { background: var(--bad); }
.panel button:hover { filter: brightness(1.12); }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.row > button { flex: 1 1 auto; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modes .mode { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; }
.modes .mode b { font-size: 1.02em; }
.modes .mode small { font-weight: 600; opacity: 0.8; font-size: 0.78em; }
.modes .mode.big { grid-column: 1 / -1; padding: 14px; }
.modes .mode.big b { font-size: 1.25em; }
.langs button { flex: 0 0 auto; padding: 6px 12px; font-size: 14px; }
.langs button.on { background: rgba(255, 210, 31, 0.25); border-color: var(--accent); }

/* visible focus for keyboard / controller navigation */
.panel button:focus-visible, .panel input:focus-visible, .pad-focus, a.btn:focus-visible {
  border-color: var(--focus) !important; box-shadow: 0 0 0 3px rgba(95, 212, 255, 0.45), 0 0 14px rgba(95, 212, 255, 0.6) !important;
}
body[data-device="mouse"] .pad-focus:not(:focus-visible), body[data-device="touch"] .pad-focus:not(:focus-visible) { box-shadow: none !important; border-color: transparent !important; }

/* setup pickers */
.pickers { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.picker { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.picker h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); text-align: center; }
.picker .pk-row { display: flex; align-items: center; gap: 6px; }
.picker .pk-row button { padding: 8px 12px; font-size: 18px; }
.picker .pk-name { flex: 1; text-align: center; font-weight: 900; font-size: 1.05em; }
.picker .pk-role { text-align: center; font-size: 0.82em; color: var(--muted); min-height: 1.2em; }
.bars { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; align-items: center; font-size: 12px; }
.bar { height: 7px; background: rgba(255, 255, 255, 0.12); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #46d17c, #ffd21f); }
.kitdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.5); vertical-align: middle; margin-right: 4px; }

/* edit team */
.team-ed { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.team-ed h3 { font-size: 15px; margin-bottom: 6px; }
.ed-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.ed-row > span { min-width: 84px; font-size: 13px; color: var(--muted); font-weight: 700; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 2px solid rgba(255, 255, 255, 0.35); }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.ed-names { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 6px; }
.panel input[type="text"] {
  font: inherit; font-weight: 700; color: var(--ink); background: rgba(255, 255, 255, 0.1); border: 2px solid transparent;
  border-radius: 10px; padding: 7px 10px; width: 100%; user-select: text; -webkit-user-select: text;
}
.ed-names label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }

/* settings */
.settings { display: flex; flex-direction: column; gap: 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.set-row > span { font-weight: 700; }
.set-row .seg button { background: transparent; border-radius: 0; padding: 7px 11px; }
.set-row .seg button.on { background: var(--accent); color: var(--accent-ink); }
details.help { color: var(--muted); font-size: 13px; line-height: 1.45; }
details.help summary { cursor: pointer; font-weight: 800; color: var(--ink); }

/* stats / result */
.stat-grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; }
.stat-grid b { text-align: right; }
.result-big { text-align: center; font-size: clamp(30px, 8vw, 54px); font-weight: 900; }
.result-sub { text-align: center; color: var(--muted); }
.confirm { background: rgba(255, 90, 74, 0.15); border-radius: 12px; padding: 10px; text-align: center; display: flex; flex-direction: column; gap: 8px; }

/* on-screen keyboard */
#panel-osk { width: min(640px, 100%); }
#osk-keys { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
#osk-keys button { padding: 9px 0; font-size: 16px; }
#osk-keys button.wide { grid-column: span 2; }
#osk-keys button.wider { grid-column: span 4; }

.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

/* a controller in use: no on-screen shoot button (the meter stays); it comes
   back with the next touch / mouse input (body[data-device] changes) */
body[data-device="gamepad"] #btn-shoot, body[data-device="gamepad"] #keep-left { display: none !important; }
.st-head { font-size: 12px; font-weight: 800; color: var(--muted); text-shadow: 0 1px 2px #000; padding-left: 4px; }
body[data-device="gamepad"] .st-head.pad-only { display: block; }

/* hint line: a dark pill like the other HUD elements */
#hint { background: rgba(5, 14, 34, 0.72); padding: 4px 12px; border-radius: 999px; color: #fff; font-weight: 700; text-shadow: none; }
#hint:empty { display: none; }
/* ?fps overlay */
#fps { position: fixed; left: 8px; bottom: 8px; z-index: 50; background: rgba(0, 0, 0, 0.72); color: #9cff9c; font: 600 11px/1.35 ui-monospace, Consolas, monospace; padding: 5px 8px; border-radius: 8px; pointer-events: none; }
/* light vignette over the 3D view */
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, rgba(0,0,0,0) 58%, rgba(0,0,0,0.28) 100%); }
/* reaction close-up: letterbox bars */
body[data-phase="reaction"] #vignette { background: linear-gradient(#000 0 9%, transparent 9% 91%, #000 91%); }

/* left-footed shooter stands on the right: the shoot button moves left */
body[data-shooter-side="right"] #shoot-ui { right: auto; left: var(--gutter); flex-direction: row-reverse; }
body[data-phase="reaction"] #hud .hud-top, body[data-phase="reaction"] #hint { opacity: 0; }
