/* ruchess.fun — шахматная книга с гравированными диаграммами */

@font-face {
  font-family: "Old Standard";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-n-400-cyr.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Old Standard";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-n-400-lat.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: "Old Standard";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-n-700-cyr.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Old Standard";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-n-700-lat.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: "Old Standard";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-i-400-cyr.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Old Standard";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/oldstandard-i-400-lat.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;
}

:root {
  --paper: #FFFFFF;
  --ink: #231F1A;
  --graphite: #6E6960;
  --rule: #E4E0D8;
  --cinnabar: #B3261E;
  --tint: rgba(179, 38, 30, .15);
  --serif: "Old Standard", "Old Standard TT", Georgia, "Times New Roman", serif;
  --wrap: 1140px;
  --gutter: 16px;
  color-scheme: light;
}
@media (min-width: 600px) { :root { --gutter: 28px; } }
@media (min-width: 1000px) { :root { --gutter: 48px; } }

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (min-width: 700px) { html { font-size: 19px; } }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
  font-kerning: normal;
  font-synthesis: none;
  font-variant-numeric: oldstyle-nums;
  overflow-wrap: break-word;
}

.wrap {
  width: min(var(--wrap), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
  text-decoration-color: rgba(35, 31, 26, .4);
}
a:hover { color: var(--cinnabar); text-decoration-color: currentColor; }

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

h1, h2 { font-weight: 400; margin: 0; }

.skip {
  position: absolute;
  left: -9999px;
  top: .5rem;
  z-index: 10;
  background: var(--paper);
  padding: .3rem .7rem;
}
.skip:focus { left: var(--gutter); }

.vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Кнопки */

.btn {
  font: inherit;
  font-size: .9rem;
  line-height: 1.2;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: .5rem .95rem .55rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { color: var(--cinnabar); border-color: var(--cinnabar); }
.btn:disabled { color: #A9A49B; border-color: var(--rule); cursor: default; }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.link-btn {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
  text-decoration-color: rgba(35, 31, 26, .4);
  touch-action: manipulation;
}
.link-btn:hover { color: var(--cinnabar); text-decoration-color: currentColor; }

/* Шапка */

.masthead {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem 1.75rem;
  padding: 2rem 0 .8rem;
  margin-bottom: 5px;
  border-bottom: 2px solid var(--ink);
}
.masthead::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  border-top: 1px solid var(--ink);
}
.brand-line {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-right: auto;
}
.hop {
  position: relative;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  margin: 0 0 0 -.25rem;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.hop img { display: block; width: 100%; height: 100%; }
.hop-trace {
  position: absolute;
  left: 50%;
  top: 72%;
  overflow: visible;
  pointer-events: none;
}
.brand {
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: .01em;
  text-decoration: none;
}
.sections {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem 1.35rem;
  font-size: .95rem;
}
.sections a { text-decoration: none; }
.sections a:hover { text-decoration: underline; }

/* Титул */

.hero {
  display: grid;
  grid-template-areas: "head" "board" "links" "note";
  padding: 2.5rem 0 3.5rem;
}
.hero-head { grid-area: head; }
.hero h1 {
  font-size: clamp(3.4rem, 1.9rem + 5.4vw, 6rem);
  line-height: .92;
  letter-spacing: -.012em;
  margin: 0 0 1.4rem -.04em;
}
.lead {
  font-size: 1.06rem;
  line-height: 1.52;
  max-width: 31em;
  margin: 0 0 1.75rem;
}
@media (min-width: 700px) { .lead { font-size: 1.18rem; margin-bottom: 1.4rem; } }
.hero-links {
  grid-area: links;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.8rem;
  margin: 0;
  font-size: 1.05rem;
}
.didyou {
  grid-area: note;
  margin-top: 2rem;
  max-width: 31em;
  font-size: .95rem;
  color: var(--graphite);
}
.didyou p { margin: 0 0 .45rem; }
.didyou i { color: var(--ink); }
.didyou .link-btn { font-size: .9rem; }

.hero-board { grid-area: board; margin: 0 0 2.25rem; }
.hero-board svg { display: block; width: 100%; height: auto; }
.hero-board figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .3rem 1.2rem;
  margin: .55rem 0 0 calc(30 / 444 * 100%);
  font-size: .9rem;
  color: var(--graphite);
}
.hero-board figcaption span { font-style: italic; }
.hero-board figcaption .link-btn { color: var(--ink); }

.engraving .coord {
  font-family: var(--serif);
  font-size: 15px;
  fill: var(--graphite);
  font-style: italic;
}

@media (min-width: 861px) {
  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(0, 26rem);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "head board" "links board" "note board";
    column-gap: 3.5rem;
    padding: 4rem 0 5rem;
  }
  .hero-board { margin: 0; }
  .didyou { align-self: end; margin-top: 2.5rem; }
}
@media (min-width: 1100px) {
  .hero { grid-template-columns: minmax(0, 1fr) 28rem; column-gap: 4.5rem; }
}

