/* ==========================================================================
   paper.io — the client's own stylesheet.

   The house theme is black and green, so the palette is a near-black background
   with a single green accent. Everything is sized in rem/px so the canvas and
   the HUD scale together on a phone.
   ========================================================================== */

:root {
  --bg: #0a0d0b;
  --bg-soft: #111713;
  --bg-panel: #141b16;
  --line: #22302a;
  --text: #e6f2e9;
  --text-dim: #8fa79a;
  --accent: #1db954;
  --accent-dim: #1d7a37;
  --danger: #ff5d5d;
  --radius: 12px;
}

html[data-theme='light'] {
  --bg: #f3f7f4;
  --bg-soft: #e8efe9;
  --bg-panel: #ffffff;
  --line: #ccdacf;
  --text: #10231a;
  --text-dim: #55705f;
  --accent: #17843a;
  --accent-dim: #17843a;
}

* { box-sizing: border-box; }

/* The single most important rule in this file: `[hidden]` must always win, or an
   invisible overlay keeps swallowing taps (that bug cost real time in diep.io). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Segoe UI', system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }

.shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Header ──────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}

.home-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.home-btn svg { width: 20px; height: 20px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}
.brand-accent { color: var(--accent); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

.link-btn {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-dim);
}

/* ── Screens and panels ──────────────────────────────────────────────── */

.screen { display: none; padding: 20px; max-width: 1100px; margin: 0 auto; width: 100%; }
.screen.active { display: block; }
.screen.game { padding: 0; max-width: none; position: relative; }

.menu-hero { margin-bottom: 18px; }
.hero-title { margin: 0 0 6px; font-size: 32px; letter-spacing: -0.5px; }
.hero-sub { margin: 0; color: var(--text-dim); max-width: 70ch; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.panel.slim { padding: 10px; margin-bottom: 8px; }
.panel-title { margin: 0 0 10px; font-size: 15px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-dim); }
.count { color: var(--accent); }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.field.row { display: flex; align-items: center; justify-content: space-between; }
.field input[type='text'], .field input[type='checkbox'], .field input:not([type]) {
  font: inherit;
}
.field input:not([type='checkbox']) {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}
.field input[type='checkbox'] { accent-color: var(--accent); width: 18px; height: 18px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  font: inherit;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06180c; font-weight: 700; }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.leave { position: absolute; top: 12px; right: 12px; z-index: 5; }

.hint { color: var(--text-dim); font-size: 12px; margin: 8px 0 0; }
.rules { margin: 0; padding-left: 18px; color: var(--text-dim); font-size: 13px; }
.rules b { color: var(--text); }

.lobby-list { list-style: none; margin: 0; padding: 0; }
.lobby-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-soft);
  margin-bottom: 6px;
  font-size: 13px;
}
.lobby-list .code { font-weight: 700; letter-spacing: 0.08em; }

/* ── Game ────────────────────────────────────────────────────────────── */

canvas#canvas { display: block; width: 100%; height: calc(100vh - 57px); touch-action: none; }

.hud {
  position: absolute;
  inset: 12px 12px auto 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.hud-right { margin-left: auto; display: flex; gap: 8px; align-items: flex-start; }
.hud-right .panel { pointer-events: auto; background: rgba(10, 13, 11, 0.78); backdrop-filter: blur(3px); }

.chip {
  background: rgba(10, 13, 11, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}
.chip.big { font-size: 20px; font-weight: 700; color: var(--accent); }

.board { list-style: none; margin: 0; padding: 0; min-width: 190px; }
.board li {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  padding: 3px 0;
}
.board .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.board .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .cells { color: var(--text-dim); }
.board li.me .name { color: var(--accent); font-weight: 700; }

#minimap { display: block; background: #0a0f0c; border-radius: 6px; }

.feed {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  font-size: 12px;
}
.feed div {
  background: rgba(10, 13, 11, 0.78);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 4px 8px;
}
.feed div.bad { border-left-color: var(--danger); }

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(10, 13, 11, 0.6);
  padding: 6px 10px;
  border-radius: 999px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.swatch { width: 10px; height: 10px; display: inline-block; border-radius: 2px; }
.swatch.you { background: var(--accent); }
.swatch.land { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.swatch.line { background: var(--text); }

/* ── Touch controls ──────────────────────────────────────────────────── */

.touch { position: absolute; inset: auto 0 20px 0; display: flex;
  justify-content: space-between; padding: 0 20px; align-items: flex-end; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); }
.dbtn {
  font-size: 18px;
  background: rgba(20, 27, 22, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  margin: 2px;
}
.dbtn[data-dir='0'] { grid-area: 1 / 2; }
.dbtn[data-dir='3'] { grid-area: 2 / 1; }
.dbtn[data-dir='1'] { grid-area: 2 / 3; }
.dbtn[data-dir='2'] { grid-area: 3 / 2; }
.btn.boost { padding: 18px 22px; border-radius: 999px; font-weight: 700; }

/* ── Overlay and settings ────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 5, 0.72);
  z-index: 20;
}
.overlay-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  max-width: 420px;
  width: calc(100% - 32px);
}
.overlay-title { margin: 0 0 6px; font-size: 24px; }
.overlay-title.bad { color: var(--danger); }
.overlay-text { margin: 0 0 10px; color: var(--text-dim); }
.overlay-actions { display: flex; gap: 8px; margin-top: 14px; }

.settings-dropdown {
  position: fixed;
  top: 56px;
  right: 12px;
  width: 280px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  z-index: 30;
}
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
}
.colors button.sel { border-color: var(--text); }

@media (max-width: 720px) {
  .hero-title { font-size: 26px; }
  .hud-right .panel.slim:first-child { display: none; }
  .legend { display: none; }
}
