/* Latin subsets of the two fonts are served from fonts/ (OFL, see LICENSES.txt); Chinese falls to Noto Sans TC or the phone's own CJK face */
@font-face { font-family: 'Atkinson Hyperlegible'; font-weight: 400; font-display: swap; src: url(fonts/atkinson-400-latin.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: 'Atkinson Hyperlegible'; font-weight: 700; font-display: swap; src: url(fonts/atkinson-700-latin.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: 'M PLUS Rounded 1c'; font-weight: 800; font-display: swap; src: url(fonts/mplus-rounded-800-latin.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 {
  color-scheme: light;
  /* Night-market leaflet: uncoated stock, brown-black print, one cobalt stamp ink */
  --stock: #F5EEDF; --ink: #3A2E29; --muted: #6A5A50; --crease: #D9CDB6; --cobalt: #23479B; --unhappy: #9B3D3A; --wood: #C9A476;
  --round: "M PLUS Rounded 1c", "Noto Sans TC", ui-rounded, sans-serif;
  --pl-font: "Atkinson Hyperlegible", "Noto Sans TC", sans-serif;
  font-family: var(--pl-font);
  color: var(--ink);
  --pl-topbar-bg: var(--stock);
  --pl-topbar-text: var(--ink);
  --pl-control-text: var(--ink);
  --pl-control-bg: var(--stock);
  --pl-control-border: var(--ink);
  --pl-focus: var(--cobalt);
  --pl-overlay: rgb(58 46 41 / .55);
  --pl-card-bg: var(--stock);
  --pl-card-text: var(--ink);
  --pl-card-muted: var(--muted);
  --pl-card-border: var(--ink);
  --pl-primary: var(--cobalt);
  --pl-primary-text: var(--stock);
  --pl-radius-control: 4px;
  --pl-radius-card: 4px;
  --pl-radius-picture: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { overflow-x: hidden; background-color: var(--stock); }
button { font: inherit; touch-action: manipulation; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }

/* top bar: the guide's name, three ink-bordered tabs, a 2 px rule under it */
[data-pl="topbar"] { border-bottom: 2px solid var(--ink); box-shadow: none; }
[data-pl="back"][data-brand] svg { display: none; }
[data-pl="back"][data-brand] { padding: 4px 6px 4px 12px; margin-left: -12px; font: 800 28px/1 var(--round); letter-spacing: .01em; color: var(--ink); }
.pl-topbar__actions { gap: 8px; }
.pl-topbar__actions button { flex: none; white-space: nowrap; padding: 0 10px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); font: 700 20px/1 var(--pl-font); }
.pl-howto-question { font-size: 22px; }
[data-pl="howto-card"] { border-width: 2px; }
[data-pl="howto-card"] h2 { font-family: var(--round); font-weight: 800; font-size: 28px; }
[data-pl="howto-pictures"] canvas { background: var(--stock); border: 2px solid var(--ink); }
[data-pl="howto-lines"] { font-weight: 700; }
.pl-howto-footer button { font: 700 20px/1.1 var(--pl-font); border-width: 2px; }

.game { position: relative; width: min(100%, 430px); margin: 0 auto; padding-bottom: env(safe-area-inset-bottom); }
.board-shell { position: relative; margin: 0 auto; overflow: hidden; background: var(--stock); touch-action: manipulation; }
.board-shell canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
/* The board receives the real drag. Accessible button targets stay underneath it for keyboard users. */
#board { z-index: 2; }
#fx { z-index: 3; pointer-events: none; }

/* one column stack over the sky: takings card, then the district card or the new-rule note under it */
.stack { position: absolute; z-index: 4; left: calc(7px * var(--s, 1)); right: calc(7px * var(--s, 1)); top: calc(4px * var(--s, 1)); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none; }
.takings { align-self: stretch; padding: 4px 7px 6px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); }
.takings-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.takings-top b { font: 700 18px/1.2 var(--pl-font); }
.takings-num { white-space: nowrap; flex: none; color: var(--cobalt); font: 800 24px/1 var(--round); font-variant-numeric: tabular-nums; }
/* the scale: one crease tick per point, an ink pass mark, cobalt fill */
.scale { position: relative; height: 12px; margin: 5px 0 6px; border: 2px solid var(--ink); border-radius: 2px; background: var(--stock); overflow: visible; }
.scale-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--cobalt); transition: width .28s ease-out; }
.scale-ticks { position: absolute; inset: 0; }
.scale-ticks i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--crease); }
.scale-fill ~ .scale-ticks i.on { background: #FFFFFF55; }
.scale-pass { position: absolute; top: -7px; bottom: -7px; width: 3px; margin-left: -1.5px; background: var(--ink); }
.mood-key { display: flex; flex-wrap: wrap; gap: 0 8px; justify-content: space-between; font-size: 18px; line-height: 1.25; font-weight: 700; }
.mood-key span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.mood-key svg { flex: 0 0 auto; width: 20px; height: 20px; }
.touch-layer { z-index: 1; position: absolute; inset: 0; pointer-events: none; }
.candidate { position: absolute; pointer-events: auto; min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 8px; background: transparent; cursor: grab; touch-action: none; }
.candidate[aria-disabled="true"] { cursor: default; }
.candidate:focus-visible { outline: 3px solid var(--cobalt); outline-offset: -2px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; height: 60px; padding: 6px 10px; }
.actions button { min-height: 48px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); font-weight: 700; font-size: 20px; cursor: pointer; }
.actions button:active { transform: translateY(1px); background: var(--crease); }

