:root {
  --bg-0: #1e1c1a;
  --bg-1: #262320;
  --panel-bg: rgba(42, 39, 36, 0.68);
  --panel-bg-solid: #2a2724;
  --panel-border: rgba(255, 255, 255, 0.08);
  --hairline: rgba(255, 255, 255, 0.08);
  --text: #ece7e1;
  --text-muted: #a39c93;
  --accent: #c9a25c;
  --accent-text: #241d10;
  --fill: rgba(255, 255, 255, 0.05);
  --fill-hover: rgba(255, 255, 255, 0.09);
  --fill-active: rgba(255, 255, 255, 0.14);

  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --selected: rgba(246, 246, 130, 0.55);
  --legal-dot: rgba(20, 100, 40, 0.55);
  --legal-capture: rgba(200, 40, 40, 0.55);
  --last-move: rgba(255, 200, 0, 0.35);
  --check: rgba(220, 30, 30, 0.65);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.5);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.piece-style-btn:focus-visible {
  outline-offset: -2px;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, var(--bg-1), transparent),
    var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 40px 24px;
}

.app {
  display: flex;
  flex-wrap: wrap;
  gap: 40px;
  align-items: flex-start;
  justify-content: center;
}

[hidden] {
  display: none !important;
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.tagline {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#board {
  --board-size: min(76vmin, 540px);
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.board-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.board-wrap {
  position: relative;
  display: inline-block;
}

.board-arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.board-arrow-primary {
  stroke: rgba(21, 145, 66, 0.85);
  stroke-width: 0.16;
  stroke-linecap: round;
}

.board-arrow-secondary {
  stroke: rgba(201, 140, 26, 0.7);
  stroke-width: 0.1;
  stroke-linecap: round;
}

.eval-bar {
  width: clamp(14px, 4vmin, 22px);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: #2a2622;
  flex-shrink: 0;
}

.eval-bar-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #efe7da;
  transition: height 0.25s ease;
}

.eval-bar.flipped .eval-bar-fill {
  bottom: auto;
  top: 0;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  cursor: pointer;
}

.square.light {
  background-color: var(--light-square);
}

.square.dark {
  background-color: var(--dark-square);
}

.square.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--selected);
  pointer-events: none;
}

.square.last-move::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--last-move);
  pointer-events: none;
}

.square.in-check::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, var(--check) 0%, transparent 72%);
  pointer-events: none;
}

.square.legal-capture::after {
  content: '';
  position: absolute;
  inset: 6%;
  border: 3px solid var(--legal-capture);
  border-radius: 50%;
  pointer-events: none;
}

.move-hint {
  position: absolute;
  width: 24%;
  height: 24%;
  border-radius: 50%;
  background: var(--legal-dot);
  pointer-events: none;
}

.piece {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  z-index: 2;
}

.piece-img {
  width: 80%;
  height: 80%;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
  transition: transform 0.15s var(--ease);
}

.square:hover .piece-img {
  transform: scale(1.05);
}

.coord {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.5;
  pointer-events: none;
  z-index: 1;
}

.square.light .coord {
  color: var(--dark-square);
}

.square.dark .coord {
  color: var(--light-square);
}

.rank-label {
  top: 4px;
  left: 5px;
}

.file-label {
  bottom: 3px;
  right: 5px;
}

#status {
  margin-top: 18px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  min-height: 1.4em;
  letter-spacing: -0.01em;
}

#status.game-over {
  color: var(--accent);
  font-weight: 600;
}

#status.thinking {
  color: var(--text-muted);
  font-style: italic;
}

.opening-name {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: -0.005em;
}

