:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --panel: #fffdf6;
  --ink: #1b2e27;
  --muted: #53665e;
  --line: #d8ded2;
  --board: #172c24;
  --board-line: #456052;
  --tile: #223d33;
  --sage: #b8dfc0;
  --amber: #ffc857;
  --sans: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-underline-offset: 0.22em; }
:focus-visible { outline: 3px solid #257854; outline-offset: 4px; }

.site-header { border-bottom: 1px solid #dddccc; }
.header-inner, main { width: min(960px, calc(100% - 64px)); margin-inline: auto; }
.header-inner, .brand, nav { display: flex; align-items: center; }
.header-inner { justify-content: space-between; min-height: 72px; gap: 16px; }
.brand { gap: 11px; text-decoration: none; font-weight: 750; letter-spacing: -0.03em; font-size: 1.17rem; }
.brand-mark { position: relative; flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; background: var(--board); }
.brand-mark::before { content: ""; position: absolute; top: 8px; left: 8px; width: 14px; height: 14px; border-left: 2px solid var(--sage); border-bottom: 2px solid var(--sage); }
.brand-mark i { position: absolute; width: 6px; height: 6px; border-radius: 2px; background: var(--sage); }
.brand-mark i:nth-child(1) { top: 6px; left: 6px; }
.brand-mark i:nth-child(2) { top: 18px; left: 6px; }
.brand-mark i:nth-child(3) { top: 18px; left: 19px; background: var(--amber); }
nav { gap: 5px; }
nav button { min-height: 38px; padding: 7px 13px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 650; font-size: 0.89rem; white-space: nowrap; }
nav button[aria-pressed="true"] { background: #e2ebde; color: var(--ink); }
nav button:hover { color: var(--ink); border-color: var(--line); }
nav .rules { margin-left: 6px; border-color: #d1d9ce; color: var(--ink); }

main { padding-block: 38px 25px; }
.intro { margin-bottom: 28px; }
.intro p { margin: 0; color: var(--muted); font-size: 1.03rem; line-height: 1.5; }
.intro .challenge { font-family: var(--mono); color: #38644e; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.intro h1 { margin: 6px 0 8px; font-size: clamp(2.3rem, 6vw, 3.65rem); letter-spacing: -0.06em; line-height: 1.04; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 15px 22px; align-items: start; }
.board-shell { grid-row: 1 / 3; --gap: 9px; border-radius: 20px; background: var(--board); color: #f3f6ed; padding: 21px; box-shadow: 0 10px 20px #14281911; }
.board-heading { display: flex; justify-content: space-between; align-items: center; min-height: 30px; margin-bottom: 13px; font-weight: 670; }
.board-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.board-heading button { min-height: 30px; padding: 3px 9px; border: 1px solid var(--board-line); border-radius: 6px; background: transparent; color: #d6e8d9; font-size: 0.8rem; }
.board-heading button:hover { background: var(--tile); }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 52px;
  aspect-ratio: 1.32;
  padding: 4px;
  border: 1px solid #3e5b4e;
  border-radius: 10px;
  background: var(--tile);
  color: #e8eee6;
  font-family: var(--mono);
  font-weight: 670;
  font-size: clamp(0.95rem, 3.1vw, 1.48rem);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cell[aria-disabled="true"] { cursor: default; }
.board:focus-visible, .cell:focus-visible, .board-heading button:focus-visible { outline-color: var(--amber); outline-offset: 2px; z-index: 3; }
.cell.available { border-color: #a8c8ad; background: #335747; color: #fffdf2; }
.cell.available:hover { background: #466c56; }
.cell.visited { background: #49735e; border-color: #7fad91; color: #fffdf2; }
.cell.route-end { background: #35493c; color: #fff3c8; border-color: #647763; }
.cell.route-end.available { border-color: var(--amber); }
.cell.current { background: var(--sage); color: var(--ink); border-color: var(--sage); box-shadow: inset 0 0 0 2px #2a4c3b; }
.cell.hinted, .cell.finish-solved { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.cell.hinted:hover { background: #ffda85; }
.cell.finish-mismatch { background: #ffbeb0; color: #48261c; border-color: #ffbeb0; box-shadow: inset 0 0 0 2px #884e42; }
.tile-label { font-family: var(--sans); font-size: 0.62em; line-height: 1; letter-spacing: 0.06em; text-transform: uppercase; }
.trail-right::after, .trail-left::after, .trail-up::after, .trail-down::after {
  content: "";
  position: absolute;
  background: #96cfa7;
  border-radius: 3px;
  pointer-events: none;
  z-index: 2;
}
.trail-right::after, .trail-left::after { width: calc(var(--gap) + 6px); height: 4px; top: calc(50% - 2px); }
.trail-right::after { left: calc(100% - 2px); }
.trail-left::after { right: calc(100% - 2px); }
.trail-up::after, .trail-down::after { height: calc(var(--gap) + 6px); width: 4px; left: calc(50% - 2px); }
.trail-up::after { bottom: calc(100% - 2px); }
.trail-down::after { top: calc(100% - 2px); }
.board-instructions { margin: 14px 0 0; color: #c0d3c4; line-height: 1.45; font-size: 0.79rem; }

.values, .controls { border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.values { display: grid; grid-template-columns: 1fr 1fr; padding: 18px 6px; }
.values > div { min-width: 0; padding-inline: 15px; }
.values .target { border-left: 1px solid var(--line); }
.values p { margin: 0 0 5px; color: var(--muted); font-size: 0.77rem; font-weight: 650; }
.values .score { display: block; font: 650 clamp(1.25rem, 3.6vw, 2.3rem)/1.15 var(--mono); letter-spacing: -0.07em; overflow-wrap: anywhere; }
.values .target .score { color: #77500b; }
.controls { padding: 20px; }
.moves { display: flex; justify-content: space-between; gap: 5px; align-items: baseline; font-size: 0.84rem; }
.moves strong { font: 650 0.89rem var(--mono); }
.meter { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin: 9px 0 18px; }
.meter span { height: 5px; border-radius: 4px; background: #e1e6dc; }
.meter .used { background: #4d8567; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.actions button, .share, dialog button { min-height: 38px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--ink); font-size: 0.86rem; font-weight: 670; }
.actions button:disabled { color: #6f7d74; background: #f1f2ea; }
.actions button:not(:disabled):hover { background: #e6eee3; }
.actions #hint:not(:disabled) { background: #fff0c7; border-color: #e6cd8b; }
.actions #hint:not(:disabled):hover { background: #ffe5ab; }
.status { min-height: 2.7em; margin: 15px 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.status.solved { color: #175c37; font-weight: 670; }
.status.mismatch { color: #8f3222; }
.share { width: 100%; margin-top: 8px; color: #f8faf3; background: var(--board); }
.share:hover, dialog button:hover { background: #304a3c; }
.share-fallback { margin-top: 9px; font-size: 0.8rem; }
.share-fallback textarea { display: block; width: 100%; margin-top: 5px; border: 1px solid var(--line); border-radius: 6px; padding: 7px; background: var(--paper); color: var(--ink); resize: vertical; }
.streak { margin: 13px 0 0; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.79rem; }
.footer { display: flex; justify-content: space-between; gap: 8px 22px; flex-wrap: wrap; margin-top: 22px; color: var(--muted); font-size: 0.79rem; }

dialog { max-width: min(460px, calc(100% - 32px)); padding: 22px 24px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); color: var(--ink); box-shadow: 0 12px 55px #12271a44; }
dialog::backdrop { background: #14251cc4; }
dialog h2 { margin: 0 0 13px; font-size: 1.5rem; }
dialog ol { padding-left: 22px; line-height: 1.5; }
dialog li + li { margin-top: 7px; }
dialog p { line-height: 1.45; }
dialog button { padding-inline: 12px; background: var(--board); color: #f8faf3; }

.archive-dialog { width: 100%; max-height: calc(100dvh - 24px); }
.archive-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.archive-heading h2 { margin: 0; font-size: 1.2rem; }
.archive-list { list-style: none; padding: 0; margin: 19px 0; }
.archive-list li + li { margin-top: 5px; }
.archive-list button {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; color: var(--ink); background: var(--panel); text-align: left;
}
.archive-list button:hover, .archive-list button[aria-current="date"] { background: #e2ebde; }
.archive-list button span { color: var(--muted); font-size: .8rem; }
.archive-jump label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .85rem; }
.archive-jump div { display: flex; flex-wrap: wrap; gap: 7px; }
.archive-jump input {
  font: inherit; color: var(--ink); background: var(--panel); padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 7px; min-width: 0;
}

@media (max-width: 660px) {
  .header-inner, main { width: calc(100% - 34px); }
  .header-inner { min-height: 60px; }
  main { padding-top: 25px; }
  .intro { margin-bottom: 18px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; row-gap: 11px; }
  .values { grid-row: 1; padding-block: 10px; }
  .board-shell { grid-row: auto; --gap: 7px; padding: 13px; border-radius: 14px; }
  .board-heading { margin-bottom: 8px; }
  .cell { aspect-ratio: 1.26; font-size: clamp(1rem, 4.3vw, 1.5rem); }
  .controls { padding: 15px; }
}

@media (max-width: 400px) {
  .header-inner { gap: 8px; }
  .brand { gap: 6px; font-size: 0.93rem; }
  .brand-mark { display: none; }
  nav { gap: 2px; }
  nav button { padding-inline: 6px; font-size: 0.76rem; }
  nav .rules { margin-left: 2px; }
  .intro p { font-size: 0.91rem; }
}

.leaderboard-panel {
  margin-top: 24px;
  padding: 17px 19px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  background: #fdfbf5;
  border: 1px solid #d7d0bf;
  border-radius: 12px;
}
.leaderboard-panel h2, .standings-heading h2 {
  font-size: 1.12rem;
  margin: 0 0 3px;
}
.leaderboard-panel p, .standings-heading p { margin: 0; }
.account-status { min-height: 1.4em; font-size: .86rem; }
.account-status:empty { min-height: 0; }
.account-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
.leaderboard-panel button, .standings-dialog button {
  font: inherit;
  font-size: .88rem;
  border: 1px solid #817969;
  border-radius: 7px;
  background: #faf7ee;
  padding: 7px 10px;
  color: #242018;
}
.leaderboard-panel .start-ranked {
  background: #315a49;
  border-color: #315a49;
  color: #fff;
}
.leaderboard-panel button:disabled, .standings-dialog button:disabled { opacity: .52; cursor: not-allowed; }
.leaderboard-panel[hidden], .standings-dialog [hidden] { display: none; }
.standings-dialog {
  box-sizing: border-box;
  max-width: min(36rem, calc(100vw - 24px));
  width: 100%;
  max-height: calc(100dvh - 24px);
  overflow: auto;
}
.standings-heading, .standings-signed-in {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.standings-dialog table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.standings-dialog th, .standings-dialog td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid #dbd3c4;
  overflow-wrap: anywhere;
}
.standings-dialog th { font-size: .8rem; }
.account-form, .standings-signed-in {
  margin-top: 17px;
  padding-top: 13px;
  border-top: 1px solid #dbd3c4;
}
.account-form label { font-size: .86rem; font-weight: 650; }
.account-form input {
  display: block;
  margin: 3px 0 9px;
  width: min(100%, 23rem);
  font: inherit;
  padding: 7px 9px;
  background: #fffdf6;
  border: 1px solid #817969;
  border-radius: 6px;
}
