/* ============================================================
   THEME — change these variables to reskin the whole template
   ============================================================ */
:root {
  --accent: #4da3ff;
  --accent-2: #5aff8a;
  --danger: #ff5a5a;
  --bg: #0f1420;
  --panel: rgba(20, 28, 45, 0.95);
  --panel-border: #2c3d5f;
  --text: #eef3ff;
  --text-dim: #9db0d0;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 700px at 50% 20%, #1b2947 0%, var(--bg) 60%);
  color: var(--text);
  touch-action: manipulation;
  overscroll-behavior: none;
}
button, input, select { touch-action: manipulation; }
#screen-game { touch-action: none; user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }
kbd {
  background: #26355a; border: 1px solid #3d5488; border-bottom-width: 3px;
  border-radius: 6px; padding: 1px 7px; font-family: inherit; font-size: 0.9em;
}
code { background: #00000055; padding: 1px 6px; border-radius: 5px; color: #ffd97a; }

/* ---------- Screens & menus ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 20px; }
.menu-box {
  width: min(480px, 94vw); background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 28px; box-shadow: 0 20px 60px #000a;
  display: flex; flex-direction: column; gap: 12px; max-height: 94vh; overflow-y: auto;
}
.menu-box.slim { width: min(420px, 94vw); }
.game-title {
  font-size: 52px; letter-spacing: 3px; text-align: center; line-height: 1;
  background: linear-gradient(180deg, #fff, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.game-title.small { font-size: 34px; }
.game-subtitle, .footer-note { text-align: center; color: var(--text-dim); }
.footer-note { font-size: 12px; margin-top: 6px; }
.panel { display: flex; flex-direction: column; gap: 10px; }
.panel h2, .menu-box h3 { text-align: center; }
.hint { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.error { color: var(--danger); font-size: 14px; }
.howto table { width: 100%; border-collapse: collapse; }
.howto td { padding: 6px 4px; border-bottom: 1px solid #ffffff14; }
.howto p { margin: 8px 0; line-height: 1.5; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--text-dim); }
label.check { flex-direction: row; align-items: center; gap: 9px; color: var(--text); cursor: pointer; }
label .val { color: var(--accent-2); }
input[type="text"], select {
  background: #0b1120; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 10px 12px; font-size: 15px; font-family: inherit; width: 100%;
}
input[type="color"] { width: 100%; height: 38px; border: 1px solid var(--panel-border); border-radius: 8px; background: #0b1120; padding: 3px; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  position: relative; background: #223357; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 13px 16px; font-size: 16px; font-family: inherit;
  cursor: pointer; transition: transform .06s, background .15s, border-color .15s; text-align: center; width: 100%;
}
.btn:hover { background: #2b4472; border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: linear-gradient(180deg, #3d7bd6, #2a5dab); border-color: #6db2ff; font-weight: 700; }
.btn-primary:hover { background: linear-gradient(180deg, #4a8be4, #3269bb); }
.btn-danger:hover { border-color: var(--danger); background: #5a2a33; }
.btn-ghost { background: transparent; }
.btn-small { width: auto; padding: 9px 16px; font-size: 14px; }
.btn .tag {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10px; background: var(--accent-2); color: #06270f; font-weight: 700;
  padding: 2px 7px; border-radius: 20px; letter-spacing: .5px;
}

.room-code {
  text-align: center; font-size: 22px; font-weight: 800; letter-spacing: 4px;
  color: var(--accent-2); background: #5aff8a14; border: 1px dashed #5aff8a66;
  border-radius: var(--radius); padding: 10px;
}

/* ---------- Lobby / chat / saves ---------- */
.player-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 10px; background: #ffffff0d;
  border: 1px solid #ffffff14; padding: 9px 12px; border-radius: 8px;
}
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #0008; }
.player-list .crown { margin-left: auto; }
.chat-box { display: flex; flex-direction: column; gap: 6px; }
.chat-log {
  height: 130px; overflow-y: auto; background: #0b1120; border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.55;
}
.chat-box.small .chat-log { height: 96px; background: #0b1120cc; }
.chat-log .sys { color: var(--text-dim); font-style: italic; }
.chat-row { display: flex; gap: 6px; }
.chat-row input { flex: 1; }
.save-slot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: #ffffff0d; border: 1px solid #ffffff14; padding: 10px 12px; border-radius: 8px; font-size: 14px;
}
.save-slot .btn { width: auto; padding: 7px 12px; font-size: 13px; }
.save-slot .empty { color: var(--text-dim); }