/* Главы: слева поля с заголовком, справа доска */

.chapter {
  display: grid;
  gap: 1.6rem;
  padding: 3.5rem 0 4rem;
  border-top: 1px solid var(--rule);
}
.margin h2 {
  font-weight: 700;
  font-size: 1.62rem;
  line-height: 1.15;
  margin: 0 0 .85rem;
}
.margin p {
  font-size: .92rem;
  line-height: 1.5;
  color: var(--graphite);
  margin: 0 0 .7rem;
  max-width: 36em;
}
.body { min-width: 0; }

/* На узком экране доска идёт сразу за вступлением, второстепенные пометки — под ней */
@media (max-width: 860px) {
  .chapter { gap: 0; }
  .chapter > .margin { display: contents; }
  .chapter > .body { order: 1; margin-top: 1rem; }
  .chapter .late { order: 2; }
  .chapter p.late:not(.facts-link) { margin-top: 1.6rem; }
  .facts.late { margin-top: 1.8rem; }
}

@media (min-width: 861px) {
  .chapter {
    grid-template-columns: 15rem minmax(0, 1fr);
    gap: 3.5rem;
    padding: 4.5rem 0 5rem;
  }
  .margin { padding-top: .2rem; }
}
@media (min-width: 1100px) {
  .chapter { grid-template-columns: 16.5rem minmax(0, 1fr); gap: 5rem; }
}

.facts {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .2rem .9rem;
  margin: 1.3rem 0 .6rem;
  font-size: .92rem;
  line-height: 1.45;
}
.facts > div { display: contents; }
.facts dt { font-style: italic; color: var(--graphite); }
.facts dd { margin: 0; }
.facts-link { font-size: .92rem; }
.margin .facts-link { color: var(--ink); }

/* Доска: гравюра из книги, тёмные поля заштрихованы */

.board {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: .4rem;
  row-gap: .2rem;
  width: min(100%, 30rem);
  font-size: .78rem;
  color: var(--graphite);
}
.board-ranks {
  grid-row: 1;
  grid-column: 1;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  padding-block: 6px;
  font-style: italic;
  text-align: right;
}
.board-frame {
  grid-row: 1;
  grid-column: 2;
  border: 2px solid var(--ink);
  padding: 3px;
}
.board-files {
  grid-row: 2;
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  padding-inline: 6px;
  font-style: italic;
  text-align: center;
}
.board-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 1px solid var(--ink);
  container-type: inline-size;
}
.board-bg,
.board-ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.trail {
  stroke: var(--cinnabar);
  stroke-width: .045;
  stroke-linejoin: round;
  stroke-linecap: round;
  fill: none;
}
.trail-close { stroke-dasharray: .09 .1; }

