:root {
  --bg: #0a0b14;
  --card: #121731;
  --card-edge: rgba(255, 255, 255, .08);
  --text: #eef3ff;
  --muted: #9aa5c4;
  --cyan: #67e8f9;
  --purple: #a78bfa;
  --pink: #f472b6;
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --light-square: #e4dffb;
  --dark-square: #8a7fd4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.glow {
  position: fixed; border-radius: 50%; filter: blur(90px); opacity: .3;
  pointer-events: none; z-index: 0;
}
.glow.g1 { width: 480px; height: 480px; background: #3b2f86; top: -160px; left: -120px; }
.glow.g2 { width: 420px; height: 420px; background: #0e7490; bottom: -140px; right: -100px; }

main {
  position: relative; z-index: 1;
  max-width: 1040px; margin: 0 auto;
  padding: clamp(18px, 4vw, 36px) clamp(16px, 4vw, 32px) 24px;
}

.back { color: var(--muted); text-decoration: none; font-weight: 700; font-size: .9rem; }
.back:hover { color: var(--cyan); }

header { margin: 18px 0 22px; }
h1 { font-size: clamp(2rem, 5vw, 2.8rem); font-weight: 900; letter-spacing: -.02em; }
h1 .grad {
  background: linear-gradient(92deg, var(--cyan) 0%, var(--purple) 50%, var(--pink) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
header p { color: var(--muted); margin-top: 6px; }

.layout {
  display: grid; gap: 22px;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 820px) { .layout { grid-template-columns: minmax(0, 1fr); } }

/* ---- board ---- */
.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1; width: 100%;
  border-radius: 14px; overflow: hidden;
  border: 1px solid var(--card-edge);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .5);
}

.square {
  position: relative; display: grid; place-items: center;
  border: 0; padding: 0; font: inherit; cursor: pointer; overflow: hidden;
}
.square:disabled { cursor: default; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square:focus-visible { outline: 3px solid var(--cyan); outline-offset: -3px; z-index: 2; }

.square::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.square.last::before { background: rgba(103, 232, 249, .38); }
.square.hint::before { background: rgba(52, 211, 153, .6); }
.square.selected::before { background: rgba(251, 191, 36, .6); }
.square.check::before { background: radial-gradient(circle, rgba(248, 113, 113, .95) 0%, rgba(248, 113, 113, .35) 55%, transparent 75%); }
.square.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: rgba(10, 11, 20, .35); pointer-events: none;
}
.square.capture::after {
  content: ""; position: absolute; inset: 6%; border-radius: 50%;
  border: 5px solid rgba(10, 11, 20, .35); pointer-events: none;
}

.piece {
  position: relative; z-index: 1; line-height: 1;
  font-size: min(8.5vw, 50px);
  font-family: "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
}
.piece.white { color: #fffdf8; text-shadow: 0 0 1px #0a0b14, 0 0 2px #0a0b14, 0 2px 3px rgba(0, 0, 0, .45); }
.piece.black { color: #151833; text-shadow: 0 1px 1px rgba(255, 255, 255, .25); }

.coord {
  position: absolute; z-index: 1; font-size: 10px; font-weight: 800; pointer-events: none;
}
.coord.file { right: 4px; bottom: 2px; }
.coord.rank { left: 4px; top: 2px; }
.light .coord { color: var(--dark-square); }
.dark .coord { color: var(--light-square); }

.status { margin-top: 14px; font-weight: 800; font-size: 1.05rem; min-height: 1.5em; }
.status.over { color: var(--gold); }

/* ---- side panel ---- */
.panel {
  background: linear-gradient(165deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .012) 45%), var(--card);
  border: 1px solid var(--card-edge); border-radius: 20px;
  padding: 20px;
}
.panel label, .panel h2 {
  display: block; margin: 16px 0 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.panel label:first-child { margin-top: 0; }

.panel select, .panel button {
  font: inherit; color: var(--text);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--card-edge); border-radius: 10px;
  padding: 9px 12px;
}
.panel select { width: 100%; }
.panel select option { background: var(--card); }
.panel button { cursor: pointer; font-weight: 700; }
.panel button:hover:not(:disabled) { border-color: rgba(255, 255, 255, .25); }
.panel button:disabled { opacity: .4; cursor: default; }
.panel button.primary {
  background: linear-gradient(92deg, var(--cyan), var(--purple));
  color: #0b1020; border: 0;
}
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

input[type=range] { width: 100%; accent-color: var(--purple); }
.level-label { margin-top: 4px; font-weight: 700; color: var(--purple); }

.muted { color: var(--muted); font-size: .9rem; }
.moves {
  max-height: 240px; overflow-y: auto; padding-left: 28px;
  font-variant-numeric: tabular-nums; font-size: .95rem; line-height: 1.7;
}
.moves li::marker { color: var(--muted); }
.moves span { display: inline-block; min-width: 70px; }

footer {
  position: relative; z-index: 1;
  text-align: center; padding: 26px 16px 34px;
  color: var(--muted); font-size: .85rem;
}
footer p { max-width: 640px; margin: 0 auto 6px; }
footer a { color: var(--cyan); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
