/* ── Custom properties ─────────────────────────────────────────────────────── */
:root {
  --bg:              #f7f4f0;
  --bg-card:         #ffffff;
  --sq-light:        #f0d9b5;
  --sq-dark:         #b58863;
  --sq-selected:     #829fbe;
  --sq-check-tint:   rgba(192,57,43,0.75);
  --sq-last-tint:    rgba(255,220,0,0.4);
  --sq-legal-dot:    rgba(0,0,0,0.18);
  --piece-white:     #ffffff;
  --piece-black:     #1a1a1a;
  --shadow-w: 1px 1px 0 #333,-1px 1px 0 #333,1px -1px 0 #333,-1px -1px 0 #333;
  --shadow-b: 0 0 4px rgba(255,255,255,0.75);
  --accent:          #8b5e3c;
  --accent-dark:     #5a3e28;
  --danger:          #c0392b;
  --text:            #2c2c2c;
  --text-muted:      #888888;
  --border:          #e0dbd4;
  --sq-size:         60px;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; }
.screen.active { display: block; }

/* ── Accessibility ────────────────────────────────────────────────────────── */
.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;
}

/* ── Typography helpers ────────────────────────────────────────────────────── */
.label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 8px; display: block;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent-dark); color: #fff;
  border: none; border-radius: 6px;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; width: 100%; min-height: 44px;
}
.btn-primary:hover { background: var(--accent); }

.btn-secondary {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 14px; font-size: 13px;
  cursor: pointer; width: 100%; min-height: 44px;
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--bg-card); color: var(--danger);
  border: 1px solid #f5c6c0; border-radius: 6px;
  padding: 8px 14px; font-size: 13px;
  cursor: pointer; width: 100%; min-height: 44px;
}

.hidden { display: none !important; }

/* ── Setup card ────────────────────────────────────────────────────────────── */
.setup-card {
  background: var(--bg-card); border-radius: 10px;
  padding: 28px; max-width: 420px; margin: 0 auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  display: flex; flex-direction: column; gap: 16px;
}
.setup-title { font-size: 20px; font-weight: 700; text-align: center; }

/* ── Side picker ────────────────────────────────────────────────────────────── */
.side-picker { display: flex; gap: 8px; }
.side-btn {
  flex: 1; padding: 10px 6px;
  border: 2px solid var(--border); border-radius: 6px;
  background: var(--bg-card); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text);
  min-height: 80px; transition: border-color 0.15s;
}
.side-btn.active { border-color: var(--accent); }

