:root {
  --bg: #0f1b3d;
  --panel: rgba(12, 20, 44, 0.92);
  --text: #eef2ff;
  --muted: #9aa5c4;
  --accent: #ffd166;
  --danger: #ef476f;
  --ok: #06d6a0;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
h1 { margin: 0 0 8px; font-size: 28px; }
h2 { margin: 0 0 8px; }
h3 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); font-size: 14px; }
.screen { display: none; position: fixed; inset: 0; }
.screen.active { display: block; }
.menu { overflow: auto; padding: calc(16px + var(--sa-top)) 16px calc(16px + var(--sa-bottom)); background: radial-gradient(ellipse at top, #24407a, var(--bg)); }
.card {
  max-width: 460px; margin: 4vh auto; background: var(--panel); border-radius: 18px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); display: flex; flex-direction: column; gap: 12px;
}
input {
  font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 12px; border: 1px solid #3a4a7a;
  background: #0b1430; color: var(--text); width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }
input.code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }
button {
  font: inherit; font-size: 17px; font-weight: 600; padding: 12px 18px; border-radius: 12px; border: 0;
  background: #2b3d6e; color: var(--text); cursor: pointer; touch-action: manipulation;
}
button:active { transform: translateY(1px); filter: brightness(1.15); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #1b1b1b; }
button.danger { background: var(--danger); }
button.small { padding: 8px 12px; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.space { justify-content: space-between; }
.row > input { flex: 1; }
.room-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: #131f45; border-radius: 12px; margin-bottom: 8px; }
.player-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #131f45; border-radius: 12px; margin-bottom: 6px; }
.player-row .pname { font-weight: 600; flex: 1; }
.player-row .tags { color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.bigcode { font-size: 44px; font-weight: 800; letter-spacing: .3em; text-align: center; color: var(--accent); }
#color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; padding: 0; border: 3px solid transparent; }
.swatch.sel { border-color: #fff; }

/* game */
#s-game { background: #000; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
#hud-top {
  position: absolute; top: var(--sa-top); left: var(--sa-left); right: var(--sa-right);
  display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; gap: 10px;
}
#turn-info { background: var(--panel); padding: 8px 14px; border-radius: 12px; font-weight: 700; border: 2px solid transparent; font-size: 18px; }
#turn-info.mine { background: var(--accent); color: #1b1b1b; animation: pulse 1.2s ease-in-out infinite; }
#turn-info.mine #turn-name { color: #1b1b1b !important; }
#turn-info.mine #turn-label { color: #333; }
#turn-label { font-weight: 400; color: var(--muted); }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
select {
  font: inherit; font-size: 16px; padding: 8px 12px; border-radius: 10px; border: 1px solid #3a4a7a;
  background: #0b1430; color: var(--text);
}
#hud button { touch-action: none; user-select: none; }
.switch { position: relative; width: 52px; height: 30px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #2b3d6e; border-radius: 30px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(22px); }
.switch input:disabled + span { opacity: .5; cursor: default; }
.team-pill { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #111; }
.card.wide { max-width: 640px; width: 92vw; max-height: 86vh; overflow: auto; }
.menu .overlay { position: fixed; z-index: 20; }
.board-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; background: #131f45; border-radius: 12px; margin-bottom: 6px; }
.board-row.me { outline: 2px solid var(--accent); }
.board-row .rank { font-weight: 800; color: var(--muted); }
.board-row .who { display: flex; flex-direction: column; }
.board-row .who b { font-size: 16px; }
.board-row .tier { font-size: 12px; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.board-row .nums { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #2b3d6e; color: var(--text); }
.badge.locked { opacity: .35; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.settings-grid select { width: 100%; }
#turn-timer { font-weight: 800; margin-left: 6px; }
#turn-timer.urgent { color: #ff5d5d; animation: pulse .6s ease-in-out infinite; }
#turn-info.mine #turn-timer.urgent { color: #b00020; }
.pill { position: absolute; top: calc(60px + var(--sa-top)); left: 50%; transform: translateX(-50%); background: var(--panel); padding: 6px 14px; border-radius: 999px; display: none; }
.pill.show { display: block; }
#emote-bar { position: absolute; right: calc(10px + var(--sa-right)); top: calc(64px + var(--sa-top)); display: flex; flex-direction: column; gap: 6px; }
#emote-bar .emote { padding: 6px 10px; font-size: 16px; min-width: 44px; }
#menu-players { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow: auto; }
.help-weapon { display: grid; grid-template-columns: 32px 130px 1fr; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid #1e2a50; font-size: 14px; }
.help-weapon .wicon { font-size: 20px; text-align: center; }
#overlay-help { position: fixed; z-index: 30; }
#overlay-help ul { padding-left: 18px; margin: 4px 0 8px; font-size: 14px; line-height: 1.5; }
#rotate-hint { display: none; position: fixed; inset: 0; z-index: 40; background: var(--bg); color: var(--text); align-items: center; justify-content: center; text-align: center; font-size: 22px; line-height: 1.6; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate-hint { display: flex; }
}
#wind { background: var(--panel); padding: 8px 14px; border-radius: 12px; font-weight: 600; }
#wind-arrow { display: inline-block; color: var(--accent); }
.hud-btn { background: var(--panel); padding: 10px 14px; border-radius: 12px; font-size: 18px; }
.hud-btn.big { font-size: 30px; padding: 14px 26px; }
.hud-btn.wide { display: flex; gap: 8px; align-items: center; }
#weapon-icon { font-size: 22px; }
#weapon-ammo { color: var(--muted); font-size: 14px; }
#hud-bottom {
  position: absolute; bottom: calc(10px + var(--sa-bottom)); left: calc(10px + var(--sa-left)); right: calc(10px + var(--sa-right));
  display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
}
#hud-bottom.disabled { opacity: .35; }
#hud-bottom.disabled button { pointer-events: none; }
#hud-bottom .move { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#hud-bottom .right { display: flex; gap: 10px; align-items: center; }
#fuel { width: 90px; height: 10px; background: rgba(0,0,0,.5); border-radius: 6px; overflow: hidden; }
#fuel-bar { height: 100%; background: var(--ok); width: 100%; transition: width .1s; }
#banner {
  position: absolute; top: calc(60px + var(--sa-top)); left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #1b1b1b; padding: 8px 16px; border-radius: 999px; font-weight: 700;
  opacity: 0; transition: opacity .3s; white-space: nowrap;
}
#banner.show { opacity: 1; }
#weapon-panel {
  position: absolute; right: calc(10px + var(--sa-right)); bottom: calc(70px + var(--sa-bottom));
  background: var(--panel); border-radius: 14px; padding: 8px; display: none; flex-direction: column; gap: 4px;
  max-height: 60vh; overflow: auto; pointer-events: auto; min-width: 260px;
}
#weapon-panel.show { display: flex; }
.weapon-row { display: flex; align-items: center; gap: 12px; text-align: left; background: transparent; padding: 8px 10px; }
.weapon-row.sel { background: #2b3d6e; }
.weapon-row .wicon { font-size: 22px; width: 28px; text-align: center; }
.weapon-row .wname { flex: 1; display: flex; flex-direction: column; }
.weapon-row .wname small { color: var(--muted); font-weight: 400; font-size: 12px; }
.weapon-row .wammo { color: var(--muted); }
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; }
.overlay.show { display: flex; }
.overlay .card { margin: 0; min-width: 300px; }
#scoreboard div { padding: 4px 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--sa-bottom)); transform: translate(-50%, 20px);
  background: #fff; color: #111; padding: 10px 18px; border-radius: 999px; font-weight: 600;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  .hud-btn.big { font-size: 24px; padding: 10px 18px; }
  #turn-info, #wind { padding: 6px 10px; font-size: 14px; }
  #weapon-name { display: none; }
}

.hud-btn.util { font-size: 15px; padding: 10px 12px; }
.hud-btn.util:disabled { opacity: .4; }

/* room screen */
.room-card { max-width: 900px; }
.room-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.room-head .bigcode { text-align: left; }
.room-head-right { text-align: right; display: flex; flex-direction: column; gap: 4px; }
.room-title { font-size: 20px; font-weight: 700; }
.room-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.room-col { min-width: 0; }
.room-col h3 { margin-top: 6px; }
.settings-list { display: flex; flex-direction: column; gap: 6px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; background: #131f45; border-radius: 12px; font-size: 14px; }
.setting select { width: 46%; min-width: 130px; }
.setting .switch { flex: none; }
.room-actions { justify-content: flex-end; }
.room-actions .primary { flex: 1; max-width: 320px; font-size: 20px; padding: 14px; }
@media (max-width: 720px) {
  .room-grid { grid-template-columns: 1fr; }
  .room-head-right { text-align: left; }
  .setting select { width: 50%; }
}
.hud-btn.util.active { background: var(--accent); color: #1b1b1b; }
#player-panel { position: absolute; left: calc(10px + var(--sa-left)); top: calc(64px + var(--sa-top)); display: flex; flex-direction: column; gap: 3px; width: 180px; pointer-events: none; }
.pp-row { display: grid; grid-template-columns: 12px 1fr 52px 26px; gap: 6px; align-items: center; background: var(--panel); border-radius: 8px; padding: 3px 8px; font-size: 12px; opacity: .85; border-left: 3px solid transparent; }
.pp-row .dot { width: 10px; height: 10px; margin: 0; }
.pp-row .pp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pp-row .pp-bar { position: relative; height: 7px; background: rgba(0,0,0,.5); border-radius: 4px; overflow: hidden; }
.pp-row .pp-bar > span { position: absolute; left: 0; top: 0; height: 100%; border-radius: 4px; }
.pp-row .pp-shield { background: #4cc9f0 !important; height: 3px !important; top: auto !important; bottom: 0; }
.pp-row .pp-hp { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.pp-row.cur { opacity: 1; border-left-color: var(--accent); background: rgba(40, 55, 100, .95); }
.pp-row.me .pp-name { color: var(--accent); }
.pp-row.dead { opacity: .45; }
.pp-row.dead .pp-name { text-decoration: line-through; }
#build-confirm { position: absolute; left: 50%; bottom: calc(90px + var(--sa-bottom)); transform: translateX(-50%); display: none; gap: 8px; align-items: center; background: var(--panel); padding: 8px 12px; border-radius: 14px; pointer-events: auto; }
#build-confirm.show { display: flex; }
#build-confirm .primary { background: var(--accent); color: #1b1b1b; }
@media (max-width: 700px) { #player-panel { width: 140px; } .pp-row { grid-template-columns: 10px 1fr 36px 22px; font-size: 11px; } }
