:root {
  color-scheme: dark;
  --ink: #f7f3e8;
  --muted: #aebdb3;
  --panel: rgb(18 26 23 / 72%);
  --panel-strong: rgb(12 19 17 / 86%);
  --line: rgb(255 255 255 / 16%);
  --green: #1d7d5d;
  --green-dark: #0b3f31;
  --board-green: #18a86f;
  --board-green-bright: #24c885;
  --board-green-deep: #087146;
  --mint: #82f0bb;
  --gold: #f4c66c;
  --rose: #ff6b8f;
  --cyan: #84ddff;
  --shadow: rgb(0 0 0 / 38%);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #07110f;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 78px;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgb(132 221 255 / 20%), transparent 28rem),
    radial-gradient(circle at 78% 22%, rgb(244 198 108 / 16%), transparent 24rem),
    linear-gradient(135deg, #07110f 0%, #13261f 44%, #0a1211 100%);
  font-family:
    "Space Grotesk", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgb(255 255 255 / 4%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(255 255 255 / 4%) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 42%, black, transparent 76%);
}

button,
select {
  font: inherit;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 38px));
  min-height: calc(100svh - 58px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 690px) 288px;
  gap: 18px;
  align-items: start;
  justify-content: center;
  padding: 14px 0 8px;
}

.shell.is-analyze-mode {
  width: min(1000px, calc(100vw - 56px));
  min-height: calc(100svh - 78px);
  grid-template-columns: minmax(0, 640px) minmax(300px, 340px);
  gap: 14px;
  align-content: center;
  align-items: stretch;
  justify-content: center;
  padding: 0;
}

.shell.is-analyze-mode .play-area,
.shell.is-analyze-mode .sidebar--analyze {
  align-self: stretch;
}

.shell.is-analyze-mode .play-area {
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.shell.is-analyze-mode .topbar {
  margin-bottom: 8px;
}

.shell.is-analyze-mode h1 {
  font-size: clamp(25px, 3.2vw, 37px);
}

.shell.is-analyze-mode .board-outer {
  flex: 1;
  min-height: 0;
  margin: 0;
  gap: 10px;
  align-items: center;
}

.shell.is-analyze-mode .board-wrap {
  width: min(100%, 620px, calc(100svh - 305px));
}

.ambient {
  position: fixed;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.72;
  animation: floatAmbient 9s ease-in-out infinite alternate;
}

.ambient-one {
  width: 180px;
  height: 180px;
  top: 8%;
  left: 12%;
  background: rgb(132 221 255 / 18%);
}

.ambient-two {
  width: 220px;
  height: 220px;
  right: 10%;
  bottom: 9%;
  background: rgb(130 240 187 / 14%);
  animation-delay: -3s;
}

.ambient-three {
  width: 150px;
  height: 150px;
  left: 48%;
  bottom: 15%;
  background: rgb(255 107 143 / 12%);
  animation-delay: -5s;
}

.play-area,
.sidebar {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgb(255 255 255 / 12%), transparent 34%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px var(--shadow), inset 0 1px 0 rgb(255 255 255 / 12%);
  backdrop-filter: blur(22px) saturate(140%);
  align-self: start;
}

.play-area {
  padding: 18px;
  transform-style: preserve-3d;
}

.play-area::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent, rgb(255 255 255 / 14%), transparent);
  transform: translateX(-120%);
  animation: panelSheen 7s ease-in-out infinite;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(27px, 3.8vw, 42px);
  line-height: 0.96;
  letter-spacing: 0;
  text-shadow: 0 10px 30px rgb(0 0 0 / 30%);
}

.topbar p {
  color: var(--muted);
  margin-top: 8px;
}

.brand-block h1 span {
  color: transparent;
  background: linear-gradient(90deg, var(--ink), var(--mint), var(--cyan), var(--ink));
  background-size: 240% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  animation: titleGlint 5s linear infinite;
}

.brand-block p {
  text-shadow: 0 0 18px rgb(130 240 187 / 24%);
}

.controls {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(255 255 255 / 9%);
  color: var(--ink);
}

.controls button {
  cursor: pointer;
}

.side-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(255 255 255 / 6%);
}

.side-picker button {
  display: flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 850;
  color: var(--muted);
}

