:root {
  --bg: #0b0c10;
  --surface: #18181b;
  --pop: #191a1f;
  --border: #2a2a30;
  --text: #efeff1;
  --text2: #d5d7dd;
  --muted: #8b8b99;
  --line: rgba(208, 217, 251, 0.12);
  --s1: rgba(208, 217, 251, 0.08);
  --s2: rgba(208, 217, 251, 0.12);
  --blue: #335fff;
  --green: #3fcf8e;
  --amber: #f0b429;
  --light: #e8edf5;
  --dark: #6b7385;
  --dur: 0.22s;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --shadow: 0 2px 4px -0.5px rgba(4, 4, 8, 0.25), 0 10px 20px -0.75px rgba(4, 4, 8, 0.25);
  --radius: 14px;
  --radius-sm: 10px;
  --eval-w: 18px;
  --board-gap: 12px;
  --board: min(64vh, calc(100vw - 4.5rem), 480px);
  --frame: calc(var(--eval-w) + var(--board-gap) + var(--board));
  --page: min(560px, calc(100% - 2rem));
  --pad-x: 20px;
  --pad-top: max(4.75rem, calc(env(safe-area-inset-top, 0px) + 3.5rem));
}

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

[hidden] {
  display: none !important;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(255, 255, 255, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

.page {
  width: var(--page);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--pad-top) 0 max(4rem, calc(env(safe-area-inset-bottom, 0px) + 2.5rem));
}

/* Center the side-pick start screen in the viewport */
.page:has(#hero:not([hidden])) {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: max(1.5rem, env(safe-area-inset-top, 0px));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
}

.hero {
  text-align: center;
  animation: rise 0.28s var(--ease);
  width: 100%;
}

.hero-title {
  margin: 0 0 22px;
  font-size: clamp(30px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.gate {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(var(--frame), 100%);
  margin: 0 auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.side-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--pop);
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    border-color var(--dur) var(--ease),
    background var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.side-btn:hover {
  background: var(--s1);
  border-color: rgba(255, 255, 255, 0.28);
}

.side-btn:active {
  transform: scale(0.97);
}

.swatch {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.swatch.white {
  background: #f4f4f5;
}

.swatch.black {
  background: #0e0e10;
}

.app {
  animation: rise 0.28s var(--ease);
}

.panel {
  width: min(var(--frame), 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
  justify-items: stretch;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.chip:hover {
  background: var(--s1);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--text);
}

.status {
  margin: 0;
  min-height: 2.6em;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--s1);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
  text-align: center;
}

.board-frame {
  display: grid;
  grid-template-columns: var(--eval-w) minmax(0, 1fr);
  gap: var(--board-gap);
  align-items: stretch;
  width: 100%;
}

.eval {
  position: relative;
  width: var(--eval-w);
  min-height: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #111217;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #f4f4f5;
  transition: height 0.4s var(--ease);
}

.eval-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.92);
  mix-blend-mode: difference;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  pointer-events: none;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: #121318;
  -webkit-tap-highlight-color: transparent;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  user-select: none;
  touch-action: none;
}

.board.dragging,
.board.dragging .sq {
  cursor: grabbing;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}

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

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

.sq.last-from::before,
.sq.last-to::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(51, 95, 255, 0.28);
  pointer-events: none;
}

.sq.selected {
  box-shadow: inset 0 0 0 999px rgba(51, 95, 255, 0.38);
}

.sq.suggest-from::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(63, 207, 142, 0.28);
  pointer-events: none;
}

.sq.suggest-to {
  z-index: 1;
}

.sq.suggest-to::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 16%;
  box-shadow: inset 0 0 0 3px rgba(63, 207, 142, 0.95);
  background: rgba(63, 207, 142, 0.22);
  pointer-events: none;
  animation: pulse-target 1.4s var(--ease) infinite;
}

.sq.legal::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(63, 207, 142, 0.55);
  pointer-events: none;
}

.sq.legal.capture::after {
  width: 82%;
  height: 82%;
  background: transparent;
  box-shadow: inset 0 0 0 0.24rem rgba(63, 207, 142, 0.55);
}

.sq .coord {
  position: absolute;
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
  line-height: 1;
}

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

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

.sq.light .coord {
  color: var(--dark);
}

.sq.dark .coord {
  color: var(--light);
}

.piece {
  width: 84%;
  height: 84%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 1;
  cursor: grab;
  touch-action: none;
  transition: transform var(--dur) var(--ease);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.22));
}

.sq.selected .piece {
  transform: translateY(-2%) scale(1.03);
}

.piece.is-source {
  opacity: 0.32;
}

.drag-ghost {
  position: fixed;
  width: calc(var(--board) / 8 * 0.9);
  height: calc(var(--board) / 8 * 0.9);
  margin: 0;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
  z-index: 1000;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
  transform: translate(-50%, -50%) scale(1.06);
  will-change: left, top;
}

.sq.drag-over.legal {
  box-shadow: inset 0 0 0 999px rgba(63, 207, 142, 0.35);
}

.sq.drag-over.legal.capture {
  box-shadow: inset 0 0 0 999px rgba(63, 207, 142, 0.42);
}

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.arrows path,
.arrows polygon {
  pointer-events: none;
}

.hints {
  list-style: none;
  margin: 0;
  display: grid;
  gap: 8px;
  width: 100%;
}

.hint {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.hint.hint-loading {
  grid-template-columns: 1fr;
  justify-items: center;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
}

.hint:hover {
  background: var(--s1);
  border-color: rgba(255, 255, 255, 0.22);
}

.hint .n {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #0b0c10;
  background: var(--green);
}

.hint .san {
  font-weight: 650;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint .score {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pulse-target {
  0%,
  100% {
    box-shadow: inset 0 0 0 3px rgba(63, 207, 142, 0.95);
    background: rgba(63, 207, 142, 0.18);
  }
  50% {
    box-shadow: inset 0 0 0 4px rgba(63, 207, 142, 1);
    background: rgba(63, 207, 142, 0.3);
  }
}

@media (max-width: 640px) {
  :root {
    --page: min(100%, calc(100% - 1.25rem));
    --board: min(100%, calc(100vw - 3.5rem));
    --eval-w: 16px;
    --board-gap: 10px;
    --pad-top: max(5rem, calc(env(safe-area-inset-top, 0px) + 3.75rem));
  }

  .gate {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .side-btn {
    min-height: 52px;
    font-size: 15px;
  }

  .panel {
    width: 100%;
    gap: 12px;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chip {
    height: 40px;
    font-size: 13px;
  }

  .status {
    font-size: 13px;
    min-height: 2.8em;
  }
}

@media (max-width: 380px) {
  :root {
    --eval-w: 14px;
    --board-gap: 8px;
  }

  .chip {
    padding: 0 8px;
    font-size: 12px;
  }
}
