/* ============================================================
   Gambit — design tokens
   Direction: WARM, CALM, soft "chess study" — cream paper,
   gentle wood board, muted terracotta accent, soft shadows.
   Best move is shown ON the board (arrow + gentle glow).
   ============================================================ */
:root {
  --bg:        #f3ebdd;          /* warm cream paper */
  --bg-glow:   #faf3e7;
  --surface:   #fbf6ed;          /* card */
  --surface-2: #f1e8d7;
  --line:      #e4d8c2;
  --line-soft: #ede3d1;
  --text:      #3d362b;          /* warm dark brown */
  --muted:     #8a8074;
  --muted-2:   #a99d89;
  --accent:    #c07a4e;          /* muted terracotta */
  --accent-dim:#a5673e;
  --accent-soft:#ecdac6;

  /* board — soft warm wood */
  --sq-light:  #ecdcc0;
  --sq-dark:   #b78a61;
  --sq-sel:    #c07a4e;
  --sq-last:   rgba(214,162,86,.42);
  --sq-check:  rgba(198,92,74,.50);

  /* on-board best-move suggestion — calm friendly green */
  --suggest:    #6f9e69;
  --suggest-2:  #5e9159;
  --suggest-glow: rgba(111,158,105,.50);

  /* move quality (semantic, muted for calm) */
  --q-best:    #6fa06a;
  --q-good:    #6a92b0;
  --q-book:    #9b9082;
  --q-inacc:   #d3a24c;
  --q-mistake: #cf8a4e;
  --q-blunder: #c66a5a;

  /* eval bar */
  --eval-white: #f6efe1;
  --eval-black: #4b4034;

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --shadow-board: 0 22px 50px -22px rgba(120,86,46,.45), 0 1px 0 rgba(255,255,255,.5) inset;
  --shadow-soft: 0 10px 30px -16px rgba(120,86,46,.30);
  --ease: cubic-bezier(.22,.61,.36,1);
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(1100px 680px at 20% -8%, var(--bg-glow), transparent 60%),
    radial-gradient(900px 640px at 112% 116%, #f7ead6, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

.app { max-width: 1180px; margin: 0 auto; padding: clamp(14px, 2.2vw, 30px); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: clamp(16px, 2.4vw, 28px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 34px; line-height: 1; color: var(--accent);
  filter: drop-shadow(0 2px 5px rgba(192,122,78,.35));
}
.wordmark {
  font-family: var(--font-display);
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 600; letter-spacing: .01em; line-height: 1; color: #2f281f;
}
.tagline { color: var(--muted); font-size: 12.5px; letter-spacing: .035em; margin-top: 4px; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctl { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.ctl-label { color: var(--muted-2); }
.ctl-toggle { user-select: none; cursor: pointer; }
.ctl-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.ctl-hint span { color: var(--suggest-2); font-weight: 600; }
select#skill {
  appearance: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 7px 30px 7px 11px; font: inherit; font-size: 13px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8074'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
select#skill:hover { border-color: var(--accent-dim); }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); padding: 9px 15px;
  transition: border-color .18s var(--ease), background .18s var(--ease), transform .12s var(--ease);
}
.btn:hover { border-color: var(--accent-dim); background: #f6eaD6; }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(192,122,78,.08); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff7ee; font-weight: 600; box-shadow: var(--shadow-soft); }
.btn-primary:hover { background: #cd875a; border-color: #cd875a; }
.btn-small { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 332px;
  gap: clamp(18px, 2.4vw, 34px);
  align-items: start;
}
.board-stage { display: flex; gap: 12px; align-items: stretch; }

/* ---------- eval bar ---------- */
.evalbar {
  position: relative; width: 24px; flex: 0 0 24px;
  border-radius: 7px; overflow: hidden;
  background: var(--eval-black);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}
.evalbar-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 100%; background: var(--eval-white);
  transform-origin: bottom; transform: scaleY(0.5);
  transition: transform .55s var(--ease);
}
.evalbar-num {
  position: absolute; left: 0; right: 0; top: 6px;
  text-align: center; font-family: var(--font-mono);
  font-size: 10px; font-weight: 700; color: var(--muted);
  mix-blend-mode: difference;
}

/* ---------- board ---------- */
.board-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-board);
  user-select: none; touch-action: manipulation;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq .coord {
  position: absolute; font-size: 9px; font-weight: 700; opacity: .55;
  font-family: var(--font-mono); pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq.light .coord { color: #a07a4f; }
.sq.dark  .coord { color: #ecdcc0; }

.sq .piece {
  width: 92%; height: 92%;
  pointer-events: none;
  transition: transform .2s var(--ease);
  filter: drop-shadow(0 2px 2px rgba(80,55,25,.22));
}
.sq.dragging .piece { opacity: .25; }

.sq.last { box-shadow: inset 0 0 0 100px var(--sq-last); }
.sq.sel  { box-shadow: inset 0 0 0 3px var(--sq-sel); }
.sq.check { box-shadow: inset 0 0 22px 4px var(--sq-check); }

/* on-board best-move suggestion */
.sq.suggest-from::after {
  content: ""; position: absolute; inset: 8%;
  border-radius: 14px; border: 2.5px dashed var(--suggest);
  opacity: .8; pointer-events: none;
}
.sq.suggest-to::before {
  content: ""; position: absolute; inset: 14%;
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--suggest-glow), 0 0 18px 4px var(--suggest-glow);
  background: radial-gradient(circle, var(--suggest-glow), transparent 70%);
  pointer-events: none;
  animation: breathe 2.4s var(--ease) infinite;
}
@keyframes breathe { 0%,100% { opacity: .55; transform: scale(.94) } 50% { opacity: 1; transform: scale(1.04) } }

.sq .hint-dot {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(70,48,22,.26); pointer-events: none;
}
.sq.occupied .hint-dot {
  width: 84%; height: 84%; background: transparent;
  border: 5px solid rgba(70,48,22,.24); border-radius: 50%;
}
.sq.dark .hint-dot { background: rgba(255,250,240,.34); }
.sq.dark.occupied .hint-dot { background: transparent; border-color: rgba(255,250,240,.36); }
.sq.movable { cursor: pointer; }

.board-arrows {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; overflow: visible;
}

/* promotion chooser */
.promo {
  position: absolute; inset: 0; background: rgba(60,42,20,.55);
  display: none; align-items: center; justify-content: center; z-index: 5;
  border-radius: var(--r-md);
}
.promo:not([hidden]) { display: flex; }
.promo-card {
  display: flex; gap: 6px; padding: 10px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: 0 20px 50px -16px rgba(60,42,20,.5);
}
.promo-card button {
  width: 56px; height: 56px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.promo-card button:hover { border-color: var(--accent); background: #f1e3cd; }
.promo-card img { width: 80%; height: 80%; }

/* ---------- rail ---------- */
.rail { display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 14px 15px;
  box-shadow: var(--shadow-soft);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted-2); margin-bottom: 10px;
}
.panel-head .status { text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--muted); }
.panel-head .on-board-note { text-transform: none; letter-spacing: 0; font-size: 11.5px; color: var(--suggest-2); font-weight: 600; }

.eval-panel { padding-top: 16px; padding-bottom: 16px; }
.eval-headline { display: flex; align-items: baseline; gap: 12px; }
.eval-score {
  font-family: var(--font-mono); font-size: 34px; font-weight: 700;
  letter-spacing: -.01em; line-height: 1; color: #2f281f;
}
.eval-desc { color: var(--muted); font-size: 13px; }
.eval-thinking { margin-top: 9px; color: var(--muted-2); font-size: 12px; display: flex; align-items: center; gap: 7px; }
.dot-pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s var(--ease) infinite; }
@keyframes pulse { 0%,100%{opacity:.3; transform:scale(.8)} 50%{opacity:1; transform:scale(1.15)} }

.quality-panel { display: flex; align-items: center; gap: 11px; }
.quality-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  color: #2b2419; animation: pop .28s var(--ease);
}
.quality-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(0,0,0,.28); }
.quality-note { color: var(--muted); font-size: 12.5px; }
@keyframes pop { from { transform: scale(.82); opacity: 0 } to { transform: scale(1); opacity: 1 } }

.coach {
  border-color: var(--accent-dim);
  background: linear-gradient(180deg, #f7e9d6, #fbf3e7);
}
.coach-text { font-size: 13.5px; color: #6a4a2c; }
.coach-actions { display: flex; gap: 8px; margin-top: 11px; }

.bestline { font-family: var(--font-mono); font-size: 13px; color: var(--text); line-height: 1.7; word-break: break-word; min-height: 1.2em; }
.bestline .pv-best { color: var(--suggest-2); font-weight: 700; }

.moves-panel { flex: 0 1 auto; }
.movelist {
  list-style: none; display: grid; grid-template-columns: 30px 1fr 1fr;
  gap: 2px 8px; align-items: center;
  font-family: var(--font-mono); font-size: 13px;
  max-height: 230px; overflow-y: auto; padding-right: 4px;
}
.movelist .moveno { color: var(--muted-2); font-size: 11px; text-align: right; }
.movelist .ply {
  padding: 2px 6px; border-radius: 5px;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.movelist .ply.cur { background: rgba(192,122,78,.14); }
.movelist .qdot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }

.rail-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.engine-credit { color: var(--muted-2); font-size: 11.5px; text-align: center; line-height: 1.6; margin-top: 2px; }
.engine-credit strong { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .rail { order: 2; }
  .board-stage { order: 1; }
  .movelist { max-height: 160px; }
}
@media (max-width: 560px) {
  .controls { width: 100%; justify-content: space-between; }
  .tagline { display: none; }
  .evalbar { width: 16px; flex-basis: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
