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

:root {
  --bg-page: #f3f5f1;
  --bg-panel: #ffffff;
  --bg-muted: #eef1ea;
  --bg-strong: #202721;
  --text-primary: #1f251f;
  --text-secondary: #516052;
  --text-muted: #7a8478;
  --border-color: #d6ddd2;
  --border-soft: #e5e9e1;
  --accent: #202721;
  --accent-contrast: #ffffff;

  --sq-light: #f7f1e4;
  --sq-dark: #b88d58;
  --sq-highlight-light: #e7ddb7;
  --sq-highlight-dark: #ad8752;
  --sq-best-light: #d8ead6;
  --sq-best-dark: #97b28f;

  --clr-brilliant: #0d8f8b;
  --clr-great: #346ea5;
  --clr-best: #4f7d3c;
  --clr-excellent: #648c4d;
  --clr-good: #7b8a6f;
  --clr-book: #8f6a45;
  --clr-inaccuracy: #c88b16;
  --clr-mistake: #bf6425;
  --clr-blunder: #b12f29;
  --clr-miss: #8f1d17;

  --shadow: 0 14px 36px rgba(44, 58, 45, 0.1);
  --card-radius: 10px;
  --board-size: min(600px, calc(100vw - 620px), calc(100vh - 190px));
}

body {
  font-family: 'Inter', Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.45;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

#app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px;
}

/* ===== Shared ===== */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  border-radius: var(--card-radius);
}

.card h3 {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.material-symbols-outlined {
  font-variation-settings: 'opsz' 24, 'wght' 500, 'FILL' 0, 'GRAD' 0;
  line-height: 1;
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-note {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 0 16px;
  margin-bottom: 18px;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--border-soft);
  border-radius: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--bg-strong);
  color: var(--accent-contrast);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  border: 0;
  border-radius: 10px;
}

.brand-copy h1 {
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
  line-height: 1;
}

.brand-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

