@font-face {
  font-family: "Bevan";
  src: url(assets/fonts/bevan-latin-400-normal.woff2) format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Libre Franklin";
  src: url(assets/fonts/libre-franklin-latin-wght-normal.woff2) format("woff2");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}
:root {
  color-scheme: light;
  --canvas: #ffffff;
  --panel: #ffffff;
  --subtle: #f1f2f3;
  --ink: #121213;
  --edition: #383a3c;
  --muted: #56595d;
  --line: #d3d6da;
  --key: #d3d6da;
  --key-hover: #bdc0c3;
  --key-active: #56595d;
  --green: #538d4e;
  --primary-hover: #42733f;
  --focus: #2260a2;
  --light-square: #f6f7f6;
  --dark-square: #78a474;
  --board-grid: var(--canvas);
  --square-edge: var(--line);
  --check-square: #f0b8aa;
  --check-edge: #975240;
  --yellow: #e7ce79;
  --last-move: #a88a3b;
  --legal-move: #1c332699;
  --heart: #b93e4e;
  --heart-tile: #f9e9e9;
  --empty-heart: #75797d;
  --heart-badge: #fffafa;
  --heart-border: #e8c6cb;
  --hint-bg: #f6f2e5;
  --backdrop: #12121360;
  --sans: "NYT Franklin", "NYTFranklin", "nyt-franklin", "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
  --slab: "NYT Karnak Condensed", "NYTKarnakCondensed", "nyt-karnakcondensed", "Karnak Condensed", "Bevan", Rockwell, Georgia, serif;
  --mast-height: 61px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --viewport-height: 100vh;
  --stack-space: 390px;
}
@supports (height: 100svh) { :root { --viewport-height: 100svh; } }
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #171a19;
  --panel: #242a26;
  --subtle: #2d3430;
  --ink: #f2f4ee;
  --edition: #d2dacf;
  --muted: #b5bdb5;
  --line: #414943;
  --key: #38413b;
  --key-hover: #49564c;
  --key-active: #476c50;
  --green: #42774e;
  --primary-hover: #4f815a;
  --focus: #91caff;
  --light-square: #c0ceda;
  --dark-square: #587185;
  --board-grid: #35434e;
  --square-edge: var(--light-square);
  --check-square: #da978c;
  --check-edge: #84483e;
  --yellow: #e3c376;
  --last-move: #ffe09a;
  --legal-move: #0b2033bf;
  --heart: #ff97a0;
  --heart-tile: #3c292e;
  --empty-heart: #a0afa3;
  --heart-badge: #402d33;
  --heart-border: #8e636d;
  --hint-bg: #393625;
  --backdrop: #060a08ab;
}
* { box-sizing: border-box; }
body { margin: 0; padding: var(--safe-top) env(safe-area-inset-right, 0px) var(--safe-bottom) env(safe-area-inset-left, 0px); color: var(--ink); background: var(--canvas); font: 15px/1.4 var(--sans); -webkit-font-smoothing: antialiased; }
button { appearance: none; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button, h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }

.mast { border-bottom: 1px solid var(--line); }
.mast-inner { max-width: 1000px; height: var(--mast-height); padding: 0 12px; margin: auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.nav-tools { display: flex; justify-self: end; }
#theme-toggle .sun, [data-theme="dark"] #theme-toggle .moon { opacity: 0; }
[data-theme="dark"] #theme-toggle .sun { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .theme-fading *, .theme-fading ::before, .theme-fading ::after, .theme-fading dialog::backdrop {
    transition-property: background-color, border-color, color, outline-color, box-shadow, fill, stroke;
    transition-duration: var(--theme-fade-duration);
    transition-timing-function: ease-in-out;
  }
  .theme-fading #theme-toggle use { transition-property: opacity; }
}
.brand { font: 700 35px/1 var(--slab); letter-spacing: -.045em; text-align: center; white-space: nowrap; }
.nav-button, .close { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: none; border-radius: 3px; background: transparent; }
.nav-button .icon { width: 25px; height: 25px; }
.nav-button:hover, .close:hover { background: var(--subtle); }

