/* metachess game UI — inherits color tokens from /style.css */

:root {
  --mc-light: #d8c6b8;
  --mc-dark: #6b4d3d;
  --mc-board-border: #2a1a14;
  --mc-sel: rgba(255, 220, 80, 0.55);
  --mc-meta: rgba(80, 200, 130, 0.55);
  --mc-meta-cap: rgba(60, 220, 120, 0.85);
  --mc-hang: rgba(230, 150, 60, 0.55);
  --mc-hang-cap: rgba(255, 130, 50, 0.85);
  --mc-check: rgba(255, 80, 80, 0.95);
  --mc-metacheck: rgba(255, 170, 60, 0.95);
  --mc-last: rgba(255, 240, 130, 0.30);
}

[data-theme="dark"], [data-theme="synthwave"], [data-theme="dusk-rose"], [data-theme="terminal"] {
  --mc-light: #c9b29b;
  --mc-dark: #514033;
  --mc-board-border: #1a1014;
}

body.metachess-play {
  /* the board is the focus — kill the article max-width container; we use
     our own main.mc-stage layout instead. */
}

body.metachess-play article { display: none; } /* template fallback */

.mc-stage {
  position: relative;
  z-index: 1;
  max-width: 1160px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 320px;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 820px) {
  .mc-stage {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1.25rem;
  }
}

/* ----- board ----- */

.mc-board-pane { display: flex; flex-direction: column; align-items: center; }

.mc-board-wrap {
  position: relative;
  width: 100%;
  max-width: min(78vh, 720px);
  aspect-ratio: 1 / 1;
}

.mc-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--mc-board-border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  user-select: none;
  font-family: var(--ui-font);
}

.mc-sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

.mc-piece {
  width: 92%;
  height: 92%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
  transition: transform 0.06s ease, filter 0.12s ease;
}

.mc-piece:active { cursor: grabbing; transform: scale(1.08); }
.mc-piece[draggable="false"] { cursor: default; }

