/* game.css — board stage, quantum pieces, rail panels, modals
   ------------------------------------------------------------------
   The board is the brightest object on the page (the "specimen stage");
   the rail is a quiet instrument column. Violet appears ONLY on ghosts
   and superposition UI.                                               */

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: var(--s-8);
  align-items: start;
}

/* ---------- Board stage ---------- */

.board-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  min-width: 0;
}

.board-frame {
  position: relative;
  padding: 26px;                 /* room for engraved coordinates */
  background: linear-gradient(180deg, var(--surface-3), var(--board-rim));
  border: 1px solid var(--line-2);
  border-radius: var(--r-3);
  box-shadow: var(--sh-board);
  transition: box-shadow var(--t-med) var(--ease);
}

/* Opponent-view mode: the frame cools into violet — you're not here, they are */
.board-frame.oppview {
  box-shadow: 0 0 0 1px rgba(169,142,247,0.45), 0 0 46px var(--violet-soft), var(--sh-board);
}

.oppview-banner {
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 14px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(169,142,247,0.5);
  background: #191527;
  color: var(--violet-hot);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 5;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  /* 104px = page padding (2x24) + frame padding (2x26) + frame border (2x1) */
  width: min(640px, calc(100vw - 104px), calc(100vh - 210px));
  aspect-ratio: 1;
  border-radius: var(--r-1);
  overflow: hidden;
  outline: 1px solid rgba(0,0,0,0.55);
}

/* Engraved coordinates on the frame */
.coord-rail {
  position: absolute;
  display: flex;
  justify-content: space-around;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ink-mute);
  user-select: none;
}
.coord-rail.files { left: 26px; right: 26px; bottom: 6px; }
.coord-rail.ranks { top: 26px; bottom: 26px; left: 7px; flex-direction: column; align-items: center; }
.coord-rail span { flex: 1; display: flex; align-items: center; justify-content: center; }

/* ---------- Squares ---------- */

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* keeps piece auras/glows from bleeding onto neighboring squares */
}
.square.light { background: var(--sq-light); }
.square.dark  { background: var(--sq-dark); }

/* Layered indicators use inset box-shadows so they never shift layout */
.square.hl-last { box-shadow: inset 0 0 0 100vmax var(--sq-last); }
.square.hl-selected { box-shadow: inset 0 0 0 3px var(--sq-select); }
.square.hl-check { box-shadow: inset 0 0 0 3px var(--sq-check); }

.square.hl-legal::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--sq-legal);
  pointer-events: none;
}
/* Legal destination that holds a visible enemy piece → capture ring */
.square.hl-legal.has-piece::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 3px solid var(--sq-legal);
}
/* Legal destination holding only a ghost → violet-tinged speculative ring */
.square.hl-legal.has-ghost:not(.has-piece)::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 3px dashed var(--ghost-halo);
}

/* Speculative hint (§10): possibly legal — a hidden piece may block the
   attack on your king. Worth attempting; the referee decides. */
.square.hl-spec::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 88%;
  height: 88%;
  border-radius: 50%;
  background: transparent;
  border: 3px dashed var(--violet);
  opacity: 0.75;
  pointer-events: none;
}

/* Ghost halo on the square itself — static; motion lives on the piece aura only */
.square.has-ghost {
  background-image: radial-gradient(circle at 50% 50%, var(--ghost-halo), transparent 72%);
}

/* ---------- Pieces ---------- */

