:root {
  --bg: #1c1f24;
  --panel: #262a31;
  --panel-2: #2e333c;
  --text: #e6e7ea;
  --muted: #8a8f99;
  --accent: #c5733a;
  --accent-2: #e08e4f;
  --good: #6cc66c;
  --bad: #d65a5a;
  --line: #3a3f48;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
a { color: var(--accent-2); text-decoration: none; }

.topbar { display: flex; align-items: baseline; gap: 16px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.topbar .tagline { color: var(--muted); font-size: 13px; }

.topnav { display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.topnav .brand { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; color: var(--text); }
.topnav .tagline { color: var(--muted); font-size: 13px; }
.topnav-spacer { flex: 1; }
.topnav-link { color: var(--text); padding: 6px 10px; border-radius: 5px; font-size: 14px; }
.topnav-link:hover { background: var(--panel-2); }
.topnav-link-accent { color: var(--accent-2); }
.topnav-form { margin: 0; }
.topnav-btn { background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 5px; font-size: 13px; cursor: pointer; }
.topnav-btn:hover { color: var(--text); border-color: var(--accent-2); }

.flashes { list-style: none; margin: 0; padding: 8px 24px; display: flex; flex-direction: column; gap: 6px; }
.flash { padding: 8px 12px; border-radius: 5px; font-size: 14px; border: 1px solid var(--line); background: var(--panel); }
.flash-success { border-color: var(--good); color: var(--good); }
.flash-error { border-color: var(--bad); color: var(--bad); }
.flash-info { color: var(--text); }

.auth-card { max-width: 420px; margin: 32px auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.auth-card h2 { margin: 0 0 16px; font-size: 20px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-field span { font-weight: 600; color: var(--text); }
.auth-input { background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 8px 10px; font-size: 14px; }
.auth-input:focus { outline: none; border-color: var(--accent-2); }
.auth-error { color: var(--bad); }
.auth-hint { color: var(--muted); }
.auth-switch { margin-top: 16px; color: var(--muted); font-size: 13px; }
.auth-meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; margin: 0 0 24px; }
.auth-meta dt { color: var(--muted); }
.auth-danger { border-top: 1px solid var(--line); padding-top: 16px; }
.auth-danger summary { cursor: pointer; color: var(--bad); font-weight: 600; }
.auth-danger .auth-form { margin-top: 12px; }

main { padding: 24px; }
.game-layout { display: grid; grid-template-columns: minmax(320px, 640px) 360px;
  gap: 24px; align-items: start; }
@media (max-width: 980px) { .game-layout { grid-template-columns: 1fr; } }

.game-header { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px 16px; padding: 10px 14px; background: var(--panel);
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px;
  font-size: 13px; color: var(--muted); }
.game-header .gh-badge { background: var(--accent); color: #fff; font-weight: 600;
  font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 3px; }
.game-header .gh-vs strong { color: var(--text); }
.game-header .gh-side { color: var(--text); }
.game-header .gh-result { color: var(--accent-2); font-weight: 600; }
.game-header .gh-meta { font-variant-numeric: tabular-nums; }

.board-wrap { display: flex; flex-direction: column; gap: 12px; }
#board { width: 100%; aspect-ratio: 1 / 1; }

.info-panel { display: flex; flex-direction: column; gap: 16px; }
.panel-section { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px; }

.controls { display: flex; flex-direction: row; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.controls .btn { flex: 1 1 0; padding: 7px 10px; font-size: 13px; min-width: 0; }
.controls .btn-icon { flex: 0 0 auto; width: 38px; padding: 7px 0; font-size: 18px; line-height: 1; }
.controls-form { display: contents; margin: 0; }
.replay-controls { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 12px; }
.replay-controls .btn-sm { padding: 6px 10px; font-size: 14px; min-width: 36px; }
.replay-controls .btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }
.replay-position { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 60px; text-align: center; }
.move-list .ply.clickable { cursor: pointer; padding: 1px 4px; border-radius: 3px; transition: background .12s; }
.move-list .ply.clickable:hover { background: var(--panel-2); }
.move-list .ply.active { background: var(--accent-2); color: var(--bg); font-weight: 600; }
.pv-stale-label { font-size: 12px; padding: 4px 0 6px; font-style: italic; }
.auth-back { display: inline-block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.auth-back:hover { color: var(--accent-2); }
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 6px; font-size: 14px; cursor: pointer;
  transition: background .12s, border-color .12s; }
.btn:hover { background: #353a44; }
.btn-primary { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.depth-control { display: flex; align-items: center; gap: 10px; }
.depth-control .depth-label { color: var(--muted); font-size: 13px; }
.depth-num { font-weight: 700; font-size: 16px; min-width: 28px; text-align: center; }
.btn-sm { width: 28px; height: 28px; padding: 0; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; border-radius: 5px; }
.depth-spacer { flex: 1; }
.status-section { padding: 8px 14px !important; }
.status-inline { font-size: 13px; color: var(--muted); }
.status-inline.win { color: var(--good); }
.status-inline.loss { color: var(--bad); }
.status-inline.draw { color: var(--accent-2); }

.depth-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.depth-label #depth-value { color: var(--text); font-weight: 600; }
#depth-slider { width: 100%; accent-color: var(--accent); }

.eval-section { display: flex; flex-direction: column; gap: 4px; }
.eval-bar-wrap { position: relative; padding-bottom: 42px; }
.eval-bar { display: flex; height: 20px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--line); position: relative; }
.eval-bar-white { flex: 1; background: #e8e0d4; }
.eval-bar-black { flex: 1; background: #2a2a2a; }
.eval-bar-mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: var(--accent); transform: translateX(-1px); z-index: 1; }

.eval-pointer { position: absolute; top: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: left .4s cubic-bezier(.4,0,.2,1); }
.eval-arrow { width: 0; height: 0; border-left: 5px solid transparent;
  border-right: 5px solid transparent; border-bottom: 6px solid var(--accent); }
.eval-badge { background: var(--panel-2); border: 2px solid var(--line);
  border-radius: 5px; padding: 3px 10px; font-size: 13px; font-weight: 700;
  white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.eval-badge.positive { color: var(--good); border-color: var(--good); }
.eval-badge.negative { color: var(--bad); border-color: var(--bad); }
.eval-badge.mate { color: var(--accent-2); border-color: var(--accent-2); }
.eval-meta-line { text-align: center; }
.muted { color: var(--muted); font-size: 12px; }

.history-section .history-header { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.move-list { max-height: 360px; overflow-y: auto; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px; line-height: 1.6; }
.move-list .row { display: grid; grid-template-columns: 32px 1fr 1fr; gap: 6px; padding: 2px 4px; }
.move-list .row:nth-child(odd) { background: rgba(255,255,255,0.02); }
.move-list .num { color: var(--muted); }
.move-list .ply { padding: 2px 6px; border-radius: 3px; cursor: default; }

.board-container { position: relative; }

.promotion-overlay { position: absolute; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; }
.promotion-overlay.hidden { display: none; }
.promotion-choices { display: flex; gap: 8px; padding: 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.promotion-choices button { width: 64px; height: 64px; background-size: contain;
  background-repeat: no-repeat; background-position: center; background-color: var(--panel-2);
  border: 2px solid var(--line); border-radius: 8px; cursor: pointer; transition: border-color .12s, transform .1s; }
.promotion-choices button:hover { border-color: var(--accent-2); transform: scale(1.08); }

.btn-danger { background: #5a2020; border-color: var(--bad); color: #e88; }
.btn-danger:hover:not(:disabled) { background: var(--bad); color: #fff; }

.pv-section .pv-header { font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.pv-lines { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; line-height: 1.5; }
.pv-line { display: grid; grid-template-columns: 60px 1fr; gap: 8px; padding: 2px 4px; border-radius: 3px; }
.pv-line:nth-child(odd) { background: rgba(255,255,255,0.02); }
.pv-line .pv-eval { font-weight: 600; white-space: nowrap; }
.pv-line .pv-eval.positive { color: var(--good); }
.pv-line .pv-eval.negative { color: var(--bad); }
.pv-line .pv-eval.mate { color: var(--accent-2); }
.pv-line .pv-moves { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cg-wrap piece.king.white   { background-image: url("/static/pieces/white-king.png"); }
.cg-wrap piece.queen.white  { background-image: url("/static/pieces/white-queen.png"); }
.cg-wrap piece.rook.white   { background-image: url("/static/pieces/white-rook.png"); }
.cg-wrap piece.bishop.white { background-image: url("/static/pieces/white-bishop.png"); }
.cg-wrap piece.knight.white { background-image: url("/static/pieces/white-knight.png"); }
.cg-wrap piece.pawn.white   { background-image: url("/static/pieces/white-pawn.png"); }
.cg-wrap piece.king.black   { background-image: url("/static/pieces/black-king.png"); }
.cg-wrap piece.queen.black  { background-image: url("/static/pieces/black-queen.png"); }
.cg-wrap piece.rook.black   { background-image: url("/static/pieces/black-rook.png"); }
.cg-wrap piece.bishop.black { background-image: url("/static/pieces/black-bishop.png"); }
.cg-wrap piece.knight.black { background-image: url("/static/pieces/black-knight.png"); }
.cg-wrap piece.pawn.black   { background-image: url("/static/pieces/black-pawn.png"); }

/* Settings modal */
.modal-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.hidden { display: none; }
.modal-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: 100%; max-width: 420px; box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-title { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 22px;
  width: 32px; height: 32px; }
.modal-close:hover { color: var(--text); background: var(--panel-2); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.setting-row { display: flex; flex-direction: column; gap: 8px; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text); }
.setting-hint { margin: 0; font-size: 12px; color: var(--muted); }

.lobby { max-width: 1024px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.lobby-title { margin: 0 0 8px; font-size: 24px; font-weight: 700; letter-spacing: 0.5px; }

.lobby-grid { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
@media (max-width: 768px) { .lobby-grid { grid-template-columns: 1fr; } }

.new-game-panel, .active-games-panel, .recent-games-panel { padding: 20px; }
.new-game-panel h2, .active-games-panel h2, .recent-games-panel h2 { margin: 0 0 20px; font-size: 18px; font-weight: 600; color: var(--text); border-bottom: 1px solid var(--line); padding-bottom: 12px; }

.form-stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.5px; }
.field .input, .field .select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; font-size: 14px; width: 100%; transition: border-color .12s; }
.field .input:focus, .field .select:focus { outline: none; border-color: var(--accent-2); }
.form-stack .btn-primary { margin-top: 12px; padding: 12px 16px; font-weight: 600; font-size: 15px; }

.game-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.game-list .game-item { background: var(--panel-2); padding: 8px 12px; border-radius: 6px; border: 1px solid var(--line); display: flex; align-items: center; gap: 10px; font-size: 14px; user-select: none; }
.game-list .game-time { color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; }
.game-list .game-time:hover { color: var(--accent-2); text-decoration: underline; }
.game-list .game-label { color: var(--muted); font-size: 13px; }
.game-list .game-term { font-size: 12px; }
.game-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; display: inline-block; box-shadow: 0 0 0 1px rgba(0,0,0,0.25) inset; }
.game-dot--win     { background: #2ecc71; }
.game-dot--loss    { background: #e74c3c; }
.game-dot--draw    { background: #f1c40f; }
.game-dot--aborted { background: #7f8c8d; }
.game-dot--wait    { background: #3498db; }
.game-dot--move    { background: #f39c12; box-shadow: 0 0 0 1px rgba(0,0,0,0.25) inset, 0 0 6px rgba(243,156,18,0.7); animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.active-game { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.active-game-link { color: var(--accent-2); font-weight: 600; text-decoration: none; font-size: 15px; }
.active-game-link:hover { text-decoration: underline; }
.active-game-meta { font-size: 13px; font-variant-numeric: tabular-nums; }

.games-subhead { margin: 8px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.games-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.games-table thead th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); }
.games-table tbody td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.games-table tbody tr:last-child td { border-bottom: none; }
.games-table tbody tr:hover { background: var(--panel-2); }
.games-table-when a { color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; }
.games-table-when a:hover { color: var(--accent-2); text-decoration: underline; }
.games-table-result { display: flex; align-items: center; gap: 8px; }
.games-table-term { font-size: 13px; }

/* Landing Page */
.landing {
  max-width: 640px;
  margin: 0 auto;
  padding: 80px 24px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.landing-title {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 16px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 30%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #fff;
}
.landing-tag {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.6;
  max-width: 500px;
  margin: 0 0 32px;
}
.landing-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}
.landing-cta .btn {
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
}