.game-timecontrol {
  width: 100%;
  max-width: var(--board-size, 92vmin);
  text-align: center;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.game-accuracy {
  width: 100%;
  max-width: var(--board-size, 92vmin);
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.game-accuracy-side strong {
  color: var(--text);
  font-weight: 700;
  margin-left: 4px;
}

.player-label {
  width: 100%;
  max-width: var(--board-size, 92vmin);
  padding: 0 2px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

#player-top {
  margin-bottom: 6px;
}

#player-bottom {
  margin-top: 6px;
}

.controls {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

button,
.btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 980px;
  border: none;
  background: var(--fill);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
}

button:hover,
.btn:hover {
  background: var(--fill-hover);
}

button:active,
.btn:active {
  background: var(--fill-active);
  transform: scale(0.97);
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}

button.primary:active {
  filter: brightness(0.96);
}

.sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field-row label {
  font-size: 0.85rem;
  color: var(--text);
}

.field-row select {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 26px 6px 10px;
  border-radius: 980px;
  border: none;
  background-color: var(--fill);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2386807a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: background-color 0.15s var(--ease);
}

.field-row select:hover {
  background-color: var(--fill-hover);
}

.field-row.hidden {
  display: none;
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 1.8rem;
  flex-wrap: wrap;
}

.captured-row .label {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 72px;
}

.captured-piece-img {
  width: 20px;
  height: 20px;
  opacity: 0.85;
}

#move-list {
  max-height: min(76vmin, 540px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.move-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 6px;
  padding: 5px 2px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--hairline);
}

.move-row:last-child {
  border-bottom: none;
}

.move-num {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.move-san {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.move-san-clickable {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 4px;
  margin: -1px -4px;
}

.move-san-clickable:hover {
  background: var(--fill-hover);
}

.move-san-active {
  background: var(--fill-active);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.move-rating-badge {
  display: inline-block;
  margin-left: 3px;
  font-size: 0.72em;
  font-weight: 700;
  font-variant-numeric: normal;
  cursor: default;
}

.move-time {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.68em;
  font-weight: 400;
  color: var(--text-muted);
}

/* A small, reused palette rather than one color per tier — see the
   MOVE_RATING_BADGES comment in board-render.js. Applied to both the move's
   own SAN text and its badge symbol, so they always match. Good/Book moves
   get no class at all and stay the default text color on purpose. */
.move-rating-green { color: #7fd97f; }
.move-rating-yellow { color: #e0d24d; }
.move-rating-orange { color: #e08b4d; }
.move-rating-red { color: #e0574a; }

#movelist-panel {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.movelist-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.movelist-panel-header h2 {
  margin: 0;
}

#back-to-list-btn {
  font-size: 0.78rem;
  padding: 6px 12px;
}

.rate-moves-status {
  margin: -4px 0 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

#trigger-review-btn {
  flex: 1;
  font-size: 0.78rem;
  padding: 6px 12px;
  justify-content: center;
}

.review-trigger-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

#review-count-select {
  font-family: inherit;
  font-size: 0.78rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--fill);
  color: var(--text);
}

.review-status-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.review-status-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.review-status-row .review-status-value {
  color: var(--text);
  font-weight: 500;
}

.variation-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  margin: 3px 0;
  border-radius: 6px;
  background: var(--fill);
  border-left: 3px solid var(--accent);
}

.variation-row-text {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
  white-space: normal;
  overflow-wrap: break-word;
}

.variation-row-exit {
  flex-shrink: 0;
  font-size: 0.75rem;
  padding: 3px 9px;
  line-height: 1.3;
}

.eval-graph-wrap {
  width: 100%;
  margin-top: 10px;
}

.eval-graph {
  width: 100%;
  height: 56px;
  display: block;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #2a2622;
}

.eval-graph-fill {
  fill: #efe7da;
}

.eval-graph-line {
  fill: none;
  stroke: #efe7da;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.eval-graph-midline {
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 2 2;
}

.eval-graph-cursor {
  stroke: var(--accent);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.eval-graph-dot-blunder,
.eval-graph-dot-mistake {
  stroke: #1e1c1a;
  vector-effect: non-scaling-stroke;
  stroke-width: 1;
}

.eval-graph-dot-blunder {
  fill: #e0574a;
}

.eval-graph-dot-mistake {
  fill: #e08b4d;
}

dialog#promotion-dialog,
dialog#copy-dialog,
dialog#piece-style-dialog {
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel-bg-solid);
  color: var(--text);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}

dialog#promotion-dialog::backdrop,
dialog#copy-dialog::backdrop,
dialog#piece-style-dialog::backdrop {
  background: rgba(20, 18, 15, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

dialog#promotion-dialog p,
dialog#copy-dialog p,
dialog#piece-style-dialog p {
  margin: 0 0 14px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
}

#promotion-options {
  display: flex;
  gap: 10px;
}

