:root {
  --bg: #0b0f14;
  --bg-soft: #0e141c;
  --panel: #121821;
  --panel-2: #16202c;
  --line: #223041;
  --line-soft: #1a2532;
  --text: #e6edf3;
  --muted: #8fa3b7;
  --accent: #38e8b0;
  --accent-2: #f5c451;
  --danger: #ff6b6b;
  --sq-light: #cdd8e3;
  --sq-dark: #5a7288;
  --sq-light-hl: #e8d48a;
  --sq-dark-hl: #b39a4c;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 20% -10%, #16222f 0%, var(--bg) 60%) var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 15, 20, .82);
  position: sticky; top: 0; z-index: 10;
}

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); font-weight: 700; letter-spacing: .02em; font-size: 18px;
}
.brand:hover { text-decoration: none; }
.brand-piece { display: block; width: 30px; height: 30px; border-radius: 8px; flex: none; }
.brand-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: #06251c; background: var(--accent); border-radius: 999px; padding: 2px 8px;
}

.identity { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.nick-input, select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: inherit; outline: none;
}
.nick-input { width: 190px; }
.nick-input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 232, 176, .12); }
.who {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent); font-weight: 600; font-size: 13px;
  border: 1px solid rgba(56, 232, 176, .35); border-radius: 999px; padding: 4px 10px;
}
.switch-link { font-size: 13px; color: var(--muted); }

.wrap { width: min(1180px, 100%); margin: 0 auto; padding: clamp(16px, 3vw, 34px); }

.hero { display: grid; grid-template-columns: 1.15fr .85fr; gap: clamp(16px, 3vw, 28px); align-items: stretch; }
.eyebrow { display: inline-block; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.hero-view { padding: clamp(14px, 2vw, 22px); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hero-view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero-view-title { margin: 3px 0 0; font-size: clamp(22px, 3vw, 30px); line-height: 1.15; letter-spacing: -.01em; }
.hero-board { width: min(100%, 420px); margin: 2px auto; }
.hero-board .board { border-radius: 12px; box-shadow: 0 14px 34px rgba(0, 0, 0, .35); }
.hero-board .sq { font-size: clamp(18px, 4.8vmin, 36px); }
.hero-board .coord { display: none; }
.hero-view-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-view-meta { margin: 0; color: var(--muted); font-size: 14px; }
.hero-view-link { font-weight: 700; white-space: nowrap; }

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.create-card { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.create-card h2, .panel-head h2 { margin: 0; font-size: 17px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); }
.field-row select { min-width: 130px; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 10px 15px; font: inherit; font-weight: 600; cursor: pointer;
  transition: border-color .15s, background .15s, transform .06s;
}
.btn:hover { border-color: #32465d; background: #1a2633; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #05251c; }
.btn-primary:hover { background: #4ff0bd; border-color: #4ff0bd; }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(255, 107, 107, .4); color: #ffb3b3; }
.btn-danger:hover { background: rgba(255, 107, 107, .1); border-color: var(--danger); }
.btn-mini { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.list-panel { margin-top: clamp(16px, 3vw, 26px); padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.games-list { display: grid; gap: 10px; }
.game-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line-soft); border-radius: 12px;
  background: rgba(255, 255, 255, .015);
}
.game-row-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.game-row .topline { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.game-row .vs { color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-row .meta { color: var(--muted); font-size: 12px; }
.game-row .game-open { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }
.game-row .gname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 18ch; }
.tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); border: 1px solid rgba(56, 232, 176, .3);
  border-radius: 999px; padding: 2px 8px;
}
.tag.wait { color: var(--accent-2); border-color: rgba(245, 196, 81, .35); }
.empty { color: var(--muted); padding: 18px 6px; text-align: center; }

.screen[hidden] { display: none; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: clamp(16px, 3vw, 28px); align-items: start; }
.board-column { min-width: 0; }
.board-frame {
  width: min(100%, calc(100vh - 190px));
  margin: 0 auto;
  padding: 10px;
  background: linear-gradient(180deg, #101821, #0c1219);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.sq {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(22px, 5.4vmin, 46px);
  line-height: 1;
  cursor: default;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last.light { background: var(--sq-light-hl); }
.sq.last.dark { background: var(--sq-dark-hl); }
.sq.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.sq.playable { cursor: pointer; }
.sq.playable:hover { filter: brightness(1.06); }
.sq .piece {
  position: relative; z-index: 2;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.sq .piece.w { color: #f8fbff; text-shadow: 0 0 1px #0b0f14, 0 2px 3px rgba(0, 0, 0, .55); }
.sq .piece.b { color: #101820; text-shadow: 0 1px 1px rgba(255, 255, 255, .22); }
.sq .hint-dot {
  position: absolute;
  pointer-events: none; width: 26%; height: 26%; border-radius: 50%;
  background: rgba(56, 232, 176, .55); z-index: 1;
}
.sq.capture .hint-dot {
  width: 78%; height: 78%; background: transparent;
  border: 4px solid rgba(255, 107, 107, .65);
}
.coord {
  position: absolute; font-size: 10px; font-weight: 700; opacity: .55;
  color: #0b0f14; pointer-events: none;
}
.sq.light .coord { color: #45535f; }
.sq.dark .coord { color: #dbe5ee; }
.coord.file { right: 5px; bottom: 3px; }
.coord.rank { left: 5px; top: 3px; }

.board-meta { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; min-height: 20px; }
.board-meta a { color: var(--accent); word-break: break-all; }

.sidebar { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.side-title { font-weight: 700; font-size: 17px; }
.game-id { color: var(--muted); font-size: 12px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; margin-top: 2px; word-break: break-all; }
.players { display: grid; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 10px;
  background: rgba(255, 255, 255, .02);
}
.player.active { border-color: rgba(56, 232, 176, .55); background: rgba(56, 232, 176, .07); }
.player .dot { width: 9px; height: 9px; border-radius: 50%; background: #f8fbff; border: 1px solid #7f8b96; flex: none; }
.player .dot.b { background: #101820; }
.player .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .side-label { margin-left: auto; color: var(--muted); font-size: 12px; }
.turn-line { font-weight: 600; color: var(--accent); font-size: 14px; }
.result-line { font-weight: 700; color: var(--accent-2); font-size: 15px; }
.moves-head { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.moves {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 8px;
  max-height: 250px; overflow: auto; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px;
}
.moves li { display: contents; }
.moves .num { color: var(--muted); }
.moves .mv { color: var(--text); }
.moves .mv.last { color: var(--accent); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 auto; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1a2633; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 16px; z-index: 60; max-width: min(92vw, 520px);
  box-shadow: var(--shadow);
}
.toast.error { border-color: rgba(255, 107, 107, .6); color: #ffc9c9; }
.toast.ok { border-color: rgba(56, 232, 176, .6); }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 10, .72);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.overlay[hidden] { display: none; }
.dialog {
  width: min(420px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; box-shadow: var(--shadow);
}
.dialog h3 { margin: 0 0 12px; }
.dialog p { color: var(--muted); }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-btn {
  font-size: 34px; line-height: 1; padding: 12px 0; cursor: pointer;
  background: var(--panel-2); color: #f8fbff; border: 1px solid var(--line); border-radius: 12px;
}
.promo-btn:hover { border-color: var(--accent); }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .board-frame { width: min(100%, 92vw); }
  .sidebar { order: 2; }
  .moves { max-height: 160px; }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .identity { width: 100%; justify-content: flex-start; }
  .nick-input { flex: 1 1 130px; width: auto; }
  .switch-link { display: none; }
  .game-row { align-items: flex-start; flex-direction: column; }
}
