@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --btn-bg: linear-gradient(135deg, #e0c6a2 0%, #caa278 55%, #b58863 100%);
  --btn-bg-hover: linear-gradient(135deg, #e7cfad 0%, #d2ad84 55%, #c0926d 100%);
  --btn-text: #342111;
  --btn-shadow: 0 10px 24px rgba(103, 73, 48, 0.24);
  --btn-shadow-hover: 0 14px 30px rgba(103, 73, 48, 0.33);
  --btn-border: rgba(92, 63, 38, 0.32);
  --btn-muted-bg: #f4e8d8;
  --btn-muted-text: #4a301b;
  --btn-muted-border: #d7b792;
  --btn-focus: rgba(181, 136, 99, 0.46);
  /* board */
  --sq-light: #f0d9b5;
  --sq-dark:  #b58863;
  --sq-notation-bg: #fff;
  --sq-notation-color: #333;
  /* panels */
  --body-bg: radial-gradient(circle at 10% -5%, #f3f8ff 0%, #f8fbff 30%, #fbfcff 100%);
  --card-bg: #fff;
  --card-border: #ddd;
  --explain-bg: #fafafa;
  --explain-border: #ddd;
  --explain-color: inherit;
  --explain-placeholder: #888;
  --warning-bg: #f9e5e5;
  --warning-border: #e0b4b4;
  --warning-color: #a94442;
  --missed-how-bg: #fff9f0;
  --missed-how-border: #c8a98a;
  --missed-hint-color: #4a301b;
  --loading-bg: #f0f8ff;
  --loading-border: #aac;
  --loading-color: #333;
  --move-alt-bg: #e2e2e2;
  --move-highlight-bg: rgba(52, 152, 219, 0.3);
  --moves-border: #ddd;
  --user-email-color: #4a301b;
  --games-status-color: #444;
  --stats-subtitle-color: #5e4a37;
  --eval-graph-bg: rgba(0,0,0,0.03);
  --board-border: #888;
}

body { font-family: 'Space Grotesk', 'Segoe UI', sans-serif; margin: 1rem; background: var(--body-bg, radial-gradient(circle at 10% -5%, #f3f8ff 0%, #f8fbff 30%, #fbfcff 100%)); }
textarea { width: 100%; height: 100px; font-family: monospace; }
pre { background: #111; color: #eee; padding: 1rem; overflow-x: auto; }
button {
  border: 1px solid var(--btn-border);
  border-radius: 11px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.52rem 0.88rem;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, opacity 0.14s ease;
}
button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--btn-shadow-hover);
  background: var(--btn-bg-hover);
}
button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 5px 14px rgba(27, 44, 75, 0.25);
}
button:focus-visible {
  outline: none;
  box-shadow: var(--btn-shadow), 0 0 0 3px var(--btn-focus);
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
  box-shadow: none;
  background: #ddcfbc;
  color: #816952;
  border-color: #d0bda7;
}

.icon-button {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.filter-button {
  border-color: var(--btn-muted-border);
  background: var(--btn-muted-bg);
  color: var(--btn-muted-text);
  box-shadow: 0 2px 10px rgba(32, 50, 80, 0.09);
  font-weight: 600;
  padding: 0.35rem 0.62rem;
  border-radius: 999px;
  min-width: 2.15rem;
}

.filter-button-group {
  display: inline-flex;
  align-items: stretch;
}

.filter-button-group .filter-button {
  border-radius: 0;
  margin-left: -1px;
  box-shadow: none;
}

.filter-button-group .filter-button:first-child {
  margin-left: 0;
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
}

.filter-button-group .filter-button:last-child {
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}

.filter-button-group .filter-button:hover:not(:disabled) {
  z-index: 1;
}

.filter-button:hover:not(:disabled) {
  background: #ead8c2;
  box-shadow: 0 6px 14px rgba(86, 59, 37, 0.2);
}

.filter-button.selected {
  background: linear-gradient(135deg, #b58863 0%, #9b7150 100%);
  color: #fff8ef;
  border-color: #8d6446;
  box-shadow: 0 8px 18px rgba(90, 62, 39, 0.32);
}

/* Per-severity button colors — warm brownish palette matching the chess wood-tone design */
.filter-button[data-severity="inaccuracy"] {
  background: #fdf3d2;
  border-color: #b89010;
  color: #7a5808;
}
.filter-button[data-severity="inaccuracy"]:hover:not(:disabled) {
  background: #f5e6b0;
  box-shadow: 0 4px 12px rgba(120, 90, 8, 0.22);
}
.filter-button[data-severity="inaccuracy"].selected {
  background: linear-gradient(135deg, #c8a018 0%, #a07e0c 100%);
  color: #fff8d8;
  border-color: #8a6a08;
  box-shadow: 0 6px 16px rgba(140, 100, 8, 0.32);
}

.filter-button[data-severity="mistake"] {
  background: #fdebd0;
  border-color: #b06018;
  color: #7a3e10;
}
.filter-button[data-severity="mistake"]:hover:not(:disabled) {
  background: #f5d8b4;
  box-shadow: 0 4px 12px rgba(130, 70, 16, 0.22);
}
.filter-button[data-severity="mistake"].selected {
  background: linear-gradient(135deg, #bf7020 0%, #9a521a 100%);
  color: #fff2d8;
  border-color: #88480e;
  box-shadow: 0 6px 16px rgba(138, 72, 16, 0.32);
}

.filter-button[data-severity="blunder"] {
  background: #fdd8d4;
  border-color: #a03028;
  color: #741e18;
}
.filter-button[data-severity="blunder"]:hover:not(:disabled) {
  background: #f5c0bc;
  box-shadow: 0 4px 12px rgba(120, 38, 30, 0.22);
}
.filter-button[data-severity="blunder"].selected {
  background: linear-gradient(135deg, #ae3e2e 0%, #8a2a1e 100%);
  color: #fff0ec;
  border-color: #781e16;
  box-shadow: 0 6px 16px rgba(120, 38, 30, 0.32);
}

.filter-button[data-severity="missed"] {
  background: #ead4e8;
  border-color: #7a4472;
  color: #4e1e4a;
}
.filter-button[data-severity="missed"]:hover:not(:disabled) {
  background: #dcc0d8;
  box-shadow: 0 4px 12px rgba(90, 44, 80, 0.22);
}
.filter-button[data-severity="missed"].selected {
  background: linear-gradient(135deg, #7e4870 0%, #5c2e50 100%);
  color: #ffeaf8;
  border-color: #502848;
  box-shadow: 0 6px 16px rgba(90, 44, 80, 0.32);
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.card { border: 1px solid var(--card-border, #ddd); background: var(--card-bg, #fff); padding: 0.75rem; border-radius: 8px; }
.list-item { cursor: pointer; padding: 0.4rem; border-bottom: 1px solid #eee; }
.list-item:hover { background: #f0f0f0; }

.dark-mode {
  --sq-light: #4a6741;
  --sq-dark:  #2f4d2c;
  --sq-notation-bg: #1a1d27;
  --sq-notation-color: #8a9cc5;
  --body-bg: #13151e;
  --card-bg: #1c1f2a;
  --card-border: #2e364d;
  --explain-bg: #1a1e30;
  --explain-border: #3a4260;
  --explain-color: #d4d9f5;
  --explain-placeholder: #6a7499;
  --warning-bg: #2d1f1f;
  --warning-border: #6b3535;
  --warning-color: #e88080;
  --missed-how-bg: #21201a;
  --missed-how-border: #5a4a30;
  --missed-hint-color: #d4c9b0;
  --loading-bg: #1b2338;
  --loading-border: #3a5080;
  --loading-color: #a8c0e8;
  --move-alt-bg: #252a3d;
  --move-highlight-bg: rgba(80, 160, 255, 0.5);
  --moves-border: #2e364d;
  --user-email-color: #dfe9ff;
  --games-status-color: #dfe9ff;
  --stats-subtitle-color: #c8bba8;
  --eval-graph-bg: rgba(255,255,255,0.04);
  --board-border: #3a4262;
  background: var(--body-bg);
  color: #e0e4ff;
}
.dark-mode .card { background: var(--card-bg); border-color: var(--card-border); box-shadow: 0 2px 10px rgba(0,0,0,0.6); }
.dark-mode input, .dark-mode select { background: #252a3d; color: #eef0ff; border-color: #3d456b; }
.dark-mode input::placeholder { color: #6a7499; }
.dark-mode button:disabled { background: #292e44; color: #5a6080; border-color: #363c58; }
.dark-mode .filter-button { background: #252a3d; color: #c5caeb; border-color: #3d456b; }
.dark-mode .filter-button.selected { background: linear-gradient(135deg, #4a6741 0%, #2f4d2c 100%); color: #e8f5e8; border-color: #3a5338; }
.dark-mode .filter-button[data-severity="inaccuracy"] { background: #2e2a14; border-color: #7a6010; color: #d4aa28; }
.dark-mode .filter-button[data-severity="inaccuracy"].selected { background: linear-gradient(135deg, #c09810 0%, #8a6c08 100%); color: #fff8d8; border-color: #947410; }
.dark-mode .filter-button[data-severity="mistake"] { background: #2e1e10; border-color: #7a4610; color: #cc7a28; }
.dark-mode .filter-button[data-severity="mistake"].selected { background: linear-gradient(135deg, #ae6418 0%, #824810 100%); color: #fff2d8; border-color: #884810; }
.dark-mode .filter-button[data-severity="blunder"] { background: #2e1614; border-color: #74281e; color: #c43c2c; }
.dark-mode .filter-button[data-severity="blunder"].selected { background: linear-gradient(135deg, #a03828 0%, #76221a 100%); color: #ffeeec; border-color: #741e16; }
.dark-mode .filter-button[data-severity="missed"] { background: #261428; border-color: #562e50; color: #b068a0; }
.dark-mode .filter-button[data-severity="missed"].selected { background: linear-gradient(135deg, #784268 0%, #562848 100%); color: #ffeaf8; border-color: #4a2040; }
.dark-mode .list-item:hover { background: #252a3d; }

h2 { margin: 0; font-size: 1.15rem; color: #342111; }
select { color: #342111; background: #fff; border: 1px solid #ccc; }

.dark-mode h2 { color: #e6ecff; }
.dark-mode select { color: #eef4ff; background: #2d3042; border-color: #3a4260; }
#source { background: transparent; }
.dark-mode #source { background: #2d3042; color: #eef4ff; border-bottom-color: #5a6aaa; }
.pv-step-active { background: rgba(181,136,99,0.35); border-radius: 3px; padding: 0 2px; font-weight: 700; }
.dark-mode .pv-step-active { background: rgba(100,140,220,0.35); }

.replay-container { --replay-height: calc(100vh - 5.5rem); display: flex; gap: 1rem; align-items: stretch; height: var(--replay-height); }
.board-container { flex: 0 0 var(--replay-height); position: relative; width: var(--replay-height); height: var(--replay-height); }
#board { display: grid; border: 1px solid var(--board-border, #888); width: 100%; height: 100%; }
.panel { flex: 1 1 0; display: flex; flex-direction: column; min-width: 280px; height: 100%; }
.moves-wrap { flex: 1; min-height: 0; overflow-y: auto; border: 1px solid var(--moves-border, #ddd); }
.moves-wrap.play-mode-disabled {
  pointer-events: none;
  opacity: 0.45;
  filter: grayscale(0.35);
  background: rgba(120, 120, 120, 0.08);
}
#moves { width: 100%; border-collapse: collapse; table-layout: fixed; }
#evalGraph { flex: 0 0 auto; min-height: 160px; display: flex; align-items: flex-end; gap: 2px; background: var(--eval-graph-bg, rgba(0,0,0,0.03)); padding: 0.35rem; }

.board-cell { width: 2.5rem; height: 2.5rem; display: flex; align-items: center; justify-content: center; box-sizing: border-box; border: 1px solid #888; }
.move-cell { padding: 0.2rem 0.35rem; cursor: pointer; line-height: 1.4; height: 1.8rem; box-sizing: border-box; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: inherit; }
.move-cell.alt { background: var(--move-alt-bg, #e2e2e2); }
.move-cell.highlight { background: var(--move-highlight-bg, rgba(52, 152, 219, 0.3)) !important; }
.move-cell.filtered.inaccuracy { box-shadow: inset 0 0 0 2px #f4d03f; }
.move-cell.filtered.mistake { box-shadow: inset 0 0 0 2px #e67e22; }
.move-cell.filtered.blunder { box-shadow: inset 0 0 0 2px #e74c3c; }
.move-cell.filtered.missed { box-shadow: inset 0 0 0 2px #8e44ad; }
.board-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.highlight-from { outline: 2px solid #f4d03f; outline-offset: -2px; }
.highlight-to { outline: 2px solid #3498db; outline-offset: -2px; }
.highlight-checked-king {
  box-shadow: inset 0 0 0 2px rgba(181, 88, 32, 0.92), 0 0 14px 4px rgba(214, 131, 64, 0.66);
  border-radius: 4px;
}
.highlight-checkmated-king {
  box-shadow: inset 0 0 0 2px rgba(170, 0, 0, 0.85), 0 0 18px 6px rgba(220, 20, 20, 0.85);
  border-radius: 4px;
}

/* Play mode styles */
.play-selected { outline: 3px solid #f39c12; outline-offset: -3px; }
.play-valid-dest::after {
  content: '';
  display: block;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: rgba(52, 152, 219, 0.55);
  margin: auto;
  pointer-events: none;
}
.play-valid-capture { outline: 3px solid rgba(52, 152, 219, 0.7); outline-offset: -3px; }
.play-mode-active .board-cell { cursor: pointer; }
.play-mode-active .board-cell:hover { filter: brightness(1.08); }

@media (max-width: 1200px) {
  .replay-container { flex-direction: column; height: auto; }
  .board-container { min-width: 0; width: 100%; height: min(85vh, 85vw); }
  .panel { flex: 1 1 auto; width: 100%; min-width: 0; height: auto; }
  .moves-wrap { max-height: 45vh; }
}
@media (max-width: 700px) {
  body { margin: 0.4rem; }
  h1 { font-size: 1rem; }
  .header-stats { display: none; }
  .filter-buttons { flex-wrap: wrap; }
  .explain-actions { flex-wrap: wrap; }
}