.result-screen {
  position: absolute; z-index: 5; left: 8px; right: 8px; bottom: 6px;
  padding: 10px 12px 10px; border: 2px solid var(--ink); border-radius: 4px;
  background: var(--stock); box-shadow: 3px 3px 0 #3A2E2955; animation: dh-rise .22s ease-out both;
}
.result-screen[hidden] { display: none; }
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.result-screen h2 { margin: 0; font: 800 26px/1 var(--round); }
.result-score { margin: 0; color: var(--cobalt); font: 800 26px/1 var(--round); font-variant-numeric: tabular-nums; }
.result-mark { margin: 3px 0 8px; color: var(--muted); font-size: 18px; font-weight: 700; }
.result-why { margin: 0 0 4px; font-size: 18px; font-weight: 700; line-height: 1.25; }
.result-actions { display: flex; gap: 8px; }
.result-actions button { flex: 1 1 0; min-height: 48px; min-width: 44px; padding: 0 4px; white-space: nowrap; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); font-weight: 700; font-size: 18px; cursor: pointer; }
.result-actions button.primary { border-color: var(--cobalt); background: var(--cobalt); color: var(--stock); }
@keyframes dh-rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.levels-screen { position: fixed; z-index: 15; inset: 0; overflow-y: auto; padding: calc(70px + env(safe-area-inset-top)) 16px 16px; background: #F5EEDFf5; }
.levels-screen[hidden] { display: none; }
.levels-screen h2 { margin: 0 0 12px; font: 800 30px/1 var(--round); }
.level-map { max-width: 398px; }
.level-map .plc-cabinet { gap: 12px; }
.level-map .plc-cabinet__group { border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); box-shadow: none; }
.level-map .plc-cabinet__head { padding: 8px 11px; color: var(--ink); background: var(--crease); font: 800 20px/1.1 var(--round); }
.level-map .plc-cabinet__grid { grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 10px; }
.level-map .plc-level { min-height: 52px; border: 2px solid var(--cobalt); border-radius: 4px; background: var(--stock); color: var(--cobalt); font: 800 22px/1 var(--round); cursor: pointer; }
.level-map .plc-level[data-solved='true'] { background: var(--cobalt); color: var(--stock); }
.level-map .plc-level[data-solved='true']::after { color: inherit; }
.level-map .plc-level.current { outline: 3px solid var(--ink); outline-offset: 2px; }
.levels-back { margin-top: 16px; min-height: 48px; padding: 0 16px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); font-weight: 700; font-size: 20px; cursor: pointer; }

.why { margin: 0 15px 2px; color: var(--muted); font-size: 18px; }
.why summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; }
.why p { margin: 2px 0 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* the district card and the new-rule note flow under the takings card in .stack: nothing in the meter is hidden */
.rule-note { position: static; max-width: calc(206px * var(--s, 1)); min-height: 44px; flex: 0 0 auto;
  padding: 6px 10px 7px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); color: var(--ink); text-align: left;
  font: 700 max(18px, calc(20px * var(--s, 1)))/1.25 var(--pl-font); box-shadow: 3px 3px 0 #3A2E2940; animation: dh-pop .35s ease-out both; }
.rule-note[hidden] { display: none; }
.rule-note b { display: inline; margin: 0 6px 0 0; padding: 0; background: none; color: var(--cobalt); font: 800 18px/1.4 var(--round); }
.rule-note span { display: inline; }
.street-card { position: static; width: min(calc(236px * var(--s, 1)), 100%); min-width: 200px; flex: 0 0 auto; padding: 6px 10px 8px;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); text-align: left; box-shadow: 3px 3px 0 #3A2E2940; animation: dh-pop .4s ease-out both; }
.street-card[hidden] { display: none; }
.street-card b { display: block; font: 800 24px/1.15 var(--round); }
.street-card span { display: block; margin-top: 2px; font-size: 20px; font-weight: 700; line-height: 1.3; }
.hook-target { position: absolute; pointer-events: auto; min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer; touch-action: none; }
.hook-target.hung { cursor: grab; }
.hook-target:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 0; }
.today-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; min-height: 60px; padding: 10px 14px; border: 2px solid var(--ink); border-radius: 4px;
  background: var(--cobalt); color: var(--stock); text-align: left; cursor: pointer; }
.today-tile b { font: 800 20px/1.1 var(--round); }
.today-tile span { font-size: 18px; font-weight: 700; }
.street-preview { display: block; width: 100%; height: 96px; margin-bottom: 7px; border: 2px solid var(--ink); border-radius: 4px; background: var(--stock); }
.result-open { margin: 3px 0 8px; color: var(--cobalt); font: 800 18px/1.2 var(--round); }
@keyframes dh-pop { from { transform: translateY(6px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* A narrow board (320 px phones) leaves the result card about 240 px wide: Next level gets its own
   full-width row and the title and score may stack, so no button label is cut. */
@media (max-width: 400px) {
  .result-actions { flex-wrap: wrap; }
  .result-actions button.primary { flex: 1 1 100%; }
}
@media (max-width: 359px) {
  .result-head { flex-wrap: wrap; row-gap: 2px; }
  .result-screen h2, .result-score { white-space: nowrap; }
  .mood-key { gap: 0 4px; font-size: 18px; }
  .rule-note { max-width: 100%; }
}
/* 340 px and narrower: the tabs lose their border, keep their 44 px targets */
@media (max-width: 340px) {
  .pl-topbar__actions { gap: 8px; }
  .pl-topbar__actions button { border-color: transparent; background: transparent; padding: 0 4px; font-size: 18px; width: auto; min-width: 44px; }
  [data-pl="back"][data-brand] { font-size: 22px; padding: 4px 2px 4px 12px; white-space: nowrap; }
  .pl-topbar__inner { padding: 0 4px 0 12px; gap: 2px; }
  .street-card { min-width: 0; width: 100%; }
  .street-card b { font-size: 22px; }
}
