:root {
  color-scheme: light dark;
  --bg: #faf8f4;
  --surface: #ffffff;
  --border: #e2ddd3;
  --text: #2a2620;
  --text-dim: #6b6357;
  --accent: #3a6b45;
  --accent-hover: #2d5636;
  --blunder: #c0392b;
  --mistake: #d97b1f;
  --inaccuracy: #c9a227;
  --good: #3a6b45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #262320;
    --border: #3a352e;
    --text: #ede8e0;
    --text-dim: #a89f8f;
    --accent: #6fbf7a;
    --accent-hover: #8ad494;
    --blunder: #ff6b5e;
    --mistake: #ffab4d;
    --inaccuracy: #e8cf5a;
    --good: #6fbf7a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.page-header {
  padding: 3rem 1.5rem 2rem;
  text-align: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 9px;
}

.page-header h1 {
  margin: 0;
  font-size: 2.25rem;
  letter-spacing: -0.02em;
}

.brand-board { color: var(--text); }
.brand-sense { color: var(--accent); }

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 1.05rem;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.lookup-panel, .games-panel {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.lookup-panel, .games-panel, .analysis-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

input[type="text"] {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  cursor: pointer;
}

#lookup-btn {
  padding: 0.7rem 1.3rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

#lookup-btn:hover { background: var(--accent-hover); }
#lookup-btn:disabled { opacity: 0.6; cursor: default; }

.status {
  margin: 0.9rem 0 0;
  color: var(--text-dim);
  font-size: 0.92rem;
  min-height: 1.2em;
}

.status.error { color: var(--blunder); }

.games-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.game-item:hover { border-color: var(--accent); }

.game-players {
  font-weight: 600;
}

.game-meta {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.result-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--border);
  white-space: nowrap;
}

.analysis-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  padding: 0;
}

.engine-progress {
  margin: 1rem 0;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

#progress-label {
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.game-summary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin: 1.25rem 0;
}

.game-summary h3 {
  margin: 0 0 0.4rem;
  font-size: 1.02rem;
}

.game-summary p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.94rem;
  line-height: 1.55;
}

.phase-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.phase-chip {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  text-align: center;
}

.summary-card .num {
  font-size: 1.6rem;
  font-weight: 700;
  display: block;
}