.sq {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sq:focus { outline: none; }
.sq:focus-visible { z-index: 2; outline: 3px solid var(--cinnabar); outline-offset: -3px; }
.sq.lift { z-index: 3; }

.pc {
  position: absolute;
  inset: 4%;
  background: center / contain no-repeat;
  pointer-events: none;
}
.pc:not([data-p]) { display: none; }
.pc[data-p="wK"] { background-image: url(/assets/pieces/wK.svg); }
.pc[data-p="wQ"] { background-image: url(/assets/pieces/wQ.svg); }
.pc[data-p="wR"] { background-image: url(/assets/pieces/wR.svg); }
.pc[data-p="wB"] { background-image: url(/assets/pieces/wB.svg); }
.pc[data-p="wN"] { background-image: url(/assets/pieces/wN.svg); }
.pc[data-p="wP"] { background-image: url(/assets/pieces/wP.svg); }
.pc[data-p="bK"] { background-image: url(/assets/pieces/bK.svg); }
.pc[data-p="bQ"] { background-image: url(/assets/pieces/bQ.svg); }
.pc[data-p="bR"] { background-image: url(/assets/pieces/bR.svg); }
.pc[data-p="bB"] { background-image: url(/assets/pieces/bB.svg); }
.pc[data-p="bN"] { background-image: url(/assets/pieces/bN.svg); }
.pc[data-p="bP"] { background-image: url(/assets/pieces/bP.svg); }

/* номера ходов на пройденных полях — как на старых диаграммах обхода */
.n {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 58%;
  height: 58%;
  border-radius: 50%;
  background: var(--paper);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-size: 4.4cqi;
  line-height: 1;
  font-variant-numeric: lining-nums;
  pointer-events: none;
}
.n:empty { display: none; }
.n.deg {
  width: 44%;
  height: 44%;
  font-size: 13px;
  font-size: 3.4cqi;
  font-style: italic;
  color: var(--graphite);
}
.sq.reach .n { color: var(--ink); box-shadow: 0 0 0 2px var(--cinnabar); }

/* последний ход: уголки киноварью */
.sq.last::before {
  content: "";
  position: absolute;
  inset: 3px;
  --c: var(--cinnabar);
  --l: 28%;
  --w: 2.5px;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) top left / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) top right / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) top right / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) bottom left / var(--w) var(--l),
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--w),
    linear-gradient(var(--c), var(--c)) bottom right / var(--w) var(--l);
  background-repeat: no-repeat;
}
.sq.sel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tint);
}
.sq.hinted::before { box-shadow: inset 0 0 0 3px var(--cinnabar); }

/* куда можно пойти */
.sq.tgt::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 24%;
  height: 24%;
  border-radius: 50%;
  background: var(--cinnabar);
  box-shadow: 0 0 0 2px var(--paper);
}
.sq.tgt.cap::after {
  width: 90%;
  height: 90%;
  background: none;
  border: 3px solid var(--cinnabar);
  box-shadow: 0 0 0 1px var(--paper), inset 0 0 0 1px var(--paper);
}
.sq.tgt.hint::after {
  width: 34%;
  height: 34%;
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--cinnabar);
}
@media (hover: hover) {
  .sq.tgt:hover::after { width: 32%; height: 32%; }
}

.nope {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  z-index: 3;
  text-align: center;
  font-style: italic;
  font-size: 15px;
  font-size: max(13px, 3.6cqi);
  line-height: 1;
  color: var(--cinnabar);
  pointer-events: none;
  animation: nope 1.3s ease-out forwards;
}
.nope span { background: var(--paper); padding: .05em .3em .12em; }
@keyframes nope {
  0% { opacity: 0; }
  10% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; }
}

.caption { margin: 1rem 0 0; max-width: 30rem; }
.moves { font-variant-numeric: lining-nums; }
.status { margin: .3rem 0 1.1rem; min-height: 1.55em; max-width: 34em; }
.status.solved { color: var(--cinnabar); }
.controls { display: flex; flex-wrap: wrap; gap: .55rem; }
#tour-board + .status { margin-top: 1rem; }

/* Хроника */