.promo-btn {
  padding: 10px 14px;
  line-height: 1;
  border-radius: 14px;
  background: var(--fill);
}

.promo-piece-img {
  width: 44px;
  height: 44px;
  display: block;
}

#piece-style-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.piece-style-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 14px;
  font-size: 0.78rem;
}

.piece-style-btn.active {
  background: var(--fill-active);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.piece-style-preview {
  width: 38px;
  height: 38px;
}

#credits {
  max-width: 900px;
  margin: 28px auto 0;
  padding: 0 16px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.6;
  opacity: 0.85;
}

#credits a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.page-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.page-form input {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--fill);
  color: var(--text);
}

.page-form input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--legal-capture);
}

.form-success {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------------------------------------------------------- Account search (Review page) */

.search-bar {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 0 16px;
}

.search-bar select {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 30px 10px 14px;
  border-radius: 980px;
  border: none;
  background-color: var(--fill);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2386807a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 16px;
  border-radius: 980px;
  border: 1px solid var(--panel-border);
  background: var(--fill);
  color: var(--text);
}

.search-bar input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-bar button {
  flex-shrink: 0;
}

#search-error {
  max-width: 560px;
  margin: 8px auto 0;
  padding: 0 16px;
  text-align: center;
}

.saved-accounts-row {
  max-width: 560px;
  margin: 14px auto 0;
  padding: 0 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.saved-chip {
  display: inline-flex;
  align-items: stretch;
  border-radius: 980px;
  overflow: hidden;
  background: var(--fill);
}

.saved-chip-view {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 0;
  background: transparent;
}

.saved-chip-remove {
  padding: 6px 10px;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
}

.saved-chip-remove:hover {
  background: var(--fill-hover);
  color: var(--text);
}

.games-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.games-panel-header h2 {
  margin: 0;
}

#save-account-btn {
  font-size: 0.78rem;
  padding: 6px 12px;
}

#save-account-btn.saved {
  background: var(--accent);
  color: var(--accent-text);
}

#sync-btn {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

.eval-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.eval-panel-header h2 {
  margin: 0;
}

.analysis-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
}

.eval-status {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.eval-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.eval-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--fill);
  font-size: 0.82rem;
}

.eval-line-clickable {
  cursor: pointer;
}

.eval-line-clickable:hover {
  background: var(--fill-hover);
}

.eval-line-expanded {
  align-items: flex-start;
  background: var(--fill-active);
}

.eval-line-expanded .eval-line-moves {
  white-space: normal;
  overflow-wrap: break-word;
}

.eval-line-score {
  flex-shrink: 0;
  min-width: 44px;
  font-weight: 700;
}

.eval-line-score.positive {
  color: #9fd98a;
}

.eval-line-score.negative {
  color: #e08b7f;
}

.eval-line-moves {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------- Top nav */

.nav-bar {
  width: 100%;
  max-width: 900px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--fill);
  padding: 4px;
  border-radius: 980px;
}

.nav-tab {
  padding: 7px 18px;
  border-radius: 980px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: var(--accent);
  color: var(--accent-text);
}

