/* style.css — Endgame Drill Tool */

:root {
  --bg: #161512;
  --bg-raise: #201e1a;
  --bg-inset: #26241f;
  --text: #e9e5dc;
  --text-dim: #a49d8d;
  --accent: #d8a24a;
  --ok: #4caf6d;
  --bad: #e05252;
  --soft: #d8a24a;
  --light-sq: #b9a98c;
  --dark-sq: #7d6b52;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.js-error {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #b03a3a;
  color: #fff;
  z-index: 999;
  padding: 4px 10px;
  font-size: 12px;
  font-family: monospace;
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-raise);
  border-bottom: 1px solid #2e2b25;
}
.topbar h1 { font-size: 1.15rem; margin: 0; letter-spacing: 0.02em; }
.tagline { color: var(--text-dim); font-size: 0.8rem; }
.topbar-next { margin-left: auto; padding: 0.25rem 0.7rem; font-size: 0.78rem; }
.menu-toggle {
  display: none;
  background: none;
  border: 1px solid #3a372f;
  color: var(--text);
  font-size: 1.1rem;
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------- sidebar ---------- */

.sidebar { display: flex; flex-direction: column; gap: 0.9rem; }
.cat {
  background: var(--bg-raise);
  border: 1px solid #2e2b25;
  border-radius: var(--radius);
  padding: 0.7rem;
}
.cat header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.cat h3 { margin: 0; font-size: 0.85rem; }
.cat .count { color: var(--text-dim); font-size: 0.8rem; }
.bar {
  height: 5px;
  background: var(--bg-inset);
  border-radius: 3px;
  margin: 0.4rem 0 0.6rem;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--ok); transition: width 0.3s; }

.pos-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.83rem;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
}
.pos-item:hover { background: var(--bg-inset); }
.pos-item.active { background: #33302a; outline: 1px solid var(--accent); }
.pos-item .check { width: 1em; color: var(--ok); }
.pos-item .name { flex: 1; }
.pos-item .stars { color: var(--accent); font-size: 0.7rem; }

/* ---------- board area ---------- */

.board-area { min-width: 0; }

.drill-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.drill-head h2 { margin: 0; font-size: 1.05rem; }
.pos-meta { margin: 0.15rem 0 0; color: var(--text-dim); font-size: 0.82rem; }

.eval {
  font-size: 0.9rem;
  background: var(--bg-raise);
  border: 1px solid #2e2b25;
  border-radius: var(--radius);
  padding: 0.45rem 0.8rem;
  white-space: nowrap;
}

.banner {
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  background: #3b3423;
  border: 1px solid var(--soft);
  color: var(--text);
}
.banner.warn { border-color: var(--soft); }

/* ---------- board (chessboard.js) ---------- */

.board-wrap {
  position: relative;
  max-width: min(640px, 100%);
  margin: 0 auto;
}

#board { width: 100%; }
#board.disabled .piece-417db { cursor: default; }
#board.disabled { opacity: 0.85; }

/* highlights layered onto chessboard.js squares (targeted via data-square;
   its own class names are mangled, so we key off the attribute) */
#board [data-square].hl-sel   { box-shadow: inset 0 0 0 3px var(--accent); }
#board [data-square].hl-last  { box-shadow: inset 0 0 0 3px rgba(216, 162, 74, 0.55); }
#board [data-square].hl-ok    { box-shadow: inset 0 0 0 3px var(--ok); }
#board [data-square].hl-bad   { box-shadow: inset 0 0 0 3px var(--bad); }
#board [data-square].hl-hint  { box-shadow: inset 0 0 0 3px #6db3e0; }

/* spinner */
.spinner {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  z-index: 5;
}
.spinner.visible { display: block; }
.spinner .ring {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls ---------- */

.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
  justify-content: center;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  background: var(--bg-raise);
  color: var(--text);
  border: 1px solid #3a372f;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #211a0c; }
.btn.warn { border-color: var(--bad); color: var(--bad); }
.btn.muted { color: var(--text-dim); }
.btn.block { width: 100%; }
.btn small { opacity: 0.75; }

/* ---------- right panel ---------- */

.panel {
  background: var(--bg-raise);
  border: 1px solid #2e2b25;
  border-radius: var(--radius);
  padding: 0.9rem;
  align-self: start;
}
.panel h3 { margin: 0 0 0.5rem; font-size: 0.9rem; }

.move-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.move-list li { padding: 0.15rem 0.2rem; border-radius: 4px; }
.move-list li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.move-list .num { color: var(--text-dim); margin-right: 0.35rem; }
.move-list .placeholder { color: var(--text-dim); font-style: italic; }

.feedback {
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.88rem;
  margin-bottom: 0.6rem;
}
.feedback.ok { background: #1e3a29; border: 1px solid var(--ok); }
.feedback.bad { background: #3f2020; border: 1px solid var(--bad); }
.feedback.warn, .feedback.error { background: #3b3423; border: 1px solid var(--soft); }
.feedback.soft { background: #3b3423; border: 1px solid var(--soft); }
.feedback.info { background: var(--bg-inset); border: 1px solid #3a372f; }

.legend { color: var(--text-dim); font-size: 0.75rem; margin: 0; }
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: middle;
}
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.soft { background: var(--soft); }

/* ---------- modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--bg-raise);
  border: 1px solid #3a372f;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  min-width: 280px;
  max-width: 92vw;
  text-align: center;
}
.promo-row { display: flex; gap: 0.5rem; justify-content: center; margin: 0.75rem 0; }
.promo-row button {
  font-size: 2rem;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid #3a372f;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}
.modal-box[data-color="b"] .promo-row button { color: #1d1a15; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
.sum-title.ok { color: var(--ok); }
.sum-title.bad { color: var(--bad); }
#sumBody p { margin: 0.35rem 0; font-size: 0.9rem; color: var(--text-dim); }
#sumBody p:first-child { color: var(--text); }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr); }
  .panel { grid-column: 1 / -1; }
  .move-list { max-height: 20vh; }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding: 0.75rem; gap: 0.75rem; }
  .menu-toggle { display: inline-block; }
  .sidebar {
    display: none;
    position: fixed;
    inset: 3.2rem 0 0 0;
    z-index: 50;
    background: var(--bg);
    padding: 1rem;
    overflow-y: auto;
    border-top: 1px solid #2e2b25;
  }
  body.menu-open .sidebar { display: flex; }
  .board-wrap { max-width: 100%; }
  .eval { font-size: 0.8rem; }
}