.mc-coord {
  position: absolute;
  font-family: var(--ui-font);
  font-size: 0.65rem;
  opacity: 0.55;
  pointer-events: none;
  line-height: 1;
}
.mc-coord-rank { top: 2px; left: 3px; }
.mc-coord-file { bottom: 2px; right: 4px; }
.mc-sq.mc-light .mc-coord { color: #4a3024; }
.mc-sq.mc-dark  .mc-coord { color: #e8d8c8; }

/* highlights */
.mc-sq.mc-sel { box-shadow: inset 0 0 0 4px var(--mc-sel); }

.mc-sq.mc-target-meta::after,
.mc-sq.mc-target-hang::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  pointer-events: none;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.mc-sq.mc-target-meta::after { background: var(--mc-meta); }
.mc-sq.mc-target-hang::after { background: var(--mc-hang); }

.mc-sq.mc-target-cap-meta { box-shadow: inset 0 0 0 4px var(--mc-meta-cap); }
.mc-sq.mc-target-cap-hang { box-shadow: inset 0 0 0 4px var(--mc-hang-cap); }

.mc-sq.mc-last-from, .mc-sq.mc-last-to {
  background-image: linear-gradient(var(--mc-last), var(--mc-last));
}

/* King-highlight on the piece itself (standard chess-UI convention).
   Red = chess check (alarm). Amber = metacheck (warning). They stack if
   the king happens to be in both. drop-shadow stacks naturally so the
   piece silhouette gets a colored halo. */
.mc-piece.mc-king-check {
  filter:
    drop-shadow(0 1px 1px rgba(0,0,0,0.35))
    drop-shadow(0 0 6px var(--mc-check))
    drop-shadow(0 0 12px var(--mc-check));
}
.mc-piece.mc-king-metacheck {
  filter:
    drop-shadow(0 1px 1px rgba(0,0,0,0.35))
    drop-shadow(0 0 6px var(--mc-metacheck))
    drop-shadow(0 0 12px var(--mc-metacheck));
}
.mc-piece.mc-king-check.mc-king-metacheck {
  filter:
    drop-shadow(0 1px 1px rgba(0,0,0,0.35))
    drop-shadow(0 0 5px var(--mc-check))
    drop-shadow(0 0 10px var(--mc-check))
    drop-shadow(0 0 16px var(--mc-metacheck));
}

/* ----- orient button below board ----- */

.mc-orient {
  margin-top: 0.6rem;
  display: flex;
  justify-content: flex-end;
  width: 100%;
}

.mc-iconbtn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-family: var(--ui-font);
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.mc-iconbtn:hover { opacity: 1; color: var(--fg); }

/* ----- side panel ----- */

.mc-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-family: var(--ui-font);
  font-size: 0.92rem;
}

.mc-status {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mc-status-mode {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mc-spectator-badge {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent, #9ecbff);
  border: 1px solid currentColor;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  align-self: flex-start;
}

.mc-status-turn {
  font-size: 1.1rem;
  color: var(--fg);
  font-weight: 500;
}

.mc-status-flags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 1.4em;
}

.mc-flag {
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.mc-flag-check { background: var(--mc-check); color: #fff; }
.mc-flag-metacheck { background: var(--mc-metacheck); color: #fff; }

.mc-status-terminal {
  margin-top: 0.4rem;
  font-size: 1.05rem;
  font-weight: 500;
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent);
}
.mc-terminal-metacheckmate { border-left-color: #ff5050; }
.mc-terminal-metastalemate,
.mc-terminal-fifty_moves,
.mc-terminal-threefold_repetition,
.mc-terminal-insufficient_material { border-left-color: var(--muted); }
.mc-terminal-resigned { border-left-color: var(--mc-check); }

/* ----- share box ----- */

.mc-share {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.mc-share label {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.mc-share-row {
  display: flex;
  gap: 0.4rem;
}

.mc-share-row input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-family: var(--code-font);
  font-size: 0.78rem;
}

.mc-share-row button { white-space: nowrap; }

.mc-share-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  font-style: italic;
}

/* ----- history ----- */

.mc-history-wrap h3 {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
  font-weight: 500;
}

.mc-history {
  list-style: decimal inside;
  margin: 0;
  padding: 0.4rem 0.5rem;
  max-height: 14rem;
  overflow-y: auto;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-family: var(--code-font);
  font-size: 0.86rem;
  color: var(--fg);
}

.mc-history li {
  display: flex;
  gap: 0.6rem;
  padding: 0.1rem 0;
}

.mc-history li::marker { color: var(--muted); }

.mc-ply { min-width: 3.2em; }
.mc-ply-w { color: var(--fg); }
.mc-ply-b { color: var(--muted); }

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

.mc-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mc-controls button {
  flex: 1;
  min-width: 6rem;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.5rem 0.7rem;
  font-family: var(--ui-font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.mc-controls button:hover:not(:disabled) {
  border-color: var(--fg);
  background: rgba(255,255,255,0.04);
}
.mc-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}
.mc-controls .mc-secondary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ----- legend ----- */

.mc-legend {
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding-top: 0.75rem;
}
.mc-legend summary {
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mc-legend ul {
  list-style: none;
  padding: 0.5rem 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.mc-swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 0.5em;
}
.mc-swatch-meta { background: var(--mc-meta); }
.mc-swatch-hang { background: var(--mc-hang); }
.mc-swatch-check { background: var(--mc-check); }
.mc-swatch-metacheck { background: var(--mc-metacheck); box-shadow: 0 0 6px 1px var(--mc-metacheck); }
.mc-swatch-check { box-shadow: 0 0 6px 1px var(--mc-check); }

/* ----- promotion picker ----- */

.mc-promo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  z-index: 10;
}
.mc-promo[hidden] { display: none; }
.mc-promo-inner {
  display: flex;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.8rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.mc-promo-inner button {
  width: 3.5rem;
  height: 3.5rem;
  background-color: var(--code-bg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 80%;
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.mc-promo-inner button:hover {
  border-color: var(--accent);
  background: rgba(255,255,255,0.06);
}

/* ----- toast ----- */

.mc-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-family: var(--ui-font);
  font-size: 0.9rem;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
  pointer-events: none;
}
.mc-toast[hidden] { display: none; }

/* ----- landing page ----- */

.mc-landing {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.mc-cta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.mc-cta a {
  display: block;
  padding: 1rem 1.2rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  font-family: var(--ui-font);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.mc-cta a:hover {
  border-color: var(--accent);
  background: rgba(255,255,255,0.07);
  transform: translateY(-1px);
}
.mc-cta a strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 0.2rem;
  font-weight: 500;
}
.mc-cta a span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}
/* ----- explainer section (landing page) ----- */

.mc-explainer {
  margin: 3rem 0 1rem;
}
.mc-explainer-header {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 1.2rem;
  font-family: var(--ui-font);
}
.mc-examples {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}
@media (min-width: 720px) {
  .mc-examples { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1080px) {
  .mc-examples { grid-template-columns: repeat(3, 1fr); }
}

.mc-example {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.mc-example h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  font-family: var(--ui-font);
  color: var(--fg);
  letter-spacing: 0.01em;
}
.mc-example p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.55;
}
.mc-example p em { color: var(--fg); font-style: normal; font-weight: 500; }
.mc-example .mc-hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
  opacity: 0.7;
}

/* mini-board: reuses .mc-board grid but shrinks pieces to fit */
.mc-mini {
  width: 100%;
}
.mc-mini-board {
  /* Override .mc-board's height: 100% — mini-boards have no fixed-height
     wrapper, so aspect-ratio is what gives them a square shape. */
  height: auto;
  aspect-ratio: 1 / 1;
  border-width: 1px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  cursor: default;
}
.mc-mini-board .mc-piece {
  cursor: pointer;
}
.mc-mini-board .mc-sq { cursor: pointer; }

/* ----- attribution line under the article header ----- */

.mc-credit {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.3rem 0 1.4rem;
}

/* ----- endgame tablebase downloads ----- */

.mc-downloads {
  margin: 3rem 0 1rem;
}
.mc-downloads h2 {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.8rem;
  font-family: var(--ui-font);
  font-weight: 500;
}
.mc-downloads p {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 1rem;
}
.mc-downloads p code {
  font-size: 0.82rem;
  background: rgba(255,255,255,0.05);
  padding: 1px 4px;
  border-radius: 3px;
}
.mc-downloads-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}
@media (min-width: 540px) {
  .mc-downloads-list { grid-template-columns: repeat(2, 1fr); }
}
.mc-downloads-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: rgba(255,255,255,0.02);
  font-size: 0.9rem;
}
.mc-downloads-list a {
  color: var(--fg);
  font-family: var(--ui-font);
}
.mc-dl-size {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
