:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --ink: #22201c;
  --muted: #6f6a61;
  --line: rgba(48, 43, 36, 0.14);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #fffdf8;
  --accent: #2e7d68;
  --accent-dark: #185844;
  --danger: #c44836;
  --gold: #d7a44a;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-shadow: rgba(38, 29, 18, 0.24);
  --square-size: min(8.8vh, 8.2vw);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(130deg, rgba(46, 125, 104, 0.11), transparent 32%),
    linear-gradient(310deg, rgba(215, 164, 74, 0.18), transparent 34%),
    var(--bg);
  color: var(--ink);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.app {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 310px;
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.panel,
.board-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 22px 55px rgba(56, 46, 32, 0.1);
  backdrop-filter: blur(18px);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  border-radius: 8px;
  padding: 18px;
}

.left-panel,
.right-panel {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: linear-gradient(150deg, var(--ink), #4b4135);
  color: #fff8eb;
  font-weight: 800;
  font-size: 1.3rem;
  box-shadow: inset 0 -8px 18px rgba(255, 255, 255, 0.1);
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 1.15rem;
  letter-spacing: 0;
}

.brand p,
.account-card p,
.login-note,
.section-label,
.stat-label,
.detail-line span {
  color: var(--muted);
  font-size: 0.78rem;
}

.section-label,
.stat-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 750;
}

.routine-list {
  display: grid;
  gap: 8px;
}

.account-card {
  display: grid;
  gap: 12px;
}

.account-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #fff8eb;
  background: var(--accent-dark);
  font-weight: 850;
}

.account-summary strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card p {
  overflow: hidden;
  margin-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-actions,
.login-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.routine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.48);
  color: var(--ink);
  border: 1px solid transparent;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.routine:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: rgba(46, 125, 104, 0.3);
}

.routine.active {
  background: var(--ink);
  color: #fff7ea;
  box-shadow: 0 12px 24px rgba(34, 32, 28, 0.16);
}

.routine:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.routine strong {
  font-size: 0.78rem;
}

.routine-chooser-panel {
  display: grid;
  gap: 8px;
}

.superchess-set-panel {
  display: grid;
  gap: 8px;
}

.superchess-set-panel[hidden] {
  display: none !important;
}

.set-select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: #fffdf8;
  font: inherit;
  font-weight: 750;
}

.mini-card,
.rating-card,
.details-card,
.engine-card {
  min-width: 0;
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid var(--line);
}

.theme-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.swatch {
  min-width: 0;
  height: 38px;
  border-radius: 8px;
  padding: 4px;
  background: transparent;
  border: 2px solid transparent;
}

.swatch span {
  display: block;
  height: 100%;
  border-radius: 6px;
  background:
    linear-gradient(90deg, var(--light) 0 50%, var(--dark) 50%),
    var(--light);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.swatch.active {
  border-color: var(--accent);
}

.compact-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.compact-stats.single-stat {
  grid-template-columns: 1fr;
}

.compact-stats strong {
  display: block;
  margin-top: 3px;
  font-size: 1.7rem;
}

.history-slot {
  display: flex;
  align-items: stretch;
}

.history-slot .history-button {
  min-height: 100%;
}

.board-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 14px;
}

.celebration-layer {
  position: absolute;
  inset: -18px;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
  border-radius: 8px;
  opacity: 0;
  mix-blend-mode: multiply;
}

.celebration-layer.playing {
  opacity: 1;
}

.firework-dot,
.firework-ring {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.firework-dot {
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.96) 0 18%, var(--color) 22% 58%, transparent 62%);
  box-shadow: 0 0 14px var(--color), 0 0 28px rgba(255, 255, 255, 0.28);
  transform: translate(-50%, -50%) scale(0.35);
  animation: firework-dot 1200ms cubic-bezier(0.16, 0.84, 0.24, 1) forwards;
}

.firework-ring {
  width: var(--size);
  height: var(--size);
  border: 2px solid var(--color);
  border-radius: 50%;
  box-shadow: 0 0 22px var(--color);
  transform: translate(-50%, -50%) scale(0.12);
  animation: firework-ring 1150ms ease-out forwards;
}

@keyframes firework-dot {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25);
  }

  18% {
    opacity: 0.95;
  }

  72% {
    opacity: 0.8;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(var(--dx), var(--dy)) scale(0.82);
  }
}

@keyframes firework-ring {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.12);
  }

  16% {
    opacity: 0.48;
  }

  72% {
    opacity: 0.34;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.9);
  }
}

.board-card {
  position: relative;
  z-index: 1;
  width: min(100%, 820px);
  border-radius: 8px;
}