.piece-stack {
  position: relative;
  width: 82%;
  height: 82%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Soft plinth — pieces sit on the stone, not float on it */
.piece-stack::before {
  content: '';
  position: absolute;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
  width: 74%;
  height: 20%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.piece-stack--white::before {
  background: var(--piece-plinth-white);
}
.piece-stack--black::before {
  background: var(--piece-plinth-black);
}
.square.light .piece-stack--black::before {
  width: 58%;
  height: 14%;
  opacity: 0.45;
}
.square.dark .piece-stack--black::before {
  background: var(--piece-plinth-black-dark);
  opacity: 0.85;
}

.piece-stack .piece {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.piece {
  pointer-events: none;
}

.square.light .piece-stack--white .piece { filter: var(--piece-shadow-white-light); }
.square.dark  .piece-stack--white .piece { filter: var(--piece-shadow-white-dark); }
.square.light .piece-stack--black .piece { filter: var(--piece-shadow-black-light); }
.square.dark  .piece-stack--black .piece { filter: var(--piece-shadow-black-dark); }

/* Quantum pieces: identical rendering to certain pieces + violet aura behind.
   Uses alternate direction (expand → contract → expand) so the loop never
   resets — that reset was the visible "boom" jump at the end of each cycle. */
.piece-stack--ghost {
  z-index: 1;
}
.piece-stack--ghost::after {
  content: '';
  position: absolute;
  inset: -6%;
  z-index: 0;
  border-radius: 50%;
  background: var(--ghost-back-glow);
  box-shadow: var(--ghost-aura-shadow);
  pointer-events: none;
  transform-origin: center;
  animation: quantum-glow var(--t-glow) ease-in-out var(--ghost-phase, 0s) infinite alternate;
}
.piece-stack--ghost::before { z-index: 1; }
.piece-stack--ghost .piece { z-index: 2; }

@keyframes quantum-glow {
  from { opacity: 0.48; transform: scale(0.99); }
  to   { opacity: 0.88; transform: scale(1.015); }
}

/* Measurement pulse: violet possibility resolving into amber fact */
.square.pulse-measure::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: 2px;
  animation: measure 0.7s var(--ease-out);
  opacity: 0;
}
@keyframes measure {
  0%   { box-shadow: inset 0 0 0 4px var(--violet), 0 0 18px var(--violet-glow); opacity: 1; }
  55%  { box-shadow: inset 0 0 0 4px var(--amber), 0 0 22px var(--amber-glow); opacity: 1; }
  100% { box-shadow: inset 0 0 0 4px transparent; opacity: 0; }
}

/* A possibility was ruled out here: brief violet dissolve */
.square.ghost-dissolve::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, var(--violet-glow), transparent 70%);
  animation: ghost-dissolve 0.9s var(--ease-out);
  opacity: 0;
}
@keyframes ghost-dissolve {
  0%   { opacity: 0.95; transform: scale(1); filter: blur(0); }
  100% { opacity: 0; transform: scale(1.5); filter: blur(4px); }
}

/* Move animation: FLIP slide from the previous square */
.piece-stack.piece-sliding {
  transition: transform 0.28s var(--ease-out);
  z-index: 6;
}

/* A ghost that just appeared: condense out of nothing */
.piece-stack.ghost-enter {
  animation: ghost-enter 0.45s var(--ease-out);
}
@keyframes ghost-enter {
  from { opacity: 0; transform: scale(0.6); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- Announcer: engine explanations over the board ---------- */

#qc-announcer {
  position: absolute;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  width: min(92%, 560px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
  z-index: 20;
}

.qc-banner {
  max-width: 100%;
  padding: 9px 18px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(169,142,247,0.55);
  background: rgba(19, 15, 32, 0.92);
  color: var(--violet-hot);
  font-size: 13.5px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 6px 26px rgba(0,0,0,0.55), 0 0 22px var(--violet-soft);
  backdrop-filter: blur(4px);
  animation: qc-banner-in 0.32s var(--ease-out);
}
.qc-banner.leaving {
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
  opacity: 0;
  transform: translateY(6px);
}
.qc-banner--collapse {
  border-color: rgba(226,177,102,0.6);
  background: rgba(32, 24, 12, 0.92);
  color: var(--amber-hot);
  box-shadow: 0 6px 26px rgba(0,0,0,0.55), 0 0 22px var(--amber-soft);
}
.qc-banner--exposed {
  border-color: rgba(221,107,92,0.55);
  color: #f0b3a9;
}
@keyframes qc-banner-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Quantum log ---------- */

.quantum-log-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.quantum-log {
  max-height: 210px;
  overflow-y: auto;
  padding: var(--s-2) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  line-height: 1.45;
}
.quantum-log .empty { color: var(--ink-mute); padding: var(--s-2) 0; }
.qlog-item { display: flex; gap: var(--s-2); color: var(--ink-dim); }
.qlog-n {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  flex-shrink: 0;
  min-width: 22px;
  padding-top: 1px;
}
.qlog-collapse .qlog-text { color: var(--amber); }
.qlog-exposed  .qlog-text { color: var(--red); }
.qlog-measure  .qlog-text { color: var(--ink); }
.qlog-prune    .qlog-text,
.qlog-spread   .qlog-text { color: var(--violet); opacity: 0.9; }

/* ---------- Board footer ---------- */

.board-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
  width: 100%;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-dim);
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 34px;
  height: 19px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  position: relative;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.toggle input:checked + .toggle-track {
  background: var(--violet-soft);
  border-color: var(--violet);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(15px);
  background: var(--violet-hot);
}
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ---------- Rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}