.summary-card .label {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-card.blunder .num { color: var(--blunder); }
.summary-card.mistake .num { color: var(--mistake); }
.summary-card.inaccuracy .num { color: var(--inaccuracy); }
.summary-card.accuracy .num { color: var(--good); }

.moves-report {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.moves-report:not(:empty) {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.moves-report-heading {
  margin: 0 0 0.9rem;
  font-size: 1rem;
}

/* --- Game review layout --- */

.analysis-panel {
  max-width: none;
}

.review {
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(260px, 340px);
  gap: 1.75rem;
  align-items: start;
  justify-content: center;
}

@media (max-width: 760px) {
  .review {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }
}

.review-board-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board-row {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
}

.eval-bar {
  position: relative;
  width: 22px;
  flex: 0 0 22px;
  border-radius: 6px;
  overflow: hidden;
  background: #262421;
  border: 1px solid var(--border);
}

.eval-bar-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #f5f2ea;
  transition: height 0.25s ease;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  flex: 1 1 auto;
  min-width: 0;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #1e1c19;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
}

.sq.light { background: #ecebd6; }
.sq.dark { background: #7a9066; }

.sq.highlight-from, .sq.highlight-to {
  box-shadow: inset 0 0 0 999px rgba(255, 214, 92, 0.45);
}

.coord {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  opacity: 0.75;
}

.coord-file { right: 3px; bottom: 2px; }
.coord-rank { left: 3px; top: 2px; }

.sq.light .coord { color: #7a9066; }
.sq.dark .coord { color: #ecebd6; }

.piece {
  width: 82%;
  height: 82%;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.chess-board.interactive .piece {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.piece.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
}

.sq.legal-dest::after {
  content: "";
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.22);
  pointer-events: none;
}

.sq.legal-dest.legal-capture::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 4px solid rgba(20, 20, 20, 0.28);
  box-sizing: border-box;
}

.move-badge {
  position: absolute;
  top: -10%;
  right: -10%;
  width: 50%;
  height: 50%;
  min-width: 22px;
  min-height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 3.1vw, 1.25rem);
  line-height: 1;
  font-weight: 800;
  color: #fff;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.45),
    0 0 0 2.5px var(--bg),
    inset 0 1.5px 2px rgba(255, 255, 255, 0.55),
    inset 0 -2px 3px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 2;
}

.move-badge svg {
  width: 58%;
  height: 58%;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.move-badge.blunder { background: radial-gradient(circle at 32% 28%, #ff8577, var(--blunder) 70%); }
.move-badge.mistake { background: radial-gradient(circle at 32% 28%, #ffc07a, var(--mistake) 70%); }
.move-badge.inaccuracy { background: radial-gradient(circle at 32% 28%, #f5e08a, var(--inaccuracy) 70%); color: #2a2620; }
.move-badge.best, .move-badge.excellent { background: radial-gradient(circle at 32% 28%, #8fe39a, var(--good) 70%); }
.move-badge.good { background: radial-gradient(circle at 32% 28%, #fff, var(--border) 70%); color: var(--text); }

.board-nav {
  display: flex;
  gap: 0.4rem;
}

.board-nav button {
  flex: 1;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.board-nav button:hover { border-color: var(--accent); color: var(--accent); }

.current-move-info {
  min-height: 4.4em;
  font-size: 0.94rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
}

.current-move-info .cmi-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.current-move-info .cmi-eval {
  margin-left: auto;
  font-weight: 700;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.current-move-info .cmi-tip {
  color: var(--text-dim);
  margin: 0;
}

.board-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.explore-panel {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.9rem;
}

.explore-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.explore-panel #explore-eval {
  margin: 0.35rem 0 0;
  color: var(--text-dim);
}

.review-moves-col {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 0.75rem;
}

.review-moves-col h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.move-list-head {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 3px;
  margin-bottom: 0.3rem;
}

.move-list-head span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  padding: 0 0.55rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-btn.mine {
  box-shadow: inset 2px 0 0 var(--accent);
}

.current-move-info .cmi-who {
  margin: 0 0 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.current-move-info .cmi-who.mine { color: var(--accent); }
.current-move-info .cmi-who.opponent { color: var(--text-dim); }

.move-list {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 3px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.move-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0.4rem 0.2rem;
}

.move-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  padding: 0.4rem 0.55rem;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
}

.move-btn:hover { border-color: var(--accent); }
.move-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.move-btn .icon {
  font-size: 0.78rem;
  font-weight: 700;
}

.move-btn.blunder .icon { color: var(--blunder); }
.move-btn.mistake .icon { color: var(--mistake); }
.move-btn.inaccuracy .icon { color: var(--inaccuracy); }
.move-btn.best .icon, .move-btn.excellent .icon { color: var(--good); }

.move-btn.active .icon { color: #fff; }

.move-card {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 10px;
  padding: 0.9rem 1rem;
}

.move-card.blunder { border-left-color: var(--blunder); }
.move-card.mistake { border-left-color: var(--mistake); }
.move-card.inaccuracy { border-left-color: var(--inaccuracy); }

.move-card-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: #fff;
}

.tag.blunder { background: var(--blunder); }
.tag.mistake { background: var(--mistake); }
.tag.inaccuracy { background: var(--inaccuracy); color: #2a2620; }
.tag.best, .tag.excellent { background: var(--good); }
.tag.good { background: var(--border); color: var(--text); }

.move-eval {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 400;
}

.move-tip {
  margin: 0.4rem 0 0;
  font-size: 0.94rem;
}

.move-best {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 1rem 0;
}

.page-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  padding: 1rem 1.5rem 3rem;
  max-width: 600px;
  margin: 0 auto;
}
