:root {
  --board-size: clamp(360px, 54vw, 680px);
  --bg: #0f1722;
  --bg-2: #182638;
  --bg-3: #22344b;
  --line: #2f4863;
  --text: #e6f1ff;
  --muted: #99afc9;
  --accent: #6bc1ff;
  --accent-2: #8de6b2;
  --danger: #ff7a7a;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-selected: rgba(74, 171, 87, 0.58);
  --sq-hover: rgba(255, 255, 255, 0.08);
  --sq-last: rgba(255, 221, 74, 0.45);
  --sq-check: rgba(225, 64, 64, 0.64);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Offline banner */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 9999;
  background: #7a3a00;
  color: #ffe5b4;
  text-align: center;
  padding: 7px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-bottom: 1px solid #c06000;
}
.offline-banner.hidden { display: none; }

body {
  min-height: 100vh;
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(73, 152, 255, 0.18), transparent 30%),
    radial-gradient(circle at 85% 84%, rgba(72, 255, 176, 0.14), transparent 28%),
    linear-gradient(180deg, #08121f 0%, #0e1a2b 100%);
}

  .link-no-underline { text-decoration: none; }
  .header-actions { display: flex; gap: 6px; align-items: center; }
  .panel-body-compact { border-top: 1px solid var(--line); padding: 6px 8px; }
  .eval-fill-default { height: 50%; }
  .field-grid-topgap { margin-top: 8px; }

.site-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 18, 31, 0.88);
  position: sticky;
  top: 0;
  z-index: 50;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.site-logo { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.site-logo span { color: var(--accent); }
.header-badges { display: flex; gap: 6px; }
.badge {
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(25, 39, 56, 0.7);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
}
.header-spacer { flex: 1; }

.page-shell { width: min(1600px, 100%); margin: 0 auto; padding: 14px 14px 48px; }
.arena {
  display: grid;
  grid-template-columns: 270px minmax(760px, 1fr) 320px;
  gap: 12px;
  align-items: start;
}

.panel, .card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(18, 30, 45, 0.8);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.32);
}
.panel-title {
  border-bottom: 1px solid var(--line);
  padding: 9px 12px;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}
.panel-body { padding: 10px 12px; }

