/* Singleplayer. One world (the town) and one UI layer on a grid over it. Pixels only at whole device multiples.
   Type scale 16 / 20 / 24 / 32 / 48 (+ the name), spacing 4 / 8 / 12 / 16 / 24 / 32 / 48. Nothing under 16 px: the
   kit's floor for text (12 / 14 from the review are not used for that reason). */
@font-face { font-family: "Pixelify Sans"; src: url("/fonts/pixelify.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Nunito Sans"; src: url("/fonts/nunito-sans.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 400 600; font-display: swap; }

:root {
  --sand: #E8D5B7; --cream: #F6EBD6; --ink: #2B2D42; --red: #D1495B; --grass: #7FB069; --water: #30638E; --amber: #EDAE49;
  --ink-2: #4A4C63; --wood-ink: #24140A; --wood-key: #F0B46A;
  --px: "Pixelify Sans", system-ui, sans-serif;
  --tx: "Nunito Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --s: 3;                         /* CSS px per native map pixel: a whole number of DEVICE pixels, set by js */
  --edge: 32px;                   /* the one side margin every floating element keeps */
  --chat-h: 56px;
  --hard: 4px 4px 0 var(--ink);
  font-size: 18px;
}
@media (max-width: 1279px) { :root { --edge: 24px; } }
@media (max-width: 760px) { :root { --edge: 16px; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--sand); color: var(--ink); font-family: var(--tx); font-variant-numeric: tabular-nums; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--water); outline-offset: 3px; }

/* ---------- plates and keys ---------- */
.plate { background: var(--cream); border: 3px solid var(--ink); box-shadow: var(--hard); }
.key {
  font: 800 16px/1 var(--tx); color: var(--ink); background: var(--amber); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  min-height: 48px; padding: 0 24px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none;
}
.key:hover { background: #F4C46E; }
.key:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.key[aria-disabled="true"], .key:disabled { background: #E3D3B6; color: var(--ink-2); cursor: not-allowed; }
.key[aria-disabled="true"]:active, .key:disabled:active { transform: none; box-shadow: 3px 3px 0 var(--ink); }
.addr { font: 500 16px/1.3 var(--mono); word-break: break-all; user-select: all; }

/* ---------- the home: the town is the page ---------- */
body.home { overflow: hidden; height: 100dvh; }
.viewport { position: fixed; inset: 0; overflow: auto; scrollbar-width: none; overscroll-behavior: none; cursor: grab; touch-action: pan-x pan-y; }
.viewport::-webkit-scrollbar { display: none; }
.viewport.dragging { cursor: grabbing; }
.world { position: relative; width: calc(480px * var(--s)); height: calc(270px * var(--s)); }
#town { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* the name inside the town's billboard (native x 148..328, y 38..80): two lines on one centre axis */
.billboard {
  position: absolute; left: calc(148 / 480 * 100%); top: calc(38 / 270 * 100%); width: calc(180 / 480 * 100%); height: calc(42 / 270 * 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--s) * 1px); pointer-events: none; text-align: center;
}
.billboard .ribbon { font: 600 calc(var(--s) * 8px)/1 var(--px); color: var(--cream); letter-spacing: .08em; text-shadow: 0 calc(var(--s) * 1px) 0 var(--wood-ink); }
.billboard .name {
  font: 700 calc(var(--s) * 24px)/1 var(--px); color: var(--cream); white-space: nowrap; letter-spacing: .01em;
  text-shadow:
    calc(var(--s) * 1px) 0 0 var(--ink), calc(var(--s) * -1px) 0 0 var(--ink), 0 calc(var(--s) * 1px) 0 var(--ink), 0 calc(var(--s) * -1px) 0 var(--ink),
    calc(var(--s) * 1px) calc(var(--s) * 1px) 0 var(--ink), calc(var(--s) * -1px) calc(var(--s) * -1px) 0 var(--ink),
    calc(var(--s) * 1px) calc(var(--s) * -1px) 0 var(--ink), calc(var(--s) * -1px) calc(var(--s) * 1px) 0 var(--ink),
    calc(var(--s) * 2px) calc(var(--s) * 2px) 0 var(--red), calc(var(--s) * 3px) calc(var(--s) * 3px) 0 var(--red);
}

/* ---------- the links: ONE group on the pier (planks over the painted signpost, the contract board beside the last
   plank, both 60 px tall and bottom-aligned); js keeps the group inside the --edge margins at every size ---------- */
.signpost {
  position: absolute; left: calc(103 / 480 * 100%); top: calc(186 / 270 * 100%); z-index: 2;
  display: grid; grid-template-columns: 240px auto; grid-template-rows: repeat(3, 60px); column-gap: 24px; row-gap: 8px; align-items: end;
}
.signpost .plank { grid-column: 1; }
.signpost .plank.ca { grid-column: 2; grid-row: 3; }
.signpost.stack { grid-template-columns: 240px; grid-template-rows: repeat(4, 60px); }
.signpost.stack .plank.ca { grid-column: 1; grid-row: 4; justify-self: start; }
.plank {
  /* a wooden arrow plank at 4x: every plank the same 240 x 60 box and the same tip */
  display: flex; align-items: center; gap: 12px; height: 60px; width: 240px; padding: 0 40px 3px 32px; text-decoration: none;
  font: 800 20px/1 var(--tx); color: var(--wood-ink); cursor: pointer; background: none;
  border-style: solid; border-width: 0; border-image: url("/img/plank-v1.png") 6 9 7 7 fill / 24px 36px 28px 28px stretch;
  image-rendering: pixelated; filter: drop-shadow(4px 4px 0 rgba(43, 45, 66, .45)); transition: transform 120ms ease-out, filter 120ms ease-out;
}
/* every mark on the same cream tile, so three different official marks read as one set */
.plank .mark { width: 32px; height: 32px; flex: none; display: grid; place-items: center; background: var(--cream); border: 2px solid var(--wood-ink); }
.plank .mark img { width: 20px; height: 20px; image-rendering: auto; display: block; }
.plank:hover { transform: translateY(-2px); filter: drop-shadow(4px 6px 0 rgba(43, 45, 66, .45)) brightness(1.06); }
.plank:active { transform: translate(2px, 2px); filter: drop-shadow(2px 2px 0 rgba(43, 45, 66, .45)); }
.plank:focus-visible { outline: 3px solid var(--water); outline-offset: 4px; }
.plank[aria-disabled="true"] { cursor: not-allowed; }
.plank[aria-disabled="true"]:hover, .plank[aria-disabled="true"]:active { transform: none; filter: drop-shadow(4px 4px 0 rgba(43, 45, 66, .45)); }
.plank[aria-disabled="true"] .mark img { opacity: .55; filter: grayscale(1); }
.plank.ca, .phone-links .plank {
  /* the straight board, 14 art rows; 60 px like the planks (two flat middle rows take the 4 px) */
  height: 60px; padding: 0 40px 3px; border-image: url("/img/board-v1.png") 6 10 6 10 fill / 24px 40px 24px 40px stretch;
}
.plank.ca { width: auto; gap: 16px; cursor: default; padding: 0 24px 3px 44px; }
.plank.ca:hover, .plank.ca:active { transform: none; filter: drop-shadow(4px 4px 0 rgba(43, 45, 66, .45)); }
.plank.ca .lab { font: 800 16px/1 var(--tx); letter-spacing: .08em; }
.plank.ca .addr { font-size: 16px; color: var(--wood-ink); white-space: nowrap; word-break: normal; }
.plank.ca .wait { font: 700 16px/1.2 var(--tx); color: var(--wood-ink); white-space: nowrap; }
/* the wooden key: lighter wood, the same ink outline as the planks */
.wood-key {
  font: 800 16px/1 var(--tx); color: var(--wood-ink); background: var(--wood-key); border: 3px solid var(--wood-ink); box-shadow: 0 3px 0 var(--wood-ink);
  min-height: 40px; padding: 0 16px; cursor: pointer; transition: transform 120ms ease-out;
}
.wood-key:hover { background: #F6C484; }
.wood-key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-ink); }
.wood-key:disabled { background: #E2B27C; cursor: not-allowed; }
.wood-key:disabled:active { transform: none; box-shadow: 0 3px 0 var(--wood-ink); }
.wood-key.done { background: var(--grass); }

/* ---------- the HUD: counters left, pages right, both on the --edge margins ---------- */
.hud { position: fixed; top: var(--edge); left: var(--edge); right: var(--edge); display: flex; justify-content: space-between; align-items: stretch; gap: 16px; pointer-events: none; z-index: 5; }
.hud > * { pointer-events: auto; }
.counters { display: flex; align-items: center; padding: 0; }
.counters .c { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 14px 24px; white-space: nowrap; }
.counters .c + .c { border-left: 2px solid #D8C3A0; }
.counters .k { font: 600 16px/1 var(--tx); color: var(--ink-2); }
.counters b { font: 700 24px/1 var(--px); color: var(--ink); }
.counters #n-online { color: var(--water); }
.nav { display: grid; grid-template-columns: 1fr 1fr; padding: 0; }
.nav a { font: 600 24px/1 var(--px); text-decoration: none; min-width: 112px; padding: 0 24px; display: flex; align-items: center; justify-content: center; }
.nav a + a { border-left: 3px solid var(--ink); }
.nav a:hover, .chat-nav a:hover { background: var(--amber); }

.follow { position: fixed; left: 50%; bottom: calc(var(--chat-h) + 16px); transform: translateX(-50%); padding: 8px 24px; font: 600 16px/1.2 var(--tx); z-index: 5; display: flex; gap: 16px; align-items: center; }
.follow button { font: 800 16px/1 var(--tx); background: none; border: 0; text-decoration: underline; cursor: pointer; color: var(--ink); min-height: 32px; }

/* ---------- the chat strip: one row on the --edge margin, everything centred on one line ---------- */
.chat { position: fixed; left: 0; right: 0; bottom: 0; min-height: var(--chat-h); padding: 0 var(--edge); gap: 16px; background: var(--cream); border-top: 3px solid var(--ink); z-index: 6; display: flex; align-items: center; }
.tag { font: 800 16px/1 var(--tx); letter-spacing: .08em; text-transform: uppercase; background: var(--water); color: var(--cream); padding: 10px 16px; text-decoration: none; border: 2px solid var(--ink); }
.chat .tag { flex: none; }
.chat-line { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 12px; padding: 8px 0; border: 0; background: none; cursor: pointer; text-align: left; color: var(--ink); font: 700 20px/1.2 var(--tx); }
.chat-line .who { font: 600 16px/1.2 var(--tx); color: var(--ink-2); white-space: nowrap; }
.chat-line .say { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-line .say.shout { color: var(--red); font: 700 24px/1 var(--px); letter-spacing: .02em; }
.chat-line .say.step { animation: say 280ms steps(3) both; }
@keyframes say { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.chat-log { position: absolute; left: 0; right: 0; bottom: 100%; margin: 0; padding: 12px var(--edge); list-style: none; background: var(--cream); border-top: 3px solid var(--ink); max-height: 50vh; overflow: auto; }
.chat-log li { padding: 4px 0; font: 700 20px/1.35 var(--tx); display: flex; gap: 16px; align-items: baseline; }
.chat-log li .who { font: 600 16px/1.6 var(--tx); color: var(--ink-2); min-width: 8em; }
.chat-nav { display: none; }

/* the contract window (phone) */
.ca-window { max-width: min(92vw, 520px); padding: 24px; color: var(--ink); }
.ca-window::backdrop { background: rgba(43, 45, 66, .45); }
.ca-title { margin: 0 0 12px; font: 700 24px/1.1 var(--px); }
.ca-row { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.ca-row .addr { flex: 1; background: #fff8ec; border: 2px solid var(--ink); padding: 8px 12px; }

.phone-links { display: none; }

@media (max-width: 760px) {
  /* the phone: a sand header (counters + the four planks) pinned on top, the town under it, the chat at the foot */
  :root { --chat-h: 112px; }
  .signpost { display: none; }
  body.home::before { content: ""; position: fixed; left: 0; right: 0; top: 0; height: 164px; background: var(--sand); border-bottom: 3px solid var(--ink); z-index: 4; }
  .viewport { top: 164px; bottom: 112px; }
  .billboard .name { font-size: calc(var(--s) * 17px); }
  .billboard .ribbon { font-size: calc(var(--s) * 7.5px); }
  .hud .nav { display: none; }
  .counters { width: 100%; }
  .counters .c { flex: 1; padding: 14px 16px; align-items: center; }
  .counters .long { display: none; }
  .phone-links { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; position: fixed; top: 100px; left: var(--edge); right: var(--edge); z-index: 5; }
  .phone-links .plank { width: auto; min-width: 0; height: 48px; padding: 0 24px 3px; justify-content: center; gap: 8px; border-image-width: 18px 30px 18px 30px; }
  .phone-links .plank > span { font: 800 16px/1 var(--tx); letter-spacing: .08em; }
  .follow { bottom: calc(var(--chat-h) + 16px); width: calc(100% - 2 * var(--edge)); justify-content: center; }
  .chat { flex-wrap: wrap; padding: 0; gap: 0; }
  .chat-line { order: 1; flex: 1 0 100%; padding: 12px var(--edge); font-size: 20px; border-bottom: 2px solid #D9C6A4; }
  .chat-line .who { display: none; }
  .chat .tag { order: 2; margin-left: var(--edge); }
  .chat-nav { order: 3; display: grid; grid-template-columns: 1fr 1fr; margin-left: auto; border-left: 3px solid var(--ink); }
  .chat-nav a { font: 600 24px/1 var(--px); text-decoration: none; min-width: 112px; display: flex; align-items: center; justify-content: center; min-height: 56px; }
  .chat-nav a + a { border-left: 3px solid var(--ink); }
}
@media (max-width: 370px) {
  :root { --chat-h: 160px; }
  body.home::before { height: 196px; }
  .counters { flex-wrap: nowrap; }
  .counters .c { flex: 1 1 0; padding: 14px 16px; white-space: normal; text-align: center; }
  .phone-links { top: 132px; }
  .viewport { top: 196px; bottom: 160px; }
  .chat .tag { flex: 1 0 calc(100% - 2 * var(--edge)); margin: 8px var(--edge); text-align: center; }
  .chat-nav { flex: 1 0 100%; margin: 0; border-left: 0; border-top: 2px solid #D9C6A4; }
  body.lost .viewport { top: 0; bottom: 56px; }
body.lost .chat { --chat-h: 56px; }
@media (max-width: 760px) { body.lost .chat-line { border-bottom: 0; } }
}

@media (prefers-reduced-motion: reduce) {
  .chat-line .say.step { animation: none; }
  .plank, .wood-key { transition: none; }
}

/* ---------- inner pages (Hill, Docs, 404): one column on the town's sand ---------- */
body.page { min-height: 100dvh; }
.top { position: sticky; top: 0; z-index: 4; background: var(--cream); border-bottom: 3px solid var(--ink); }
.top .in { max-width: 1120px; margin: 0 auto; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
.top .home-link { display: inline-flex; align-items: center; gap: 12px; font: 700 26px/1 var(--px); text-decoration: none; }
.top .home-link img { width: 40px; height: 40px; border: 2px solid var(--ink); }
.top nav { display: flex; gap: 4px; }
.top nav a { font: 600 22px/1 var(--px); text-decoration: none; padding: 12px 22px; min-height: 48px; display: inline-flex; align-items: center; }
.top nav a[aria-current="page"] { background: var(--amber); border: 3px solid var(--ink); padding: 9px 19px; }
.col { max-width: 1120px; margin: 0 auto; padding: 48px 24px 96px; }
.head { margin: 0 0 32px; }
.head h1, .head h2 { font: 700 56px/1.05 var(--px); margin: 0 0 12px; }
.head p { margin: 0; font-size: 19px; max-width: 46em; }
.section { margin-top: 64px; }
.section h2 { font: 700 40px/1.1 var(--px); margin: 0 0 12px; }
.section > p, .section li { font-size: 18px; max-width: 46em; }
.note { font-size: 17px; color: var(--ink-2); }
.mono { font-family: var(--mono); font-size: 16px; word-break: break-all; }
@media (max-width: 760px) {
  .head h1, .head h2 { font-size: 40px; }
  .section h2 { font-size: 32px; }
  .top .home-link span { display: none; }
  .col { padding: 32px 16px 64px; }
}

/* ---------- 404: the empty corner of the town, one signpost, nobody ---------- */
.lost-world .lost-map { position: absolute; inset: 0; width: 100%; height: 100%; }
.lost-plank { position: absolute; left: calc(186 / 480 * 100%); top: calc(143 / 270 * 100%); transform: translateY(-50%); width: 250px; justify-content: center;
  border-image-source: url("/img/plank-left-v1.png"); border-image-slice: 6 7 7 9 fill; border-image-width: 24px 28px 28px 36px; padding: 0 30px 3px 40px; font-size: 19px; }
.lost-line { margin: 0; cursor: default; }
.lost-line .gloss { color: var(--ink-2); font-weight: 600; }

/* ---------- the hill ---------- */
.tally { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 0 0 24px; }
.tally .t { background: var(--cream); border: 3px solid var(--ink); box-shadow: var(--hard); padding: 24px 32px; display: flex; flex-direction: column; gap: 8px; }
.tally b { font: 700 48px/1 var(--px); }
.tally span { font: 600 17px/1.3 var(--tx); }
.rec { font: 800 16px/1 var(--tx); letter-spacing: .08em; text-transform: uppercase; background: var(--water); color: var(--cream); padding: 11px 16px; margin-right: 8px; display: inline-block; vertical-align: middle; }
.graves { list-style: none; margin: 32px 0 0; padding: 0; display: grid; gap: 16px; }
.grave { display: grid; grid-template-columns: 80px 1fr; gap: 24px; align-items: start; background: var(--cream); border: 3px solid var(--ink); box-shadow: var(--hard); padding: 24px 32px; }
.stone { width: 80px; height: 80px; background: url("/img/grave-0-v1.png") center / 80px 80px no-repeat; image-rendering: pixelated; }
.stone.s1 { background-image: url("/img/grave-1-v1.png"); }
.g-body h2 { font: 700 32px/1 var(--px); margin: 0 0 8px; }
.g-facts { margin: 0 0 12px; font-size: 18px; }
.g-tx { margin: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; font-size: 16px; }
.g-tx .tx { font-weight: 700; }
.g-tx .memo { background: #fff8ec; border: 2px solid var(--ink); padding: 4px 10px; }
@media (max-width: 760px) {
  .tally { grid-template-columns: 1fr; }
  .tally b { font-size: 40px; }
  .grave { grid-template-columns: 50px 1fr; gap: 16px; padding: 16px; }
  .stone { width: 50px; height: 50px; background-size: 50px 50px; }
}

/* ---------- docs ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; counter-reset: st; }
.steps li { background: var(--cream); border: 3px solid var(--ink); box-shadow: var(--hard); padding: 20px 28px 24px; display: flex; flex-direction: column; counter-increment: st; }
.steps img { width: 256px; height: 256px; max-width: 100%; align-self: center; margin-bottom: 8px; }
.steps h2 { font: 700 26px/1.1 var(--px); margin: 0 0 8px; }
.steps h2::before { content: counter(st) ". "; color: var(--red); }
.steps p { margin: 0; font-size: 17px; }
.rules { border-collapse: collapse; width: 100%; max-width: 820px; margin-top: 16px; background: var(--cream); border: 3px solid var(--ink); }
.rules th, .rules td { text-align: left; padding: 12px 20px; border-top: 2px solid #CDB894; font-size: 17px; vertical-align: top; }
.rules tr:first-child th, .rules tr:first-child td { border-top: 0; }
.rules th { font-weight: 700; width: 46%; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 820px; margin: 16px 0; }
.split > div { background: var(--cream); border: 3px solid var(--ink); box-shadow: var(--hard); padding: 24px 32px; display: flex; gap: 16px; align-items: center; }
.split b { font: 700 48px/1 var(--px); color: var(--water); }
.split span { font-size: 17px; }
.lexicon { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin-top: 16px; background: var(--cream); border: 3px solid var(--ink); }
.lexicon .w { padding: 13px 22px; border-bottom: 1px solid #DCC9A6; display: flex; justify-content: space-between; gap: 12px; font-size: 16px; }
.lexicon .w b { font-family: var(--px); font-weight: 600; font-size: 22px; line-height: 1; }
.lexicon .w span { color: var(--ink-2); text-align: right; }
.lexicon .w.learn { background: #F7DCA0; }
@media (max-width: 1100px) { .steps { grid-template-columns: repeat(2, 1fr); } .lexicon { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; } .split { grid-template-columns: 1fr; } .lexicon { grid-template-columns: repeat(2, 1fr); } .lexicon .w { padding: 13px 22px; } }
body.lost::before { display: none; }
body.lost .viewport { top: 0; bottom: 56px; }

