:root {
  --bg: #1f2430;
  --panel: #2a303d;
  --panel-2: #333a4a;
  --text: #e8ebf2;
  --muted: #9aa3b5;
  --accent: #f5b400;
  --accent-2: #56b6ff;
  --white-tile: #f3ede0;
  --white-edge: #cbb98f;
  --black-tile: #2c2f38;
  --black-edge: #10131a;
  --target: rgba(86, 182, 255, 0.35);
  --place: rgba(120, 220, 140, 0.35);
  --danger: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------------ hub */
.hub {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.hub h1 { font-size: 2.2rem; margin: 0 0 4px; }
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 22px 0 6px;
}
.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 12px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}
.game-card:hover { transform: translateY(-2px); border-color: var(--accent); background: #3d4557; }
.game-emoji { font-size: 2.6rem; line-height: 1; }
.game-name { font-size: 1.15rem; font-weight: 700; }
.game-meta { font-size: 0.78rem; color: var(--muted); }
.home-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.home-link:hover { color: var(--text); }
@media (max-width: 420px) { .game-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- lobby */
.lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}
.lobby-card {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.lobby-card h1 { font-size: 2.4rem; margin: 0 0 4px; }
.tagline { color: var(--muted); margin: 0 0 24px; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }
.lobby-msg { color: var(--danger); min-height: 1.2em; margin: 12px 0 0; }
.warning {
  background: rgba(245, 180, 0, 0.12);
  border: 1px solid var(--accent);
  color: #ffe9a8;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  text-align: left;
  margin-bottom: 20px;
}
.warning code, code {
  background: rgba(0,0,0,0.35);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* --------------------------------------------------------------- buttons */
button { font: inherit; cursor: pointer; border: none; border-radius: 10px; }
button:disabled { opacity: 0.5; cursor: default; }
.primary {
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 700;
  padding: 14px 20px;
  width: 100%;
  font-size: 1.05rem;
}
.primary:hover:not(:disabled) { filter: brightness(1.05); }
.secondary {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  padding: 12px 20px;
  width: 100%;
  font-size: 1rem;
  margin-top: 12px;
}
.secondary:hover:not(:disabled) { background: #3d4557; }
.ghost {
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
}
.ghost:hover { background: #3d4557; }
.small { font-size: 0.85rem; padding: 6px 12px; }

/* ---------------------------------------------------------------- game */
.game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-2);
}
.turn-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status { font-size: 0.92rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); flex: none;
  border: 2px solid rgba(255,255,255,0.2);
}
.turn-dot.w { background: var(--white-tile); }
.turn-dot.b { background: #000; }

.invite-box {
  background: var(--panel);
  border-bottom: 1px solid var(--panel-2);
  padding: 12px 14px;
}
.invite-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.invite-btns { display: flex; align-items: center; gap: 8px; flex: none; }
.invite-btns .ghost { display: inline-flex; align-items: center; gap: 5px; }
.invite-btns svg { display: block; }
.invite-link {
  width: 100%;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--panel-2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

/* --------------------------------------------------------------- board */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #262c39, var(--bg));
  overflow: hidden;
}
#board { width: 100%; height: 100%; touch-action: none; display: block; }

.cell { stroke-width: 2; }
.cell.target, .cell.piece { cursor: pointer; }
.cell.target { fill: var(--target); stroke: var(--accent-2); stroke-dasharray: 4 3; }
.cell.target.place { fill: var(--place); stroke: #6fdc8c; }
.cell.piece.white { fill: var(--white-tile); stroke: var(--white-edge); }
.cell.piece.black { fill: var(--black-tile); stroke: var(--black-edge); }
.cell.piece.selected { stroke: var(--accent); stroke-width: 4; }
.cell.piece.movable { stroke: var(--accent-2); }
.target-dot { fill: var(--accent-2); stroke: #06263d; stroke-width: 2; }
.glyph { font-size: 30px; user-select: none; }

.board-controls {
  position: absolute;
  right: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.round {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(42,48,61,0.9);
  color: var(--text);
  font-size: 1.3rem;
  border: 1px solid var(--panel-2);
  backdrop-filter: blur(4px);
}
.pass {
  position: absolute;
  left: 50%; bottom: 16px; transform: translateX(-50%);
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 700;
  padding: 12px 28px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.rematch {
  position: absolute;
  left: 50%; bottom: 16px; transform: translateX(-50%);
  background: var(--accent-2);
  color: #06263d;
  font-weight: 700;
  padding: 12px 28px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: rematch-pop 0.3s ease;
}
.rematch:hover { filter: brightness(1.05); }
@keyframes rematch-pop { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------------------------------------------------------------- dock */
.dock {
  background: var(--panel);
  border-top: 1px solid var(--panel-2);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.hand {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
}
.hand.opp { opacity: 0.65; transform: scale(0.85); transform-origin: left center; }
.hand-label { font-size: 0.75rem; color: var(--muted); flex: none; width: 44px; }
.hand-empty { font-size: 0.75rem; color: var(--muted); }
.hand-piece {
  position: relative;
  flex: none;
  width: 46px; height: 46px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent;
}
.hand-piece.white { background: var(--white-tile); }
.hand-piece.black { background: var(--black-tile); }
.hand-piece .glyph { font-size: 24px; }
.hand-piece.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.hand-piece .count {
  position: absolute; right: -4px; top: -4px;
  background: var(--accent-2); color: #06263d;
  font-size: 0.7rem; font-weight: 700;
  min-width: 18px; height: 18px; line-height: 18px;
  border-radius: 9px; text-align: center;
}

@media (min-width: 700px) {
  .status { font-size: 1rem; }
  .glyph { font-size: 32px; }
}
