:root {
  --bg: #14161c;
  --panel: #1e2129;
  --panel-2: #262a34;
  --text: #e9e9e4;
  --muted: #9a9fab;
  --line: #343946;
  --blue: #4f8cff;
  --blue-soft: rgba(79, 140, 255, 0.22);
  --red: #ff5d5d;
  --red-soft: rgba(255, 93, 93, 0.22);
  --square: #fafaf7;
  --square-line: #cfd0c8;
  --hint: rgba(46, 204, 113, 0.55);
  --capture: rgba(255, 140, 0, 0.7);
  --select: #f5b02e;
  --radius: 14px;
  --board: min(92vw, 62vh, 560px);
  --n: 9; /* squares per side; app.js overrides from the rules module */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 1.1rem;
}
.brand span { color: var(--select); }
.conn { font-size: 0.8rem; color: var(--muted); transition: color 0.3s; }
.conn.online { color: #2ecc71; }
.conn.offline { color: var(--red); }

main { display: flex; justify-content: center; padding: 20px 14px 40px; }
.view { width: 100%; max-width: 720px; }

/* ---------- lobby ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 420px;
  margin: 0 auto;
}
h1 { margin: 0 0 6px; font-size: 1.5rem; line-height: 1.2; text-align: center; }
h1 small { display: block; font-size: 0.9rem; color: var(--muted); font-weight: 500; margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
input[type="text"] {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 1rem;
  outline: none;
}
input[type="text"]:focus { border-color: var(--blue); }
#code { text-transform: uppercase; letter-spacing: 0.35em; font-weight: 700; text-align: center; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--select); color: #1a1400; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: 8px 12px; font-size: 0.9rem; }

.or { text-align: center; color: var(--muted); font-size: 0.85rem; }
.join { display: flex; gap: 8px; }
.join input { flex: 1; }

.error { color: var(--red); font-size: 0.9rem; margin: 0; text-align: center; }

.rules {
  max-width: 420px;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.rules summary { cursor: pointer; color: var(--text); font-weight: 600; }
.rules ul { padding-left: 18px; }
.rules li { margin: 6px 0; }
.rules b { color: var(--text); }

/* ---------- table ---------- */
.table { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.side {
  width: var(--board);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 30px;
}
.player { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.player .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); display: inline-block; }
.player.blue .dot { background: var(--blue); }
.player.red .dot { background: var(--red); }
.player .pstatus { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.player.active .pname { text-decoration: underline; text-decoration-color: var(--select); text-underline-offset: 4px; }

.captured { display: flex; gap: 2px; font-size: 1rem; opacity: 0.85; min-height: 1.2em; }

.board-wrap {
  position: relative;
  width: var(--board);
  height: var(--board);
}
.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  background: var(--square-line);
  border: 2px solid var(--square-line);
  border-radius: 6px;
  overflow: hidden;
  gap: 1px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.sq {
  position: relative;
  background: var(--square);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}
.sq.zone-blue { background: #dbe7ff; }
.sq.zone-red { background: #ffdede; }
.sq.last { box-shadow: inset 0 0 0 3px rgba(245, 176, 46, 0.55); }
.sq.selected { box-shadow: inset 0 0 0 4px var(--select); }
.sq.hint::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--hint);
}
.sq.hint.capture::after {
  width: 84%;
  height: 84%;
  background: transparent;
  border: 4px solid var(--capture);
  box-sizing: border-box;
}
.sq.hint, .sq.own-turn { cursor: pointer; }

.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--board) / var(--n) * 0.5);
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  border: 3px solid transparent;
  transition: transform 0.12s;
}
.piece.blue { background: var(--blue); border-color: #2f63c9; }
.piece.red { background: var(--red); border-color: #c93c3c; }
.sq.selected .piece { transform: scale(1.08); }

.coords {
  position: absolute;
  display: grid;
  color: var(--muted);
  font-size: 0.7rem;
  pointer-events: none;
}
.ranks { left: -16px; top: 0; height: 100%; grid-template-rows: repeat(var(--n), 1fr); }
.ranks span { display: flex; align-items: center; }
.files { bottom: -18px; left: 0; width: 100%; grid-template-columns: repeat(var(--n), 1fr); }
.files span { text-align: center; }

.status {
  min-height: 1.6em;
  font-weight: 600;
  text-align: center;
  padding: 6px 12px;
  border-radius: 10px;
  margin-top: 12px;
}
.status.your-turn { background: rgba(245, 176, 46, 0.15); color: var(--select); }
.status.win { background: rgba(46, 204, 113, 0.15); color: #2ecc71; }
.status.lose { background: var(--red-soft); color: var(--red); }

.actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.invite {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}
.invite b { color: var(--text); letter-spacing: 0.25em; font-size: 1.2rem; }

@media (max-width: 520px) {
  :root { --board: min(94vw, 60vh); }
  .side { font-size: 0.9rem; }
}