.side-picker button.active {
  color: #06120f;
  background: linear-gradient(135deg, var(--mint), #42bf8b);
  box-shadow: 0 8px 22px rgb(61 205 137 / 22%);
}

.mini-disc {
  width: 12px;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgb(255 255 255 / 26%), 0 0 10px rgb(130 240 187 / 16%);
}

.mini-disc.black {
  background: #0b0e0d;
}

.mini-disc.white {
  background: #edf4e8;
}

.depth-picker {
  position: relative;
  min-width: 86px;
}

.control-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.depth-trigger {
  width: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-weight: 900;
  background: rgb(255 255 255 / 8%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 12%);
}

.chevron {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 180ms ease;
}

.depth-trigger.open .chevron {
  transform: rotate(225deg) translate(-2px, -2px);
}

.depth-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 156px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgb(130 240 187 / 20%);
  border-radius: 14px;
  background: rgb(7 17 15 / 88%);
  box-shadow: 0 18px 48px rgb(0 0 0 / 42%), 0 0 34px rgb(130 240 187 / 12%);
  backdrop-filter: blur(18px);
  animation: menuPop 180ms ease-out;
}

.sidebar .depth-menu {
  position: static;
  width: 100%;
  max-height: min(260px, 45svh);
  margin-top: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.depth-menu button {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 0 10px;
  text-align: left;
  border-radius: 10px;
  background: rgb(255 255 255 / 6%);
}

.depth-menu button.selected {
  color: #06120f;
  background: linear-gradient(135deg, var(--mint), var(--cyan));
}

.depth-menu small {
  color: inherit;
  opacity: 0.72;
}

.new-game-button {
  position: relative;
  padding: 0 17px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--mint), #38a978);
  border-color: rgb(130 240 187 / 44%);
  color: #06120f;
  font-weight: 900;
  box-shadow: 0 10px 24px rgb(61 205 137 / 22%);
}

.new-game-button::before {
  content: "";
  position: absolute;
}

.new-game-button span {
  position: relative;
  z-index: 1;
}

button:disabled {
  cursor: not-allowed;
}

.controls button:disabled,
.depth-trigger:disabled,
.side-picker button:disabled,
.arrow-button:disabled {
  opacity: 0.58;
}

.square:disabled {
  opacity: 1;
}

.board-outer {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
}

/* ── Eval bar ─────────────────────────────── */
.eval-bar-outer {
  position: relative;
  flex-shrink: 0;
  width: 32px;
  align-self: stretch;
}

.eval-bar-track {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow:
    0 8px 28px rgb(0 0 0 / 44%),
    0 0 16px rgb(130 240 187 / 8%),
    inset 0 1px 0 rgb(255 255 255 / 14%);
  transition: box-shadow 600ms ease;
}

/* Glassmorphism top-edge shine */
.eval-bar-track::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 32%), transparent);
  z-index: 3;
  pointer-events: none;
}

/* State-aware glow — colour shifts with who's winning */
.eval-bar-outer[data-eval="black"] .eval-bar-track {
  box-shadow:
    0 8px 32px rgb(0 0 0 / 54%),
    0 0 22px rgb(0 0 0 / 24%),
    inset 0 1px 0 rgb(255 255 255 / 14%);
}

.eval-bar-outer[data-eval="white"] .eval-bar-track {
  box-shadow:
    0 8px 28px rgb(0 0 0 / 38%),
    0 0 20px rgb(215 228 208 / 16%),
    inset 0 1px 0 rgb(255 255 255 / 18%);
}

.eval-bar-outer[data-eval="equal"] .eval-bar-track {
  box-shadow:
    0 8px 28px rgb(0 0 0 / 42%),
    0 0 18px rgb(130 240 187 / 16%),
    inset 0 1px 0 rgb(255 255 255 / 16%);
}

.eval-bar-black {
  flex-shrink: 0;
  height: var(--eval-black-pct);
  position: relative;
  background: linear-gradient(
    180deg,
    #2c3b36 0%,
    #141e1b 20%,
    #080e0c 55%,
    #030706 100%
  );
  transition: height 480ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Inset highlight at top of black section */
.eval-bar-black::after {
  content: "";
  position: absolute;
  top: 0;
  left: 14%;
  right: 14%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 24%), transparent);
  pointer-events: none;
}

.eval-bar-white {
  flex: 1;
  position: relative;
  background: linear-gradient(
    180deg,
    #eef5e9 0%,
    #d9e8cf 40%,
    #c1d4b6 100%
  );
}

/* Shadow at the black / white junction */
.eval-bar-white::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(180deg, rgb(0 0 0 / 24%), transparent);
  pointer-events: none;
}

