/* ============ base ============ */

:root {
  --bg: #0f1117;
  --bg-raised: #171a21;
  --bg-card: #1e222b;
  --bg-hover: #242935;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --sq-light: #4a5468;
  --sq-dark: #343c4e;
  --piece-white: #f5f7fa;
  --piece-black: #14161c;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* ============ top bar ============ */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  font-size: 15px;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand strong { color: var(--text); }
.brand .knight { margin-right: 6px; }

.spacer { flex: 1; }

.pill {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.pill.live { color: var(--green); border-color: rgba(52, 211, 153, 0.35); }
.pill.warn { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); }

/* ============ buttons ============ */

.btn {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: var(--bg-hover); border-color: #3a4150; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(248, 113, 113, 0.3); background: transparent; }
.btn.danger:hover { background: rgba(248, 113, 113, 0.1); }
.btn.wide { width: 100%; display: block; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn.live {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.4);
}

body.time-traveling .btn.live {
  background: var(--green);
  color: #06281c;
  border-color: var(--green);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
}

/* ============ lobby ============ */

.lobby {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}

.game-card:hover { border-color: #3a4150; transform: translateY(-1px); }

.game-card .matchup {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.game-card .matchup .vs { color: var(--muted); font-weight: 400; font-size: 12px; }

.game-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
}

.game-card .game-status { color: var(--text); }
.game-card .game-status.over { color: var(--amber); }
.game-card .game-status.check { color: var(--red); }
.game-card .move-count { font-family: var(--mono); font-size: 11px; }

.side-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.side-dot.w { background: var(--piece-white); }
.side-dot.b { background: var(--piece-black); border: 1px solid var(--muted); }

.empty {
  max-width: 420px;
  margin: 10vh auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.empty .empty-piece { font-size: 56px; margin-bottom: 12px; opacity: 0.4; }
.empty strong { color: var(--text); }
.empty p { margin-bottom: 8px; }

/* ============ game layout ============ */

.game {
  display: flex;
  flex: 1;
  min-height: 0;
}

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 18px;
  min-width: 0;
  overflow: auto;
  transition: filter 0.3s;
}

body.time-traveling .board-area {
  filter: sepia(0.25) saturate(0.75);
}

.status {
  font-size: 15px;
  font-weight: 600;
  min-height: 22px;
  text-align: center;
}

.status .check-flag { color: var(--red); }
.status.over { color: var(--amber); }

/* ============ board ============ */

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(76vmin, 620px);
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }

.square .piece {
  font-size: min(8.4vmin, 68px);
  line-height: 1;
  pointer-events: none;
}

.square .piece.w {
  color: var(--piece-white);
  text-shadow: 0 0 1px #14161c, 0 1px 1px rgba(0, 0, 0, 0.45);
}

.square .piece.b {
  color: var(--piece-black);
  text-shadow: 0 0 1px #aab2c2, 0 1px 1px rgba(0, 0, 0, 0.35);
}

.square .coord {
  position: absolute;
  font-size: min(1.6vmin, 11px);
  font-family: var(--mono);
  color: var(--text);
  opacity: 0.35;
  pointer-events: none;
}

.square .coord.file { right: 4px; bottom: 3px; }
.square .coord.rank { left: 4px; top: 3px; }

/* interaction states */

.square.selectable { cursor: pointer; }
.square.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.square.last-move { box-shadow: inset 0 0 0 100vmax rgba(251, 191, 36, 0.14); }
.square.selected.last-move { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 100vmax rgba(251, 191, 36, 0.14); }
.square.check-square { box-shadow: inset 0 0 0 100vmax rgba(248, 113, 113, 0.28); }

.square.target { cursor: pointer; }

.square.target::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.55);
}

.square.target.capture::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 3px solid rgba(99, 102, 241, 0.65);
}

.square.target:hover { box-shadow: inset 0 0 0 3px var(--accent-soft); }

@keyframes land {
  from { transform: scale(1.25); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.square.landed .piece { animation: land 0.18s ease-out; }

/* ============ sidebar ============ */

.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.panel-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-section.grow { flex: 1; overflow-y: auto; }

.panel-section h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 8px 0 0; }
.hint-inline { font-size: 11px; color: var(--muted); text-transform: none; letter-spacing: 0; }

.players {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}

.players .player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.players .player span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .vs { color: var(--muted); font-size: 11px; font-weight: 400; }

.moves {
  list-style: none;
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 0;
  font-family: var(--mono);
  font-size: 13px;
}

.moves .move-num {
  color: var(--muted);
  font-size: 11px;
  padding: 4px 8px 4px 0;
  text-align: right;
  min-width: 28px;
}

.moves .ply {
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.moves .ply:hover { background: var(--bg-card); }
.moves .ply.current { background: var(--accent-soft); color: var(--text); }
.moves .ply.empty { cursor: default; }
.moves .ply.empty:hover { background: transparent; }

.moves-empty {
  grid-column: 1 / -1;
  font-family: var(--font);
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
  padding: 6px 0;
}

.actions .resign-row { display: flex; gap: 8px; margin-bottom: 8px; }
.actions .resign-row .btn { flex: 1; padding-left: 6px; padding-right: 6px; }

/* ============ time bar ============ */

.timebar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.timebar input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.time-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  min-width: 150px;
  text-align: right;
  white-space: nowrap;
}

/* ============ banner, toasts, modals ============ */

.banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: #2a2410;
  border: 1px solid rgba(251, 191, 36, 0.4);
  color: var(--amber);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: 80vw;
}

.banner button {
  font-size: 12px;
  font-weight: 600;
  color: #06281c;
  background: var(--green);
  border: none;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.toasts {
  position: fixed;
  bottom: 76px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  max-width: 420px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow);
  animation: slide-in 0.25s ease-out;
}

.toast.error { border-color: rgba(248, 113, 113, 0.5); }
.toast.conflict { border-color: rgba(251, 191, 36, 0.5); }

.toast .toast-title { font-weight: 600; margin-bottom: 3px; }
.toast .toast-detail { color: var(--muted); font-size: 12px; }
.toast .toast-detail code { font-family: var(--mono); font-size: 11px; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal {
  margin: auto;
  width: 440px;
  max-width: 92vw;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal::backdrop { background: rgba(5, 7, 12, 0.6); backdrop-filter: blur(2px); }

.modal h3 { font-size: 15px; margin-bottom: 14px; }

.modal input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  outline: none;
}

.modal input:focus { border-color: var(--accent); }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

.modal.promo { width: auto; text-align: center; }

.promo-choices { display: flex; gap: 10px; justify-content: center; }

.promo-choices button {
  font-size: 44px;
  line-height: 1;
  width: 68px;
  height: 68px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--piece-white);
  text-shadow: 0 0 1px #14161c;
  cursor: pointer;
}

.promo-choices button.black {
  color: var(--piece-black);
  text-shadow: 0 0 1px #aab2c2;
}

.promo-choices button:hover { background: var(--bg-hover); border-color: var(--accent); }