.board-card {
  padding: 14px;
  background: rgba(255, 253, 248, 0.84);
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.history-button,
.external-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #eee6d9;
  text-decoration: none;
  border: 1px solid rgba(48, 43, 36, 0.11);
  transition:
    transform 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.icon-button:hover,
.history-button:hover,
.external-link:hover {
  transform: translateY(-1px);
  background: #e5dccd;
}

.icon-button.primary {
  color: white;
  background: var(--accent);
}

.icon-button.primary:hover {
  background: var(--accent-dark);
}

.icon-button:disabled {
  opacity: 0.48;
  transform: none;
}

.board-wrap {
  position: relative;
  width: min(74vh, 74vw, 720px);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 8px;
  box-shadow:
    0 22px 42px var(--board-shadow),
    0 0 0 8px rgba(66, 50, 30, 0.12);
  overflow: hidden;
  background: var(--board-dark);
}

.board-start-button {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  min-width: 154px;
  min-height: 58px;
  border: 1px solid rgba(255, 248, 235, 0.44);
  border-radius: 8px;
  padding: 0 28px;
  color: #fff8eb;
  background: linear-gradient(145deg, var(--accent), var(--accent-dark));
  box-shadow:
    0 18px 42px rgba(24, 88, 68, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  font-size: 1.02rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease;
}

.board-start-button:hover {
  box-shadow:
    0 22px 48px rgba(24, 88, 68, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transform: translate(-50%, calc(-50% - 2px));
}

.board-start-button[hidden] {
  display: none !important;
}

.chessground-board {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  --cg-light: #f0d9b5;
  --cg-dark: #b58863;
}

.chessground-board cg-container,
.chessground-board cg-board {
  border-radius: inherit;
  overflow: hidden;
}

.chessground-board coords coord {
  opacity: 1;
  font-weight: 850;
}

.chessground-board cg-container coords coord.coord-light {
  color: rgba(65, 45, 28, 0.9) !important;
  text-shadow: 0 1px 1px rgba(255, 247, 229, 0.66);
}

.chessground-board cg-container coords coord.coord-dark {
  color: rgba(255, 244, 221, 0.94) !important;
  text-shadow: 0 1px 2px rgba(42, 30, 18, 0.58);
}

.chessground-board cg-container coords.ranks coord.coord-light {
  color: rgba(255, 244, 221, 0.94) !important;
  text-shadow: 0 1px 2px rgba(42, 30, 18, 0.58);
}

.chessground-board cg-container coords.ranks coord.coord-dark {
  color: rgba(65, 45, 28, 0.9) !important;
  text-shadow: 0 1px 1px rgba(255, 247, 229, 0.66);
}

.chessground-board.green-board {
  --cg-light: #eeeed2;
  --cg-dark: #769656;
}

.chessground-board.blue-board {
  --cg-light: #d9e4f5;
  --cg-dark: #6682a4;
}

.chessground-board.slate-board {
  --cg-light: #d8d2c3;
  --cg-dark: #6f7564;
}

.chessground-board.green-board cg-board,
.chessground-board.blue-board cg-board,
.chessground-board.slate-board cg-board {
  background-color: var(--cg-light);
  background-image: conic-gradient(
    var(--cg-dark) 90deg,
    var(--cg-light) 90deg 180deg,
    var(--cg-dark) 180deg 270deg,
    var(--cg-light) 270deg
  );
  background-size: 25% 25%;
}

.chessground-board cg-board square.last-move {
  background-color: rgba(155, 199, 0, 0.41);
}

.chessground-board svg.cg-shapes {
  overflow: visible;
}

.move-banner {
  min-height: 58px;
  margin-top: 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 9px 13px;
  background: rgba(46, 125, 104, 0.1);
  color: var(--accent-dark);
  font-weight: 750;
}

.move-banner > strong {
  display: block;
  font-size: 0.9rem;
}

.move-context {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  color: rgba(24, 88, 68, 0.82);
  font-size: 0.78rem;
  font-weight: 750;
}

.move-context[hidden] {
  display: none;
}

.move-banner.wrong {
  color: #852717;
  background: rgba(196, 72, 54, 0.12);
}

.move-banner.correct {
  color: var(--accent-dark);
  background: rgba(46, 125, 104, 0.14);
}

.rating-card {
  background: var(--ink);
  color: #fff8eb;
}

.rating-card .section-label {
  color: rgba(255, 248, 235, 0.66);
}

.estimate-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-top: 8px;
}

.estimate-row strong {
  font-size: 3rem;
  line-height: 0.95;
}

.estimate-row span {
  color: rgba(255, 248, 235, 0.72);
  font-weight: 750;
}

.range-meter {
  position: relative;
  height: 8px;
  margin-top: 18px;
  border-radius: 999px;
  background: rgba(255, 248, 235, 0.18);
  overflow: hidden;
}

.range-meter span {
  position: absolute;
  top: 0;
  bottom: 0;
}

#rangeLow {
  left: 0;
  background: rgba(255, 248, 235, 0.28);
}

#rangeMid {
  background: var(--gold);
}

#rangeHigh {
  right: 0;
  background: rgba(255, 248, 235, 0.28);
}

.details-card {
  display: grid;
  gap: 10px;
  overflow: hidden;
}

.detail-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(48, 43, 36, 0.09);
  padding-bottom: 8px;
}

.details-card .detail-line[hidden] {
  display: none !important;
}

.detail-line strong {
  min-width: 0;
  max-width: 66%;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.detail-value {
  min-width: 0;
  max-width: 66%;
}

.details-card.superchess-details .detail-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}