.chronicle {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 41rem;
}
.chronicle li {
  display: grid;
  grid-template-columns: 7.4rem minmax(0, 1fr);
  column-gap: 1.2rem;
  padding: .85rem 0 .9rem;
  border-top: 1px solid var(--rule);
}
.chronicle li:first-child { border-top: 0; padding-top: 0; }
.chronicle time {
  font-style: italic;
  color: var(--graphite);
  font-size: .92rem;
  line-height: 1.6;
  padding-top: .1em;
}
.chronicle a {
  font-size: 1.05rem;
  line-height: 1.4;
  text-decoration: none;
}
.chronicle a:hover { text-decoration: underline; }
.chronicle .src {
  grid-column: 2;
  font-size: .85rem;
  color: var(--graphite);
}
.chronicle .chronicle-empty {
  display: block;
  font-style: italic;
  color: var(--graphite);
}
.updated { font-style: italic; }
@media (max-width: 540px) {
  .chronicle li { grid-template-columns: minmax(0, 1fr); }
  .chronicle .src { grid-column: 1; }
}

/* Часы */

.clock {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
  max-width: 36rem;
  margin-bottom: 1.1rem;
}
.clock-side {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 3px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.clock-face {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-height: 9.5rem;
  padding: .7rem .7rem .8rem;
  border: 1px solid var(--ink);
}
.clock-name { font-style: italic; }
.clock-time {
  margin-top: auto;
  font-weight: 700;
  font-size: clamp(2.3rem, 1rem + 5.4vw, 4.4rem);
  line-height: 1;
  letter-spacing: -.01em;
  white-space: nowrap;
  font-variant-numeric: lining-nums tabular-nums;
}
@media (min-width: 600px) { .clock-face { padding: .75rem .95rem .85rem; } }
.clock-note { min-height: 1.4em; font-size: .9rem; font-style: italic; line-height: 1.4; }
.clock-side.is-running .clock-face { background: var(--ink); color: var(--paper); }
.clock-side.is-flag { border-color: var(--cinnabar); }
.clock-side.is-flag .clock-face { border-color: var(--cinnabar); color: var(--cinnabar); }
.presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .3rem;
  max-width: 36rem;
  margin: 0 0 .9rem;
}
.presets .btn { padding-inline: 0; white-space: nowrap; font-size: .85rem; font-variant-numeric: lining-nums; }
@media (min-width: 600px) {
  .presets { display: flex; flex-wrap: wrap; gap: .4rem; }
  .presets .btn { padding-inline: .7rem; font-size: .9rem; }
}

/* Подвал */

.colophon {
  position: relative;
  margin-top: 1.5rem;
  padding: 1.7rem 0 3rem;
  border-top: 1px solid var(--ink);
  font-size: .85rem;
  line-height: 1.5;
  color: var(--graphite);
}
.colophon::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 3px;
  border-top: 2px solid var(--ink);
}
.colophon p { margin: 0 0 .4rem; max-width: 40em; }
.colophon p:first-child { color: var(--ink); }

.noscript { padding: 0 0 2rem; font-style: italic; color: var(--graphite); }

/* Страница 404 */

.lost {
  display: grid;
  gap: 2.5rem;
  align-items: center;
  padding: 3.5rem 0 5rem;
}
.lost h1 {
  font-size: clamp(2.8rem, 1.6rem + 4.6vw, 5rem);
  line-height: .95;
  margin: 0 0 1.4rem;
}
.lost p { max-width: 30em; margin: 0 0 1rem; }
.lost svg { display: block; width: min(100%, 17rem); height: auto; }
.lost figcaption { margin-top: .5rem; font-size: .9rem; font-style: italic; color: var(--graphite); }
.lost figure { margin: 0; }
@media (min-width: 861px) {
  .lost { grid-template-columns: minmax(0, 1fr) 18rem; gap: 4rem; padding: 5rem 0 7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .nope { animation-duration: 1.6s; }
}
