* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  background: #000000;
  color: #ffffff;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.preview-badge {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 80;
  border: 1px solid #666666;
  background: #000000;
  color: #cfcfcf;
  padding: 5px 7px;
  font-size: 11px;
  line-height: 1;
}

button {
  border: 1px solid #ffffff;
  background: #000000;
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

button:hover,
button.active {
  background: #ffffff;
  color: #000000;
}

.app {
  height: 100vh;
  min-height: 0;
  width: min(100%, 1900px);
  margin: 0 auto;
  display: grid;
  grid-template-columns:
    clamp(190px, 15vw, 300px)
    minmax(620px, min(68vw, calc(100vh - 58px), 1000px))
    clamp(260px, 18vw, 360px);
  grid-template-areas: "moves board inference";
  justify-content: center;
  align-content: start;
  align-items: start;
  gap: clamp(40px, 3.5vw, 96px);
  padding: clamp(10px, 1.35vmin, 18px);
  overflow: hidden;
}

.board-stage {
  grid-area: board;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.board {
  grid-column: 1 / -1;
}

.status {
  grid-column: 1;
}

.controls {
  grid-column: 2;
}

.status,
.controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #d8d8d8;
  font-size: 13px;
  line-height: 1;
}

#wakeHint {
  color: #8f8f8f;
  font-size: 11px;
  white-space: nowrap;
}

.controls {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.controls button {
  min-width: 58px;
  height: 30px;
  padding: 0 9px;
}

.controls button.ready {
  border-color: #8cff8c;
  color: #8cff8c;
}

.controls button.ready:hover {
  background: #8cff8c;
  color: #000000;
}

#connectionStatus {
  color: #a8a8a8;
}

#connectionStatus.ready {
  color: #8cff8c;
}

#connectionStatus.waking {
  color: #ffffff;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 1px #000000, 0 0 0 5px #ffffff;
  background:
    conic-gradient(#f4f4f4 25%, #080808 0 50%, #f4f4f4 0 75%, #080808 0)
    0 0 / 25% 25%;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
}

.square.light {
  background: #f4f4f4;
}

.square.dark {
  background: #080808;
}

.square.last-move::before {
  content: "";
  position: absolute;
  inset: 0;
  outline: 3px solid #a7a7a7;
  outline-offset: -3px;
}

.square.selected {
  box-shadow: inset 0 0 0 4px #a7a7a7;
}

.square.target::after {
  content: "";
  position: absolute;
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #9b9b9b;
}

.square.capture::after {
  content: "";
  position: absolute;
  width: 76%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid #9b9b9b;
}

.square.king-check {
  box-shadow:
    inset 0 0 0 4px #ffffff,
    inset 0 0 0 8px #000000;
}

.square.king-checkmate {
  box-shadow:
    inset 0 0 0 4px #ffffff,
    inset 0 0 0 8px #000000,
    inset 0 0 0 12px #ffffff;
}

.square.king-checkmate::before {
  content: "";
  position: absolute;
  inset: 18%;
  border: 2px solid #ffffff;
  transform: rotate(45deg);
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 1;
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 1px 0 #000000) drop-shadow(0 0 1px #ffffff);
}