.side-icon {
  width: 44px; height: 44px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.side-icon--white {
  background: var(--sq-dark);
  color: var(--piece-white); text-shadow: var(--shadow-w);
}
.side-icon--black {
  background: var(--sq-light);
  color: var(--piece-black); text-shadow: var(--shadow-b);
}
.side-icon--random {
  overflow: hidden;
  background: linear-gradient(to right, var(--sq-dark) 50%, var(--sq-light) 50%);
}
.side-icon--random span:first-child {
  flex: 1; font-size: 20px; display: flex; align-items: center; justify-content: center;
  color: var(--piece-white); text-shadow: var(--shadow-w);
}
.side-icon--random span:last-child {
  flex: 1; font-size: 20px; display: flex; align-items: center; justify-content: center;
  color: var(--piece-black); text-shadow: var(--shadow-b);
}

/* ── Time picker ────────────────────────────────────────────────────────────── */
.time-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.time-btn {
  padding: 7px 13px; border-radius: 20px;
  border: 1px solid var(--border);
  background: #e8e0d8; color: #3a3028;
  font-size: 13px; font-weight: 500; cursor: pointer;
  min-height: 44px;
}
.time-btn.active { background: var(--accent-dark); color: #fff; border-color: var(--accent-dark); }

/* ── Skill slider ────────────────────────────────────────────────────────────── */
#skill-slider { width: 100%; accent-color: var(--accent); margin-bottom: 6px; }
.skill-band { display: flex; height: 5px; border-radius: 3px; overflow: hidden; margin-bottom: 5px; }
.skill-band__segment { flex: 1; }
.skill-band__segment--beginner     { background: #4a9a6a; }
.skill-band__segment--intermediate { background: #e6a817; }
.skill-band__segment--advanced     { background: #e07820; }
.skill-band__segment--master       { background: #c0392b; }
.skill-labels { display: flex; justify-content: space-between; font-size: 11px; }
.skill-labels span:nth-child(1) { color: #4a9a6a; font-weight: 600; }
.skill-labels span:nth-child(2) { color: #e6a817; font-weight: 600; }
.skill-labels span:nth-child(3) { color: #e07820; font-weight: 600; }
.skill-labels span:nth-child(4) { color: #c0392b; font-weight: 600; }

/* ── Game layout ────────────────────────────────────────────────────────────── */
.game-layout {
  display: flex; gap: 20px; align-items: flex-start;
  max-width: 900px; margin: 0 auto;
}
.board-col { flex: 0 0 auto; }
.side-panel {
  flex: 1; min-width: 180px; max-width: 260px;
  display: flex; flex-direction: column; gap: 12px;
}

/* ── Player bars ────────────────────────────────────────────────────────────── */
.player-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; margin: 4px 0;
}
.player-name { font-size: 13px; font-weight: 600; }
.clock {
  font-family: monospace; font-size: 15px; font-weight: 700;
  padding: 4px 10px; border-radius: 4px;
  background: #2c2c2c; color: #fff;
  min-width: 60px; text-align: center;
}
.clock.active  { background: var(--accent); }
.clock.flagged { background: var(--danger); }

/* ── Captures ────────────────────────────────────────────────────────────────── */
.captures { font-size: 16px; min-height: 22px; letter-spacing: 2px; }

/* ── Board ────────────────────────────────────────────────────────────────────── */
.board-wrap { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq-size));
  grid-template-rows:    repeat(8, var(--sq-size));
  border: 2px solid #8b7355;
  user-select: none;
}
.sq {
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sq-size) * 0.70);
  cursor: pointer; position: relative;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.selected  { background: var(--sq-selected) !important; }
.sq.in-check  { background: var(--sq-check-tint) !important; }
.sq.last-from,
.sq.last-to   { outline: 3px solid rgba(255,220,0,0.5); outline-offset: -3px; }

.sq.legal-move::after {
  content: ''; position: absolute;
  width: 32%; height: 32%;
  border-radius: 50%; background: var(--sq-legal-dot);
  pointer-events: none;
}
.sq.legal-capture::after {
  content: ''; position: absolute;
  width: 90%; height: 90%;
  background: transparent;
  border: 4px solid var(--sq-legal-dot);
  border-radius: 50%;
}

/* Pieces — white: color #fff + dark outline shadow; black: dark + light glow */
.piece-w { color: var(--piece-white); text-shadow: var(--shadow-w); }
.piece-b { color: var(--piece-black); text-shadow: var(--shadow-b); }

/* ── Promotion overlay ────────────────────────────────────────────────────────── */
.promotion-overlay {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border: 2px solid var(--accent); border-radius: 8px;
  display: flex; gap: 4px; padding: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3); z-index: 10;
}
.promo-btn {
  width: calc(var(--sq-size) * 0.9);
  height: calc(var(--sq-size) * 0.9);
  font-size: calc(var(--sq-size) * 0.6);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 4px; border: none; background: var(--bg);
}
.promo-btn:hover { background: var(--sq-light); }

/* ── Engine overlay ────────────────────────────────────────────────────────────── */
.engine-overlay {
  position: absolute; inset: 0;
  background: rgba(247,244,240,0.35);
  z-index: 5; pointer-events: all;
}
@keyframes pulse { 0%,100%{opacity:0.35} 50%{opacity:0.6} }
.engine-overlay:not(.hidden) { animation: pulse 1.2s ease-in-out infinite; }

/* ── Move list ────────────────────────────────────────────────────────────────── */
.move-list-wrap { background: var(--bg-card); border-radius: 6px; padding: 12px; flex: 1; }
.move-list {
  font-size: 13px; font-family: monospace; line-height: 2;
  max-height: 220px; overflow-y: auto;
}
.move-num   { color: var(--text-muted); }
.half-move  { padding: 1px 4px; border-radius: 3px; cursor: pointer; min-height: 28px; display: inline-flex; align-items: center; }
.half-move:hover   { background: var(--bg); }
.half-move.current { background: var(--accent-dark); color: #fff; }

/* ── Confidence bar ────────────────────────────────────────────────────────────── */
.confidence-wrap { background: var(--bg-card); border-radius: 6px; padding: 12px; }
.confidence-bar-outer {
  width: 100%; height: 6px; background: #e8e0d8;
  border-radius: 3px; overflow: hidden; margin: 6px 0 4px;
}
.confidence-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; width: 0; transition: width 0.4s; }
.confidence-meta { font-size: 11px; color: var(--text-muted); }

/* ── Action buttons ────────────────────────────────────────────────────────────── */
.action-btns { display: flex; gap: 8px; }
.action-btns .btn-secondary,
.action-btns .btn-primary,
.action-btns .btn-danger  { flex: 1; }

/* ── Nav bar ────────────────────────────────────────────────────────────────────── */
.nav-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; margin-top: 10px;
}
.nav-btn {
  padding: 8px 12px; font-size: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; color: var(--text);
  min-width: 44px; min-height: 44px;
}
.nav-btn:hover { background: var(--bg); }
.nav-counter   { font-size: 12px; color: var(--text-muted); font-family: monospace; padding: 0 8px; }
.nav-hint      { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* ── Result banner ────────────────────────────────────────────────────────────── */
.result-banner {
  background: var(--accent-dark); color: #fff;
  border-radius: 6px; padding: 14px; text-align: center;
}
.result-title { font-size: 20px; font-weight: 700; }
.result-sub   { font-size: 12px; color: #d4b896; margin-top: 3px; }

/* ── Live badge ────────────────────────────────────────────────────────────────── */
.live-badge {
  font-size: 12px; font-weight: 600; padding: 2px 8px;
  border-radius: 12px; background: #27ae60; color: #fff;
}
.live-badge.finished { background: var(--text-muted); }
@keyframes livepulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.live-badge:not(.finished) { animation: livepulse 1.5s ease-in-out infinite; }

/* ── Submit status ────────────────────────────────────────────────────────────── */
.submit-status { font-size: 11px; color: var(--text-muted); text-align: center; }

/* ── QR modal ────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-box {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card); border-radius: 10px;
  padding: 24px; min-width: 280px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-box h2 { font-size: 18px; }
#qr-code canvas { border: 1px solid var(--border); border-radius: 4px; }
.share-url-input {
  width: 100%; padding: 8px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 12px; font-family: monospace;
  background: var(--bg);
}

/* ── Responsive ────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sq-size: calc((100vw - 40px) / 8); }

  body { align-items: flex-start; padding: 8px; }
  .game-layout { flex-direction: column; align-items: center; }
  .side-panel { max-width: 100%; width: 100%; }
  .move-list { max-height: 120px; }
  .setup-card { padding: 16px; }
  .side-btn span { display: none; }
  .action-btns { flex-wrap: wrap; }
}

@media (min-width: 641px) and (max-width: 900px) {
  :root { --sq-size: 52px; }
}
