:root {
  --bg: #0f1418;
  --panel: #19212a;
  --panel-2: #212c37;
  --line: #2c3a47;
  --text: #e7edf2;
  --muted: #8ea0af;
  --accent: #4f9dde;
  --accent-2: #3b7fbd;
  --ok: #57c98a;
  --err: #e06c6c;
  --light-sq: #e9e2cf;
  --dark-sq: #7fa2b8;
  --wizard-sq: #b58b5a;
  --sel: #f2c14e;
  --last: #d6e64a;
  --board-max: 720px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .3px; }
.userbar { display: flex; align-items: center; gap: 12px; }

#app { max-width: 1100px; margin: 0 auto; padding: 22px 16px 60px; }
.view { display: block; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 18px; margin-bottom: 18px;
}
.narrow { max-width: 420px; margin: 40px auto; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 6px; }
h3 { font-size: 15px; margin: 0; }

.field { margin: 12px 0; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input, select {
  width: 100%; padding: 10px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { background: #b03a3a; border-color: #b03a3a; color: #fff; font-weight: 600; }
.btn.danger:hover { background: #c04040; border-color: #c04040; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }

.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.row.spread { justify-content: space-between; }

.msg { min-height: 18px; margin: 10px 0 0; font-size: 13px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }

/* lobby */
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.games { list-style: none; margin: 10px 0 0; padding: 0; }
.game-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 8px;
  background: var(--panel-2);
}
.gi-code { font-weight: 600; letter-spacing: .5px; }
.tag { font-size: 11px; background: var(--line); padding: 2px 7px; border-radius: 20px; margin-left: 6px; color: var(--muted); }

/* game layout */
.game-grid { display: grid; grid-template-columns: minmax(0, var(--board-max)) 300px; gap: 22px; align-items: start; }
.board-wrap { width: 100%; }
.player-line { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid #0006; }
.dot.w { background: #f2f2f2; }
.dot.b { background: #2b2b2b; }
.to-move { color: var(--accent); font-size: 12.5px; }
.status-line { margin-top: 10px; font-size: 13.5px; color: var(--muted); min-height: 20px; }
.status-line a { color: var(--accent); }

/* confirm bar */
.confirm-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px; margin-top: 8px;
  background: linear-gradient(135deg, #3a3118, #2d2b1e);
  border: 1px solid #7a6c3a; border-radius: 10px;
  font-size: 13.5px; color: #f5e5a6;
  animation: confirmSlide .22s ease-out;
}
.confirm-bar .confirm-label { flex: 1; min-width: 0; }
.confirm-bar .confirm-actions { display: flex; gap: 8px; flex-shrink: 0; }
@keyframes confirmSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* preview board glow */
.board.preview {
  box-shadow: 0 0 18px 3px #c8a82c55, inset 0 0 6px 1px #c8a82c22;
}
.sq.pending-from::after,
.sq.pending-to::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0;
}
.sq.pending-from::after { background: #e8c63d; opacity: .30; }
.sq.pending-to::after   { background: #e8c63d; opacity: .38; }


/* board */
.board {
  --cell: calc(min(92vw, var(--board-max)) / 12);
  width: calc(var(--cell) * 12);
  height: calc(var(--cell) * 12);
  display: grid;
  grid-template-columns: repeat(12, var(--cell));
  grid-template-rows: repeat(12, var(--cell));
  background: #10171d;
  border-radius: 8px;
  border: 1px solid var(--line);
  user-select: none;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.wizard-sq { box-shadow: inset 0 0 0 2px var(--wizard-sq); }
.sq.lastmove::after {
  content: ''; position: absolute; inset: 0; background: var(--last); opacity: .28; pointer-events: none;
}
.sq.selected { box-shadow: inset 0 0 0 3px var(--sel); }

.piece {
  font-size: calc(var(--cell) * 0.74);
  line-height: 1; z-index: 2; pointer-events: none;
}
.p-white { color: #fbfbfb; text-shadow: 0 0 2px #000, 0 0 1px #000, 0 1px 1px #0009; }
.p-black { color: #1b1b1b; text-shadow: 0 0 2px #fff8, 0 1px 1px #0006; }
.piece.letter {
  font-size: calc(var(--cell) * 0.5);
  font-weight: 800; font-family: system-ui, sans-serif;
  width: calc(var(--cell) * 0.74); height: calc(var(--cell) * 0.74);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.p-white.letter { background: #fbfbfb; color: #1b1b1b; text-shadow: none; box-shadow: 0 1px 2px #0007; }
.p-black.letter { background: #1b1b1b; color: #fbfbfb; text-shadow: none; box-shadow: 0 1px 2px #0007; }

.target {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: #1e6b3e88; z-index: 1; pointer-events: none;
}
.target.capture {
  width: 86%; height: 86%; background: transparent;
  border: 4px solid #1e6b3eaa; box-sizing: border-box;
}
.label {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); pointer-events: none;
}

/* sidebar */
.sidebar { position: sticky; top: 14px; }
.game-meta { display: grid; gap: 6px; font-size: 13.5px; }
.stepper { display: flex; gap: 4px; }
.moves-card { max-height: 62vh; display: flex; flex-direction: column; }
.move-list {
  list-style: none; margin: 12px 0 0; padding: 0; overflow-y: auto; flex: 1;
  font-variant-numeric: tabular-nums;
}
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; align-items: center; padding: 2px 0; }
.mnum { color: var(--muted); font-size: 12.5px; }
.mhalf { padding: 3px 6px; border-radius: 5px; cursor: pointer; font-size: 13.5px; }
.mv:hover { background: var(--panel-2); }
.mv.active { background: var(--accent-2); color: #fff; }

/* modal */
.modal {
  position: fixed; inset: 0; background: #000a; display: flex;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: 300px; }
.promo-choices { display: grid; gap: 8px; margin-top: 12px; }
.promo-choices .btn { display: flex; align-items: center; gap: 10px; text-align: left; }
.promo-choices .piece { font-size: 22px; }
.promo-choices .piece.letter { width: 26px; height: 26px; font-size: 15px; }

/* realtime live indicator */
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); display: inline-block; flex: 0 0 auto;
  box-shadow: 0 0 6px var(--ok); transition: background .2s, box-shadow .2s;
}
.live-dot.off { background: #6b7785; box-shadow: none; }

/* toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px #0007;
}

@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .game-grid { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .board { --cell: calc(min(92vw, var(--board-max)) / 12); }
}
