:root {
  --bg-0: #0b1220;
  --bg-1: #0f1d35;
  --ink: #e9f0ff;
  --muted: #a9b7d6;
  --line: rgba(189, 206, 243, 0.16);
  --glass: rgba(14, 23, 40, 0.72);
  --glass-2: rgba(17, 29, 50, 0.76);
  --accent: #f59e0b;
  --accent-2: #fb923c;
  --primary: #22c55e;
  --primary-2: #16a34a;
  --danger: #ef4444;
  --board-dark: #805a3b;
  --board-light: #efe2c6;
  --square-outline: rgba(255, 255, 255, 0.1);
  --select: rgba(34, 197, 94, 0.45);
  --target: rgba(59, 130, 246, 0.5);
  --last: rgba(245, 158, 11, 0.35);
  --check: rgba(239, 68, 68, 0.5);
  --shadow: 0 24px 60px rgba(2, 7, 23, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(34, 197, 94, 0.12), transparent 36%),
    radial-gradient(circle at 88% 20%, rgba(59, 130, 246, 0.16), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(245, 158, 11, 0.14), transparent 44%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(360px, 1fr);
  gap: 18px;
  padding: 16px;
}

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 20px;
  backdrop-filter: blur(12px);
}

.glass-sub {
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.side-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hero {
  padding-bottom: 4px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.76rem;
}

.hero h1 {
  margin: 6px 0 6px;
  font-size: clamp(1.9rem, 3vw, 2.5rem);
  line-height: 0.95;
}

.hero-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.mode-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.22);
}

.mode-btn.is-active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(251, 146, 60, 0.18));
  border-color: rgba(245, 158, 11, 0.4);
}

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

.stat-card {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-card.wide {
  grid-column: 1 / -1;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 4px;
}

.stat-card strong {
  display: block;
  font-size: 1rem;
}

.stat-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.control-group {
  padding: 12px;
}

.group-head h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.field span {
  font-size: 0.84rem;
  color: var(--muted);
}

select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  color: var(--ink);
  padding: 8px 10px;
}

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

.actions-row.single-row {
  grid-template-columns: 1fr;
  margin-top: 8px;
}

.btn {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover {
  border-color: rgba(255, 255, 255, 0.24);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: rgba(34, 197, 94, 0.35);
  color: #04110a;
}

.hint-line {
  margin: 8px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.4;
}

.mini-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.mini-stat {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.025);
}

.mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.mini-stat strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
}

.ai-progress-wrap {
  margin-top: 10px;
}

.ai-progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.ai-progress-bar {
  width: 36%;
  height: 100%;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.25), rgba(34, 197, 94, 0.85), rgba(59, 130, 246, 0.25));
  transform: translateX(-120%);
  opacity: 0;
}

.ai-progress-track.is-thinking .ai-progress-bar {
  opacity: 1;
  animation: ai-indeterminate 900ms linear infinite;
}

@keyframes ai-indeterminate {
  from {
    transform: translateX(-120%);
  }
  to {
    transform: translateX(340%);
  }
}

.lesson-note {
  margin-top: 8px;
  min-height: 72px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #dbe8ff;
  line-height: 1.45;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.error-banner {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  font-size: 0.9rem;
}

.board-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.board-shell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
    rgba(12, 18, 32, 0.7);
  box-shadow: var(--shadow);
}

.move-anim-layer {
  position: absolute;
  inset: 10px;
  pointer-events: none;
  z-index: 3;
}

.move-anim-piece {
  position: absolute;
  width: var(--size, 48px);
  height: var(--size, 48px);
  display: grid;
  place-items: center;
  font-size: calc(var(--size, 48px) * 0.75);
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
  transform: translate(var(--from-x, 0px), var(--from-y, 0px)) scale(0.96);
  transition: transform 170ms ease-out, opacity 170ms ease-out;
  opacity: 0.95;
}

.move-anim-piece.is-enter {
  transform: translate(var(--to-x, 0px), var(--to-y, 0px)) scale(1);
  opacity: 0;
}

.board {
  width: min(78vh, 100%, 820px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 18px 40px rgba(0, 0, 0, 0.35);
}

.sq {
  position: relative;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  font-size: clamp(1.7rem, 4vw, 3.2rem);
  line-height: 1;
  display: grid;
  place-items: center;
  color: #101010;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

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

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

.sq::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--square-outline);
  pointer-events: none;
}

.sq.is-selected::before,
.sq.is-target::before,
.sq.is-last::before,
.sq.is-check::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sq.is-selected::before {
  background: var(--select);
}

.sq.is-target::before {
  background: radial-gradient(circle, rgba(59, 130, 246, 0.7) 0 18%, transparent 20%);
}

.sq.is-last::before {
  background: var(--last);
}

.sq.is-check::before {
  background: var(--check);
}

.sq .coord-file,
.sq .coord-rank {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 700;
  opacity: 0.78;
  text-transform: lowercase;
}

.sq .coord-file {
  right: 4px;
  bottom: 3px;
}

.sq .coord-rank {
  left: 4px;
  top: 3px;
}

.sq[disabled] {
  cursor: default;
}

.moves-panel {
  padding: 12px;
}

.promotion-picker {
  position: absolute;
  inset: auto 18px 18px auto;
  width: min(88vw, 280px);
  padding: 12px;
  z-index: 4;
}

.promotion-picker h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.promo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.promo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-weight: 700;
}

.promo-btn:hover {
  border-color: rgba(255, 255, 255, 0.24);
}

.promo-glyph {
  display: inline-grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  font-size: 1.2rem;
}

.moves-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.moves-head h2 {
  margin: 0;
  font-size: 1rem;
}

.moves-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.moves-table-wrap {
  margin-top: 8px;
  max-height: 30vh;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.moves-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.moves-table th,
.moves-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
}

.moves-table th {
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.92);
  color: var(--muted);
  font-weight: 700;
  z-index: 1;
}

.moves-table tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .board-stage {
    order: -1;
  }

  .board {
    width: min(92vw, 720px);
  }
}

@media (max-width: 680px) {
  .mode-switch,
  .actions-row {
    grid-template-columns: 1fr;
  }

  .mini-stats-grid {
    grid-template-columns: 1fr;
  }

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

  .stat-card.wide {
    grid-column: auto;
  }

  .sq {
    font-size: clamp(1.35rem, 9vw, 2.5rem);
  }

  .moves-table-wrap {
    max-height: 24vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mode-btn {
    transition: none;
  }
}
