:root {
  --paper: #f3ead8;
  --sheet: #faf6ec;
  --ink: #2c2416;
  --muted: #5c5346;
  --rule: #cbb99a;
  --oxblood: #8a2e1f;
  --oxblood-d: #6c2116;
  --board-light: #f0dcc0;
  --board-dark: #b06a45;
  --sel: #e2c15a;
  --last: #d7c07a;
  --check: #d36a4e;
  --dot: #2c2416;
  --white-piece: #fbf6ea;
  --black-piece: #3a2a1c;
  --serif: Palatino, "Palatino Linotype", "Book Antiqua", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: Candara, Calibri, "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  min-height: 100%;
}

body {
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 11px,
      rgba(44, 36, 22, 0.03) 11px,
      rgba(44, 36, 22, 0.03) 12px
    );
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
}

.masthead {
  width: min(1080px, 100%);
  padding: 22px 24px 0;
  border-bottom: 3px double var(--ink);
  margin-bottom: 22px;
}

.mast-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  padding: 6px 0;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.folio { color: var(--oxblood); font-weight: 700; letter-spacing: 0.16em; }

h1 {
  margin: 16px 0 8px;
  font-weight: 700;
  font-size: clamp(32px, 6vw, 54px);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0 0 18px;
  max-width: 46em;
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
}

.tabs {
  display: flex;
  gap: 0;
  margin: 0;
}

.tab {
  appearance: none;
  background: transparent;
  border: 1px solid var(--ink);
  border-bottom: none;
  padding: 8px 20px;
  margin-right: -1px;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.tab.is-on {
  background: var(--sheet);
  color: var(--ink);
  font-weight: 700;
}

main {
  width: min(1080px, 100%);
  padding: 0 24px;
  flex: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 22px;
  box-shadow: 0 1px 0 rgba(44, 36, 22, 0.06);
}

.layout.is-hidden { display: none; }

.stage {
  display: flex;
  justify-content: center;
  width: min(100%, 500px);
  max-width: 100%;
  margin-inline: auto;
  container-type: inline-size;
  min-width: 0;
}

.board {
  width: 100%;
  --sq: calc((100cqw - 36px) / 8);
  display: grid;
  grid-template-columns: 18px repeat(8, var(--sq)) 18px;
  grid-template-rows: 16px repeat(8, var(--sq)) 16px;
  user-select: none;
  touch-action: manipulation;
}

.coord {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--sq) * 0.72);
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sq.light { background: var(--board-light); }
.sq.dark { background: var(--board-dark); }
.sq.last { box-shadow: inset 0 0 0 1000px rgba(215, 192, 122, 0.42); }
.sq.sel { box-shadow: inset 0 0 0 4px var(--sel); }
.sq.check { box-shadow: inset 0 0 0 1000px rgba(211, 106, 78, 0.45); }
.sq.check.sel { box-shadow: inset 0 0 0 1000px rgba(211, 106, 78, 0.45), inset 0 0 0 4px var(--sel); }

.piece { pointer-events: none; font-family: "Segoe UI Symbol", "Apple Color Emoji", "Noto Sans Symbols", serif; }
.piece.w {
  color: var(--white-piece);
  text-shadow:
    -1px -1px 0 #3a2a1c,
     1px -1px 0 #3a2a1c,
    -1px  1px 0 #3a2a1c,
     1px  1px 0 #3a2a1c;
}
.piece.b { color: var(--black-piece); }

.dot, .cap {
  position: absolute;
  pointer-events: none;
}
.dot {
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: rgba(44, 36, 22, 0.35);
}
.cap {
  inset: 6%;
  border-radius: 50%;
  border: 4px solid rgba(44, 36, 22, 0.38);
}

.desk { min-width: 0; }
.status {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.3;
  min-height: 2.6em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  width: 100%;
}

select, button {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--ink);
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
}

