:root {
  --bg: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e1dc;
  --red: #b3191f;
  --red-ink: #ffffff;
  --sq-light: #eeece6;
  --sq-dark: #aaa69c;
  --lm: rgba(179, 25, 31, 0.28);
  --btn: #f3f2ef;
  --btn-hover: #e7e5e0;
  --sticky-h: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151516;
    --ink: #ececee;
    --muted: #9c9ca3;
    --line: #2c2c2f;
    --red: #e0454b;
    --btn: #232326;
    --btn-hover: #2e2e32;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--red); }
img { max-width: 100%; }

.wrap { max-width: 1040px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* Kopf */
.site-head { border-bottom: 1px solid var(--line); }
.site-head .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { width: 30px; height: auto; border: 1px solid var(--line); display: block; }
.brand b { display: block; font-size: 1.15rem; letter-spacing: 0.01em; line-height: 1.1; }
.brand small { display: block; color: var(--red); font-size: 0.85rem; line-height: 1.2; }

main { padding-top: 28px; padding-bottom: 48px; }
main:has(> .pager:last-of-type) { padding-bottom: 0; }

/* Partie-Kopf */
.game-head { margin-bottom: 16px; }
.kicker { margin: 0; color: var(--red); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
h1 { margin: 2px 0 2px; font-size: 1.6rem; line-height: 1.2; }
.meta { margin: 0; color: var(--muted); }

/* Brett + Züge */
.game { position: relative; }
.board-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: 8px 0 10px;
  border-bottom: 1px solid var(--line);
}
.board {
  --size: min(100%, 56vh);
  width: var(--size);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 1px solid #8d897f;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.lm { box-shadow: inset 0 0 0 100vmax var(--lm); }
.sq img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sq img.moving { z-index: 3; }
.sq img.ghost { z-index: 1; }
.sq[data-rank]::before, .sq[data-file]::after {
  position: absolute;
  font-size: 10px;
  line-height: 1;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.sq[data-rank]::before { content: attr(data-rank); top: 2px; left: 2px; }
.sq[data-file]::after { content: attr(data-file); bottom: 2px; right: 3px; }

.controls { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.controls button {
  appearance: none;
  border: 1.5px solid var(--red);
  background: transparent;
  color: var(--red);
  border-radius: 8px;
  width: 52px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}
.controls button:hover:not(:disabled) { background: var(--red); color: var(--red-ink); }
.controls button:active:not(:disabled) { transform: translateY(1px); }
.controls button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.controls button:disabled { border-color: var(--line); color: var(--muted); opacity: 0.6; cursor: default; }
.controls button[data-act="flip"] { margin-left: 10px; width: 44px; }
.controls svg { width: 22px; height: 22px; fill: currentColor; }
.game:not(.ready) .controls { visibility: hidden; }

.moves {
  padding: 14px 0 0;
  font-size: 1.05rem;
  line-height: 2;
  word-spacing: 1px;
}
.mv {
  padding: 1px 4px;
  margin: 0 -1px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  scroll-margin-top: calc(var(--sticky-h) + 12px);
  scroll-margin-bottom: 24px;
}
.mv:hover { background: var(--btn); }
.mv.cur { background: var(--red); color: var(--red-ink); }
.num { color: var(--muted); margin-left: 4px; }
.var { color: var(--muted); font-size: 0.95em; }
.var > .num:first-child { margin-left: 0; }
.var .mv.cur { color: var(--red-ink); }
.moves > .var { display: block; margin: 2px 0 2px 1rem; padding-left: 0.75rem; border-left: 2px solid var(--line); }
.comment { color: var(--muted); font-style: italic; }
.result { font-weight: 700; margin-left: 6px; }

@media (min-width: 860px) {
  .game { display: grid; grid-template-columns: minmax(0, 470px) minmax(0, 1fr); gap: 36px; align-items: start; }
  .board-wrap { top: 16px; padding: 0; border: 0; }
  .board { --size: 100%; }
  .moves { padding-top: 0; }
}

/* Blättern */
.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 40px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.pager a { text-decoration: none; font-weight: 600; }
.pager a[rel="next"] { justify-self: end; }
.pager .mid { color: var(--muted); }
.pager .mid:hover { color: var(--red); }

/* Startseite */
.hero { display: grid; gap: 24px; align-items: center; }
.hero img { width: 180px; height: auto; border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08); }
.hero h1 { font-size: 2.2rem; }
.hero .sub { color: var(--red); font-style: italic; font-size: 1.15rem; margin: 0 0 12px; }
@media (min-width: 640px) { .hero { grid-template-columns: auto 1fr; } .hero img { width: 220px; } }
.toc { list-style: none; padding: 0; margin: 12px 0 0; columns: 2 300px; column-gap: 32px; }
.toc li { break-inside: avoid; display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.toc .pg { color: var(--muted); min-width: 4.2em; font-variant-numeric: tabular-nums; }
.toc a { text-decoration: none; color: var(--ink); }
.toc a:hover { color: var(--red); }

/* Textseiten */
.prose { max-width: 680px; }
.prose h2 { font-size: 1.2rem; margin: 28px 0 4px; }
.prose .book-meta { color: var(--muted); margin: 0 0 6px; font-size: 0.95rem; }

/* Fuß */
.site-foot { color: var(--muted); font-size: 0.9rem; }
.site-foot .wrap { padding-bottom: 28px; }
.site-foot nav { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding-top: 18px; border-top: 1px solid var(--line); }
.site-foot a { color: var(--ink); text-decoration: none; }
.site-foot a:hover { color: var(--red); }
.site-foot .copy { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
