/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --panel:    #1c2333;
  --border:   #30363d;
  --accent:   #238636;
  --accent2:  #1f6feb;
  --danger:   #e94560;
  --text:     #c9d1d9;
  --muted:    #8b949e;
  --p1:       #e94560;
  --p2:       #4a90e2;
  --board-bg: #1a2e22;
  --radius:   6px;
  --font:     'Courier New', Courier, monospace;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Typography helpers ────────────────────────────────────────────────────── */
.muted   { color: var(--muted); }
.logo    { font-size: 1.6rem; letter-spacing: 0.12em; color: var(--text); }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); font-size: 0.8rem; letter-spacing: 0.2em; margin-top: 2px; }
.tag     { background: var(--panel); border: 1px solid var(--border);
           padding: 2px 8px; border-radius: var(--radius); font-size: 0.8rem; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-family: var(--font); font-size: 0.82rem;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover    { background: var(--border); }
.btn-primary  { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-ghost    { background: transparent; }
.btn-ghost:hover  { background: var(--panel); }
.btn-sm  { padding: 3px 10px; font-size: 0.78rem; }
.w-full  { width: 100%; margin-top: 6px; }

/* ── Flash messages ─────────────────────────────────────────────────────────── */
.flash {
  background: #3d1a1a; border: 1px solid var(--danger);
  color: var(--danger); padding: 8px 12px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: 0.82rem;
}
.flash-bottom {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 999; white-space: nowrap;
}

/* ── Form elements ─────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%; padding: 6px 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 0.85rem;
  outline: none; transition: border-color 0.15s;
}
input:focus { border-color: var(--accent2); }

label { display: block; color: var(--muted); font-size: 0.78rem;
        letter-spacing: 0.06em; margin-bottom: 4px; }

.field-row { margin-bottom: 10px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

.btn-row { display: flex; gap: 8px; margin-top: 6px; }
.btn-row .btn { flex: 1; }

/* ── Auth page ─────────────────────────────────────────────────────────────── */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg);
}
.auth-card {
  width: 340px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 36px 32px;
}
.auth-form { margin-top: 24px; }

/* ── Lobby ─────────────────────────────────────────────────────────────────── */
.lobby-wrap { display: flex; flex-direction: column; height: 100vh; }

.lobby-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.lobby-user { display: flex; align-items: center; gap: 10px; }