button:hover, select:hover { background: #fff; }
button:active { background: var(--paper); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }

.row { margin-bottom: 10px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns button { flex: 1 1 140px; }

.desk-title {
  margin: 18px 0 8px;
  font-size: 13px;
  font-family: var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
  font-weight: 700;
}

.moves {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 280px;
  overflow: auto;
  font-size: 16px;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

.moves li { display: grid; grid-template-columns: 2em 1fr 1fr; gap: 8px; }
.moves .n { color: var(--muted); }

.plist {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 340px;
  overflow: auto;
}

.plist button {
  width: 100%;
  text-align: left;
  border-color: var(--rule);
  padding: 8px 10px;
}

.plist button.is-on {
  border-color: var(--oxblood);
  background: #f6ebe0;
  color: var(--oxblood-d);
  font-weight: 700;
}

.plist .pn {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}

.promo {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 22, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.promo[hidden] { display: none; }

.promo p {
  font-family: var(--sans);
  background: var(--sheet);
  margin: 0;
  padding: 10px 16px 0;
  width: min(280px, 90vw);
  border: 1px solid var(--ink);
  border-bottom: 0;
}

.promo-row {
  display: flex;
  background: var(--sheet);
  border: 1px solid var(--ink);
  width: min(280px, 90vw);
}

.promo-row button {
  flex: 1;
  font-size: 36px;
  border: 0;
  border-right: 1px solid var(--rule);
  padding: 12px 0;
  line-height: 1;
}

.promo-row button:last-child { border-right: 0; }

footer {
  width: min(1080px, 100%);
  padding: 20px 24px 28px;
  margin-top: auto;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

footer p { margin: 0; border-top: 1px solid var(--rule); padding-top: 12px; }

@media (max-width: 820px) {
  .masthead, main, footer { padding-left: 14px; padding-right: 14px; }
  .masthead { padding-top: 12px; margin-bottom: 14px; }
  h1 { font-size: 30px; margin-top: 12px; }
  .lead { font-size: 15px; margin-bottom: 12px; }
  .layout {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px;
  }
  .board { width: min(100%, 500px); }
  .status { font-size: 18px; min-height: 0; }
  .moves { max-height: 160px; }
  .plist { max-height: 220px; }
  footer { padding-bottom: 16px; }
}

@media (max-width: 400px) {
  .mast-top { font-size: 10px; letter-spacing: 0.08em; }
  h1 { font-size: 26px; }
  .tab { padding: 7px 12px; font-size: 12px; }
  .board { width: 100%; }
}

.sq.hint { box-shadow: inset 0 0 0 1000px rgba(46, 110, 80, 0.42); }
.sq.hint.last { box-shadow: inset 0 0 0 1000px rgba(46, 110, 80, 0.42); }
.sq.hint.sel { box-shadow: inset 0 0 0 1000px rgba(46, 110, 80, 0.42), inset 0 0 0 4px var(--sel); }
.sq.hint.check { box-shadow: inset 0 0 0 1000px rgba(46, 110, 80, 0.35), inset 0 0 0 3px var(--check); }

.board-arrows {
  grid-column: 2 / 10;
  grid-row: 2 / 10;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.hint-count {
  margin: -8px 0 14px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.puzzle-meta {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.puzzle-meta strong {
  color: var(--ink);
  font-weight: 700;
}

.status.is-ok { color: #2e5a45; }
.status.is-bad { color: var(--oxblood); }

.dialog-card {
  background: var(--sheet);
  border: 1px solid var(--ink);
  width: min(360px, 92vw);
  padding: 18px 18px 14px;
}

.dialog-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.dialog-text {
  margin: 0 0 16px;
  font-size: 16px;
  line-height: 1.4;
}

#dialog-ok { font-weight: 700; }

footer .attr {
  text-transform: none;
  letter-spacing: 0.04em;
  margin-top: 6px;
  border-top: 0;
  padding-top: 0;
}