.move-panel { max-height: calc(100vh - 110px); position: sticky; top: 70px; display: flex; flex-direction: column; }
.move-list { padding: 8px; overflow: auto; font-family: Consolas, monospace; font-size: 0.86rem; }
.move-pair { display: flex; gap: 6px; padding: 3px 0; }
.move-num { color: var(--muted); width: 28px; text-align: right; }
.move-san { flex: 1; padding: 1px 5px; border-radius: 4px; }
.move-san.active { background: rgba(107, 193, 255, 0.25); color: #fff; }
.ml-empty { color: var(--muted); font-size: 0.82rem; }
.move-time { color: var(--muted); min-width: 52px; text-align: right; font-size: 0.75rem; }

.move-clock-shell { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.move-clock-title { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.move-clock-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.84rem; padding: 2px 0; }
.move-clock-row strong { font-family: Consolas, monospace; font-size: 0.95rem; }
.move-clock-row-accent strong { color: var(--accent-2); }

.move-input-shell { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.move-input-label { display: block; color: var(--muted); font-size: 0.74rem; margin-bottom: 6px; }
.opening-shell { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.opening-line { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--muted); }
.opening-line strong { color: var(--accent-2); }
.opening-name { margin-top: 4px; font-size: 0.8rem; color: var(--text); }

.board-col { display: flex; flex-direction: column; gap: 8px; }
.player-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(20, 32, 48, 0.9);
}
.player-strip.active-turn { box-shadow: inset 0 0 0 1px var(--accent-2), 0 0 18px rgba(128, 250, 172, 0.2); }
.player-avatar { width: 28px; text-align: center; font-size: 1.2rem; }
.player-details { flex: 1; min-width: 0; text-align: center; }
.player-name { font-weight: 700; text-align: center; }
.player-rating { color: var(--muted); font-size: 0.8rem; }
.player-clock { min-width: 74px; text-align: right; font-size: 1.1rem; font-family: Consolas, monospace; }
.captured-pieces { color: var(--muted); }

.board-area { display: flex; gap: 10px; align-items: stretch; }
.eval-bar-wrap { width: 24px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.eval-bar { width: 16px; flex: 1; border: 1px solid var(--line); border-radius: 6px; background: #15130f; position: relative; overflow: hidden; }
.eval-fill-white { position: absolute; left: 0; right: 0; bottom: 0; background: #ece2d6; transition: height 0.35s ease; }
.eval-score { font-size: 0.72rem; color: var(--muted); font-family: Consolas, monospace; }

.board-with-coords { flex: 1; min-width: 0; }
.board-row-wrap { display: flex; }
.board-stack { position: relative; width: var(--board-size); min-width: var(--board-size); max-width: var(--board-size); }
.rank-labels {
  width: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.file-labels {
  margin-left: 18px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.file-label { text-align: center; margin-top: 2px; }

.board {
  width: var(--board-size);
  min-width: var(--board-size);
  max-width: var(--board-size);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid #5c7ea5;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}
.arrow-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}
.square {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  font-size: 0;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.square:hover::after { content: ""; position: absolute; inset: 0; background: var(--sq-hover); }
.square.selected { background: var(--sq-selected) !important; }
.square.premove-from,
.square.premove-to { box-shadow: inset 0 0 0 3px rgba(141, 230, 178, 0.95); }
.square.last-move { box-shadow: inset 0 0 0 4px var(--sq-last); }
.square.in-check { box-shadow: inset 0 0 0 4px var(--sq-check); }
.square.legal::before {
  content: "";
  width: 24%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  position: absolute;
}
.square.legal-capture::before {
  content: "";
  position: absolute;
  inset: 11%;
  border-radius: 999px;
  border: 6px solid rgba(0, 0, 0, 0.3);
}
.piece-white, .piece-black {
  font-size: clamp(22px, calc(var(--board-size) / 15), 46px);
  line-height: 1;
  position: relative;
  z-index: 2;
  -webkit-user-select: none;
  user-select: none;
}
.piece-white { color: #fffef1; text-shadow: 0 1px 0 #403113, 0 2px 3px rgba(0, 0, 0, 0.5); }
.piece-black { color: #1f1305; text-shadow: 0 1px 1px rgba(255, 243, 216, 0.22); }

.control-bar { display: flex; align-items: center; gap: 10px; }
.turn-label { font-weight: 700; color: #fff; }
.result-pill { padding: 3px 10px; border-radius: 999px; background: rgba(141, 230, 178, 0.18); border: 1px solid var(--accent-2); color: #d8ffe8; }
.result-pill.hidden { display: none; }
.control-btns { margin-left: auto; display: flex; gap: 6px; }
.ctrl-btn, .btn-primary, .btn-secondary, .action-row button, .card button, .icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(31, 49, 71, 0.9);
  cursor: pointer;
  padding: 7px 11px;
}
.ctrl-btn.primary, .btn-primary { background: rgba(90, 178, 255, 0.2); border-color: #6bc1ff; color: #e8f6ff; }
.ctrl-btn.danger { border-color: #d46e6e; color: #ffd9d9; background: rgba(125, 38, 38, 0.4); }

.lobby-panel { position: sticky; top: 70px; max-height: calc(100vh - 110px); overflow: auto; }
.lobby-section { padding: 12px; border-bottom: 1px solid var(--line); }
.lobby-section:last-child { border-bottom: none; }
.lobby-section-title { color: var(--muted); font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field-row label { color: var(--muted); font-size: 0.8rem; }
.field-row input, .field-row select, .field-grid input, .field-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 31, 47, 0.85);
  color: var(--text);
  padding: 8px;
}
.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; }
.profile-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--muted); background: rgba(20, 31, 46, 0.85); }

.sections-below { display: flex; flex-direction: column; gap: 18px; margin-top: 16px; }
.section-title { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.74rem; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; }
.card { padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 0.96rem; }
.field-grid { display: grid; grid-template-columns: auto 1fr; gap: 7px 9px; align-items: center; }
.action-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.status-chip { display: inline-block; margin-top: 8px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 0.76rem; }
.list-panel { max-height: 220px; overflow: auto; }
.job-row, .game-row { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid rgba(68, 98, 128, 0.45); padding: 6px 0; }
.state-log { white-space: pre-wrap; font-size: 0.76rem; color: var(--muted); max-height: 140px; overflow: auto; }

@media (max-width: 1360px) {
  .arena { grid-template-columns: 1fr; }
  .move-panel, .lobby-panel { position: static; max-height: none; }
  :root { --board-size: min(92vw, 640px); }
  .board, .board-stack { min-width: 0; max-width: none; }
}

@media (max-width: 720px) {
  .control-bar { flex-wrap: wrap; }
  .control-btns { width: 100%; margin-left: 0; }
  :root { --board-size: min(94vw, 500px); }
}