.details-card.superchess-details .detail-line strong,
.details-card.superchess-details .detail-value {
  max-width: 100%;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.castle-rights {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 6px;
}

.castle-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid rgba(48, 43, 36, 0.14);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}

.castle-pill.available {
  color: #0f4b39;
  border-color: rgba(46, 125, 104, 0.28);
  background: rgba(46, 125, 104, 0.14);
}

.castle-pill.unavailable {
  color: #8b2e1d;
  border-color: rgba(196, 72, 54, 0.24);
  background: rgba(196, 72, 54, 0.1);
}

.external-link {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.engine-card {
  min-height: 332px;
}

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

.engine-table,
.history-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.engine-table {
  margin-top: 12px;
  font-size: 0.82rem;
}

.engine-table th,
.engine-table td,
.history-table th,
.history-table td {
  overflow: hidden;
  padding: 7px 5px;
  border-bottom: 1px solid rgba(48, 43, 36, 0.09);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.engine-table th,
.history-table th {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.engine-table th:first-child,
.engine-table td:first-child,
.history-table th:first-child,
.history-table td:first-child {
  text-align: left;
}

.engine-table th:nth-child(1),
.engine-table td:nth-child(1) {
  width: 50px;
}

.engine-table th:nth-child(2),
.engine-table td:nth-child(2) {
  text-align: left;
}

.engine-table tr.chosen td {
  color: var(--accent-dark);
  background: rgba(46, 125, 104, 0.11);
  font-weight: 850;
}

.engine-table tr:last-child td,
.history-table tr:last-child td,
.detail-line:last-of-type {
  border-bottom: 0;
}

.history-dialog,
.login-dialog {
  width: min(980px, calc(100vw - 30px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel-solid);
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(34, 32, 28, 0.22);
}

.login-dialog {
  width: min(640px, calc(100vw - 30px));
}

.history-dialog::backdrop,
.login-dialog::backdrop {
  background: rgba(34, 32, 28, 0.34);
  backdrop-filter: blur(4px);
}

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

.login-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 248, 235, 0.42);
}

.login-note {
  margin-top: 10px;
}

.google-login-button {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf8;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.google-login-button span {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fffdf8;
  background: var(--ink);
  font-size: 0.88rem;
  font-weight: 900;
}

.google-login-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.local-login input {
  width: 100%;
  min-height: 42px;
  margin: 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fffdf8;
  font: inherit;
}

.history-table {
  margin-top: 14px;
  font-size: 0.86rem;
}

.history-table th:nth-child(1),
.history-table td:nth-child(1) {
  width: 78px;
}

.history-table th:nth-child(2),
.history-table td:nth-child(2) {
  width: 96px;
  text-align: left;
}

.history-table th:nth-child(3),
.history-table td:nth-child(3) {
  width: 220px;
  text-align: left;
}

.history-table th:nth-child(4),
.history-table td:nth-child(4),
.history-table th:nth-child(5),
.history-table td:nth-child(5) {
  width: 88px;
}

.history-table th:nth-child(6),
.history-table td:nth-child(6) {
  width: 92px;
  text-align: center;
}

.analysis-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 8px;
  padding: 0 9px;
  color: var(--accent-dark);
  background: rgba(46, 125, 104, 0.12);
  font-size: 0.75rem;
  font-weight: 850;
  text-decoration: none;
}

.result-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 24px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 850;
}

.result-pill.correct {
  color: #0f4b39;
  background: rgba(46, 125, 104, 0.18);
}

.result-pill.wrong {
  color: #8b2e1d;
  background: rgba(196, 72, 54, 0.16);
}

.result-pill.neutral {
  color: #72551d;
  background: rgba(214, 170, 77, 0.2);
}

.history-button {
  width: 100%;
}

.history-button.subtle {
  color: var(--muted);
  background: rgba(238, 230, 217, 0.56);
}

body.theme-green {
  --board-light: #eeeed2;
  --board-dark: #769656;
  --board-shadow: rgba(43, 72, 30, 0.22);
}

body.theme-blue {
  --board-light: #d9e4f5;
  --board-dark: #6682a4;
  --board-shadow: rgba(42, 61, 89, 0.22);
}

body.theme-slate {
  --board-light: #d8d2c3;
  --board-dark: #6f7564;
  --board-shadow: rgba(48, 54, 43, 0.22);
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 230px minmax(360px, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .engine-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app {
    display: flex;
    flex-direction: column;
    min-height: auto;
    padding: 12px;
    gap: 12px;
  }

  .left-panel,
  .right-panel {
    position: static;
    height: auto;
  }

  .left-panel {
    order: 2;
  }

  .board-stage {
    order: 1;
  }

  .celebration-layer {
    inset: 0;
  }

  .right-panel {
    order: 3;
    display: flex;
  }

  .routine-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .login-grid {
    grid-template-columns: 1fr;
  }

  .board-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .board-wrap {
    width: 100%;
    box-shadow:
      0 16px 34px var(--board-shadow),
      0 0 0 5px rgba(66, 50, 30, 0.1);
  }

  .history-dialog {
    padding: 12px;
  }

  .history-table {
    font-size: 0.78rem;
  }
}
