:root {
  --bg: #1d2125;
  --panel: #2a3036;
  --text: #e8e6e3;
  --muted: #9aa3ab;
  --accent: #e0a84f;
  --light: #f0d9b5;
  --dark: #b58863;
  --size: min(calc(92vw - 32px), 76vh, 620px);
  --glyphs: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", "Arial Unicode MS", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body.size-large { --size: min(calc(92vw - 32px), 88vh, 900px); }
body.size-max { --size: min(calc(96vw - 40px), calc(100vh - 80px)); }
body.size-max header { display: none; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #30383f, var(--bg) 70%);
}

header { text-align: center; padding: 18px 12px 0; }
h1 { margin: 0; font-size: 2rem; letter-spacing: .5px; }
.tagline { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  padding: 16px;
}

/* ---------- Board ---------- */
.board-area { display: flex; flex-direction: column; gap: 6px; }
.board-wrap { display: flex; gap: 8px; }

.board {
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.square.light { background-color: var(--light); }
.square.dark { background-color: var(--dark); }
.square.last { background-image: linear-gradient(rgba(255, 220, 60, .42), rgba(255, 220, 60, .42)); }
.square.selected { background-image: linear-gradient(rgba(30, 120, 50, .55), rgba(30, 120, 50, .55)); }
.square.hint { background-image: linear-gradient(rgba(60, 140, 255, .55), rgba(60, 140, 255, .55)); }
.square.check { background-image: radial-gradient(circle, rgba(255, 30, 30, .95) 0%, rgba(230, 0, 0, .5) 45%, transparent 75%); }

.square.target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .22);
  pointer-events: none;
}
.square.capture::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  border: calc(var(--size) / 90) solid rgba(0, 0, 0, .28);
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 1;
  font-family: var(--glyphs);
  font-size: calc(var(--size) / 8 * .78);
  line-height: 1;
  transition: transform .12s;
}
.piece[draggable="true"] { cursor: grab; }
.square:hover .piece[draggable="true"] { transform: scale(1.08); }

.white {
  color: #fff;
  text-shadow: 1px 1px 0 #333, -1px -1px 0 #333, 1px -1px 0 #333, -1px 1px 0 #333, 0 3px 5px rgba(0, 0, 0, .4);
}
.black {
  color: #1b1b1b;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .3), 0 3px 5px rgba(0, 0, 0, .35);
}

.coord {
  position: absolute;
  font-size: calc(var(--size) / 46);
  font-weight: 700;
  pointer-events: none;
}
.coord.rank { top: 3px; left: 4px; }
.coord.file { bottom: 2px; right: 4px; }
.square.light .coord { color: var(--dark); }
.square.dark .coord { color: var(--light); }