.page {
  --board-limit: clamp(260px, calc(var(--viewport-height) - var(--stack-space) - var(--safe-top) - var(--safe-bottom)), 660px);
  width: min(calc(100% - 36px), var(--board-limit));
  margin: 0 auto;
  padding-bottom: 12px;
}
.intro { text-align: center; margin: 24px 0 19px; }
.issue { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); line-height: 1.4; }
.issue > span:first-child { color: var(--edition); }
.intro h1 { font-size: 35px; line-height: 1.05; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -1.55px; margin: 7px 0 6px; }
#score-note { font-size: 14px; line-height: 1.35; color: var(--muted); }
.board-top, .hearts, .modal-score, .actions, .countdown, .modal-actions { display: flex; align-items: center; }
.board-top { min-height: 32px; justify-content: space-between; gap: 7px; margin-bottom: 9px; }
.turn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.turn::before { content: ""; width: 9px; height: 9px; border: 1.5px solid var(--ink); border-radius: 50%; background: #fff; flex: none; }
.turn[data-side="b"]::before { background: #121213; }
.turn.waiting { color: var(--muted); }
.hearts, .modal-score { gap: 4px; }
.heart { width: 28px; height: 28px; padding: 5px; display: block; background: var(--heart-tile); fill: var(--heart); stroke: var(--heart); stroke-width: 1.3px; stroke-linejoin: round; }
.heart.empty { background: var(--subtle); fill: none; stroke: var(--empty-heart); }

.frame { position: relative; margin-bottom: 17px; }
.board { width: 100%; position: relative; aspect-ratio: 1; display: grid; grid-template: repeat(8,minmax(0,1fr)) / repeat(8,minmax(0,1fr)); gap: 2px; background: var(--board-grid); touch-action: manipulation; }
.ranks, .files { position: absolute; display: grid; color: var(--muted); font: 700 9px/1 var(--sans); user-select: none; }
.ranks { top: 0; bottom: 0; right: calc(100% + 5px); width: 9px; grid-template-rows: repeat(8,1fr); }
.files { left: 0; right: 0; top: calc(100% + 4px); grid-template-columns: repeat(8,1fr); }
.ranks span, .files span { display: grid; place-items: center; }
.square { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; background: var(--light-square); border: 1px solid var(--square-edge); border-radius: 0; padding: 0; user-select: none; touch-action: manipulation; }
.square.dark { background: var(--dark-square); border-color: var(--dark-square); }
.square img { position: relative; z-index: 1; display: block; width: 88%; height: 88%; pointer-events: none; user-select: none; object-fit: contain; }
.piece-motion { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.piece-motion img { position: absolute; display: block; object-fit: contain; }
.board-effect {
  --duration: 900ms;
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center;
  pointer-events: none; animation: board-effect-visibility var(--duration) ease-out both;
}
.heart-badge {
  display: grid; place-items: center; width: clamp(70px, 22%, 96px); aspect-ratio: 1;
  border-radius: 50%; background: var(--heart-badge); border: 2px solid var(--heart-border);
  box-shadow: 0 4px 16px #31131938;
  animation: board-effect-pop var(--duration) ease-out both;
}
.heart-badge svg { width: 74%; fill: var(--heart); }
.heart-half { transform-origin: 24px 24px; animation: heart-split var(--duration) ease-out both; }
.heart-half.left { --split: translate(-2.8px, 1px) rotate(-9deg); }
.heart-half.right { --split: translate(2.8px, 2px) rotate(9deg); }
.checkmate-win { --duration: 1250ms; }
.mate-badge {
  display: grid; justify-items: center; gap: 2px; padding: 11px 23px 15px;
  border: 2px solid #fff4d6; border-radius: 9px; background: #24513b; color: #fff8e8;
  box-shadow: 0 0 0 1px #28543d, 0 5px 18px #10251d4d;
  animation: board-effect-pop var(--duration) ease-out both;
}
.mate-badge strong { font: 700 clamp(24px, 5vw, 32px)/1.04 var(--slab); letter-spacing: -.8px; }
.mate-crown { width: 80px; color: #ffda82; }
.mate-sparks { transform-origin: 50% 55%; animation: mate-rays var(--duration) ease-out both; }
@keyframes mate-rays {
  0%, 15% { opacity: 0; transform: scale(.6); }
  35%, 100% { opacity: 1; transform: scale(1); }
}
@keyframes board-effect-visibility {
  0%, 100% { opacity: 0; }
  12%, 78% { opacity: 1; }
}
@keyframes board-effect-pop {
  0% { transform: scale(.68); }
  22% { transform: scale(1.08); }
  38%, 78% { transform: scale(1); }
  100% { transform: scale(.96); }
}
@keyframes heart-split {
  0%, 24% { transform: none; }
  49%, 100% { transform: var(--split); }
}
@media (prefers-reduced-motion: reduce) {
  .board-effect { --duration: 550ms; }
  .checkmate-win { --duration: 850ms; }
  .heart-badge, .heart-half, .mate-badge, .mate-sparks { animation: none; }
  .heart-half { transform: var(--split); }
}
.square.arriving img { visibility: hidden; }
.square.last { border-color: var(--last-move); box-shadow: inset 0 0 0 1px var(--last-move); }
.square.selected { background: var(--yellow); border-color: #51431c; box-shadow: inset 0 0 0 1px #51431c; }
.square.target::after { content: ""; position: absolute; z-index: 2; width: 25%; height: 25%; background: var(--legal-move); border-radius: 50%; }
.square.target.capture::after { width: 80%; height: 80%; background: transparent; border: 3px solid var(--legal-move); }
.square.hinted::before { content: ""; position: absolute; inset: 3px; border: 2px dashed #47390f; z-index: 2; }
.square.in-check { background: var(--check-square); border-color: var(--check-edge); }
.square:focus-visible { z-index: 3; outline-offset: -3px; }
.board-note { padding: 5px 0 0; text-align: center; color: var(--muted); font-size: 12px; min-height: 23px; }
.actions { gap: 6px; margin: 12px 0 0; }
.key, .tool-button, .primary, .result-open { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 4px; font-size: 12px; font-weight: 750; }
.key { flex: 1; min-height: 44px; padding: 7px 4px; text-transform: uppercase; letter-spacing: .5px; background: var(--key); }
.key .icon { width: 16px; height: 16px; }
.key:enabled:hover, .tool-button:hover { background: var(--key-hover); }
.key[aria-expanded="true"] { background: var(--key-active); color: #fff; }
.hint-msg { padding: 10px 12px; border-left: 4px solid #c9b458; background: var(--hint-bg); margin-top: 10px; font-size: 13px; }
.result-open, .primary { background: var(--green); color: #fff; min-height: 42px; padding: 10px 14px; }
.result-open { width: 100%; margin-top: 9px; }
.result-open:hover, .primary:hover { background: var(--primary-hover); }
#sheet-panel { margin-top: 14px; }
#sheet-panel h2 { font-size: 15px; margin: 0 0 7px; }
.table-wrap { max-height: 170px; overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; text-align: left; }
thead { background: var(--subtle); }
th, td { padding: 6px 10px; }
th { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; }
th:first-child { width: 20%; }
td { border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
td.blank, td:first-child { color: var(--muted); font-weight: 400; }
footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); margin-top: 15px; color: var(--muted); }
.countdown { gap: 5px; font-size: 11px; }
.countdown .icon { width: 13px; height: 13px; }
.countdown strong { color: var(--ink); font: 700 11px/1 var(--sans); font-variant-numeric: tabular-nums; }
#credits { background: transparent; border: 0; font-size: 11px; color: var(--muted); padding: 10px 0 10px 8px; }
#credits:hover { text-decoration: underline; }

dialog { width: min(414px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); max-height: calc(var(--viewport-height) - 16px - var(--safe-top) - var(--safe-bottom)); overflow: auto; overscroll-behavior: contain; padding: clamp(16px, 4vw, 28px); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 26px #0003; font: 15px/1.5 var(--sans); }
dialog::backdrop { background: var(--backdrop); }
.close { position: absolute; top: 7px; right: 7px; width: 38px; height: 38px; }
dialog h2 { padding-right: 18px; margin: 3px 0 15px; font: 700 30px/1.12 var(--slab); letter-spacing: -1px; }
dialog p, dialog li { font-size: 14px; }
dialog p { margin: 10px 0; }
dialog ol { margin: 10px 0 17px; padding-left: 20px; }
dialog li { margin: 7px 0; padding-left: 3px; }
dialog a { color: inherit; }
dialog .primary { width: 100%; margin: 12px 0 0; font-size: 14px; }
.modal-actions { gap: 8px; margin-top: 16px; }
.modal-actions > button { flex: 1; margin: 0; }
.tool-button { padding: 10px 13px; background: var(--key); min-height: 42px; }
.modal-score { margin: 8px 0 14px; }
.modal-score .heart { width: 37px; height: 37px; padding: 7px; }
.replay-figure { margin: 14px 0 8px; }
.replay-figure figcaption { font-weight: 750; margin-bottom: 8px; }
.replay-frame { position: relative; margin: 0 2px 20px 14px; }
.replay-frame .board { gap: 1px; }
.move-arrow { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
.move-arrow path { fill: #ffcf53; stroke: #3b2b12; stroke-width: .035; stroke-linejoin: round; }
#replay-steps { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 6px; text-align: center; }
#replay-steps button { min-height: 44px; }
#replay-counter { font-size: 14px; font-weight: 750; }
.replay-description { text-align: center; font-size: 13px; margin: 6px 0; }
.result-layout > * { min-width: 0; }
.result-overview p { margin: 3px 0; }
.result-tools .modal-actions { margin-top: 8px; }
.stat-grid { display: flex; justify-content: space-around; margin: 16px 0 20px; text-align: center; }
.stat-grid b { display: block; font: 500 37px/1.05 var(--sans); }
.stat-grid small { font-size: 11px; color: var(--muted); }
.result-bars { display: grid; grid-template-columns: 44px 1fr 17px; gap: 5px 7px; align-items: center; font-size: 12px; }
.track { height: 14px; background: var(--subtle); }
.track i { display: block; height: 100%; background: var(--green); }
.promotion { display: flex; gap: 5px; }
.promotion button { border: 1px solid var(--line); background: var(--subtle); padding: 5px; width: 25%; }
.promotion img { width: 100%; display: block; background: var(--light-square); border-radius: 2px; }
.promotion small { font-size: 11px; }
.share-text { white-space: pre-wrap; background: var(--subtle); padding: 10px; font: 13px/1.4 var(--sans); }
#share-state { font-size: 13px; margin-top: 8px; }
.load-error { grid-area: 1 / 1 / -1 / -1; display: grid; gap: 8px; place-content: center; text-align: center; background: var(--subtle); }

@media (max-width: 500px), (max-height: 740px) {
  :root { --mast-height: 52px; --stack-space: 350px; }
  .brand { font-size: 30px; }
  .intro { margin: 18px 0 13px; }
  .intro h1 { font-size: 30px; }
  #score-note { font-size: 13px; }
  .heart { width: 25px; height: 25px; padding: 4px; }
  .board-top { margin-bottom: 6px; }
  footer { margin-top: 11px; }
}
@media (max-width: 360px) {
  .board { gap: 1px; }
  .turn { font-size: 11px; }
}
@media (max-width: 420px) {
  .mast-inner { padding-inline: 5px; }
  .brand { font-size: clamp(22px, 7vw, 28px); letter-spacing: -1px; }
}
@media (max-height: 740px) {
  :root { --mast-height: 46px; --stack-space: 278px; }
  .intro { margin: 8px 0 4px; }
  .intro h1 { margin: 3px 0 2px; font-size: 26px; }
  .board-top { min-height: 26px; margin-bottom: 4px; }
  .board-note { min-height: 0; padding: 0; }
  .actions { margin-top: 7px; }
  footer { margin-top: 6px; }
  .page { padding-bottom: 6px; }
}
@media (min-width: 540px) and (min-aspect-ratio: 6/5) {
  .page {
    --edge: clamp(8px, 2.4vh, 28px);
    --board-limit: min(680px, calc(var(--viewport-height) - var(--mast-height) - var(--edge) - var(--edge) - 18px - var(--safe-top) - var(--safe-bottom)));
    --rail: clamp(208px, 30vw, 300px);
    --gap: clamp(18px, 4vw, 56px);
    width: min(calc(100% - 40px), calc(var(--board-limit) + var(--rail) + var(--gap)));
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--rail);
    grid-template-rows: 1fr repeat(4, auto) 1fr;
    column-gap: var(--gap);
    padding-block: var(--edge);
    align-items: start;
  }
  .board-section { grid-area: 1 / 1 / -1 / 2; }
  .intro { grid-area: 2 / 2; text-align: left; margin: 0 0 14px; }
  .issue { justify-content: flex-start; }
  .board-top { grid-area: 3 / 2; margin: 0; }
  .board-note { grid-area: 4 / 2; text-align: left; margin: 6px 0; }
  .puzzle-tools { grid-area: 5 / 2; min-width: 0; }
  .key { gap: 4px; font-size: clamp(10px, 1.3vw, 12px); }
  .key .icon { width: 14px; height: 14px; }
  dialog[data-view="result"] { width: min(780px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); }
  .result-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    gap: 8px clamp(14px, 3vw, 26px);
    align-items: start;
  }
  .replay-figure { margin: 0; grid-area: 1 / 1 / -1 / 2; }
  .result-overview, .replay-controls, .result-tools { grid-column: 2; }
  .result-overview .modal-score { margin: 0 0 5px; }
  .result-tools .modal-actions { flex-wrap: wrap; }
}
@media (min-width: 540px) and (min-aspect-ratio: 6/5) and (max-height: 500px) {
  dialog[data-view="result"] { padding: 12px 16px; }
  dialog[data-view="result"] h2 { margin: 0 0 5px; font-size: 24px; }
  .replay-frame { max-width: calc(var(--viewport-height) - 116px - var(--safe-top) - var(--safe-bottom)); }
  .result-layout { grid-template-columns: minmax(0, min(45%, calc(var(--viewport-height) - 98px))) minmax(0, 1fr); }
  .result-overview .heart { width: 25px; height: 25px; padding: 4px; }
  .result-overview p { font-size: 12px; }
}