/* ---------- Game / HUD ---------- */
#screen-game { padding: 0; background: #060a14; }
#canvas-2d { position: absolute; inset: 0; width: 100%; height: 100%; }
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-card {
  background: #0b1120b8; border: 1px solid #ffffff22; border-radius: 10px;
  padding: 10px 14px; backdrop-filter: blur(3px); font-size: 14px;
}
.hud-top-left { position: absolute; top: 14px; left: 14px; width: 230px; }
.hud-top-center { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); text-align: center; min-width: 160px; }
.hud-top-right { position: absolute; top: 14px; right: 14px; text-align: right; }
.hud-bottom-left { position: absolute; left: 14px; bottom: 14px; width: 320px; max-width: 44vw; pointer-events: auto; }
.hud-bottom-right { position: absolute; right: 14px; bottom: 14px; min-width: 170px; }
.hud-name { font-weight: 700; margin-bottom: 6px; }
.hud-row { display: flex; justify-content: space-between; margin-top: 5px; }
.bar { height: 14px; background: #000a; border-radius: 8px; overflow: hidden; border: 1px solid #ffffff2a; }
.bar-fill { height: 100%; width: 100%; transition: width .2s; }
.bar-fill.health { background: linear-gradient(90deg, #ff5a5a, #ffb35a); }
#hud-timer { font-size: 26px; font-weight: 800; letter-spacing: 1px; }
#hud-objective { color: var(--text-dim); font-size: 12px; }
#hud-stats, #hud-net { color: var(--text-dim); font-size: 12px; margin-bottom: 3px; }
#minimap { margin-top: 6px; border-radius: 6px; background: #0009; }
#hud-feed { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); text-align: center; display: flex; flex-direction: column; gap: 4px; }
#hud-feed div { background: #0b1120b8; padding: 5px 14px; border-radius: 20px; font-size: 13px; animation: fadeout 4s forwards; }
#hud-center-msg {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: 44px; font-weight: 800; text-shadow: 0 4px 20px #000; letter-spacing: 2px;
}
#hud-scoreboard table { border-collapse: collapse; width: 100%; }
#hud-scoreboard td, #hud-scoreboard th { padding: 2px 6px; text-align: left; font-size: 13px; }
@keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Overlays / toasts ---------- */
.overlay {
  position: fixed; inset: 0; background: #04060cd9; display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--accent); padding: 10px 20px; border-radius: 24px; font-size: 14px; box-shadow: 0 8px 30px #000a; animation: fadeout 3s forwards; }
#gameover-results table { width: 100%; border-collapse: collapse; }
#gameover-results td, #gameover-results th { padding: 7px 8px; border-bottom: 1px solid #ffffff14; }

/* ---------- HUD pause button ---------- */
.hud-top-center { position: absolute; }
#btn-pause-hud {
  position: absolute; top: 50%; right: -52px; transform: translateY(-50%);
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid #ffffff33;
  background: #0b1120b8; color: var(--text); font-size: 17px; cursor: pointer; pointer-events: auto;
}
#btn-pause-hud:active { transform: translateY(-50%) scale(0.94); }

/* ---------- Touch controls (phones/tablets) ---------- */
#touch-controls { display: none; }
@media (pointer: coarse) {
  #touch-controls {
    display: flex; position: absolute; left: 0; right: 0;
    bottom: calc(14px + env(safe-area-inset-bottom));
    justify-content: space-between; align-items: flex-end;
    padding: 0 calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
    pointer-events: none;
  }
  /* keep the chat readable above the joystick */
  .hud-bottom-left { bottom: calc(165px + env(safe-area-inset-bottom)); width: min(320px, 62vw); }
  .hud-bottom-right { display: none; } /* scoreboard hidden on small touch screens — less clutter */
  #chat-hint { display: none; }
}
#joystick {
  width: 128px; height: 128px; border-radius: 50%; flex: none;
  background: #ffffff10; border: 2px solid #ffffff2e;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto; touch-action: none;
}
#joystick-knob {
  width: 56px; height: 56px; border-radius: 50%;
  background: #ffffff2b; border: 2px solid #ffffff55;
  transition: transform 0.03s linear; pointer-events: none;
}
#touch-buttons { display: flex; gap: 12px; align-items: flex-end; pointer-events: none; }
.touch-btn {
  width: 60px; height: 60px; border-radius: 50%; font-size: 24px;
  background: #ffffff14; border: 2px solid #ffffff33; color: var(--text);
  pointer-events: auto; touch-action: none; cursor: pointer;
}
.touch-btn.active, .touch-btn:active { background: var(--accent); transform: scale(0.94); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .game-title { font-size: 38px; }
  .menu-box { padding: 20px; }
  .btn { padding: 14px 16px; } /* bigger tap targets */
  input[type="text"], select { font-size: 16px; } /* 16px stops iOS auto-zoom on focus */
  .hud-top-left { width: 128px; padding: 8px 10px; font-size: 12px; }
  .hud-top-right { display: none; } /* stats + minimap hidden on phones */
  .hud-top-center { padding: 8px 12px; min-width: 104px; }
  #btn-pause-hud { right: -46px; width: 38px; height: 38px; }
  #hud-timer { font-size: 20px; }
  #hud-center-msg { font-size: 30px; width: 92vw; text-align: center; }
  .chat-log { height: 96px; }
  .screen { padding: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
}
