:root {
  --bg: #20242b;
  --panel: #2b2f36;
  --panel-2: #343a43;
  --ink: #e7ebf0;
  --muted: #9aa3af;
  --line: #404754;
  --accent: #ffd23f;
  --accent-ink: #2b2f36;
  --good: #4ade80;
  --bad: #f87171;
  --floor: #3a4049;
  --wall: #23272e;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ===================== HOME ===================== */
#home {
  overflow: auto;
  background:
    radial-gradient(1200px 600px at 50% -10%, #2f343d 0%, var(--bg) 60%);
}
.home-wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand { text-align: center; }
.brand h1 {
  font-size: clamp(40px, 9vw, 76px);
  letter-spacing: 4px;
  margin: 0;
  font-weight: 900;
  color: var(--ink);
  text-shadow: 0 2px 0 #1a1d22;
}
.brand h1 span {
  color: var(--accent-ink);
  background: var(--accent);
  padding: 0 12px;
  border-radius: 10px;
  margin-left: 10px;
  display: inline-block;
  transform: rotate(-2deg);
}
.tagline { color: var(--muted); font-size: 17px; margin: 14px 0 6px; }
.live { color: var(--ink); margin: 0; font-size: 15px; }
.live-num { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; }

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 700px) { .cards { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 16px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: .15s transform, .15s filter;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .6; cursor: default; }

.error { color: var(--bad); font-size: 14px; min-height: 18px; margin: 2px 0 10px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 14px 0 0; }
.hint strong { color: var(--ink); }

.board-card h2 { margin: 0 0 14px; font-size: 18px; }
.board { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.board li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 6px;
  border-bottom: 1px dashed var(--line);
  font-variant-numeric: tabular-nums;
}
.board li:last-child { border-bottom: none; }
.board-empty { color: var(--muted); justify-content: center; }
.board .rank {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  flex: none;
}
.board li:nth-child(1) .rank { background: var(--accent); color: var(--accent-ink); }
.board li:nth-child(2) .rank { background: #c7cdd6; color: var(--accent-ink); }
.board li:nth-child(3) .rank { background: #cd9b6a; color: var(--accent-ink); }
.board .pnum { font-weight: 700; }
.board .pts { margin-left: auto; color: var(--accent); font-weight: 800; }
.board .pts small { color: var(--muted); font-weight: 600; }

.howto-card h2 { margin: 0 0 12px; font-size: 18px; }
.howto { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.howto li {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  padding-left: 22px;
  position: relative;
}
.howto li::before { content: "▸"; position: absolute; left: 2px; color: var(--accent); }
.howto li strong { color: var(--ink); }
.howto-cta {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
.howto-cta strong { color: var(--accent); }

.foot { text-align: center; color: var(--muted); font-size: 13px; }
.foot strong { color: var(--ink); }

/* ===================== GAME ===================== */
#game { background: var(--wall); }
#view { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  pointer-events: none;
}
.hud-item {
  background: rgba(27,30,36,.82);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 16px;
  backdrop-filter: blur(6px);
  text-align: center;
  min-width: 92px;
}
.hud-label { display: block; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.hud-value { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
#hudActive { color: var(--good); }
#hudScore { color: var(--accent); }

.hud-logout {
  pointer-events: auto;
  margin-left: auto;
  align-self: flex-start;
  background: rgba(27,30,36,.82);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}
.hud-logout:hover { border-color: var(--bad); color: var(--bad); }

#flash {
  position: absolute;
  top: 28%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 64px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 4px 0 #1a1d22;
  pointer-events: none;
  opacity: 0;
}
#flash.show { animation: pop 900ms ease-out; }
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(.5) rotate(-6deg); }
  20%  { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(3deg); }
  60%  { opacity: 1; transform: translate(-50%,-70%) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%,-120%) scale(1) rotate(0); }
}

#touchhint {
  position: absolute;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: rgba(27,30,36,.82);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
  transition: opacity .4s;
}

#idlewarn {
  position: absolute;
  top: 92px; left: 50%;
  background: rgba(248,113,113,.18);
  border: 1px solid var(--bad);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: idlepulse 1s ease-in-out infinite;
}
#idlewarn #idlenum { color: var(--accent); font-variant-numeric: tabular-nums; }
@keyframes idlepulse {
  0%, 100% { opacity: .85; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

#respawn {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20,23,28,.82);
  backdrop-filter: blur(4px);
  z-index: 10;
}
.respawn-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px 34px;
  text-align: center;
  max-width: 360px;
  margin: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.respawn-card h2 { margin: 0 0 10px; font-size: 24px; }
.respawn-card p { color: var(--muted); margin: 0 0 18px; }
.respawn-hint { font-size: 13px; margin: 12px 0 0 !important; }
.linkbtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 16px;
  padding: 6px;
}
.linkbtn:hover { color: var(--ink); }

/* Compact the in-game HUD + overlays on phones so nothing clips off-screen. */
@media (max-width: 560px) {
  #hud { gap: 5px; padding: 7px; }
  .hud-item { min-width: 0; padding: 5px 7px; }
  .hud-label { font-size: 9px; letter-spacing: .2px; }
  .hud-value { font-size: 16px; }
  .hud-logout { padding: 7px 9px; font-size: 13px; }
  #idlewarn { top: 84px; font-size: 13px; max-width: 92vw; white-space: normal; text-align: center; padding: 8px 14px; }
  #touchhint { max-width: 92vw; font-size: 12px; text-align: center; }
}
