/* ---------------------------------------------------------------------
   Knight Line — design tokens
   Ink navy stage, warm walnut/cream board, burnished-gold accent.
   Display: Fraunces · Body: Inter · Clock digits: JetBrains Mono
--------------------------------------------------------------------- */
:root {
  --ink:        #12141c;
  --panel:      #1b1e29;
  --panel-2:    #232838;
  --line:       #2c3142;
  --ivory:      #ede6d6;
  --muted:      #9aa0b4;
  --gold:       #c9a227;
  --gold-soft:  #e8c96a;
  --rose:       #b8534a;
  --teal:       #4a8b7c;
  --square-light: #ede0c8;
  --square-dark:  #3a5a40;
  --square-select: rgba(201, 162, 39, 0.55);
  --square-move:   rgba(201, 162, 39, 0.32);
  --square-lastmove: rgba(74, 139, 124, 0.4);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 15% -10%, #1a2030 0%, var(--ink) 55%);
  color: var(--ivory);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100vh; }
a { color: var(--gold-soft); }

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
}
button:active { transform: translateY(1px) scale(0.99); }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 2px;
}

input {
  font-family: var(--font-body);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ivory);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
input::placeholder { color: var(--muted); }

.btn-primary {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #201705;
  font-weight: 700;
  padding: 12px 20px;
  font-size: 15px;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; display: block; }

.btn-secondary {
  background: var(--panel-2);
  color: var(--ivory);
  border: 1px solid var(--line);
  padding: 10px 16px;
  font-size: 14px;
}
.btn-secondary:hover { background: var(--line); }

.btn-danger {
  background: rgba(184, 83, 74, 0.16);
  color: #f0a89f;
  border: 1px solid rgba(184, 83, 74, 0.4);
  padding: 10px 16px;
  font-size: 14px;
}
.btn-danger:hover { background: rgba(184, 83, 74, 0.28); }

/* ---------------------------- Home screen ---------------------------- */
.home {
  max-width: 880px;
  margin: 0 auto;
  padding: 48px 20px 80px;
}
.home-hero { text-align: center; margin-bottom: 40px; }
.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.wordmark .accent { color: var(--gold-soft); font-style: italic; }
.tagline { color: var(--muted); font-size: 16px; margin: 0; }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 720px) {
  .home-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.card h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0 0 4px;
}
.card .card-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.preset {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ivory);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  font-size: 13px;
  font-family: var(--font-mono);
  text-align: center;
}
.preset.selected {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.14);
  color: var(--gold-soft);
}
.custom-time-row { display: flex; gap: 10px; }
.custom-time-row .field { flex: 1; }

.error-banner {
  background: rgba(184, 83, 74, 0.16);
  border: 1px solid rgba(184, 83, 74, 0.4);
  color: #f0a89f;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
}

/* ---------------------------- Game screen ---------------------------- */
.game-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .game-shell { grid-template-columns: 1fr; padding: 12px 10px 40px; }
}

.board-column { display: flex; flex-direction: column; gap: 10px; }

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.player-row.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.player-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.player-name .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.player-name .dot.you { background: var(--teal); }
.captures { display: flex; gap: 1px; min-height: 20px; align-items: center; }
.captured-icon { width: 18px; height: 18px; flex-shrink: 0; }

.clock {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 22px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ivory);
  min-width: 92px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.clock.running { background: var(--gold); color: #201705; }
.clock.low { color: #ffb4a8; }
.clock.running.low { background: var(--rose); color: #fff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

.board-wrap { width: 100%; aspect-ratio: 1 / 1; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px -20px rgba(0,0,0,0.6);
  user-select: none;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.square.light { background: var(--square-light); }
.square.dark { background: var(--square-dark); }
.square.selected::before {
  content: ""; position: absolute; inset: 0; background: var(--square-select);
}
.square.lastmove::before {
  content: ""; position: absolute; inset: 0; background: var(--square-lastmove);
}
.square.check::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(184,83,74,0.85) 0%, rgba(184,83,74,0.15) 70%);
}
.square .move-dot {
  position: absolute; width: 26%; height: 26%; border-radius: 50%;
  background: var(--square-move); pointer-events: none;
}
.square .capture-ring {
  position: absolute; inset: 6%; border-radius: 50%;
  border: 4px solid var(--square-select); pointer-events: none;
}
.piece-icon {
  position: relative;
  z-index: 1;
  width: 82%;
  height: 82%;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
  transition: transform 0.08s ease;
}
.square:hover .piece-icon { transform: scale(1.06); }

.coord-file, .coord-rank {
  position: absolute; font-size: 9px; font-family: var(--font-mono); opacity: 0.55;
}
.coord-file { bottom: 2px; right: 3px; }
.coord-rank { top: 2px; left: 3px; }

.board-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------------------- Side panel ---------------------------- */
.side-panel {
  display: flex; flex-direction: column; gap: 14px;
}
.panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-block h3 {
  margin: 0 0 10px; font-family: var(--font-display); font-size: 15px; color: var(--muted); font-weight: 600;
}
.share-code {
  font-family: var(--font-mono);
  font-size: 22px;
  letter-spacing: 0.12em;
  background: var(--panel-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  margin-bottom: 8px;
}
.moves-list {
  font-family: var(--font-mono);
  font-size: 13px;
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  row-gap: 4px;
  column-gap: 8px;
}
.moves-list .idx { color: var(--muted); }
.status-banner {
  font-family: var(--font-display);
  font-size: 17px;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(201,162,39,0.18), rgba(201,162,39,0.05));
  border: 1px solid rgba(201,162,39,0.4);
}
.panel-hidden { display: none; }
.draw-offer-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(74,139,124,0.15); border: 1px solid rgba(74,139,124,0.4);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px;
}

.promo-overlay {
  position: fixed; inset: 0; background: rgba(10,11,16,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.promo-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; gap: 12px;
}
.promo-choice {
  width: 56px; height: 56px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.promo-choice:hover { border-color: var(--gold); }
.promo-icon { width: 70%; height: 70%; }

.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ivory);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}
.toast-error {
  background: rgba(184, 83, 74, 0.16);
  border-color: rgba(184, 83, 74, 0.4);
  color: #f0a89f;
}