/* ===== Buttons ===== */
.btn,
.btn-control,
.input-select {
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.btn {
  min-height: 40px;
  padding: 10px 15px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  background: var(--bg-panel);
  color: var(--text-primary);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.btn-symbol {
  font-size: 1.16rem;
}

.btn:hover:not(:disabled),
.btn-control:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled,
.btn-control:disabled,
.input-select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-primary,
.btn-review {
  background: var(--bg-strong);
  color: var(--accent-contrast);
}

.btn-secondary {
  background: var(--bg-panel);
}

.btn-review {
  width: 100%;
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
  border-radius: var(--card-radius);
}

.btn-review .btn-content {
  position: relative;
  z-index: 1;
}

.btn-review:hover:not(:disabled) {
  background: #000000;
}

.btn-control {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  background: var(--bg-panel);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ===== Layout ===== */
.main-content {
  display: grid;
  grid-template-columns: minmax(320px, var(--board-size)) minmax(360px, 1fr);
  grid-template-areas:
    "eval analysis"
    "board analysis";
  align-items: start;
  gap: 18px;
  min-width: 0;
}

/* ===== Eval ===== */
.eval-bar-container {
  grid-area: eval;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: var(--board-size);
  padding: 8px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  box-shadow: none;
  border-radius: var(--card-radius);
}

.eval-bar {
  width: 100%;
  height: 24px;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.eval-bar-black {
  background: #111111;
  height: 100%;
  width: 100%;
  flex: 0 0 auto;
  transition: height 0.4s ease, width 0.4s ease;
}

.eval-bar-white {
  background: #ffffff;
  height: 100%;
  width: 100%;
  flex: 0 0 auto;
  transition: height 0.4s ease, width 0.4s ease;
}

.eval-score {
  min-width: 42px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.84rem;
  font-weight: 600;
  text-align: center;
}

#eval-graph {
  width: 100%;
  height: 120px;
  display: block;
  margin-top: 12px;
  background: linear-gradient(180deg, #faf8f2 0%, #f5efe3 100%);
  border: 2px solid var(--border-color);
}

/* ===== Board ===== */
.board-section {
  grid-area: board;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-info {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  box-shadow: none;
  border-radius: var(--card-radius);
}

.player-name {
  font-weight: 600;
}

.player-captured {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.board-wrapper {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  border-radius: var(--card-radius);
  overflow: hidden;
}

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

.board-loading-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 9;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  max-width: min(240px, calc(100% - 24px));
  padding: 8px 10px;
  background: rgba(25, 24, 20, 0.78);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.board-loading-overlay.active {
  display: flex;
}

.board-loading-overlay.on-square {
  min-width: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  background: #ffffff;
  border: 2px solid var(--border-color);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(17, 17, 17, 0.18);
}

.board-loading-overlay.on-square .board-loading-text {
  display: none;
}

.board-loading-overlay.on-square .board-loading-spinner {
  width: 28px;
  height: 28px;
}

.board-loading-spinner {
  width: 30px;
  height: 30px;
  object-fit: contain;
  animation: spinner-rotate 0.8s linear infinite;
}

.board-loading-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 700;
}

.chess-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
}

.square.light {
  background: var(--sq-light);
}

.square.dark {
  background: var(--sq-dark);
}

.square.highlight.light {
  background: var(--sq-highlight-light);
}

.square.highlight.dark {
  background: var(--sq-highlight-dark);
}

.square.best-from.light,
.square.best-to.light {
  background: var(--sq-best-light);
  box-shadow: inset 0 0 0 3px var(--clr-best);
}

.square.best-from.dark,
.square.best-to.dark {
  background: var(--sq-best-dark);
  box-shadow: inset 0 0 0 3px var(--clr-best);
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.square.dragging .piece {
  opacity: 0.35;
}

.square .piece {
  width: 84%;
  height: 84%;
  position: absolute;
  pointer-events: none;
  z-index: 1;
  inset: 8%;
}

.square .coord-label {
  position: absolute;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.64rem;
  font-weight: 600;
  z-index: 2;
}

.square .coord-file {
  right: 4px;
  bottom: 2px;
}

.square .coord-rank {
  top: 2px;
  left: 4px;
}

.square.light .coord-label {
  color: #694c29;
}

.square.dark .coord-label {
  color: #f5ebd5;
}

.square .legal-dot {
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(17, 17, 17, 0.18);
  position: absolute;
  left: 37%;
  top: 37%;
  pointer-events: none;
  z-index: 2;
}

.square.has-piece .legal-dot {
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  background: transparent;
  border: 4px solid rgba(17, 17, 17, 0.18);
  left: 6px;
  top: 6px;
}

.drag-piece {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
}

.move-classification-badge {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.88);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(17, 17, 17, 0.22);
}

.badge-icon {
  font: inherit;
  line-height: 1;
}

.classification-google-icon {
  font-family: 'Material Symbols Outlined';
  font-size: 1.05rem;
  font-weight: normal;
  font-variation-settings: 'opsz' 24, 'wght' 600, 'FILL' 0, 'GRAD' 0;
}

.classification-text-icon {
  font-family: 'IBM Plex Mono', monospace;
}

.badge-text {
  display: none;
}

.board-flash {
  display: none;
}

.board-flash.flash-brilliant,
.board-flash.flash-great,
.board-flash.flash-blunder {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: 0.95;
  mix-blend-mode: multiply;
}

.board-flash.flash-brilliant {
  background:
    radial-gradient(circle at 50% 50%, rgba(13, 143, 139, 0.28) 0%, rgba(13, 143, 139, 0.12) 32%, transparent 65%),
    linear-gradient(135deg, rgba(13, 143, 139, 0.15), transparent 65%);
  animation: brilliantPulse 900ms ease-out;
}

.board-flash.flash-great {
  background:
    radial-gradient(circle at 50% 50%, rgba(52, 110, 165, 0.22) 0%, rgba(52, 110, 165, 0.1) 34%, transparent 68%);
  animation: greatPulse 900ms ease-out;
}

.board-flash.flash-blunder {
  background:
    radial-gradient(circle at 50% 50%, rgba(177, 47, 41, 0.22) 0%, rgba(177, 47, 41, 0.12) 35%, transparent 70%),
    linear-gradient(135deg, rgba(177, 47, 41, 0.18), transparent 64%);
  animation: blunderPulse 1100ms ease-out;
}

.move-classification-badge {
  border-radius: 999px;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.board-controls {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  width: var(--board-size);
}

/* ===== Analysis ===== */
.analysis-panel {
  grid-area: analysis;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
}

.engine-info { order: 1; }
.live-eval { order: 2; }
.btn-review { order: 3; }
.move-list-container { order: 4; }
.analysis-overview { order: 5; }
.review-summary { order: 6; }
.critical-moments { order: 7; }

.panel-wide {
  grid-column: 1 / -1;
}

.analysis-overview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.analysis-overview .opening-info,
.analysis-overview .game-status {
  min-height: 72px;
}

.analysis-overview .move-insights {
  grid-column: 1 / -1;
}

.engine-config,
.review-summary,
.engine-info,
.move-insights,
.coach-card,
.critical-moments,
.move-list-container,
.opening-info,
.live-eval,
.game-status {
  padding: 14px;
}

.engine-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.engine-source-field {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.input-select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  background: var(--bg-panel);
  color: var(--text-primary);
  appearance: none;
}

.review-summary {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.summary-col h4 {
  margin-bottom: 10px;
  font-size: 0.88rem;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accuracy-ring {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 10px;
}

.accuracy-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--bg-muted);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: square;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.8s ease;
}

.accuracy-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
}

.summary-counts,
.phase-breakdown,
.critical-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-count-row,
.phase-row,
.insight-row,
.alt-row {
  font-size: 0.8rem;
}

.summary-count-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-count-row .dot {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0;
}

.summary-count-row .dot.classification-google-icon {
  font-family: 'Material Symbols Outlined';
  font-size: 1rem;
}

.summary-count-row .label {
  flex: 1;
  color: var(--text-secondary);
}

.summary-count-row .count {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.summary-metric-card {
  padding: 10px;
  background: var(--bg-muted);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}

.metric-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
}

.phase-breakdown {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}

.phase-title {
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.phase-row {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1.15fr;
  gap: 10px;
}

.phase-name {
  color: var(--text-secondary);
}

.phase-cell,
.engine-line,
.critical-loss,
.move-eval,
.opening-name {
  font-family: 'IBM Plex Mono', monospace;
}

.engine-status {
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.engine-status.ready {
  color: var(--clr-best);
}

.engine-line {
  min-height: 20px;
  font-size: 0.8rem;
  color: var(--text-primary);
  word-break: break-word;
}

.engine-load-progress {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.engine-load-progress-fill {
  width: 0%;
  height: 100%;
  background: var(--clr-best);
  transition: width 0.22s ease;
}

.engine-load-progress.ready {
  display: none;
}

.engine-info[hidden],
.live-eval[hidden] {
  display: none;
}

.live-eval {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.live-eval-grid {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.live-eval-score {
  display: grid;
  place-items: center;
  min-height: 92px;
  padding: 10px;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  border-radius: 8px;
}

.live-eval-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.live-eval-line {
  font-size: 0.86rem;
  color: var(--text-primary);
}

.live-eval-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.live-eval-status,
.game-status-reason {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.live-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--clr-best);
  box-shadow: 0 0 0 2px rgba(150, 188, 75, 0.18);
}

.live-status-dot.spinning {
  animation: spinPulse 1s linear infinite;
}

.game-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-status-details {
  font-size: 0.84rem;
  color: var(--text-primary);
}

.btn-control .btn-symbol {
  font-size: 1.05rem;
}

@keyframes spinPulse {
  0% { transform: scale(0.9); opacity: 0.55; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.55; }
}

@keyframes brilliantPulse {
  0% { transform: scale(0.98); opacity: 0; }
  25% { opacity: 0.95; }
  100% { transform: scale(1.02); opacity: 0; }
}

@keyframes greatPulse {
  0% { opacity: 0; }
  35% { opacity: 0.8; }
  100% { opacity: 0; }
}

@keyframes blunderPulse {
  0% { transform: scale(0.985); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1.01); opacity: 0; }
}

.insight-empty,
.move-list-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.insight-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insight-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.insight-move {
  font-weight: 700;
  font-size: 0.94rem;
}

.insight-class {
  padding: 4px 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 999px;
}

.insight-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-secondary);
}

.insight-row strong {
  color: var(--text-primary);
}

.insight-coach {
  font-size: 0.82rem;
}

.coach-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.coach-card[hidden] {
  display: none;
}

.coach-card.coach-focus {
  animation: coachFocus 800ms ease;
}

.coach-card-header,
.coach-identity,
.coach-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.coach-card-header {
  justify-content: space-between;
}

.coach-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.coach-avatar img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.coach-coming-soon,
.coach-state {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.coach-state {
  padding: 5px 8px;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
}

.coach-dialog {
  min-height: 54px;
  padding: 12px;
  background: #f8faf5;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.coach-controls {
  align-items: end;
  flex-wrap: wrap;
}

.coach-controls .field {
  flex: 1 1 130px;
}

.coach-action {
  min-height: 44px;
}

@keyframes coachFocus {
  0% { transform: translateY(0); }
  35% { transform: translateY(-2px); box-shadow: 8px 8px 0 rgba(17, 17, 17, 0.18); }
  100% { transform: translateY(0); }
}

.insight-alternatives {
  margin-top: 2px;
  padding-top: 10px;
  border-top: 2px solid var(--border-soft);
}

.alt-title {
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.alt-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  padding: 4px 0;
}

.alt-rank {
  color: var(--text-muted);
}

.alt-move {
  font-weight: 600;
}

.critical-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
}

.critical-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: #ffffff;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
}

.critical-badge.classification-google-icon {
  font-family: 'Material Symbols Outlined';
  font-size: 1.05rem;
}

.critical-text {
  font-size: 0.82rem;
  font-weight: 600;
}

.progress-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: #ffffff;
  transition: width 0.25s ease;
}

.move-list {
  max-height: min(440px, 46vh);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.move-list::-webkit-scrollbar {
  width: 10px;
}

.move-list::-webkit-scrollbar-thumb {
  background: #c7c0b2;
  border: 2px solid #f6f3ed;
}

.move-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}

.move-number {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.move-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 38px;
  border: 1px solid transparent;
  background: #f8faf5;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 500;
  border-radius: 8px;
}

.move-cell:hover {
  border-color: var(--border-color);
}

.move-cell.active {
  background: var(--bg-strong);
  color: var(--accent-contrast);
  border-color: var(--border-color);
}

.move-icon {
  min-width: 22px;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0;
  color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
}

.move-icon.classification-google-icon {
  font-family: 'Material Symbols Outlined';
  font-size: 0.98rem;
}

.move-eval {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.move-cell.active .move-eval {
  color: rgba(255, 255, 255, 0.72);
}

.opening-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  border-radius: var(--card-radius);
}

.opening-icon {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.opening-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 17, 17, 0.45);
  z-index: 100;
}

.modal {
  width: min(640px, 100%);
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  box-shadow: 10px 10px 0 rgba(17, 17, 17, 0.16);
}

.modal-settings {
  width: min(760px, 100%);
}

.modal-header,
.modal-footer {
  padding: 16px 18px;
  border-bottom: 2px solid var(--border-soft);
}

.modal-footer {
  border-top: 2px solid var(--border-soft);
  border-bottom: none;
  display: flex;
  justify-content: flex-end;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  font-size: 1.1rem;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-body {
  padding: 18px;
}

.modal-help {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal-body textarea {
  width: 100%;
  min-height: 220px;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 0;
  resize: vertical;
  background: #faf8f2;
  color: var(--text-primary);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.84rem;
}

.import-source-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 0.7fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.import-action {
  min-height: 44px;
}

.import-status {
  min-height: 22px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.import-status.loading {
  color: var(--clr-great);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.import-status.loading::before {
  content: '';
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  background: url('../assets/spinner.png') center / contain no-repeat;
  animation: spinner-rotate 0.8s linear infinite;
}

.import-status.success {
  color: var(--clr-best);
}

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

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.import-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.import-result {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  background: #faf8f2;
  border: 2px solid var(--border-color);
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
}

.import-result:hover {
  background: #fff;
}

.import-result-title {
  font-weight: 600;
}

.import-result-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.modal-divider {
  height: 1px;
  margin: 10px 0 14px;
  background: var(--border-soft);
}

.modal-body textarea:focus,
.input-select:focus {
  outline: none;
  background: #ffffff;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  :root {
    --board-size: min(520px, calc(100vw - 120px));
  }

  .main-content {
    grid-template-columns: minmax(320px, var(--board-size));
    grid-template-areas:
      "eval"
      "board"
      "analysis";
  }

  .analysis-panel {
    grid-column: auto;
  }

  .engine-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .analysis-panel {
    grid-template-columns: 1fr;
  }

  .panel-wide {
    grid-column: auto;
  }

  .analysis-overview {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  #app {
    padding: 10px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .header-actions .btn {
    width: 100%;
    padding: 10px 8px;
  }

  .main-content {
    grid-template-columns: 38px minmax(0, 1fr);
    grid-template-areas:
      "eval board"
      "analysis analysis";
    gap: 10px;
  }

  .eval-bar-container {
    flex-direction: column;
    justify-content: center;
    width: 100%;
    height: var(--board-size);
    padding: 8px 6px;
  }

  .eval-bar {
    width: 22px;
    height: 100%;
    flex-direction: column;
  }

  .eval-bar-white,
  .eval-bar-black {
    width: 100%;
  }

  #eval-graph {
    height: 96px;
  }

  .board-section,
  .analysis-panel,
  .player-info,
  .board-wrapper {
    width: 100%;
  }

  :root {
    --board-size: min(520px, calc(100vw - 68px));
  }

  .summary-grid,
  .summary-metrics {
    grid-template-columns: 1fr;
  }

  .engine-config,
  .review-summary,
  .engine-info,
  .move-insights,
  .coach-card,
  .critical-moments,
  .move-list-container,
  .opening-info,
  .live-eval,
  .game-status {
    padding: 14px;
  }

  .live-eval-grid {
    grid-template-columns: 1fr;
  }

  .live-eval-score {
    min-height: 72px;
    font-size: 1.2rem;
  }

  .phase-row,
  .critical-item,
  .alt-row {
    grid-template-columns: 1fr;
  }

  .board-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .btn-control {
    height: 42px;
    min-width: 0;
    width: 100%;
    padding: 0;
  }

  .btn-control .btn-label {
    display: none;
  }

  .coach-card-header,
  .coach-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .coach-controls .field,
  .coach-action {
    width: 100%;
  }

  .insight-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .import-source-grid {
    grid-template-columns: 1fr;
  }
}
