/* ============================================================================
   Claude Chess — styles.css
   Theming via [data-theme] (light/dark) and [data-board] (square palette).
   ========================================================================== */

:root {
  --bg: #1b1d22;
  --bg-elev: #24272e;
  --bg-elev-2: #2c303a;
  --text: #e7e9ee;
  --text-dim: #aab0bd;
  --border: #3a3f4b;
  --accent: #6ea8fe;
  --accent-strong: #4f86f7;
  --danger: #e5616b;
  --good: #57c08a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 10px;

  /* default board (classic green) */
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --hl-select: rgba(255, 235, 59, 0.55);
  --hl-last: rgba(255, 235, 59, 0.28);
  --hl-last-ring: rgba(255, 235, 59, 0.5);
  --hl-legal: rgba(20, 20, 20, 0.32);
  --hl-check: #e5616b;
}

html[data-theme="light"] {
  --bg: #f3f4f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef0f4;
  --text: #1c2030;
  --text-dim: #5b6275;
  --border: #d3d7e0;
  --accent: #2f6df0;
  --accent-strong: #2257d6;
  --shadow: 0 6px 20px rgba(30, 40, 70, 0.12);
}

/* Board palettes */
html[data-board="classic"] { --sq-light: #ebecd0; --sq-dark: #739552; }
html[data-board="blue"]    { --sq-light: #dee3e6; --sq-dark: #4a7ba6; }
html[data-board="walnut"]  { --sq-light: #ecd9b8; --sq-dark: #9c6b3f; }
html[data-board="gray"]    { --sq-light: #d8dbe0; --sq-dark: #6d7480; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 0.5rem; font-weight: 650; }

/* Accessibility helpers */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent-strong); color: #fff; padding: 0.5rem 0.75rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* Header / footer */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 1.25rem; margin: 0; }
.header-controls { display: flex; align-items: center; gap: 0.5rem; }
.icon-btn {
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
.link-btn {
  color: var(--accent); text-decoration: none; font-size: 0.9rem; padding: 0.4rem 0.6rem;
  border: 1px solid var(--border); border-radius: 8px;
}
.link-btn:hover { border-color: var(--accent); }
.app-footer { padding: 1rem; text-align: center; color: var(--text-dim); }

/* Screens */
.screen { padding: 1rem; }
[hidden] { display: none !important; }

/* ----- Setup screen ----- */
.setup-card {
  max-width: 680px; margin: 1.5rem auto; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}
.setup-card fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 1rem; padding: 0.75rem 1rem 1rem; }
.setup-card legend { padding: 0 0.4rem; font-weight: 650; color: var(--text-dim); }
.option-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.time-grid { grid-template-columns: repeat(3, 1fr); }
.color-grid { grid-template-columns: repeat(3, 1fr); }
.option { position: relative; display: block; cursor: pointer; }
.option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.option-body {
  display: flex; flex-direction: column; gap: 0.1rem;
  border: 2px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem; background: var(--bg-elev-2);
}
.option-body small { color: var(--text-dim); font-size: 0.78rem; }
.option input:checked + .option-body { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg-elev-2)); }
.option input:focus-visible + .option-body { outline: 3px solid var(--accent); outline-offset: 2px; }
.hint { color: var(--text-dim); font-size: 0.8rem; margin: 0.5rem 0 0; }
.custom-time { display: flex; gap: 1rem; margin-top: 0.75rem; flex-wrap: wrap; }
.custom-time label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 0.25rem; }
.custom-time input { width: 120px; }

input[type="number"], input[type="text"], .select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.4rem 0.5rem; font: inherit;
}
input:focus-visible, .select:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 1px;
}

.resume-panel {
  border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-elev));
  border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 1rem;
}
.resume-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Buttons */
.btn {
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.5rem 0.8rem; font: inherit; cursor: pointer; transition: border-color .12s, background .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent-strong); color: #fff; border-color: var(--accent-strong); }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.big { width: 100%; padding: 0.7rem; font-size: 1.05rem; font-weight: 650; }
.btn.small { padding: 0.35rem 0.55rem; font-size: 0.85rem; }

/* ----- Game layout ----- */
.game-layout {
  display: flex; gap: 1.25rem; align-items: flex-start; justify-content: center;
  max-width: 1100px; margin: 0 auto; flex-wrap: wrap;
}
.board-column { flex: 0 1 auto; }
.side-panel {
  flex: 1 1 300px; min-width: 280px; max-width: 360px;
  display: flex; flex-direction: column; gap: 0.85rem;
}

.status-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.8rem; margin-bottom: 0.5rem; min-height: 2.6rem;
}
.status-turn { font-weight: 650; }
.status-detail { color: var(--accent); font-weight: 600; }
.status-detail.thinking::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ----- Board ----- */
.board-wrap {
  position: relative;
  width: min(92vw, 70vh, 640px);
  height: min(92vw, 70vh, 640px);
}
.board {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  border: 3px solid var(--bg-elev-2); border-radius: 6px; overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none; /* allow custom pointer dragging on touch */
  user-select: none;
}
.board-row { display: flex; flex: 1 1 0; }
.cell {
  position: relative; flex: 1 1 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 0; padding: 0; margin: 0;
  font-size: clamp(1.5rem, 7.2vw, 3rem);
}
.board-wrap { font-size: 0; }
.cell.light { background: var(--sq-light); }
.cell.dark { background: var(--sq-dark); }

