@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/cormorant-garamond-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/cormorant-garamond-cyrillic-500.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/cormorant-garamond-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/cormorant-garamond-cyrillic-600.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/source-sans-3-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/source-sans-3-cyrillic-400.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/source-sans-3-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/source-sans-3-cyrillic-600.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  --bg: #0E1A14;
  --card: #16241C;
  --gold: #C4A15A;
  --gold-ink: #0E1A14;
  --paper: #F3EAD7;
  --text: #F3EAD7;
  --muted: #A39880;
  --line: rgba(196, 161, 90, 0.45);
  --sq-light: #EFE6D2;
  --sq-dark: #6B8F71;
  --ink: #142019;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

html[data-theme="day"] {
  --bg: #F3EAD7;
  --card: #E7DCC4;
  --gold: #6E5424;
  --gold-ink: #F3EAD7;
  --paper: #F7F1E4;
  --text: #142019;
  --muted: #5C5648;
  --line: rgba(110, 84, 36, 0.35);
  --ink: #142019;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { font-size: 17px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  font-weight: 400;
  line-height: 1.55;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  transition: background-color 0.45s ease, color 0.45s ease;
}

main { flex: 1 0 auto; }

h1, h2, .count, .eyebrow {
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  font-weight: 500;
}

a { color: var(--gold); text-underline-offset: 0.18em; }
a:hover { color: var(--text); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  transform: translateY(-160%);
  background: var(--gold);
  color: var(--gold-ink);
  padding: 0.7rem 1rem;
  z-index: 20;
  text-decoration: none;
}
.skip:focus { transform: none; }

.cover {
  padding: clamp(3.2rem, 9vw, 7rem) 1.25rem clamp(2.4rem, 6vw, 4.5rem);
  text-align: center;
}

.langs {
  display: flex;
  justify-content: center;
  gap: 0.35rem 1.1rem;
  margin: 0 0 1.35rem;
}

.langs a {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.92rem;
}

.langs a[aria-current="page"] { color: var(--gold); }

.eyebrow {
  margin: 0;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.95rem;
  color: var(--gold);
}

.cover h1 {
  margin: 0.55rem auto 0;
  max-width: 16ch;
  font-size: clamp(2.7rem, 11vw, 6.4rem);
  line-height: 0.92;
  font-weight: 500;
  color: var(--gold);
  animation: rise 0.9s ease both;
}

.rule {
  width: min(11rem, 42%);
  height: 1px;
  margin: 1.35rem auto 1.15rem;
  background: var(--gold);
  transform-origin: center;
  animation: draw 1s ease both;
}

.subtitle {
  margin: 0 auto;
  max-width: 28rem;
  font-size: 1.2rem;
  color: var(--text);
  animation: rise 0.9s ease 0.18s both;
}

.count {
  margin: 1.1rem 0 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  color: var(--gold);
  animation: rise 0.9s ease 0.32s both;
}

.letter {
  max-width: 58rem;
  margin: 0 auto 2.5rem;
  padding: 0 1.25rem;
  display: grid;
  gap: 1.4rem;
  align-items: center;
  justify-items: center;
}

.portrait { margin: 0; }

.portrait img {
  display: block;
  width: min(16rem, 72vw);
  height: auto;
  background: var(--paper);
  border: 1px solid var(--gold);
  padding: 0.4rem;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
  animation: rise 0.8s ease 0.12s both;
}

html[data-theme="night"] .letter-sheet,
html:not([data-theme="day"]) .letter-sheet {
  background: var(--paper);
  color: var(--ink);
  padding: clamp(1.3rem, 3vw, 2rem);
  border: 1px solid var(--line);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
}

.letter-sheet { animation: rise 0.8s ease 0.2s both; }

html[data-theme="day"] .letter-sheet {
  padding: 0.25rem 0 0;
}

.letter p {
  margin: 0 0 0.85rem;
  font-size: 1.22rem;
  line-height: 1.5;
}

.letter p:last-child { margin-bottom: 0; }

.sign { color: inherit; }

.tools-sentinel { height: 1px; margin-top: -1px; }

.tools {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: max(0.35rem, env(safe-area-inset-top)) 0.4rem 0.35rem;
  transition: box-shadow 0.3s ease, background-color 0.45s ease;
}

.tools.is-stuck { box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22); }