.nav-auth {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.nav-user-name {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-auth button {
  padding: 6px 14px;
  font-size: 0.78rem;
}

.nav-signin {
  padding: 7px 16px;
  font-size: 0.82rem;
}

/* ---------------------------------------------------------- Sign-in gate */

.signin-gate {
  max-width: 420px;
  margin: 10vh auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.signin-gate .btn {
  padding: 11px 22px;
  font-size: 0.9rem;
}

button:disabled,
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#game-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.game-row {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--fill);
  cursor: pointer;
  transition: background 0.15s var(--ease);
}

.game-row:hover {
  background: var(--fill-hover);
}

.game-row.active {
  background: var(--fill-active);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.game-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 500;
}

.game-opponent {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 980px;
  flex-shrink: 0;
}

.result-badge.result-win {
  background: rgba(120, 180, 100, 0.18);
  color: #9fd98a;
}

.result-badge.result-loss {
  background: rgba(200, 80, 70, 0.18);
  color: #e08b7f;
}

.result-badge.result-draw {
  background: var(--fill);
  color: var(--text-muted);
}

.game-row-meta {
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pagination-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

#games-panel .btn,
#games-panel button.primary {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .sidebar,
  #movelist-panel {
    width: 100%;
    max-width: var(--board-size, 92vmin);
  }
}

/* ---------- Flags, ratings, filters, export (Review) ---------- */

[hidden] {
  display: none !important;
}

img.flag {
  width: 1.25em;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  vertical-align: -0.12em;
  margin-right: 0.4em;
  flex-shrink: 0;
}

.player-rating {
  margin-left: 0.4em;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.player-rating::before {
  content: '(';
}

.player-rating::after {
  content: ')';
}

.game-opponent {
  display: flex;
  align-items: center;
  min-width: 0;
}

.game-opponent > span:first-of-type {
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-row-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.game-filters select,
.game-filters input {
  min-width: 0;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 24px 6px 10px;
  border-radius: 980px;
  border: none;
  background-color: var(--fill);
  color: var(--text);
}

.game-filters select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2386807a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.game-filters input {
  padding-right: 10px;
  border: 1px solid var(--panel-border);
}

.game-filters select:hover {
  background-color: var(--fill-hover);
}

.export-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.export-row button,
.export-row .btn {
  font-size: 0.75rem;
  padding: 6px 12px;
}

.export-status {
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  color: var(--accent);
  min-height: 1em;
}

.shortcut-hint {
  margin: 4px 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

dialog#copy-dialog textarea {
  display: block;
  width: min(560px, 80vw);
  margin-bottom: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--fill);
  color: var(--text);
  resize: vertical;
}

/* ---------- Database tab ---------- */

body.page-wide {
  justify-content: flex-start;
}

.db-page {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.segmented {
  align-self: center;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 980px;
  background: var(--fill);
}

.segmented-option {
  padding: 7px 18px;
  background: transparent;
  color: var(--text-muted);
}

.segmented-option:hover {
  background: var(--fill-hover);
  color: var(--text);
}

.segmented-option.active {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.db-library-total,
.db-result-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.player-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 6px;
}

.player-chip {
  justify-content: flex-start;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 12px;
  text-align: left;
}

.player-chip.active {
  background: var(--fill-active);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.player-chip-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.player-chip-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-chip-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.db-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px 12px;
}

.db-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.db-field input,
.db-field select {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--fill);
  color: var(--text);
  min-width: 0;
  color-scheme: dark;
}

.db-filter-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.db-active-player {
  margin-right: auto;
  font-size: 0.8rem;
  color: var(--accent);
}

.db-table-wrap {
  overflow-x: auto;
  margin: 0 -6px;
}

.db-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.db-table th {
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px;
  border-bottom: 1px solid var(--hairline);
}

.db-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.db-table tbody tr {
  cursor: pointer;
  transition: background 0.15s var(--ease);
}

.db-table tbody tr:hover,
.db-table tbody tr:focus-visible {
  background: var(--fill-hover);
}

.db-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.db-date,
.db-event {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.db-winner > span:first-of-type {
  font-weight: 600;
}

.db-result {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.db-opening,
.db-event {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-event {
  max-width: 180px;
}

.db-import-help {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.db-import-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
}

.db-page code {
  font-size: 0.8rem;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--fill);
}

@media (max-width: 640px) {
  body {
    padding: 24px 16px;
  }

  .db-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .db-event,
  .db-table th:last-child {
    display: none;
  }
}

/* ---------- Opening explorer (Review) ---------- */

.segmented-small {
  display: flex;
  margin-bottom: 8px;
}

.segmented-small .segmented-option {
  flex: 1;
  justify-content: center;
  padding: 5px 8px;
  font-size: 0.75rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.explorer-row {
  cursor: pointer;
}

.explorer-row td {
  padding: 4px 3px;
  border-bottom: 1px solid var(--hairline);
}

.explorer-row:hover,
.explorer-row:focus-visible {
  background: var(--fill-hover);
}

.explorer-row-played .explorer-san {
  color: var(--accent);
}

.explorer-san {
  font-weight: 600;
  width: 3.6em;
}

.explorer-count,
.explorer-rating {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  width: 3.4em;
}

.explorer-bar-cell {
  width: 100%;
}

.wdl-bar {
  display: flex;
  height: 15px;
  border-radius: 4px;
  overflow: hidden;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 15px;
  font-variant-numeric: tabular-nums;
}

.wdl-bar span {
  display: block;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}

.wdl-white {
  background: #ece7e1;
  color: #2a2724;
}

.wdl-draw {
  background: #8a847d;
  color: #1e1c1a;
}

.wdl-black {
  background: #121110;
  color: #ece7e1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.explorer-games {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.explorer-games-heading {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.explorer-game {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  text-align: left;
}

.explorer-game-players {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-game-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ---------- Stats tab ---------- */

#games-panel .games-panel-header h2 {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.games-panel-stats,
.stats-link {
  font-size: 0.78rem;
  padding: 6px 12px;
  flex-shrink: 0;
}

.stats-page {
  width: min(1100px, 100%);
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.stats-subhead {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stats-empty {
  margin: 4px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: left;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.stat-tile {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fill);
}

.stat-tile-value {
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.stat-tile-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-tile-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.8;
}

.wdl-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wdl-row {
  display: grid;
  grid-template-columns: 80px 1fr 110px;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
}

.wdl-row-count {
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.result-bar {
  display: flex;
  gap: 2px;
  height: 16px;
  min-width: 60px;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 16px;
}

.result-bar span {
  min-width: 2px;
  overflow: hidden;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.result-bar span:first-child {
  border-radius: 4px 0 0 4px;
}

.result-bar span:last-child {
  border-radius: 0 4px 4px 0;
}

.result-bar span:only-child {
  border-radius: 4px;
}

.rb-win {
  background: #78b464;
  color: #14210f;
}

.rb-draw {
  background: #8a847d;
  color: #1e1c1a;
}

.rb-loss {
  background: #c8504a;
  color: #fff;
}

.chart-legend {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-wrap,
.map-wrap {
  position: relative;
}

.line-chart {
  display: block;
  width: 100%;
  height: auto;
}

.chart-grid {
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 1;
}

.chart-tick {
  fill: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-end-label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 600;
}

.chart-cursor {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
}

.chart-dot {
  stroke: var(--panel-bg-solid);
  stroke-width: 2;
}

.chart-hit {
  fill: transparent;
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 140px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-bg-solid);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  font-size: 0.75rem;
}

.chart-tooltip-title {
  display: flex;
  align-items: center;
  font-weight: 600;
  margin-bottom: 4px;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.chart-tooltip-row strong {
  margin-left: auto;
  color: var(--text);
  font-weight: 600;
}

.chart-tooltip-strong {
  color: var(--text);
  font-weight: 600;
}

.openings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.stats-table th {
  text-align: left;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--hairline);
}

.stats-table td {
  padding: 6px;
  border-bottom: 1px solid var(--hairline);
}

.stats-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stats-table th.num {
  text-align: right;
}

.stats-table caption {
  caption-side: bottom;
}

.stats-row-link {
  cursor: pointer;
}

.stats-row-link:hover,
.stats-row-link:focus-visible {
  background: var(--fill-hover);
}

.stats-opening {
  max-width: 220px;
}

.stats-opening span:first-child {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-eco {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.stats-bar-cell {
  width: 38%;
}

.stats-strong {
  font-weight: 600;
}

.stats-muted {
  color: var(--text-muted);
}

.stats-country {
  display: flex;
  align-items: center;
}

.score-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 6px;
}

.stats-more {
  font-size: 0.75rem;
  padding: 5px 12px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.world-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.world-map path {
  fill: #3a3733;
  stroke: var(--panel-bg-solid);
  stroke-width: 0.5;
}

.world-map path.hovered {
  stroke: var(--text);
  stroke-width: 1.2;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.map-legend-scale {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend-bar {
  display: inline-block;
  width: 140px;
  height: 9px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgb(230, 103, 103), rgb(138, 132, 125), rgb(57, 135, 229));
}

.map-legend-nodata {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 9px;
  border-radius: 2px;
  background: #3a3733;
}

.country-table-wrap {
  max-height: 460px;
  overflow-y: auto;
}

.match-cards {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.match-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: 14px;
  background: var(--fill);
}

.match-card-primary {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.match-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.match-name {
  display: flex;
  align-items: center;
  font-weight: 650;
  font-size: 1rem;
}

.match-card-primary .match-name {
  font-size: 1.15rem;
}

.match-score {
  font-size: 1.3rem;
  font-weight: 650;
  color: var(--accent);
}

.match-card-primary .match-score {
  font-size: 1.7rem;
}

.match-era,
.match-parts {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.match-parts {
  display: flex;
  gap: 12px;
}

.match-style {
  margin: 0;
  font-size: 0.85rem;
  font-style: italic;
}

.match-reasons {
  margin: 2px 0 0;
  padding-left: 18px;
  font-size: 0.78rem;
  line-height: 1.45;
}

.match-link {
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}

.match-link:hover {
  text-decoration: underline;
}

.trait-table-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.repertoire {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.repertoire-row,
.all-match-row {
  display: grid;
  grid-template-columns: 140px 1fr 40px;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  margin-bottom: 3px;
}

.repertoire-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--fill);
  overflow: hidden;
}

.repertoire-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: #3987e5;
}

.repertoire-pct {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.all-matches {
  margin-top: 14px;
  font-size: 0.8rem;
}

.all-matches summary {
  cursor: pointer;
  color: var(--text-muted);
}

.all-matches-list {
  margin-top: 8px;
  columns: 2;
  column-gap: 24px;
}

.all-match-row {
  grid-template-columns: 180px 1fr 40px;
  break-inside: avoid;
  color: var(--text);
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 6px;
}

.all-match-row:hover {
  background: var(--fill-hover);
}

.all-match-name {
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
}

.stats-caveat {
  margin: 12px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (max-width: 860px) {
  .openings-grid,
  .map-layout,
  .match-cards,
  .trait-table-wrap {
    grid-template-columns: 1fr;
  }

  .all-matches-list {
    columns: 1;
  }
}

@media (max-width: 640px) {
  .wdl-row {
    grid-template-columns: 64px 1fr 90px;
  }

  .repertoire-row,
  .all-match-row {
    grid-template-columns: 110px 1fr 40px;
  }
}

@media (max-width: 640px) {
  .nav-bar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .nav-tab {
    padding: 7px 12px;
  }
}