.black-piece {
  filter:
    drop-shadow(1px 0 0 #ffffff)
    drop-shadow(-1px 0 0 #ffffff)
    drop-shadow(0 1px 0 #ffffff)
    drop-shadow(0 -1px 0 #ffffff)
    drop-shadow(0 0 2px #ffffff);
}

.white-piece {
  filter:
    drop-shadow(1px 0 0 #000000)
    drop-shadow(-1px 0 0 #000000)
    drop-shadow(0 1px 0 #000000)
    drop-shadow(0 -1px 0 #000000);
}

.piece-fallback {
  display: grid;
  place-items: center;
  font-family: "Times New Roman", Georgia, serif;
  font-size: clamp(2rem, 8vw, 5rem);
  line-height: 1;
}

.coord {
  display: none;
}

.side-panel {
  width: 100%;
  height: min(calc(100vh - 58px), 920px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: 1px solid #2f2f2f;
  background: #050505;
  color: #f3f3f3;
  overflow: hidden;
}

.move-panel {
  grid-area: moves;
}

.prescience {
  grid-area: inference;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 14px 14px 6px;
}

.panel-tools {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.thought-indicator {
  min-width: 112px;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #343434;
  padding: 5px 7px;
  color: #777777;
  font-size: 12px;
  line-height: 1;
}

.thought-indicator em {
  font-style: italic;
  font-weight: 500;
}

.bulb-icon {
  position: relative;
  width: 15px;
  height: 15px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transform: translateY(-2px);
}

.bulb-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -7px;
  height: 5px;
  border-top: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  background: #050505;
}

.thought-indicator.active .bulb-icon::before {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  animation: bulb-pulse 680ms ease-in-out infinite alternate;
}

.thought-spiral {
  width: 13px;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-right-color: currentColor;
  border-radius: 50%;
  opacity: 0;
}

.thought-indicator.active {
  border-color: #ffffff;
  color: #ffffff;
}

.thought-indicator.active .bulb-icon {
  background: #ffffff;
  box-shadow: 0 0 12px #ffffff, 0 0 26px rgba(255, 255, 255, 0.55);
}

.thought-indicator.active .thought-spiral {
  opacity: 1;
  animation: spiral-spin 700ms linear infinite;
}

.thought-indicator.active em {
  font-weight: 800;
}

@keyframes spiral-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes bulb-pulse {
  from {
    opacity: 0.25;
    transform: scale(0.8);
  }
  to {
    opacity: 0.85;
    transform: scale(1.15);
  }
}

.kicker,
.section-label,
.metric span {
  color: #9f9f9f;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
}

.side-panel h1 {
  margin: 4px 0 0;
  font-size: clamp(18px, 1.4vw, 24px);
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0;
}

.move-panel h1 {
  font-size: clamp(17px, 1.1vw, 21px);
}

.prescience-state {
  min-width: 66px;
  border: 1px solid #505050;
  padding: 6px 8px;
  color: #d8d8d8;
  font-size: 12px;
  line-height: 1;
  text-align: center;
  display: none;
}

.prescience-state.has-step {
  display: block;
}

.prescience-state.thinking {
  border-color: #ffffff;
  color: #ffffff;
}

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

.model-block {
  display: grid;
  gap: 9px;
  min-height: 0;
  margin: 0 10px;
  padding: 10px;
  border: 1px solid #282828;
  background: #080808;
}

.prescience .model-block {
  flex: 1 1 auto;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.compact-block {
  flex: 0 0 auto;
}

.trace-block {
  flex: 1 1 auto;
}

.metric {
  min-width: 0;
  border: 1px solid #2f2f2f;
  padding: 9px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  font-weight: 650;
  line-height: 1;
}

.maps {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  gap: 8px;
  min-height: 0;
}

.mind-panel {
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  justify-items: center;
}

.section-label {
  margin-bottom: 4px;
}

.mind-panel .section-label {
  font-size: 11px;
  white-space: nowrap;
}

.mind-board {
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 1px solid #303030;
  overflow: hidden;
}

.prescience .mind-board {
  width: min(100%, clamp(118px, calc((100vh - 246px) / 3.35), 208px));
  align-self: center;
}

.mind-panel:nth-child(3) {
  grid-column: auto;
}

.mind-panel:nth-child(3) .mind-board {
  width: min(100%, clamp(118px, calc((100vh - 246px) / 3.35), 208px));
}

.mind-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #080808;
}

.mind-cell.light {
  background: #1d1d1d;
}

.mind-cell::after {
  content: "";
  position: absolute;
  inset: 12%;
  background: #ffffff;
  opacity: var(--heat, 0);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.85);
  transition: opacity 110ms ease;
}

.candidate-list,
.trace-list {
  display: grid;
  gap: 7px;
  min-height: 0;
}

.candidate-list {
  flex: 0 0 auto;
}

.trace-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 3px;
}

.candidate,
.trace-row {
  display: grid;
  gap: 5px;
  border: 1px solid #2a2a2a;
  padding: 6px;
}

.trace-row.active {
  border-color: #ffffff;
  background: #101010;
}

.result-burst {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  pointer-events: none;
  overflow: hidden;
}

.result-burst.show {
  display: block;
}

.game-over-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
}

.game-over-modal[hidden] {
  display: none;
}

.game-over-card {
  width: min(92vw, 360px);
  display: grid;
  gap: 12px;
  border: 2px solid #ffffff;
  background: #000000;
  padding: 18px;
  box-shadow: 0 0 0 1px #000000, 0 0 0 4px #ffffff;
}

.game-over-card h2 {
  margin: 0;
  font-size: clamp(30px, 5vw, 52px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0;
}

.game-over-card p {
  margin: 0;
  color: #d2d2d2;
  font-size: 14px;
  line-height: 1.35;
}

.game-over-card button {
  width: 100%;
  height: 38px;
  font-weight: 650;
}

.result-toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -50%) scale(0.82);
  border: 3px solid #ffffff;
  background: #000000;
  color: #ffffff;
  padding: 16px 24px;
  font-size: clamp(42px, 7vw, 112px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0;
  animation: result-pop 920ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.result-burst.lose .result-toast {
  top: 50%;
  border-width: 5px;
  animation: loser-pop 1100ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.confetti {
  position: absolute;
  top: -20px;
  left: var(--x);
  width: 8px;
  height: 16px;
  background: var(--shade);
  animation: confetti-fall var(--dur) linear var(--delay) both;
}

@keyframes result-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
  }
  18%,
  78% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes loser-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1) rotate(3deg);
  }
  48% {
    transform: translate(-50%, -50%) scale(0.98) rotate(-2deg);
  }
  78% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.22) rotate(0);
  }
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translateY(-20px) rotate(0deg);
  }
  8% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(110vh) rotate(var(--rot));
  }
}

.candidate-top,
.trace-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  line-height: 1;
}

.candidate strong,
.trace-row strong {
  font-weight: 650;
}

.candidate span,
.trace-row span {
  color: #b8b8b8;
}

.bar {
  height: 4px;
  background: #222222;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: calc(var(--bar, 0) * 100%);
  background: #ffffff;
}

.empty-panel {
  border: 1px solid #2a2a2a;
  padding: 12px;
  color: #9f9f9f;
  font-size: 13px;
  line-height: 1.35;
}

@media (max-width: 1180px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: minmax(0, min(96vw, 680px));
    grid-template-areas:
      "board"
      "moves"
      "inference";
    gap: 16px;
    padding: 12px;
    overflow: visible;
  }

  .status,
  .controls,
  .board {
    grid-column: 1;
    width: 100%;
  }

  .board-stage {
    grid-template-columns: 1fr;
  }

  .controls {
    justify-content: center;
  }

  .controls button {
    min-width: 56px;
  }

  .status {
    font-size: 12px;
  }

  .side-panel {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .trace-list {
    max-height: none;
  }
}

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

  .side-panel h1,
  .metric strong {
    font-size: 21px;
  }

  .side-panel {
    border-left: 0;
    border-right: 0;
  }

  .model-block {
    margin: 0 6px;
    padding: 8px;
  }
}