.tools-bar {
  max-width: 68rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.filters, .modes {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.2rem;
}

.filters { flex: 1 1 auto; min-width: 0; justify-content: center; }
.modes { flex: 0 0 auto; }

.tools-bar > .search-toggle,
.tools-bar > .download,
.modes button {
  flex: 0 0 2.55rem;
  width: 2.55rem;
  height: 2.55rem;
  min-height: 2.55rem;
  padding: 0;
}

.filters button {
  min-width: 0;
  height: 2.55rem;
  min-height: 2.55rem;
  padding: 0 0.15rem;
  flex: 1 1 0;
  white-space: nowrap;
}

.filters .mark { font-size: 0.78rem; letter-spacing: 0; }

.tools-bar svg { width: 1.2rem; height: 1.2rem; display: block; }
.mini-piece { width: 1.35rem; height: 1.35rem; }

.filters .label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-panel {
  max-width: 68rem;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}

.search-panel.is-open { grid-template-rows: 1fr; }

.search-inner { min-height: 0; overflow: hidden; }

.search-panel.is-open .search-inner { padding-top: 0.55rem; }

.search-inner input {
  width: 100%;
  min-height: 48px;
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0.55rem 0.8rem;
}

button, .btn {
  min-height: 48px;
  padding: 0.55rem 1rem;
  touch-action: manipulation;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button[aria-pressed="true"], .download {
  background: var(--gold);
  color: var(--gold-ink);
  border-color: var(--gold);
}

.download:hover { color: var(--gold-ink); }

.shown {
  max-width: 68rem;
  margin: 0.4rem auto 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-size: 0.92rem;
}

.shown[hidden] { display: none; }

.games { padding-bottom: 3rem; }

.game {
  max-width: 68rem;
  margin: 0 auto;
  padding: 2rem 1rem 2.4rem;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 4.6rem;
}

.game[hidden] { display: none; }

.game.is-fresh { animation: rise 0.45s ease; }

@media (hover: hover) {
  .game h2 {
    background-image: linear-gradient(var(--gold), var(--gold));
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0 1px;
    transition: background-size 0.4s ease;
  }
  .game:hover h2 { background-size: 3.4rem 1px; }
}

.ordinal {
  margin: 0 0 0.2rem;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.game h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 500;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.elo { color: var(--muted); font-size: 0.72em; }

.meta, .source {
  margin: 0.7rem 0 0;
  color: var(--muted);
}

.source a { overflow-wrap: anywhere; }

.game-body {
  display: grid;
  gap: 1.1rem;
  margin-top: 1.15rem;
}

.board-shell { width: min(100%, 26rem); }

.board-row {
  display: grid;
  grid-template-columns: 1.35rem minmax(0, 1fr);
  gap: 0.2rem;
  align-items: stretch;
}

.ranks, .files {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.ranks {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
}

.ranks span, .files span {
  display: grid;
  place-items: center;
}

.files {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin: 0.15rem 0 0;
  padding: 0 7px;
  height: 1.2rem;
}

.board-frame {
  padding: 7px;
  border: 1px solid var(--gold);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: var(--sq-dark);
}

.sq { aspect-ratio: 1; }
.sq.l { background: var(--sq-light); }
.sq.d { background: var(--sq-dark); }
.sq.moved { box-shadow: inset 0 0 0 2px var(--gold); animation: gleam 0.55s ease; }

.piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  left: calc(var(--f) * 12.5%);
  top: calc(var(--r) * 12.5%);
  transition: left 0.34s ease, top 0.34s ease;
  z-index: 1;
  pointer-events: none;
}

.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 0 rgba(20, 32, 25, 0.35));
}

.board.is-instant .piece { transition: none; }

.board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  margin-top: 0.75rem;
}

.status {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.moves {
  margin: 0;
  padding: 1rem 1rem 0.7rem;
  background: var(--card);
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.mn { color: var(--muted); }

.ply {
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.4rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  vertical-align: middle;
}

.ply.is-on {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 0.22em;
}

.board.is-playing { box-shadow: inset 0 0 0 2px var(--gold); }

.playbar {
  height: 2px;
  margin-top: 0.7rem;
  background: var(--line);
  overflow: hidden;
}

.playbar-fill {
  display: block;
  height: 100%;
  background: var(--gold);
  transform: scaleX(1);
  transform-origin: left center;
  transition: transform 0.34s ease;
}

.empty {
  max-width: 68rem;
  margin: 0 auto;
  padding: 2rem 1rem;
  color: var(--muted);
}

.site-footer {
  margin-top: auto;
  padding: 2rem 1.25rem max(2.5rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.site-footer p { margin: 0.3rem 0; }
.site-footer .credit { margin-top: 0.85rem; }

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.to-top {
  display: none;
}

@media (min-width: 760px) {
  .tools-bar { justify-content: flex-start; gap: 0.45rem; }
  .filters { flex: 0 0 auto; justify-content: flex-start; }
  .tools-bar > .search-toggle,
  .modes button,
  .tools-bar > .download {
    flex: 0 0 2.7rem;
    width: 2.7rem;
    height: 2.7rem;
    min-height: 2.7rem;
  }
  .filters button {
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
    padding: 0 0.9rem;
  }
  .filters .mark, .filters .mini-piece { display: none; }
  .filters .label {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
  }
  .letter {
    grid-template-columns: minmax(11rem, 16rem) minmax(0, 38rem);
    justify-content: center;
  }
}

@media (min-width: 860px) {
  .game-body {
    grid-template-columns: minmax(240px, 26rem) minmax(0, 1fr);
    align-items: start;
    column-gap: 1.5rem;
  }
}

@media (min-width: 1101px) {
  .to-top {
    display: grid;
    place-items: center;
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 2.75rem;
    height: 2.75rem;
    min-height: 2.75rem;
    padding: 0;
    border-radius: 2px;
    background: var(--gold);
    color: var(--gold-ink);
    border: 0;
    z-index: 7;
    opacity: 0;
    pointer-events: none;
  }
  .to-top.is-on { opacity: 1; pointer-events: auto; }
  .to-top svg { width: 1.15rem; height: 1.15rem; }
}

@media (max-width: 389px) {
  .tools { padding-left: 0.3rem; padding-right: 0.3rem; }
  .tools-bar { gap: 0.15rem; }
  .tools-bar > .search-toggle,
  .modes button,
  .tools-bar > .download,
  .filters button {
    flex-basis: 2.35rem;
    width: 2.35rem;
    height: 2.45rem;
    min-height: 2.45rem;
  }
  .filters button { width: auto; flex: 1 1 0; }
}

html { scroll-padding-top: 4.6rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes draw {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes gleam {
  from { box-shadow: inset 0 0 0 4px var(--gold); }
  to { box-shadow: inset 0 0 0 2px var(--gold); }
}

@media print {
  .tools, .to-top, .board-actions, .skip, .langs, .search-panel { display: none !important; }
  body { background: #fff; color: #142019; }
  .game { break-inside: avoid; }
  a { color: #142019; }
}