.eval-bar-label {
  position: absolute;
  left: 50%;
  top: var(--eval-black-pct);
  z-index: 6;
  transform: translate(-50%, -50%);
  padding: 2px 5px;
  border-radius: 4px;
  background: rgb(4 11 9 / 84%);
  border: 1px solid rgb(130 240 187 / 32%);
  backdrop-filter: blur(10px);
  color: var(--mint);
  font-size: 9px;
  font-weight: 900;
  font-family: ui-monospace, "JetBrains Mono", "Space Mono", monospace;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 0 8px rgb(130 240 187 / 58%);
  box-shadow: 0 2px 10px rgb(0 0 0 / 52%), 0 0 12px rgb(130 240 187 / 14%);
  transition: top 480ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Laser separator line between black and white sections */
.eval-bar-separator {
  position: absolute;
  left: -4px;
  right: -4px;
  top: var(--eval-black-pct);
  height: 1.5px;
  z-index: 5;
  transform: translateY(-50%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgb(130 240 187 / 30%) 8%,
    rgb(255 255 255 / 88%) 28%,
    rgb(255 255 255 / 100%) 50%,
    rgb(255 255 255 / 88%) 72%,
    rgb(130 240 187 / 30%) 92%,
    transparent 100%
  );
  box-shadow:
    0 0 3px 1px rgb(255 255 255 / 70%),
    0 0 7px 3px rgb(130 240 187 / 55%),
    0 0 14px 6px rgb(130 240 187 / 30%),
    0 0 24px 10px rgb(130 240 187 / 14%);
  pointer-events: none;
  transition: top 480ms cubic-bezier(0.16, 1, 0.3, 1);
  animation: laserPulse 2.4s ease-in-out infinite;
}

@keyframes laserPulse {
  0%, 100% {
    opacity: 0.82;
    box-shadow:
      0 0 3px 1px rgb(255 255 255 / 65%),
      0 0 7px 3px rgb(130 240 187 / 45%),
      0 0 14px 6px rgb(130 240 187 / 24%),
      0 0 24px 10px rgb(130 240 187 / 10%);
  }
  50% {
    opacity: 1;
    box-shadow:
      0 0 4px 2px rgb(255 255 255 / 80%),
      0 0 9px 4px rgb(130 240 187 / 65%),
      0 0 18px 8px rgb(130 240 187 / 38%),
      0 0 30px 14px rgb(130 240 187 / 18%);
  }
}

.board-wrap {
  position: relative;
  z-index: 1;
  width: min(100%, 596px, calc(100svh - 318px));
  perspective: 1200px;
}

.files {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin: 0 38px;
  color: rgb(247 243 232 / 70%);
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.files-top {
  margin-bottom: 8px;
}

.files-bottom {
  margin-top: 8px;
}

.board-row-layout {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 24px;
  gap: 12px;
  align-items: stretch;
}

.ranks {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  height: 100%;
  min-height: 0;
  color: rgb(247 243 232 / 70%);
  font-weight: 800;
  text-align: center;
}

.ranks span {
  display: grid;
  place-items: center;
  min-height: 0;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border: 5px solid #06402a;
  border-radius: 18px;
  background: var(--board-green-deep);
  box-shadow:
    0 36px 70px rgb(0 0 0 / 42%),
    0 10px 0 #052718,
    inset 0 1px 0 rgb(255 255 255 / 20%),
    inset 0 0 48px rgb(36 200 133 / 28%),
    0 0 42px rgb(24 168 111 / 16%);
  transform: rotateX(9deg) rotateZ(-1deg);
  transform-style: preserve-3d;
  transition: transform 350ms ease, box-shadow 350ms ease;
}

.is-thinking .board {
  transform: rotateX(12deg) rotateZ(1deg) translateY(-4px);
  box-shadow:
    0 42px 90px rgb(0 0 0 / 48%),
    0 12px 0 #061e18,
    0 0 70px rgb(130 240 187 / 18%);
}

.board::after {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: 0;
  pointer-events: none;
  background: conic-gradient(from 140deg, transparent, rgb(130 240 187 / 8%), transparent, rgb(132 221 255 / 6%), transparent);
  mix-blend-mode: screen;
  opacity: 0.22;
  animation: boardAura 12s linear infinite;
}

.square {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid rgb(4 36 27 / 62%);
  border-radius: 0;
  background:
    radial-gradient(circle at 34% 24%, rgb(189 255 220 / 22%), transparent 25%),
    radial-gradient(circle at 78% 80%, rgb(4 85 49 / 22%), transparent 38%),
    linear-gradient(145deg, #31d08c 0%, var(--board-green) 52%, #0c8b55 100%);
  cursor: default;
  transform-style: preserve-3d;
}

.square.legal {
  cursor: pointer;
}

.square.legal:hover {
  background:
    radial-gradient(circle at 34% 24%, rgb(215 255 234 / 32%), transparent 28%),
    radial-gradient(circle at 78% 80%, rgb(4 85 49 / 18%), transparent 38%),
    linear-gradient(145deg, #45e99f 0%, var(--board-green-bright) 54%, #109a5f 100%);
}

.square.last {
  background:
    radial-gradient(circle at 34% 24%, rgb(255 226 139 / 34%), transparent 34%),
    radial-gradient(circle at 78% 80%, rgb(4 85 49 / 18%), transparent 38%),
    linear-gradient(145deg, #50d897 0%, #1fb978 54%, #0e8f57 100%);
}

.legal-orbit {
  position: absolute;
  z-index: 2;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgb(189 255 220 / 76%);
  box-shadow: 0 0 26px rgb(36 200 133 / 48%);
  animation: legalPulse 1.6s ease-in-out infinite;
}

.legal-orbit::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: rgb(208 255 228 / 72%);
}

.disc {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translateZ(28px);
  animation: discDrop 360ms cubic-bezier(0.2, 0.9, 0.2, 1.15);
}

.disc::after {
  content: "";
  position: absolute;
  inset: 12% 16% auto auto;
  width: 32%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgb(255 255 255 / 52%);
  filter: blur(2px);
}

.disc.black,
.score-disc.black {
  background:
    radial-gradient(circle at 31% 24%, #87948b 0%, #303b35 18%, transparent 32%),
    radial-gradient(circle at 68% 74%, #050806, #111715 52%, #000000 100%);
  box-shadow:
    inset 0 12px 18px rgb(255 255 255 / 22%),
    inset 0 -13px 22px rgb(0 0 0 / 70%),
    0 12px 18px rgb(0 0 0 / 42%),
    0 0 18px rgb(130 240 187 / 10%);
}

.disc.white,
.score-disc.white {
  background:
    radial-gradient(circle at 31% 23%, #ffffff 0%, #ffffff 18%, transparent 34%),
    radial-gradient(circle at 64% 78%, #d5dfd0, #fbfff7 56%, #edf8e8 100%);
  border: 1px solid rgb(255 255 255 / 86%);
  box-shadow:
    inset 0 12px 18px rgb(255 255 255 / 70%),
    inset 0 -13px 22px rgb(113 135 112 / 20%),
    0 12px 18px rgb(0 0 0 / 20%),
    0 0 20px rgb(255 255 255 / 12%);
}

.thinking-dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 4;
  display: grid;
  grid-template-columns: auto auto 120px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgb(130 240 187 / 24%);
  border-radius: 14px;
  background: rgb(7 17 15 / 76%);
  box-shadow: 0 18px 42px rgb(0 0 0 / 32%), inset 0 1px 0 rgb(255 255 255 / 12%);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.history-nav {
  position: relative;
  z-index: 3;
  width: min(100%, 500px);
  margin: 14px auto 0;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 10px;
  align-items: center;
}

.arrow-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  min-height: 42px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 25%, rgb(255 255 255 / 20%), transparent 28%),
    rgb(255 255 255 / 8%);
  box-shadow: 0 12px 28px rgb(0 0 0 / 28%), inset 0 1px 0 rgb(255 255 255 / 14%);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.arrow-button:not(:disabled):hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 18px 34px rgb(0 0 0 / 34%), 0 0 26px rgb(130 240 187 / 20%);
}

.arrow-button span {
  width: 13px;
  height: 13px;
  border-top: 3px solid var(--mint);
  border-left: 3px solid var(--mint);
  filter: drop-shadow(0 0 8px rgb(130 240 187 / 70%));
  animation: arrowPulse 1.5s ease-in-out infinite;
}

.arrow-button.left span {
  transform: rotate(-45deg) translate(2px, 2px);
}

.arrow-button.right span {
  transform: rotate(135deg) translate(2px, 2px);
}

.timeline {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(255 255 255 / 9%);
  box-shadow: inset 0 1px 4px rgb(0 0 0 / 42%);
}

.timeline span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), var(--cyan), var(--gold));
  box-shadow: 0 0 18px rgb(130 240 187 / 34%);
  transition: width 180ms ease;
}

.search-core {
  position: relative;
  width: 44px;
  aspect-ratio: 1;
}

.search-core span {
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-top-color: var(--mint);
  border-right-color: rgb(132 221 255 / 82%);
  border-radius: 50%;
  animation: searchSpin 1.1s linear infinite;
}

.search-core span:nth-child(2) {
  inset: 8px;
  border-top-color: var(--gold);
  animation-duration: 0.78s;
  animation-direction: reverse;
}

.search-core span:nth-child(3) {
  inset: 17px;
  background: var(--mint);
  border: 0;
  box-shadow: 0 0 24px var(--mint);
  animation: corePulse 0.9s ease-in-out infinite alternate;
}

.thinking-copy {
  display: grid;
  gap: 2px;
  white-space: nowrap;
}

.thinking-copy small {
  color: var(--muted);
}

.search-bars {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  align-items: end;
  height: 36px;
}

.search-bars span {
  display: block;
  min-height: 7px;
  border-radius: 999px;
  background: linear-gradient(var(--mint), var(--cyan));
  animation: barScan 0.9s ease-in-out infinite alternate;
}

.search-bars span:nth-child(2n) {
  animation-delay: -0.28s;
}

.search-bars span:nth-child(3n) {
  animation-delay: -0.52s;
}

.sidebar {
  padding: 18px;
  display: grid;
  gap: 14px;
  align-self: center;
}

.sidebar-glow {
  position: absolute;
  inset: -80px -80px auto auto;
  width: 180px;
  height: 180px;
  border-radius: 999px;
  background: rgb(130 240 187 / 14%);
  filter: blur(22px);
  pointer-events: none;
}

.sidebar h2 {
  position: relative;
  font-size: 23px;
  text-shadow: 0 0 18px rgb(130 240 187 / 22%);
}

.side-note {
  position: relative;
  color: var(--muted);
  font-weight: 750;
}

.sidebar h3 {
  position: relative;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score > div {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 6px 9px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgb(255 255 255 / 7%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 10%);
}

.score strong {
  font-size: 26px;
  line-height: 1;
}

.score small {
  grid-column: 2;
  color: var(--muted);
}

.score-disc {
  width: 20px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.moves {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.moves span {
  min-width: 40px;
  text-align: center;
  padding: 6px 9px;
  border-radius: 10px;
  background: rgb(255 255 255 / 8%);
  border: 1px solid var(--line);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 10%);
}

.error {
  color: var(--rose);
  font-weight: 800;
}

.thinking {
  color: var(--mint);
  font-weight: 800;
}

.engine-loader {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  align-items: center;
  padding: 11px;
  border: 1px solid rgb(130 240 187 / 22%);
  border-radius: 14px;
  background: rgb(130 240 187 / 8%);
}

.loader-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 52px;
  aspect-ratio: 1;
}

.loader-grid span {
  border-radius: 4px;
  background: rgb(130 240 187 / 20%);
  animation: nodeBlink 1.25s ease-in-out infinite;
}

.loader-grid span:nth-child(3n) {
  animation-delay: -0.35s;
}

.loader-grid span:nth-child(4n) {
  animation-delay: -0.65s;
}

.log {
  position: relative;
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.bottom-links {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: 100%;
  min-height: 58px;
  padding: 10px 16px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  pointer-events: none;
}

.bottom-link {
  pointer-events: auto;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  width: fit-content;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--mint);
  text-decoration: none;
  text-shadow: 0 0 14px rgb(130 240 187 / 22%);
  white-space: nowrap;
}

.bottom-link:hover {
  color: var(--cyan);
  background: rgb(130 240 187 / 7%);
  border-color: rgb(130 240 187 / 14%);
}

.footer-icon,
.bottom-link svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
  flex: 0 0 auto;
}

.source-link {
  justify-self: start;
}

.bottom-copy {
  justify-self: center;
  color: rgb(247 243 232 / 62%);
}

.bottom-copy strong {
  color: rgb(247 243 232 / 80%);
}

.site-link {
  justify-self: end;
}

/* ════════════════════════════════════════════════════
   ANALYZE MODE
   ════════════════════════════════════════════════════ */

/* Mode toggle — lives inside the sidebar, matches .side-picker style */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(255 255 255 / 6%);
}

.mode-toggle button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}

.mode-toggle button.active {
  color: #06120f;
  background: linear-gradient(135deg, var(--mint), #42bf8b);
  box-shadow: 0 8px 22px rgb(61 205 137 / 22%);
}

/* Compact analyze sidebar — overrides the default .sidebar */
.sidebar--analyze {
  gap: 7px;
  padding: 12px;
  align-self: start;
  min-width: 0;
  min-height: 0;
  align-content: start;
  overflow-x: hidden;
  overflow-y: auto;
}

.sidebar--analyze .mode-toggle button,
.sidebar--analyze .editor-tool-btn {
  min-height: 30px;
}

.sidebar--analyze .score > div {
  padding: 9px;
}

.sidebar--analyze .score strong {
  font-size: 23px;
}

.sidebar--analyze .run-analysis-btn,
.sidebar--analyze .play-from-here-btn {
  min-height: 36px;
}

.analyze-control-group {
  display: grid;
  gap: 5px;
}

.analyze-row {
  display: contents;
}

.analyze-divider {
  height: 1px;
  background: var(--line);
  margin: 2px 0;
}

.analyze-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.analyze-result-row .control-label {
  margin-bottom: 0;
  flex-shrink: 0;
}

.analyze-tip-inline {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  margin: 0;
}

/* Editor toolbar */
.editor-toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.editor-tool-section {
  display: grid;
  gap: 6px;
}

.editor-tool-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(255 255 255 / 6%);
}

.editor-tool-group.turn-group {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-tool-btn {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  min-width: 0;
  padding: 0 6px;
  border-radius: 8px;
  background: transparent;
  font-size: 12px;
  font-weight: 850;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.editor-tool-btn.active {
  color: #06120f;
  background: linear-gradient(135deg, var(--mint), #42bf8b);
  box-shadow: 0 8px 22px rgb(61 205 137 / 22%);
}

.erase-x {
  font-size: 11px;
  font-weight: 900;
  opacity: 0.7;
}

/* Editor board overrides */
.board.editor-mode {
  cursor: default;
}

.square.editor-sq {
  cursor: crosshair;
}

.square.editor-sq:hover {
  background:
    radial-gradient(circle at 34% 24%, rgb(215 255 234 / 28%), transparent 28%),
    radial-gradient(circle at 78% 80%, rgb(4 85 49 / 18%), transparent 38%),
    linear-gradient(145deg, #45e99f 0%, var(--board-green-bright) 54%, #109a5f 100%);
}

/* Best-move highlight — gold accent */
.square.editor-best-move {
  background:
    radial-gradient(circle at 34% 24%, rgb(244 198 108 / 44%), transparent 36%),
    radial-gradient(circle at 78% 80%, rgb(4 85 49 / 18%), transparent 38%),
    linear-gradient(145deg, #4ce89a 0%, #1db975 54%, #0e8f57 100%);
}

.best-move-ring {
  position: absolute;
  z-index: 2;
  width: 40%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgb(244 198 108 / 88%);
  box-shadow: 0 0 22px rgb(244 198 108 / 56%), inset 0 0 8px rgb(244 198 108 / 22%);
  animation: bestMovePulse 1.4s ease-in-out infinite;
}

@keyframes bestMovePulse {
  0%, 100% { transform: scale(0.85); opacity: 0.7; }
  50%       { transform: scale(1.15); opacity: 1;   }
}

/* Legal-move indicator in analyze mode — cyan instead of mint */
.square.editor-legal {
  cursor: default;
}

.legal-orbit.editor-legal-orbit {
  border-color: rgb(132 221 255 / 72%);
  box-shadow: 0 0 22px rgb(132 221 255 / 40%);
}

.legal-orbit.editor-legal-orbit::after {
  background: rgb(180 235 255 / 66%);
}

/* Analysis action buttons */
.analysis-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.analysis-primary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.analysis-secondary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.run-analysis-btn {
  position: relative;
  padding: 0 17px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--mint), #38a978);
  border-color: rgb(130 240 187 / 44%);
  color: #06120f;
  font-weight: 900;
  box-shadow: 0 10px 24px rgb(61 205 137 / 22%);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.run-analysis-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.play-from-here-btn {
  padding: 0 14px;
  background: linear-gradient(135deg, var(--cyan), #5ab8d8);
  border-color: rgb(132 221 255 / 40%);
  color: #06120f;
  font-weight: 900;
  box-shadow: 0 10px 24px rgb(132 221 255 / 18%);
  cursor: pointer;
}

.play-from-here-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.editor-util-btn {
  padding: 0 8px;
  background: rgb(255 255 255 / 7%);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
  border-radius: 10px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.editor-util-btn:hover:not(:disabled) {
  background: rgb(255 255 255 / 11%);
  color: var(--ink);
}

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

/* Spinner for run-analysis button */
.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgb(6 18 15 / 30%);
  border-top-color: #06120f;
  border-radius: 50%;
  animation: searchSpin 0.7s linear infinite;
  flex-shrink: 0;
}

/* Analyze sidebar */
.analysis-eval-text {
  font-size: 18px;
  font-weight: 900;
  color: var(--mint);
  text-shadow: 0 0 14px rgb(130 240 187 / 30%);
}

.analysis-best-move {
  display: flex;
  align-items: center;
  gap: 8px;
}

.best-move-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 6px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgb(244 198 108 / 22%), rgb(244 198 108 / 10%));
  border: 1px solid rgb(244 198 108 / 40%);
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
  text-shadow: 0 0 12px rgb(244 198 108 / 40%);
  box-shadow: 0 4px 14px rgb(244 198 108 / 14%);
}

.analysis-hint {
  color: var(--muted);
  font-size: 13px;
}

.move-best {
  background: rgb(244 198 108 / 16%) !important;
  border-color: rgb(244 198 108 / 36%) !important;
  color: var(--gold) !important;
}

.analyze-tip {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 13px;
  line-height: 1.6;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(255 255 255 / 4%);
}

.analyze-tip p {
  margin: 0;
}

@keyframes floatAmbient {
  from {
    transform: translate3d(-10px, 0, 0) scale(1);
  }
  to {
    transform: translate3d(16px, 20px, 0) scale(1.12);
  }
}

@keyframes panelSheen {
  0%,
  62% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(120%);
  }
}

@keyframes boardAura {
  to {
    transform: rotate(360deg);
  }
}

@keyframes legalPulse {
  0%,
  100% {
    transform: translateZ(20px) scale(0.82);
    opacity: 0.48;
  }
  50% {
    transform: translateZ(20px) scale(1.12);
    opacity: 1;
  }
}

@keyframes discDrop {
  from {
    transform: translateZ(80px) scale(0.7) rotateX(45deg);
    opacity: 0;
  }
  to {
    transform: translateZ(28px) scale(1) rotateX(0deg);
    opacity: 1;
  }
}

@keyframes searchSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes corePulse {
  to {
    transform: scale(1.38);
  }
}

@keyframes barScan {
  from {
    height: 8px;
    opacity: 0.42;
  }
  to {
    height: 34px;
    opacity: 1;
  }
}

@keyframes nodeBlink {
  0%,
  100% {
    background: rgb(130 240 187 / 16%);
    transform: scale(0.86);
  }
  50% {
    background: rgb(132 221 255 / 82%);
    transform: scale(1);
    box-shadow: 0 0 16px rgb(132 221 255 / 36%);
  }
}

@keyframes titleGlint {
  to {
    background-position: 240% 0;
  }
}

@keyframes menuPop {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes arrowPulse {
  0%,
  100% {
    opacity: 0.58;
  }
  50% {
    opacity: 1;
  }
}

.new-game-pulse .play-area::after {
  content: "";
  position: absolute;
  inset: -30%;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(circle, rgb(130 240 187 / 24%), transparent 34%);
  animation: newGameWave 850ms ease-out forwards;
}

.new-game-pulse .board {
  animation: boardReboot 850ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes newGameWave {
  from {
    opacity: 1;
    transform: scale(0.18) rotate(0deg);
  }
  to {
    opacity: 0;
    transform: scale(1.6) rotate(90deg);
  }
}

@keyframes boardReboot {
  0% {
    filter: brightness(1);
  }
  42% {
    filter: brightness(1.55) saturate(1.35);
  }
  100% {
    filter: brightness(1);
  }
}

@media (max-width: 980px) {
  html {
    min-height: 0;
  }

  body {
    min-height: 0;
    padding-bottom: 0;
  }

  .shell {
    grid-template-columns: 1fr;
    width: min(100vw - 28px, 730px);
    min-height: auto;
    padding: 8px 0 8px;
    gap: 10px;
  }

  .shell.is-analyze-mode {
    grid-template-columns: 1fr;
    width: min(100vw - 28px, 730px);
    min-height: auto;
    align-items: start;
    padding: 8px 0;
  }

  .shell.is-analyze-mode .play-area,
  .shell.is-analyze-mode .sidebar--analyze {
    align-self: start;
  }

  .shell.is-analyze-mode .play-area {
    display: block;
  }

  .shell.is-analyze-mode .board-outer {
    margin: 0;
  }

  .shell.is-analyze-mode .sidebar--analyze {
    align-content: start;
  }

  .play-area,
  .sidebar {
    border-radius: 16px;
  }

  .play-area {
    padding: 12px;
    overflow: visible;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .controls {
    width: 100%;
  }

  .controls button,
  .controls label,
  .depth-picker {
    flex: 1;
  }

  .board {
    transform: none;
    border-width: 4px;
    border-radius: 14px;
  }

  .is-thinking .board {
    transform: none;
  }

  .board-outer {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .eval-bar-outer {
    order: 2;
    width: min(100%, calc(100vw - 64px));
    height: 24px;
    align-self: auto;
  }

  .eval-bar-track {
    flex-direction: row;
    border-radius: 8px;
  }

  .eval-bar-black {
    height: 100%;
    width: var(--eval-black-pct);
    transition: width 480ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Horizontal mode: highlight on right edge of black, shadow on left of white */
  .eval-bar-black::after {
    inset: 14% 0 14% auto;
    width: 1px;
    height: auto;
    background: linear-gradient(180deg, transparent, rgb(255 255 255 / 22%), transparent);
  }

  .eval-bar-white::before {
    inset: 0 auto 0 0;
    width: 5px;
    height: auto;
    background: linear-gradient(90deg, rgb(0 0 0 / 22%), transparent);
  }

  .eval-bar-label {
    top: 50%;
    left: var(--eval-black-pct);
    transform: translate(-50%, -50%);
    transition: left 480ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Horizontal laser on mobile */
  .eval-bar-separator {
    left: var(--eval-black-pct);
    top: -4px;
    bottom: -4px;
    right: auto;
    width: 1.5px;
    height: auto;
    transform: translateX(-50%);
    background: linear-gradient(
      180deg,
      transparent 0%,
      rgb(130 240 187 / 30%) 8%,
      rgb(255 255 255 / 88%) 28%,
      rgb(255 255 255 / 100%) 50%,
      rgb(255 255 255 / 88%) 72%,
      rgb(130 240 187 / 30%) 92%,
      transparent 100%
    );
    box-shadow:
      0 0 3px 1px rgb(255 255 255 / 70%),
      0 0 7px 3px rgb(130 240 187 / 55%),
      0 0 14px 6px rgb(130 240 187 / 30%),
      0 0 24px 10px rgb(130 240 187 / 14%);
    transition: left 480ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .board-wrap {
    --mobile-rank-width: 14px;
    --mobile-board-gap: 4px;
    width: min(100%, calc(100vw - 64px));
    perspective: none;
  }

  .board-row-layout {
    grid-template-columns: var(--mobile-rank-width) minmax(0, 1fr) var(--mobile-rank-width);
    gap: var(--mobile-board-gap);
    width: 100%;
  }

  .files {
    margin-left: calc(var(--mobile-rank-width) + var(--mobile-board-gap));
    margin-right: calc(var(--mobile-rank-width) + var(--mobile-board-gap));
    font-size: 13px;
  }

  .ranks {
    font-size: 13px;
  }

  .board {
    width: 100%;
    min-width: 0;
  }

  .history-nav {
    grid-template-columns: 38px 1fr 38px;
    gap: 9px;
  }

  .arrow-button {
    width: 38px;
    min-height: 38px;
  }

  .thinking-dock {
    position: relative;
    left: auto;
    bottom: auto;
    grid-template-columns: auto 1fr;
    margin: 16px auto 0;
    transform: none;
  }

  .search-bars {
    grid-column: 1 / -1;
  }

  .bottom-links {
    position: static;
    min-height: 104px;
    padding: 10px 10px 14px;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
  }

  .bottom-link {
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .source-link {
    justify-self: start;
  }

  .site-link {
    justify-self: end;
  }

  .bottom-copy {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    order: 3;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100vw - 20px, 760px);
    padding-top: 6px;
  }

  .play-area {
    padding: 9px;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: clamp(25px, 9.5vw, 34px);
  }

  .controls {
    gap: 7px;
  }

  .side-picker {
    width: 100%;
  }

  .depth-picker {
    min-width: 78px;
  }

  .depth-trigger {
    width: 78px;
  }

  .new-game-button {
    flex: 1 1 130px;
  }

  .eval-bar-outer {
    width: min(100%, calc(100vw - 48px));
    height: 20px;
  }

  .board-wrap {
    --mobile-rank-width: 12px;
    --mobile-board-gap: 3px;
    width: min(100%, calc(100vw - 48px));
  }

  .files,
  .ranks {
    font-size: 11px;
  }

  .board {
    border-width: 3px;
    border-radius: 12px;
  }

  .history-nav {
    margin-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .eval-bar-separator {
    animation: none;
  }
}