/* coordinate labels */
.coord { position: absolute; font-size: 0.62rem; font-weight: 700; line-height: 1; opacity: 0.8; pointer-events: none; }
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }
.cell.light .coord { color: var(--sq-dark); }
.cell.dark .coord { color: var(--sq-light); }

/* pieces — rendered as bundled SVG images that scale with the square size */
.piece {
  pointer-events: none;
  width: 92%; height: 92%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  /* subtle lift so white pieces read on light squares and black on dark ones,
     across every board palette and both light/dark UI themes */
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.45));
}

/* move/selection indicators (shape-based, not color-only) */
.cell.selected::before {
  content: ""; position: absolute; inset: 0; background: var(--hl-select); z-index: 1;
}
.cell.last-move::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--hl-last);
  box-shadow: inset 0 0 0 2px var(--hl-last-ring);
}
.cell.legal-move .dot {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: var(--hl-legal); z-index: 2;
}
.cell.legal-capture .dot {
  position: absolute; inset: 6%; border-radius: 50%;
  border: 4px solid var(--hl-legal); background: transparent; z-index: 2;
  box-sizing: border-box;
}
.cell.in-check { box-shadow: inset 0 0 0 4px var(--hl-check); }
.cell.focused { outline: 4px solid var(--accent); outline-offset: -4px; z-index: 3; }
.cell.drag-over { box-shadow: inset 0 0 0 4px var(--accent); }
.cell .piece { position: relative; z-index: 2; }

/* drag ghost */
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  transform: translate(-50%, -50%); will-change: left, top;
  display: flex; align-items: center; justify-content: center;
}

/* sliding piece used for move animations (click-to-move, keyboard, bot) */
.slide-ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  background-position: center; background-repeat: no-repeat; background-size: contain;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.45));
  will-change: transform;
}

/* Promotion overlay */
.promotion {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; gap: 0.5rem; flex-wrap: wrap;
}
.promotion button {
  width: 22%; aspect-ratio: 1; min-width: 56px;
  background: var(--bg-elev); border: 2px solid var(--border); border-radius: 10px;
  cursor: pointer; font-size: clamp(1.8rem, 6vw, 2.6rem); display: flex; align-items: center; justify-content: center;
}
.promotion button:hover, .promotion button:focus-visible { border-color: var(--accent); }

/* Toast */
.toast {
  min-height: 1.4rem; margin-top: 0.5rem; text-align: center;
  color: var(--danger); font-weight: 600; transition: opacity .2s; opacity: 0;
}
.toast.show { opacity: 1; }
.shake { animation: shake 0.32s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}

/* ----- Side panel blocks ----- */
.clocks { display: flex; flex-direction: column; gap: 0.4rem; }
.clock {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.8rem;
}
.clock-label { color: var(--text-dim); font-weight: 600; }
.clock-time { font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 700; letter-spacing: 0.5px; }
.clock.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-elev)); }
.clock.low .clock-time { color: var(--danger); }

.captured-row { display: flex; flex-direction: column; gap: 0.25rem; }
.captured {
  min-height: 1.8rem; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.2rem 0.5rem; line-height: 1.4; display: flex; align-items: center; flex-wrap: wrap; gap: 1px;
}
.captured .adv { margin-left: auto; font-size: 0.85rem; color: var(--good); font-weight: 700; }
.cap-piece {
  display: inline-block; width: 1.4rem; height: 1.4rem;
  background-position: center; background-repeat: no-repeat; background-size: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }

.panel-block {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem;
}
.panel-block h3 { font-size: 0.95rem; color: var(--text-dim); }
.move-history {
  list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto;
  display: grid; grid-template-columns: 2.2rem 1fr 1fr; gap: 0.1rem 0.4rem; font-variant-numeric: tabular-nums;
}
.move-history .movenum { color: var(--text-dim); }
.move-history .san { padding: 0.05rem 0.3rem; border-radius: 4px; }
.move-history .san.current { background: color-mix(in srgb, var(--accent) 25%, transparent); }

.field-label { display: block; font-size: 0.78rem; color: var(--text-dim); margin-bottom: 0.2rem; }
.fen-input { width: 100%; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.78rem; }
.btn-row { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }
.select { width: 100%; }

/* ----- Responsive ----- */
@media (max-width: 900px) {
  .game-layout { flex-direction: column; align-items: center; }
  .side-panel { max-width: min(92vw, 640px); width: min(92vw, 640px); }
}
@media (max-width: 520px) {
  .option-grid { grid-template-columns: 1fr 1fr; }
  .app-header h1 { font-size: 1.05rem; }
  .controls { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .shake, .status-detail.thinking::after { animation: none; }
}