.player-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  transition: border-color var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease);
}
.player-card.is-turn {
  border-color: var(--amber-deep);
  box-shadow: 0 0 0 1px var(--amber-deep), 0 0 24px rgba(226,177,102,0.09);
}

.player-line {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-2);
  flex-shrink: 0;
}
.is-turn .turn-dot {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
  animation: dot-breathe 1.8s var(--ease) infinite;
}
@keyframes dot-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

.player-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-color {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.captures {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  min-height: 20px;
}
.captures img { width: 20px; height: 20px; opacity: 0.85; }
.captures .none { color: var(--ink-mute); font-size: 11.5px; font-family: var(--font-mono); }

/* Status */
.game-status {
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink-dim);
  text-align: center;
}
.game-status.your-turn { color: var(--amber-hot); border-color: var(--amber-deep); }
.game-status.in-check  { color: var(--red); border-color: rgba(221,107,92,0.5); }
.game-status.game-over { color: var(--ink); }

/* Move list */
.move-list-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 120px;
}
.move-list-head {
  padding: var(--s-2) var(--s-4);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--line);
}
.move-list {
  flex: 1;
  max-height: 300px;
  overflow-y: auto;
  padding: var(--s-2) var(--s-4);
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-content: start;
  column-gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.move-list .ply-num { color: var(--ink-mute); padding: 3px 0; }
.move-list .ply { color: var(--ink); padding: 3px 0; white-space: nowrap; }
.move-list .ply.hidden-move { color: var(--violet); }
.move-list .ply.check { color: var(--red); }
.move-list .empty { grid-column: 1 / -1; color: var(--ink-mute); font-size: 12px; padding: var(--s-2) 0; }

/* Controls */
.game-controls {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.game-controls .btn-row { display: flex; gap: var(--s-2); }
.game-controls .btn-row button { flex: 1; }

#draw-offer-ui {
  border: 1px solid rgba(226,177,102,0.35);
  border-radius: var(--r-2);
  background: var(--amber-soft);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  font-size: 13px;
}
#draw-offer-ui .btn-row { display: flex; gap: var(--s-2); }
#draw-offer-ui .btn-row button { flex: 1; }
.hidden { display: none !important; }

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 8, 7, 0.72);
  backdrop-filter: blur(3px);
  z-index: 80;
}
.modal-content {
  background: linear-gradient(180deg, var(--surface-3), var(--surface));
  border: 1px solid var(--line-2);
  border-radius: var(--r-3);
  box-shadow: var(--sh-2);
  padding: var(--s-8);
  text-align: center;
  max-width: min(400px, calc(100vw - 32px));
  animation: modal-in var(--t-med) var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.modal-content h3 {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: var(--s-4);
}

.promo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.promo-buttons button { font-size: 15px; padding: 12px; }

.outcome {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 40px;
  line-height: 1.1;
}
.outcome.win  { color: var(--amber-hot); }
.outcome.loss { color: var(--red); }
.outcome.draw { color: var(--ink-dim); }
.reason {
  margin-top: var(--s-2);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.modal-actions {
  margin-top: var(--s-6);
  display: flex;
  gap: var(--s-2);
  justify-content: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .game-shell { grid-template-columns: 1fr; gap: var(--s-5); }
  .rail { order: 2; }
  .board-zone { order: 1; }
  /* The frame must fit the viewport WITH its own chrome:
     74px = page padding (2x16) + frame padding (2x20) + border (2x1). */
  .board-frame { padding: 20px; }
  .coord-rail.files { left: 20px; right: 20px; bottom: 3px; }
  .coord-rail.ranks { top: 20px; bottom: 20px; left: 4px; }
  .board { width: min(560px, calc(100vw - 74px), calc(100vh - 210px)); }
  .move-list { max-height: 200px; }
}