/* ---------- 3D board ---------- */
.board3d {
  width: var(--size);
  height: var(--size);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  cursor: grab;
}
.board3d canvas { display: block; }
.board3d { position: relative; }
/* Cinema letterbox during a replay. */
.board3d::before, .board3d::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  z-index: 2;
  background: #000;
  transition: height .6s ease;
  pointer-events: none;
}
.board3d::before { top: 0; }
.board3d::after { bottom: 0; }
.board3d.replaying::before, .board3d.replaying::after { height: 10%; }
.replay-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 10%;
  padding: 0 12px;
  color: #eee;
  font-size: .9rem;
}
.replay-bar .rec { color: #ff4040; font-weight: 700; letter-spacing: 1px; animation: pulse 1.2s ease-in-out infinite; }
.replay-bar #replay-info { flex: 1; font-family: Consolas, monospace; }
.replay-bar button { padding: 4px 10px; font-size: .85rem; background: #3c444c; color: #eee; }
/* Full-screen replay: the page goes full screen and the 3D board covers it, so effect overlays stay visible. */
body.cinema .board3d {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}
body.cinema { overflow: hidden; }
body.cinema .replay-bar { font-size: 1.1rem; }

/* ---------- Evaluation bar ---------- */
.eval-bar {
  position: relative;
  width: 24px;
  height: var(--size);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: #3b3b3b;
  border-radius: 4px;
  overflow: hidden;
}
.eval-bar.flipped { justify-content: flex-start; }
.eval-fill { height: 50%; background: #f2f2f2; transition: height .5s ease; }
.eval-text {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #888;
}

/* ---------- Player rows ---------- */
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  padding-left: 32px;
}
.player-row .name { font-weight: 600; }
.player-row .captured { font-family: var(--glyphs); font-size: 20px; letter-spacing: -3px; }
.player-row .diff { color: var(--muted); font-size: .9rem; }

/* ---------- Side panel ---------- */
.panel { width: min(92vw, 340px); display: flex; flex-direction: column; gap: 14px; }

.status {
  padding: 14px 16px;
  border-radius: 10px;
  border-left: 4px solid var(--accent);
  background: var(--panel);
  font-size: 1.1rem;
  font-weight: 600;
}
.status.busy { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.controls, .card { padding: 12px 16px; border-radius: 10px; background: var(--panel); }
.controls { display: flex; flex-direction: column; gap: 10px; }

label { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); }

select {
  padding: 6px 8px;
  border: 1px solid #454d55;
  border-radius: 6px;
  background: #1d2226;
  color: var(--text);
  font: inherit;
}

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

button {
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #1f1f1f;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
button.secondary { background: #3c444c; color: var(--text); }
.view-switch { grid-column: 1 / -1; display: flex; }
.view-switch button { flex: 1; border-radius: 0; background: #3c444c; color: var(--text); }
.view-switch button:first-child { border-radius: 8px 0 0 8px; }
.view-switch button:last-child { border-radius: 0 8px 8px 0; }
.view-switch button + button { border-left: 1px solid #2a3036; }
.view-switch button.active { background: var(--accent); color: #1f1f1f; }
button.wide { grid-column: 1 / -1; }

.card h2 {
  margin: 0 0 8px;
  font-size: .85rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.moves {
  max-height: 190px;
  margin: 0;
  padding-left: 2.4em;
  overflow-y: auto;
  font-family: Consolas, "Courier New", monospace;
}
.moves li { padding: 1px 0; }
.moves li span { display: inline-block; min-width: 72px; }
.moves li::marker { color: var(--muted); }

.think-info { margin: 0; color: var(--muted); line-height: 1.6; white-space: pre-line; }

.import-row { display: flex; gap: 6px; margin-bottom: 8px; }
.import-row input, .import-row select {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #454d55;
  border-radius: 6px;
  background: #1d2226;
  color: var(--text);
  font: inherit;
}
.import-row input { flex: 1; }
.import-row button { padding: 6px 10px; font-size: .85rem; }
.imp-msg { margin: 0 0 6px; min-height: 1.2em; color: var(--muted); font-size: .85rem; }
.game-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.game-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid #353c43;
}
.game-list li > div { flex: 1; min-width: 0; }
.g-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-meta { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-list button { padding: 5px 9px; font-size: .8rem; white-space: nowrap; }
#paste-text {
  width: min(80vw, 560px);
  padding: 8px;
  border: 1px solid #454d55;
  border-radius: 6px;
  background: #1d2226;
  color: var(--text);
  font: .9rem Consolas, monospace;
}
#paste-dialog .buttons { margin-top: 10px; }

.about summary { cursor: pointer; font-weight: 600; }
.about p { color: var(--muted); line-height: 1.55; }
.about code { color: var(--accent); }

/* ---------- Battle effects ---------- */
.piece.floating {
  position: fixed;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: none;
}
.fx-spark, .fx-orb { position: fixed; z-index: 80; border-radius: 50%; pointer-events: none; }
.fx-flash { position: fixed; inset: 0; z-index: 85; background: #fff; pointer-events: none; }
.fx-lens { position: fixed; z-index: 86; overflow: hidden; pointer-events: none; }
.duel-bar {
  position: fixed;
  z-index: 88;
  transform: translate(-50%, -100%);
  pointer-events: none;
  color: #fff;
  font: 700 11px/1.2 "Segoe UI", sans-serif;
  text-align: center;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.duel-bar div { height: 8px; margin-top: 2px; overflow: hidden; border: 1px solid #000; border-radius: 4px; background: rgba(0, 0, 0, .6); }
.duel-bar i { display: block; width: 100%; height: 100%; background: #4caf50; transition: width .35s ease, background .35s; }
.lens-drop {
  position: absolute;
  background: radial-gradient(ellipse at 50% 45%, rgba(150, 0, 0, .9) 0 45%, rgba(115, 0, 0, .85) 75%, rgba(90, 0, 0, .35) 100%);
  box-shadow: inset 0 0 4px rgba(40, 0, 0, .7), inset 2px 2px 3px rgba(255, 120, 120, .25);
  filter: blur(.3px);
}
.lens-drip {
  position: absolute;
  border-radius: 0 0 50% 50%;
  background: linear-gradient(rgba(150, 0, 0, .88), rgba(110, 0, 0, .8));
}
.fx-blood {
  position: fixed;
  z-index: 82;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: inset -1px -2px 2px rgba(0, 0, 0, .45);
}
.fx-stain { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.fx-vignette {
  position: fixed;
  inset: 0;
  z-index: 84;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(170, 0, 0, .6) 100%);
}
.fx-layer { position: fixed; inset: 0; z-index: 75; width: 100vw; height: 100vh; pointer-events: none; }
.fx-layer .bolt {
  fill: none;
  stroke: #effcff;
  stroke-width: 4;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px #7fe3ff) drop-shadow(0 0 14px #3fb8ff);
}
.fx-layer .bolt.thin { stroke-width: 2; opacity: .7; }
.fx-word {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  white-space: nowrap;
  font-family: Impact, "Arial Black", sans-serif;
  font-weight: 900;
  letter-spacing: 1px;
  -webkit-text-stroke: 2px #111;
  text-shadow: 3px 3px 0 #111;
}

/* ---------- Dialogs ---------- */
dialog {
  padding: 20px 26px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin-top: 0; }

.promo-choices { display: flex; gap: 8px; }
.promo-choices button {
  width: 72px;
  height: 72px;
  padding: 0;
  background: var(--light);
  font-family: var(--glyphs);
  font-size: 52px;
  line-height: 1;
}
