:root {
  --bg: #0f0f11;
  --raise: #17171b;
  --sunk: #121216;
  --line: #26262c;
  --line-soft: #1e1e23;
  --ink: #e8e8eb;
  --muted: #8d8d96;
  --faint: #62626b;

  --light: #f0d9b5;
  --dark: #b58863;
  --freeze: #45a9e8;
  --jump: #dfa03f;
  --select: #6fc46f;

  --sq: clamp(42px, calc((100dvh - 106px) / 8), 92px);
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.02em; }

a { color: var(--muted); text-underline-offset: 3px; }
a:hover { color: var(--ink); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.note {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.5;
}

.note.error { color: #e08d8d; }
.note:empty { display: none; }

/* ---------- controls ---------- */

button, select, textarea, input {
  color: var(--ink);
  font: inherit;
}

button {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}

button:not(.sq):hover:not(:disabled) { border-color: #3a3a43; background: #1c1c21; }
button:disabled { opacity: .38; cursor: not-allowed; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible,
summary:focus-visible {
  outline: 1px solid #6f7280;
  outline-offset: 2px;
}

button.primary {
  border-color: #e6e6ea;
  background: #e6e6ea;
  color: #101013;
}

button.primary:hover:not(:disabled) { border-color: #fff; background: #fff; }
button.ghost { border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { border-color: var(--line); color: var(--ink); }

button.arm-freeze { border-color: var(--freeze); color: #b7e0fb; }
button.arm-jump { border-color: var(--jump); color: #f2d19a; }

select, textarea, input[type="number"], input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sunk);
  font-size: 13px;
}

input[type="text"] {
  color: #f4f4f7;
  caret-color: #f4f4f7;
}

input[type="text"]::placeholder {
  color: #777782;
  opacity: 1;
}

textarea {
  min-height: 54px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.field { display: grid; gap: 6px; }

.field > span,
.field-inline > span {
  color: var(--muted);
  font-size: 12px;
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-inline select { width: auto; min-width: 130px; }
.field-inline input[type="number"] { width: 130px; }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.row { display: flex; flex-wrap: wrap; gap: 8px; }

/* switch */

.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch input:disabled { cursor: not-allowed; }

.track {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--sunk);
  transition: background .15s, border-color .15s;
}

.track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #6a6a74;
  transition: transform .15s, background .15s;
}

.switch input:checked + .track { border-color: #3f7a58; background: #1d4230; }
.switch input:checked + .track i { background: #8ce0ae; transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 1px solid #6f7280; outline-offset: 2px; }

.switch-copy { min-width: 0; }
.switch-copy b { display: block; font-size: 13px; font-weight: 500; }
.switch-copy small { display: block; color: var(--faint); font-size: 11.5px; line-height: 1.45; }

/* disclosure */

.fold, .rules-fold { border-top: 1px solid var(--line-soft); }

.fold > summary, .rules-fold > summary {
  padding: 13px 0;
  color: var(--muted);
  font-size: 13px;
  list-style: none;
  cursor: pointer;
}

.fold > summary::-webkit-details-marker, .rules-fold > summary::-webkit-details-marker { display: none; }

.fold > summary::before, .rules-fold > summary::before {
  content: "+";
  display: inline-block;
  width: 14px;
  color: var(--faint);
}

.fold[open] > summary, .rules-fold[open] > summary { color: var(--ink); }
.fold[open] > summary::before, .rules-fold[open] > summary::before { content: "−"; }
.fold > summary:hover, .rules-fold > summary:hover { color: var(--ink); }

.fold-body {
  display: grid;
  gap: 12px;
  justify-items: start;
  padding: 2px 0 18px;
}

.fold-body > *:not(button):not(kbd) { justify-self: stretch; }

/* ---------- home ---------- */

.home {
  display: grid;
  align-content: center;
  min-height: 100dvh;
  padding: 40px 24px 48px;
}

.column {
  display: grid;
  gap: 22px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.topbar,
.guide-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.mark {
  color: var(--faint);
  font-size: 12.5px;
  letter-spacing: .01em;
  text-decoration: none;
}

.mark:hover { color: var(--muted); }

.site-links {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12.5px;
}

.site-links a { text-decoration: none; }

.intro { margin-top: 4px; }
.intro h1 { font-size: 30px; }
.intro p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

.block { display: grid; gap: 10px; }

.custom-setup {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.arena-side-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.arena-side {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--sunk);
}

.arena-side > b {
  font-size: 13px;
  font-weight: 600;
}

.arena-side .note { min-height: 0; }

.player-name-field {
  gap: 5px;
  padding: 8px;
  border: 1px solid #2d2d35;
  border-radius: 7px;
  background: #19191e;
  transition: border-color .12s, background .12s;
}

.player-name-field > span {
  color: #b0b0ba;
  font-size: 11.5px;
  font-weight: 550;
}

.player-name-field input {
  border-color: #3a3a44;
  background: #101014;
  box-shadow: inset 0 1px 0 #ffffff08;
}

.player-name-field:focus-within {
  border-color: #555561;
  background: #1c1c22;
}

.player-name-field input:focus {
  border-color: #6f7280;
}

.arena-position {
  display: grid;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.custom-position-actions { margin-top: 2px; }

.count-grid {
  display: grid;
  grid-template-columns: 58px 78px 78px;
  gap: 6px 8px;
  align-items: center;
  justify-content: start;
}

.count-grid > span,
.count-grid label { color: var(--muted); font-size: 12px; }
.count-grid > span:nth-child(2),
.count-grid > span:nth-child(3) { text-align: center; }
.count-grid input { text-align: center; }

.sides { grid-template-columns: repeat(3, 1fr); }

.learn-card {
  display: grid;
  gap: 11px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(135deg, #17171b 0%, #121216 100%);
}

.eyebrow {
  margin: 0;
  color: var(--jump);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.learn-card h2 { font-size: 20px; }

.wheel-card {
  border-color: #33333b;
  background:
    radial-gradient(circle at 100% 0%, #e0663f26 0, transparent 42%),
    radial-gradient(circle at 0% 100%, #45a9e822 0, transparent 40%),
    linear-gradient(135deg, #17171b 0%, #121216 100%);
}

.wheel-card .eyebrow { color: #e0663f; }
.wheel-card-link span { margin-left: 6px; color: #8a4a2a; }
.learn-card > p:not(.eyebrow) { margin: 0; color: var(--muted); }

.quick-rules {
  display: grid;
  gap: 7px;
  margin: 2px 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
}

.quick-rules b { color: var(--ink); font-weight: 550; }

.learn-link {
  width: fit-content;
  color: var(--ink);
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
}

.learn-link span { color: var(--jump); }
.learn-link:hover { color: #fff; }

.site-footer {
  display: grid;
  gap: 7px;
}

.site-footer nav { display: flex; gap: 8px; align-items: center; }
.site-footer p { max-width: 500px; margin: 0; color: var(--faint); font-size: 11px; }

/* ---------- how-to guide ---------- */

.guide-page { min-height: 100dvh; }

.guide-topbar {
  width: min(100% - 36px, 820px);
  margin: 0 auto;
  padding: 26px 0;
}

.play-link { color: var(--ink); }

.guide-shell {
  display: grid;
  gap: 54px;
  width: min(100% - 36px, 760px);
  margin: 46px auto 72px;
}

.guide-hero {
  display: grid;
  gap: 16px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--line);
}

.guide-hero h1 { max-width: 680px; font-size: clamp(38px, 8vw, 62px); line-height: 1.04; }

.guide-lede {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.65;
}

.guide-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 11px 16px;
  border: 1px solid #e6e6ea;
  border-radius: 7px;
  background: #e6e6ea;
  color: #101013;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.guide-cta:hover { border-color: #fff; background: #fff; color: #101013; }

.guide-section { display: grid; gap: 16px; scroll-margin-top: 28px; }
.guide-section h2 { font-size: 26px; }
.guide-section > p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.7; }

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

.spell-card {
  display: flex;
  gap: 14px;
  min-height: 176px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
}

.spell-card h3,
.guide-steps h3 { margin: 0; font-size: 16px; }

.spell-card p,
.guide-steps p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.spell-icon {
  display: grid;
  flex: 0 0 34px;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 18px;
}

.freeze-card .spell-icon { background: #45a9e822; color: #8ed2fc; }
.jump-card .spell-icon { background: #dfa03f22; color: #f1c477; }

.guide-steps {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-steps li {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  padding: 18px 0;
  border-top: 1px solid var(--line-soft);
}

.guide-steps li > span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
}

.strategy-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.strategy-list strong { color: var(--ink); font-weight: 550; }

.practice-card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
}

.practice-card > div { display: grid; gap: 8px; }
.practice-card h2 { font-size: 22px; }
.practice-card p:not(.eyebrow) { margin: 0; color: var(--muted); }

.guide-footer {
  display: grid;
  gap: 8px;
  width: min(100% - 36px, 820px);
  margin: 0 auto;
  padding: 24px 0 40px;
  border-top: 1px solid var(--line-soft);
  color: var(--faint);
  font-size: 11px;
}

.guide-footer nav { display: flex; gap: 8px; align-items: center; }
.guide-footer p { max-width: 620px; margin: 0; }

.sides button {
  display: grid;
  gap: 1px;
  padding: 11px 13px;
  text-align: left;
  font-size: 14px;
}

.sides small { color: var(--faint); font-size: 11px; }
.sides .primary small { color: #55555f; }

.ratings { gap: 16px; }

.rating-card { display: grid; gap: 2px; }

.rating-card > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}

.rating-card > header span { font-size: 13px; }
.rating-card > header small { color: var(--faint); font-size: 11.5px; }

.rating-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}

.rating-row > div { display: grid; min-width: 0; gap: 1px; }
.rating-row b { font-size: 13px; font-weight: 500; }
.rating-row small { color: var(--faint); font-size: 11px; line-height: 1.4; }

.rating-row > strong {
  font: 500 19px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: -.02em;
}

.rating-rows-unavailable > div {
  display: grid;
  gap: 2px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}

.rating-rows-unavailable b { font-size: 13px; font-weight: 500; }
.rating-rows-unavailable small { color: var(--faint); font-size: 11.5px; }

.rating-card > .note { padding-top: 7px; }

.foot { padding-top: 4px; font-size: 12px; }
.foot a { color: var(--faint); text-decoration: none; }
.foot a:hover { color: var(--muted); }

/* ---------- game ---------- */

.game {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 28px;
  min-height: 100dvh;
  padding: 24px;
}

.board-shell {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
}

/* Keep the board in view while long side content (history, analysis lines)
   scrolls. Only applies when the board and sidebar sit side by side. */
@media (min-width: 1001px) {
  .board-shell {
    position: sticky;
    top: 24px;
  }
}

#board {
  display: grid;
  grid-template: repeat(8, var(--sq)) / repeat(8, var(--sq));
  overflow: hidden;
  border-radius: 3px;
  /* Pieces are dragged with pointer events; the board itself never pans. */
  touch-action: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--sq);
  height: var(--sq);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  cursor: pointer;
  user-select: none;
}

.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq:focus-visible { z-index: 8; outline: 3px solid #fff; outline-offset: -3px; }

.coord {
  position: absolute;
  z-index: 7;
  color: #241d16;
  font-size: 9px;
  font-weight: 600;
  opacity: .5;
  pointer-events: none;
}

.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }

.piece {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

.pc-wK { background-image: url("./assets/pieces/wK.svg"); }
.pc-wQ { background-image: url("./assets/pieces/wQ.svg"); }
.pc-wR { background-image: url("./assets/pieces/wR.svg"); }
.pc-wB { background-image: url("./assets/pieces/wB.svg"); }
.pc-wN { background-image: url("./assets/pieces/wN.svg"); }
.pc-wP { background-image: url("./assets/pieces/wP.svg"); }
.pc-bK { background-image: url("./assets/pieces/bK.svg"); }
.pc-bQ { background-image: url("./assets/pieces/bQ.svg"); }
.pc-bR { background-image: url("./assets/pieces/bR.svg"); }
.pc-bB { background-image: url("./assets/pieces/bB.svg"); }
.pc-bN { background-image: url("./assets/pieces/bN.svg"); }
.pc-bP { background-image: url("./assets/pieces/bP.svg"); }

.frozen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: repeating-linear-gradient(45deg, #45a9e866 0 8px, #45a9e830 8px 16px);
}

.preview::after, .placed::after, .jumphint::after, .jumpsel::after, .selected::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.preview::after { background: #45a9e845; box-shadow: inset 0 0 0 2px var(--freeze); }
.placed::after { background: #45a9e870; box-shadow: inset 0 0 0 3px var(--freeze); }
.jumphint::after { box-shadow: inset 0 0 0 3px #dfa03fa0; }
.jumpsel::after { background: #dfa03f40; box-shadow: inset 0 0 0 3px var(--jump); }
.selected::after { box-shadow: inset 0 0 0 4px var(--select); }

.sq.last-from {
  background-image: linear-gradient(#f5d74270, #f5d74270);
  box-shadow: inset 0 0 0 3px #fff0a0b8;
}

.sq.last-to {
  background-image: linear-gradient(#f5d742a8, #f5d742a8);
  box-shadow: inset 0 0 0 4px #fff3a8e6;
}

.dot::before {
  content: "";
  position: absolute;
  z-index: 4;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: #16120d5c;
}

.dot.capture::before {
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  border: 5px solid #16120d47;
  background: transparent;
}

/* sidebar */

#side {
  display: grid;
  gap: 14px;
  width: min(370px, 100%);
  align-content: start;
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
}

.side-top .home-nav {
  padding: 7px 11px;
  border-color: #414149;
  background: #1a1a1f;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.side-top .home-nav:hover:not(:disabled) {
  border-color: #5a5a64;
  background: #24242a;
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.loading.ready { display: none; }

.spinner {
  width: 11px;
  height: 11px;
  border: 1.5px solid #ffffff2b;
  border-top-color: #c9c9d1;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.side-head h1 { font-size: 22px; }

.setup-line {
  margin: 3px 0 0;
  color: var(--faint);
  font-size: 12px;
}

.player-matchup {
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--sunk);
}

.player-side {
  display: grid;
  grid-template-columns: 10px 46px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 8px 11px;
}

.player-side + .player-side { border-top: 1px solid var(--line-soft); }

.player-color-dot {
  width: 9px;
  height: 9px;
  border: 1px solid #777781;
  border-radius: 50%;
}

.white-player .player-color-dot { background: #eeeeeb; }
.black-player .player-color-dot { background: #17171b; }
.player-color { color: var(--faint); font-size: 11.5px; }

.player-side b {
  min-width: 0;
  color: #d9d9de;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  text-align: right;
  overflow-wrap: anywhere;
}

.player-resources {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  min-height: 22px;
}

.player-captured {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
  min-width: 0;
}

.player-captured:empty { display: none; }

.player-captured .captured-piece {
  width: 16px;
  height: 16px;
  flex: none;
}

.player-captured .captured-piece + .captured-piece { margin-left: -5px; }

.material-advantage {
  margin-left: 4px;
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 600;
}

.player-spells {
  flex: none;
  padding: 3px 7px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #ffffff05;
  color: #d2d2d8;
  font-size: 11.5px;
  line-height: 1.25;
  white-space: pre;
}

.opponent {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 2px 11px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  transition: border-color .2s;
}

.opponent.thinking { border-color: #43434e; }

.avatar-frame {
  grid-row: 1 / span 2;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border-radius: 7px;
  background: var(--sunk);
}

.avatar-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.05) translateY(2%);
}

.thinking .avatar-frame { animation: amog-think .72s ease-in-out infinite alternate; }

@keyframes amog-think {
  from { transform: rotate(-1.5deg) translateY(0); }
  to { transform: rotate(1.5deg) translateY(-2px); }
}

.opponent-copy b { display: block; font-size: 13px; font-weight: 500; }
.opponent-copy span { color: var(--faint); font-size: 12px; }

.speech {
  grid-column: 2;
  margin-top: 5px;
  padding: 6px 9px;
  border-radius: 7px;
  background: var(--raise);
  color: #cfcfd6;
  font-size: 12px;
  line-height: 1.4;
}

.engine-settings {
  padding: 11px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}

.match-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.match-head b { font-size: 13px; font-weight: 500; }
.match-head span { color: var(--faint); font-size: 12px; }
.engine-settings .field-row { margin-bottom: 2px; }
.thinking-time-control { display: grid; gap: 8px; width: 100%; }

.engine-settings .arena-side {
  padding: 9px;
  background: transparent;
}

.engine-settings .arena-side select,
.engine-settings .arena-side input { min-width: 0; }

#status { min-height: 22px; font-size: 15px; font-weight: 500; }

#prompt {
  min-height: 20px;
  margin-top: -8px;
  color: var(--muted);
  font-size: 13px;
}

#prompt:empty { display: none; }

.spell-buttons, .controls { display: flex; flex-wrap: wrap; gap: 7px; }
.spell-buttons button, .controls button { font-size: 13.5px; }
.icon-group { display: flex; gap: 7px; }
.icon { padding: 9px 11px; color: var(--muted); line-height: 1.2; }

.panel {
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.panel-head label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--faint);
  font-size: 11.5px;
  cursor: pointer;
}

.panel-head input { width: auto; margin: 0; accent-color: #8a8a95; }

#moveCount { color: var(--faint); white-space: nowrap; }
#moveCount.reviewing { color: #e8c789; font-weight: 700; }

#moveList {
  max-height: 118px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  font: 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  scrollbar-color: #3a3a43 transparent;
  scrollbar-width: thin;
}

#moveList:empty { display: none; }

.move-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr);
  gap: 4px;
  margin-top: 3px;
}

.move-number { padding-top: 4px; color: var(--faint); text-align: right; }

.move-entry {
  min-width: 0;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--sunk);
  color: #c2c2ca;
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.move-entry:hover:not(:disabled) { border-color: var(--line); background: #1f1f25; }
.move-entry.future { opacity: .45; }

.move-entry small {
  display: block;
  color: var(--faint);
  font: 500 9px/1.3 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .03em;
}

.move-entry.current {
  border-color: #a9854f;
  background: #302b24;
  color: var(--ink);
  opacity: 1;
  box-shadow: inset 3px 0 #e8c789;
}

.move-entry.current::after {
  content: "Viewing";
  display: block;
  margin-top: 2px;
  color: #e8c789;
  font: 700 8px/1.2 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.analysis { background: var(--sunk); }

.local-analysis-control {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.local-analysis-control label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.local-analysis {
  display: grid;
  gap: 8px;
}

.local-analysis-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.local-analysis-settings label {
  display: flex;
  flex: 1 1 120px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--faint);
  font-size: 11px;
}

.local-analysis-settings select {
  width: auto;
  min-width: 82px;
  padding: 4px 7px;
  border-radius: 5px;
  font-size: 11px;
}

.local-analysis-status {
  margin: 0;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.4;
}

.local-analysis-status { color: #aab7aa; }

.local-analysis-lines {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.local-analysis-line {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: rgba(255, 255, 255, .018);
  font: 11.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.local-analysis-line:first-child {
  border-color: rgba(134, 166, 134, .27);
  background: rgba(126, 156, 126, .055);
}

.local-analysis-eval {
  color: #d1ddd1;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.local-analysis-eval[title] {
  cursor: help;
  text-decoration: underline dotted rgba(209, 221, 209, .45);
  text-underline-offset: 3px;
}

.local-analysis-pv {
  min-width: 0;
  color: #9fb59f;
  overflow-wrap: anywhere;
}

.local-analysis.eval-only .local-analysis-line {
  grid-template-columns: 1fr;
  font-size: 14px;
  text-align: center;
}

.local-analysis.eval-only .local-analysis-pv {
  display: none;
}

.recorded-analysis {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--line-soft);
  color: var(--faint);
  font-size: 10.5px;
}

.recorded-analysis > summary {
  display: inline-block;
  cursor: pointer;
  user-select: none;
}

.recorded-analysis > summary::marker { color: var(--faint); }

.recorded-analysis.live-evaluation { color: var(--muted); }

.recorded-analysis.live-evaluation > summary {
  color: #e8c789;
  font-weight: 700;
}

#recordedLineControl {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  cursor: pointer;
}

#recordedLineControl input { width: auto; margin: 0; accent-color: #8a8a95; }

#think {
  max-height: 74px;
  overflow: hidden;
  margin: 6px 0 0;
  color: #9fb59f;
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

#log {
  height: 88px;
  overflow: auto;
  padding: 9px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--sunk);
  color: var(--muted);
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

#shareStatus { color: #9fb59f; }

.cloud-storage {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--sunk);
}

.cloud-storage .note { margin: 0; }

#cloudSyncStatus { color: #9fb59f; }

kbd {
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
}

/* ---------- position editor ---------- */

.position-editor-dialog {
  width: min(960px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: auto;
  border: 1px solid #3b3b44;
  border-radius: 12px;
  background: var(--raise);
  color: var(--ink);
  box-shadow: 0 24px 80px #000a;
}

.position-editor-dialog::backdrop { background: #09090bcf; }

.position-editor-form { display: grid; gap: 18px; padding: 18px; }

.position-editor-head,
.position-editor-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.position-editor-head h2 { font-size: 20px; }
.position-editor-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.position-editor-head > .icon { padding: 5px 10px; font-size: 22px; }

.position-editor-workspace {
  display: grid;
  grid-template-columns: minmax(330px, 1fr) minmax(250px, .8fr);
  gap: 18px;
  align-items: start;
}

.position-editor-board-column { display: grid; gap: 10px; justify-items: center; }

.position-editor-board {
  --editor-square: clamp(39px, 6.3vw, 62px);
  display: grid;
  grid-template: repeat(8, var(--editor-square)) / repeat(8, var(--editor-square));
  overflow: hidden;
  border: 1px solid #42424b;
  border-radius: 5px;
}

.editor-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--editor-square);
  height: var(--editor-square);
  padding: 0;
  border: 0;
  border-radius: 0;
}

.editor-square.light { background: var(--light); }
.editor-square.dark { background: var(--dark); }

.position-editor-palette {
  display: grid;
  grid-template-columns: repeat(7, 42px);
  gap: 5px;
  justify-content: center;
}

.position-editor-palette button {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 2px;
  border-color: #36363e;
  background: var(--sunk);
}

.position-editor-palette button.selected {
  border-color: #90c590;
  background: #253528;
  box-shadow: inset 0 0 0 1px #90c59066;
}

.position-editor-palette .piece { display: block; }
.position-editor-palette .editor-eraser { color: var(--muted); font-size: 26px; line-height: 1; }
.position-editor-board-actions { justify-content: center; }

.position-photo-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--sunk);
}

.position-photo-frame {
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: hidden;
  border: 1px dashed #3b3b44;
  border-radius: 7px;
  background: #0d0d10;
}

.position-photo-frame img {
  display: block;
  width: 100%;
  max-height: 430px;
  object-fit: contain;
}

.position-photo-empty {
  display: grid;
  gap: 4px;
  padding: 24px;
  color: var(--faint);
  text-align: center;
}

.position-photo-empty > span { font-size: 34px; }
.position-photo-empty b { color: var(--muted); font-size: 13px; font-weight: 500; }
.position-photo-empty small { font-size: 11.5px; }

.button-label {
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.button-label:hover { border-color: #3a3a43; background: #1c1c21; }
.button-label input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#positionPhotoStatus[data-state="reading"] { color: #d8c989; }
#positionPhotoStatus[data-state="recognized"] { color: #9bd39b; }
#positionPhotoStatus[data-state="uncertain"],
#positionPhotoStatus[data-state="not-found"] { color: #e1bd72; }
#positionPhotoStatus[data-state="error"] { color: var(--danger); }

.position-editor-settings {
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) 230px minmax(260px, .9fr);
  gap: 14px;
  align-items: start;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.position-editor-settings > .note { grid-column: 1 / -1; }
.position-editor-settings > .field-row { grid-template-columns: 120px minmax(220px, 1fr); }
.position-editor-counts { align-self: end; }

.castling-field {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 5px 10px;
  margin: 0;
  padding: 7px 9px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.castling-field legend { padding: 0 4px; color: var(--muted); font-size: 12px; }
.castling-field label { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.castling-field input { width: auto; margin: 0 4px 0 0; vertical-align: -1px; }

.position-editor-footer { align-items: center; padding-top: 2px; }
.position-editor-footer .note { max-width: 620px; }
.position-editor-footer .primary { flex: 0 0 auto; }

/* ---------- responsive ---------- */

/* ---------- Variant Wheel games (pockets, hill, explosions) ---------- */

.board-shell { display: grid; gap: 6px; }

.pocket {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: calc(var(--sq) * .62);
  padding: 2px 6px 6px 0;
}

.pocket button {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(var(--sq) * .62);
  height: calc(var(--sq) * .62);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--sunk);
}

.pocket button[disabled] { opacity: .55; }
.pocket button .piece { width: 88%; height: 88%; }
.pocket button.selected { outline: 2px solid var(--select); outline-offset: -2px; }

.pocket button .count {
  position: absolute;
  right: 1px;
  bottom: 1px;
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 8px;
  background: var(--ink);
  color: #101013;
  font: 600 10px/1.3 ui-monospace, Menlo, monospace;
  text-align: center;
}

.pocket .pocket-empty { align-self: center; color: var(--faint); font-size: 11px; }

.sq.hill::after, .sq.goal::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.sq.hill::after { box-shadow: inset 0 0 0 3px #b58fd9aa; }
.sq.goal::after { background: repeating-linear-gradient(135deg, #45a9e83a 0 6px, transparent 6px 12px); }
.sq.check { background-image: radial-gradient(circle, #e0433a99 0, #e0433a55 35%, transparent 70%); }

.sq.drop-target::before {
  content: "";
  position: absolute;
  z-index: 4;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: #16120d5c;
}

.sq.boom { animation: boom .55s ease-out; }

@keyframes boom {
  0% { box-shadow: inset 0 0 0 0 #ffb347ff; background-color: #ffd27a; }
  45% { box-shadow: inset 0 0 0 12px #ff7b2e88; }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

/* Puzzle attempt verdict: badge on the square the judged move landed on,
   shown while the move sits on the board before being taken back. */
.sq .puzzle-mark {
  position: absolute;
  top: 3%;
  right: 3%;
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(11px, 2.6vmin, 20px);
  font-weight: 800;
  line-height: 1;
  color: #fff;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 1px 4px #0007;
  animation: puzzle-mark-pop .18s ease-out;
}

.sq .puzzle-mark.wrong { background: #d64045; }
.sq .puzzle-mark.good { background: #d9822b; }

/* A cast Jump stays open over its square for one reply; the ring and badge
   make that state as visible as a freeze zone. */
.sq.jump-open { box-shadow: inset 0 0 0 3px #b06ee0cc; }

.sq .jump-open-mark {
  position: absolute;
  top: 3%;
  left: 3%;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(10px, 2vmin, 15px);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: #b06ee0;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 1px 3px #0006;
}

@keyframes puzzle-mark-pop {
  from { transform: scale(.4); opacity: .2; }
  to { transform: scale(1); opacity: 1; }
}

.combo-rules {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.combo-rules li::marker { color: var(--faint); }
.combo-rules b { color: var(--ink); font-weight: 600; }
.combo-rules.house li::marker { content: "↳ "; color: var(--jump); }

.side-top .home-nav + .home-nav { margin-left: 6px; }

/* ---------- dragging pieces ---------- */

.pocket { touch-action: none; }

.drag-ghost {
  position: fixed;
  z-index: 60;
  width: var(--sq);
  height: var(--sq);
  transform: translate(-50%, -50%) scale(1.08);
  pointer-events: none;
  filter: drop-shadow(0 6px 10px #0009);
}

.drag-ghost .piece { width: 100%; height: 100%; }
.sq.dragging .piece { opacity: .28; }
.sq.drag-over { box-shadow: inset 0 0 0 4px var(--select); }
body.drag-in-progress { cursor: grabbing; user-select: none; }
body.drag-in-progress .sq { cursor: grabbing; }

@media (max-width: 1000px) {
  :root { --sq: clamp(38px, calc((100vw - 72px) / 8), 70px); }
  .game {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 16px;
  }
  #side { width: calc(8 * var(--sq) + 22px); }
}

@media (max-width: 780px) {
  .position-editor-workspace { grid-template-columns: 1fr; }
  .position-photo-frame { min-height: 190px; }
  .position-editor-settings { grid-template-columns: 1fr 1fr; }
  .position-editor-settings > .field-row {
    grid-column: 1 / -1;
    grid-template-columns: 140px minmax(230px, 1fr);
  }
  .position-editor-settings > .field:last-of-type { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  :root { --sq: calc((100vw - 34px) / 8); }
  .home { padding: 0 18px; }
  .intro h1 { font-size: 26px; }
  .sides { grid-template-columns: 1fr; }
  .arena-side-grid { grid-template-columns: 1fr; }
  .learn-card { padding: 16px; }
  .guide-topbar { padding-top: 20px; }
  .guide-shell { gap: 42px; margin-top: 24px; }
  .guide-lede { font-size: 16px; }
  .spell-grid { grid-template-columns: 1fr; }
  .spell-card { min-height: 0; }
  .practice-card { grid-template-columns: 1fr; }
  .practice-card .guide-cta { width: 100%; }
  .game { gap: 14px; padding: 10px 8px 24px; }
  .board-shell { padding: 5px; border-radius: 7px; }
  #side { width: 100%; }
  #moveList { max-height: min(42dvh, 360px); }
  .position-editor-dialog { width: 100vw; max-height: 100dvh; border-radius: 0; }
  .position-editor-form { padding: 12px; }
  .position-editor-workspace { gap: 14px; }
  .position-editor-board { --editor-square: calc((100vw - 38px) / 8); }
  .position-editor-palette { grid-template-columns: repeat(7, minmax(36px, 1fr)); width: 100%; }
  .position-editor-palette button { width: 100%; height: 38px; }
  .position-editor-settings { grid-template-columns: 1fr; }
  .position-editor-settings > .field-row { grid-template-columns: 1fr; }
  .castling-field { min-width: 0; grid-template-columns: 1fr 1fr; }
  .position-editor-settings > .field:last-of-type { grid-column: auto; }
  .position-editor-footer { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .thinking .avatar-frame { animation: none; }
}

:fullscreen .game { align-items: center; }

/* Tactics trainer chrome: the announcement banner on the home screen and the
   puzzle controls row on the game screen. */
.site-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
}

.site-banner a {
  flex: 1;
  color: inherit;
  text-decoration: none;
}

.site-banner a:hover { text-decoration: underline; }

.site-banner button {
  padding: 0 8px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: .7;
}

.site-banner button:hover { opacity: 1; }

.puzzle-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.puzzle-bar-rating {
  font-weight: 600;
  margin-right: auto;
}

.puzzle-bar button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raise);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.puzzle-bar button:disabled { opacity: .45; cursor: default; }

.puzzle-bar .puzzle-next {
  border-color: #7dc97f;
  box-shadow: 0 0 0 2px rgba(125, 201, 127, .35);
}