.lobby-body { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 18px 20px;
}
.panel h2, .panel h3 {
  font-size: 0.9rem; letter-spacing: 0.1em; color: var(--muted);
  text-transform: uppercase; margin-bottom: 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

.session-table { width: 100%; border-collapse: collapse; }
.session-table th, .session-table td {
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.session-table th { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.session-table tr:last-child td { border-bottom: none; }
.session-table tr:hover td { background: var(--panel); }
.open { color: var(--accent); }

/* ── Game layout ────────────────────────────────────────────────────────────── */
.game-wrap { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 12px;
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-center { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.session-title { font-size: 0.95rem; letter-spacing: 0.08em; }

.player-tag {
  padding: 3px 10px; border-radius: var(--radius); font-size: 0.8rem;
  border: 1px solid; font-weight: bold;
}
.player-tag.p1 { color: var(--p1); border-color: var(--p1); }
.player-tag.p2 { color: var(--p2); border-color: var(--p2); }
.vs { color: var(--muted); font-size: 0.75rem; }

.player-tag.active-turn {
  box-shadow: 0 0 0 2px currentColor;
  opacity: 1;
}
.player-tag:not(.active-turn) { opacity: 0.45; }

.turn-indicator {
  font-size: 0.78rem; padding: 2px 8px;
  border-radius: var(--radius); white-space: nowrap;
}
.turn-indicator.my-turn    { color: var(--accent); border: 1px solid var(--accent); }
.turn-indicator.their-turn { color: var(--muted);  border: 1px solid var(--border); }

.btn:disabled {
  opacity: 0.35; cursor: not-allowed; pointer-events: none;
}

.game-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.panel-sm { padding: 14px 16px; }
.panel-sm h3 { font-size: 0.78rem; }

/* Dice results */
.dice-results { margin-top: 10px; }
.dice-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.dice-table th, .dice-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.dice-table th { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
.dice-total { text-align: right; color: var(--muted); padding-top: 6px; font-size: 0.78rem; }

.bar-cell { width: 60px; }
.bar-inner {
  height: 8px; background: var(--accent); border-radius: 2px;
  transition: width 0.3s;
}

/* Color swatches */
.color-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; transition: border-color 0.15s;
}
.swatch.selected { border-color: #fff; }
.swatch:hover    { border-color: var(--muted); }

/* Controls list */
.controls-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.controls-list li { color: var(--muted); font-size: 0.78rem; }
kbd {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; font-family: var(--font); font-size: 0.72rem;
}

/* ── Canvas area ────────────────────────────────────────────────────────────── */
.canvas-container {
  flex: 1; position: relative; overflow: hidden; background: var(--bg);
}
#board-canvas {
  display: block; width: 100%; height: 100%; cursor: grab;
}
#board-canvas:active { cursor: grabbing; }

.zoom-label {
  position: absolute; bottom: 12px; right: 14px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: var(--radius);
  font-size: 0.78rem; color: var(--muted); pointer-events: none;
}

/* ── Context menu ───────────────────────────────────────────────────────────── */
.ctx-menu {
  position: fixed; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  z-index: 1000; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-menu button {
  display: block; width: 100%; padding: 8px 16px;
  background: none; border: none; color: var(--danger);
  font-family: var(--font); font-size: 0.85rem; cursor: pointer; text-align: left;
}
.ctx-menu button:hover { background: var(--panel); }

.measure-row {
  display: flex; gap: 6px; align-items: center;
}
.measure-row input { flex: 1; }

.measure-hint {
  color: var(--muted); font-size: 0.75rem; margin-top: 8px; line-height: 1.4;
}

.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; color: var(--text); font-size: 0.82rem; letter-spacing: 0;
}
.checkbox-label input[type="checkbox"] {
  width: 14px; height: 14px; flex-shrink: 0;
  accent-color: var(--accent); cursor: pointer;
}

.btn-guest {
  background: #1c2a1c; border-color: var(--accent);
  color: var(--accent); justify-content: center;
}
.btn-guest:hover { background: #243324; }

.divider {
  text-align: center; color: var(--muted); font-size: 0.75rem;
  margin: 14px 0 10px; position: relative;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%;
  width: 42%; height: 1px; background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

.hidden { display: none !important; }

/* ── Lobby create form ──────────────────────────────────────────────────────── */
.create-form { display: flex; flex-direction: column; gap: 0; }
.create-form .btn { align-self: flex-start; margin-top: 4px; }

.lobby-type-toggle { display: flex; gap: 18px; margin-top: 4px; }

.radio-label {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; color: var(--text); font-size: 0.82rem; letter-spacing: 0;
}
.radio-label input[type="radio"] {
  width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer;
}

.lock-badge {
  font-size: 0.75rem; margin-right: 4px; opacity: 0.8;
}

/* ── Phase indicator ────────────────────────────────────────────────────────── */
.phase-indicator {
  font-size: 0.75rem; padding: 2px 8px;
  border-radius: var(--radius); white-space: nowrap; letter-spacing: 0.08em;
  text-transform: uppercase;
}
.phase-indicator.setup  { color: #ffd700; border: 1px solid #ffd700; }
.phase-indicator.active { color: var(--accent); border: 1px solid var(--accent); }

/* ── Start Game button ──────────────────────────────────────────────────────── */
.btn-start-game {
  background: #3a2800; border-color: #ffd700; color: #ffd700;
}
.btn-start-game:hover { background: #5a3e00; }

/* ── Chat ───────────────────────────────────────────────────────────────────── */
.chat-toggle {
  position: absolute; bottom: 48px; right: 14px; z-index: 10;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.chat-toggle:hover { background: var(--panel); color: var(--text); }

.chat-badge {
  position: absolute; top: -4px; right: -4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--danger); color: #fff;
  font-size: 9px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--bg); pointer-events: none;
}

.chat-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 240px;
  z-index: 9; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}

.chat-msg { display: flex; flex-direction: column; gap: 2px; max-width: 88%; }
.chat-msg-me    { align-self: flex-end;   align-items: flex-end; }
.chat-msg-them  { align-self: flex-start; align-items: flex-start; }

.chat-name { font-size: 0.72rem; letter-spacing: 0.04em; font-weight: bold; }

.chat-text {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 8px;
  font-size: 0.82rem; line-height: 1.4; word-break: break-word; color: var(--text);
}
.chat-msg-me .chat-text { background: #152215; border-color: var(--accent); }

.chat-input-row { padding: 8px 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-input-row input { width: 100%; }

/* ── Ping button ────────────────────────────────────────────────────────────── */
.btn-ping-active {
  background: #2a2200; border-color: #ffd700; color: #ffd700;
  box-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 580px;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title {
  font-size: 1rem; letter-spacing: 0.08em; color: var(--text);
  text-transform: uppercase;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer; line-height: 1;
  padding: 0 4px; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  overflow-y: auto; padding: 20px 24px; display: flex;
  flex-direction: column; gap: 20px;
}

/* ── About modal content ────────────────────────────────────────────────────── */
.about-section h3 {
  font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.about-section p, .about-section .about-note {
  font-size: 0.84rem; line-height: 1.65; color: var(--text);
}
.about-steps {
  padding-left: 18px; display: flex; flex-direction: column; gap: 6px;
  font-size: 0.84rem; line-height: 1.6; color: var(--text);
}
.about-controls {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
}
.about-controls td {
  padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.about-controls tr:last-child td { border-bottom: none; }
.about-controls td:first-child { color: var(--muted); white-space: nowrap; width: 46%; }
.about-note {
  font-size: 0.80rem; color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; line-height: 1.6;
}

/* ── Site footer ────────────────────────────────────────────────────────────── */
.site-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  text-align: center;
  padding: 7px 16px;
  font-size: 0.70rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  letter-spacing: 0.04em;
  z-index: 5;
}
.site-footer strong { color: var(--text); }
