:root {
  --bg: #11151c;
  --bg2: #161b24;
  --panel: #1c2330;
  --panel2: #232c3d;
  --line: #2d3848;
  --text: #e6ecf5;
  --muted: #8a97ab;
  --accent: #6ea8fe;
  --accent2: #4b8bf4;
  --good: #5fd08a;
  --danger: #ff6b6b;
  --light: #ebe4cf;   /* light square */
  --dark: #6f8a5a;    /* dark square (green felt) */
  --sel: #f6d76b;
  --last: rgba(246, 215, 107, .45);
  --check: #ff5757;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 700px at 70% -10%, #1d2738 0, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
}
.brand { font-size: 24px; font-weight: 800; letter-spacing: .3px; }
.brand .logo { color: var(--accent); font-size: 26px; }
.tagline { color: var(--muted); font-size: 13px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 18px 60px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- menu ---------- */
.name-field { max-width: 320px; margin-bottom: 20px; }
.field { margin: 12px 0; }
.field > label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text); font-size: 15px;
}
input:focus, select:focus { outline: none; border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(110,168,254,.18); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card p { margin: 0 0 8px; }

.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 9px 14px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--accent2); color: #fff; font-weight: 600; }

button.primary {
  width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 11px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #06101f; font-weight: 700; font-size: 15px;
  transition: transform .06s ease, filter .15s ease;
}
button.primary:hover { filter: brightness(1.06); }
button.primary:active { transform: translateY(1px); }
button.ghost {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer;
}
button.ghost:hover { border-color: var(--accent2); }
button.ghost.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }

.join-row { display: flex; gap: 8px; margin-top: 12px; }
.join-row input { text-transform: uppercase; }

.lobby { list-style: none; margin: 6px 0 10px; padding: 0; max-height: 220px; overflow: auto; }
.lobby li { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lobby .vs { font-weight: 600; }
.lobby .badge { font-size: 11px; color: var(--muted); }
.lobby button { padding: 6px 10px; font-size: 13px; }

/* ---------- game ---------- */
.game { display: grid; grid-template-columns: minmax(320px, 1fr) 320px; gap: 26px; align-items: start; }
.board-col { display: flex; flex-direction: column; gap: 8px; }
.player-tag { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 24px; }
.player-tag .dot { width: 9px; height: 9px; border-radius: 50%; background: #50607a; }
.player-tag .dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.player-tag .role { color: var(--muted); font-weight: 400; font-size: 13px; }
.player-tag .turn-pip { margin-left: auto; font-size: 12px; color: var(--accent); opacity: 0; }
.player-tag.active .turn-pip { opacity: 1; }

.board-frame { padding: 10px; background: linear-gradient(145deg, #3a2c20, #241a12); border-radius: 16px; box-shadow: var(--shadow); }
.board {
  --sq: 64px;
  width: calc(var(--sq) * 8); height: calc(var(--sq) * 8);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 6px; overflow: hidden; position: relative; user-select: none; touch-action: manipulation;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.sel { box-shadow: inset 0 0 0 4px var(--sel); }
.sq.last::after { content: ""; position: absolute; inset: 0; background: var(--last); pointer-events: none; }
.sq.check { background: radial-gradient(circle, var(--check) 0%, transparent 72%) !important; }
.sq .hint { position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(20,30,20,.32); pointer-events: none; }
.sq.cap .hint { width: 86%; height: 86%; border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 5px rgba(20,30,20,.3); }
.sq .coord { position: absolute; font-size: 10px; font-weight: 700; opacity: .55; }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: #6f8a5a; }
.sq.dark .coord { color: #ebe4cf; }

.piece {
  font-size: calc(var(--sq) * .78); line-height: 1; cursor: grab;
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
}
.piece.dragging { opacity: .35; }
.piece.w { color: #f7f7f4; text-shadow: 0 1px 1px rgba(0,0,0,.35), 0 0 2px rgba(0,0,0,.55), 0 0 1px #000; }
.piece.b { color: #2a2a2c; text-shadow: 0 1px 1px rgba(255,255,255,.18); }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 14px; }
.status {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  font-size: 16px; font-weight: 600; min-height: 22px;
}
.status.win { color: var(--good); }
.status.lose { color: var(--danger); }
.status.draw { color: var(--accent); }
.status .think { color: var(--muted); font-weight: 400; font-size: 13px; }

.invite { background: var(--panel); border: 1px dashed var(--accent2); border-radius: 12px; padding: 12px; }
.invite-row { display: flex; gap: 8px; margin-top: 6px; }
.invite-row input { font-family: ui-monospace, monospace; font-size: 13px; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.moves-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; max-height: 320px; overflow: auto; }
.moves { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.moves li { display: grid; grid-template-columns: 36px 1fr 1fr; gap: 4px; padding: 5px 8px; border-radius: 6px; }
.moves li:nth-child(odd) { background: rgba(255,255,255,.02); }
.moves .n { color: var(--muted); }
.moves .ply.last { background: var(--accent2); color: #fff; border-radius: 5px; padding: 0 4px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,8,12,.62); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.modal-title { font-weight: 700; margin-bottom: 12px; text-align: center; }
.promo-choices { display: flex; gap: 8px; }
.promo-choices button { font-size: 44px; width: 72px; height: 72px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; color: #f7f7f4; text-shadow: 0 1px 2px #000; }
.promo-choices button:hover { border-color: var(--accent); background: var(--panel2); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #0c1118; border: 1px solid var(--line); color: var(--text);
  padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 90vw;
}

.foot { text-align: center; margin-top: 40px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .game { grid-template-columns: 1fr; }
  .side { order: 2; }
  .board { --sq: min(11.2vw, 64px); }
}
@media (max-width: 520px) {
  .board { --sq: 40px; }
  .cards { grid-template-columns: 1fr; }
}
