/* Layout: full-bleed ink landscape; a thin layer of paper slips floats over it (masthead, route survey, tool dock). */
/* Tokens follow brand/tokens.css. Fonts are self-hosted subsets (see tools/subset_fonts.py). */

@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 400; font-style: normal; font-display: swap; src: url(fonts/zen-kaku-gothic-new-400.woff2) format("woff2"); }
@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 500; font-style: normal; font-display: swap; src: url(fonts/zen-kaku-gothic-new-500.woff2) format("woff2"); }
@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 700; font-style: normal; font-display: swap; src: url(fonts/zen-kaku-gothic-new-700.woff2) format("woff2"); }
@font-face { font-family: "Shippori Mincho"; font-weight: 700; font-style: normal; font-display: swap; src: url(fonts/shippori-mincho-700.woff2) format("woff2"); }
@font-face { font-family: "Shippori Mincho"; font-weight: 800; font-style: normal; font-display: swap; src: url(fonts/shippori-mincho-800.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url(fonts/ibm-plex-mono-400.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url(fonts/ibm-plex-mono-500.woff2) format("woff2"); }
@font-face { font-family: "Ma Shan Zheng"; font-weight: 400; font-style: normal; font-display: swap; src: url(fonts/ma-shan-zheng-400.woff2) format("woff2"); }

:root {
  --paper: #e8e4d6;
  --paper-slip: rgba(236, 232, 219, 0.86);
  --ink: #1f2321;
  --ink-2: #4b504b;
  --ink-3: #85877d;   /* decoration only: fails text contrast on paper */
  --rule: rgba(31, 35, 33, 0.16);
  --seal: #b5321e;
  --seal-ink: #f4ead8;
  --ochre: #b8863a;
  --indigo: #3f5a72;
  --indigo-pale: #8ea3b3;
  --f-display: "Shippori Mincho", "Songti SC", "Noto Serif", Georgia, serif;
  --f-ui: "Zen Kaku Gothic New", "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --f-brush: "Ma Shan Zheng", "STKaiti", "KaiTi", var(--f-display);
  color-scheme: light;
}
html, body { height: 100%; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-ui); overflow: hidden; -webkit-font-smoothing: antialiased; }
#bg, #gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { touch-action: none; cursor: grab; }
#gl.drawing { cursor: crosshair; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

#ui {
  position: fixed; inset: 0; pointer-events: none;
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(14px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-bottom, 0px));
}
#ui > * { min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.slip { pointer-events: auto; background: var(--paper-slip); border: 1px solid var(--rule); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

.masthead { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px 10px 10px; }
.seal { flex: none; width: 46px; height: 46px; background: var(--seal); color: var(--seal-ink); display: grid; place-items: center; font-family: var(--f-brush); font-size: 19px; line-height: 0.95; writing-mode: vertical-rl; letter-spacing: 1px; border-radius: 3px; box-shadow: inset 0 0 0 2px var(--seal), inset 0 0 0 3.5px var(--seal-ink); }
.mast-body { min-width: 0; }
.mast-row { display: flex; align-items: flex-start; gap: 10px; }
.masthead h1 { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 21px; letter-spacing: 0.01em; line-height: 1.1; text-wrap: balance; }
.masthead .sub { margin-top: 3px; font-size: 12px; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; }
.masthead .sub b { font-family: var(--f-display); font-weight: 700; color: var(--ink); font-size: 13px; }
.stamp { font-size: 11px; line-height: 1.3; color: var(--ink); border: 1px solid var(--ink); border-radius: 2px; padding: 0 5px; }
.nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.card { width: 236px; padding: 12px 14px; display: grid; gap: 10px; }
.card h2 { margin: 0; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); display: flex; justify-content: space-between; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0; }
.stats div { display: grid; gap: 1px; }
.stats dt { font-size: 11px; color: var(--ink-2); }
.stats dd { margin: 0; font-family: var(--f-num); font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; }
.hazards { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; }
.chip { font-size: 11px; padding: 2px 7px; border: 1px solid currentColor; border-radius: 2px; line-height: 1.4; }
.chip.ok { color: var(--ink-2); border-color: var(--rule); }
.chip.steep { color: #7a5820; }   /* ochre, darkened to 5.3:1 for small text */
.chip.cliff { color: var(--seal); }
.chip.deep { color: var(--indigo); }
.legend { display: grid; gap: 4px; border-top: 1px solid var(--rule); padding-top: 9px; font-size: 11.5px; color: var(--ink-2); }
.legend span { display: flex; align-items: center; gap: 8px; }
.legend i { width: 22px; height: 4px; border-radius: 2px; flex: none; }
.legend i.contour { height: 0; border-top: 1px solid var(--ink-3); border-radius: 0; }

.meter { display: grid; gap: 4px; }
.meter .row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-2); }
.meter .row b { font-family: var(--f-num); font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--rule); border-radius: 1px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); transform-origin: left; transition: background .3s; }
.clock { font-family: var(--f-num); font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.clock small { font-size: 12px; color: var(--ink-2); margin-left: 6px; letter-spacing: 0; }
.feed { display: grid; gap: 5px; font-size: 12px; max-height: 140px; overflow: hidden; }
.feed p { margin: 0; display: grid; grid-template-columns: 42px 1fr; gap: 6px; color: var(--ink-2); animation: inkin .5s ease-out; }
.feed p time { font-family: var(--f-num); color: var(--ink-2); font-size: 11px; padding-top: 1px; }
.feed p.bad { color: var(--seal); }
.feed p em { font-style: normal; font-family: var(--f-num); font-size: 11px; }
@keyframes inkin { from { opacity: 0; transform: translateY(3px); } }

.dock { justify-self: center; display: grid; gap: 8px; justify-items: center; max-width: 100%; }
.hint { pointer-events: none; font-size: 13px; color: var(--ink); background: var(--paper-slip); padding: 5px 12px; border: 1px solid var(--rule); text-align: center; max-width: 560px; text-wrap: balance; }
.hint.flash { animation: flash .9s; }
@keyframes flash { 0%,100% { color: var(--ink); } 30% { color: var(--seal); } }
.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px; }
.btn { font: 500 13px/1 var(--f-ui); color: var(--ink); background: transparent; border: 1px solid var(--rule); padding: 9px 13px; border-radius: 2px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { color: var(--ink-3); cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary { background: var(--seal); border-color: var(--seal); color: var(--seal-ink); font-weight: 700; }
.btn.primary:disabled { background: transparent; border-color: var(--rule); color: var(--ink-3); }
.btn kbd { font: 400 10px var(--f-num); opacity: 0.6; }
.btn.sm { padding: 6px 9px; font-size: 12px; }
#bHelp { min-width: 28px; justify-content: center; font-family: var(--f-num); }
.seg { display: inline-flex; }
.lang { display: inline-flex; align-self: flex-start; margin-left: auto; }
.lang .btn { padding: 5px 7px; font: 500 11px/1 var(--f-num); letter-spacing: 0.04em; }
.lang .btn:first-child, .seg .btn:first-child { border-radius: 2px 0 0 2px; }
.lang .btn:last-child, .seg .btn:last-child { border-radius: 0 2px 2px 0; border-left: 0; }
.sep { width: 1px; background: var(--rule); margin: 4px 2px; }

.pin { position: fixed; left: 0; top: 0; pointer-events: none; visibility: hidden; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; font-size: 11px; white-space: nowrap; }
.pin .tag { display: flex; align-items: center; gap: 5px; background: var(--paper-slip); border: 1px solid var(--rule); padding: 2px 7px 2px 3px; }
.pin .tag b { font-family: var(--f-brush); font-weight: 400; font-size: 13px; color: var(--seal-ink); background: var(--seal); width: 18px; height: 18px; display: grid; place-items: center; border-radius: 2px; }
.pin.start .tag b { background: var(--ink); color: var(--paper); }
.pin::after { content: ""; width: 1px; height: 18px; background: var(--ink); opacity: .5; }

/* ---- dialogs ---- */
.modal, .fallback { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: auto; background: rgba(232, 228, 214, 0.35);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px; }
.fallback { background: transparent; }
.result { box-sizing: border-box; width: min(400px, 100%); max-height: 100%; overflow: auto; background: var(--paper); border: 1px solid var(--rule); box-shadow: 0 18px 50px rgba(31,35,33,.18); padding: 22px 22px 18px; display: grid; gap: 16px; animation: inkin .5s ease-out; }
.result.wide { width: min(460px, 100%); }
.result header { display: flex; gap: 16px; align-items: center; }
.grade { flex: none; width: 76px; height: 76px; background: var(--seal); color: var(--seal-ink); display: grid; place-items: center; font: 800 46px/1 var(--f-display); border-radius: 4px; box-shadow: inset 0 0 0 3px var(--seal), inset 0 0 0 5px var(--seal-ink); transform: rotate(-4deg); }
.grade.fail { background: var(--ink); box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 5px var(--paper); color: var(--paper); }
.emblem { flex: none; width: 76px; height: 76px; display: block; }
.result h3, .result .h3 { margin: 0; font: 700 22px/1.15 var(--f-display); text-wrap: balance; }
.result h3:focus, .result .h3:focus { outline: none; }
.result h4 { margin: 0 0 6px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); }
.result .lede { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.result p, .result ul, .result ol { margin: 0; }
.banner { font-size: 13px; line-height: 1.45; padding: 8px 11px; border-left: 3px solid var(--ink); background: rgba(31, 35, 33, 0.05); }
.banner.quiet { border-left-color: var(--ink-3); color: var(--ink-2); }
.tally { width: 100%; border-collapse: collapse; font-size: 13px; }
.tally td { padding: 7px 0; border-bottom: 1px solid var(--rule); }
.tally td:nth-child(2) { color: var(--ink-2); font-family: var(--f-num); font-size: 12px; text-align: right; padding-right: 14px; font-variant-numeric: tabular-nums; }
.tally td:last-child { text-align: right; font-family: var(--f-num); font-weight: 500; font-variant-numeric: tabular-nums; width: 52px; white-space: nowrap; }
.tally tr.total td { border-bottom: 0; font-weight: 700; padding-top: 10px; }
.tally tr.total td:last-child { font-size: 17px; }
.likes { display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--ink-2); }
.likes:empty { display: none; }
.st-scroll { max-height: 42vh; overflow: auto; border-top: 1px solid var(--rule); }
.tally.st td { padding: 5px 0; font-size: 12px; }
.tally.st td:first-child { font-family: var(--f-num); }
.tally.st td.bad { color: var(--seal); font-weight: 700; }
.st-ua { margin: 0; font: 11px/1.4 var(--f-num); color: var(--ink-2); overflow-wrap: anywhere; }
#stMark { font-family: var(--f-brush); font-weight: 400; font-size: 40px; }
.result .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* onboarding */
.steps { padding-left: 1.3em; display: grid; gap: 9px; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.steps b { color: var(--ink); font-weight: 700; display: block; }
.steps li::marker { font-family: var(--f-num); color: var(--ink-2); }
.keys { font: 11.5px/1.5 var(--f-num); color: var(--ink-2); }
.fallback ul { padding-left: 1.2em; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); display: grid; gap: 4px; margin-top: 6px; }
.fallback p { font-size: 13.5px; }

/* record */
.big { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.big div { display: grid; gap: 2px; align-content: start; }
.big dt { font-size: 11px; line-height: 1.25; color: var(--ink-2); }
.big dd { margin: 0; font: 500 24px/1 var(--f-num); font-variant-numeric: tabular-nums; order: -1; }
.dist { list-style: none; padding: 0; display: grid; gap: 4px; }
.dist li { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 8px; font-size: 12px; }
.dist li > span:first-child { font: 700 13px var(--f-display); text-align: center; }
.dist .barf { display: block; height: 16px; min-width: 22px; width: var(--w); background: var(--ink-2); color: var(--paper); font: 500 11px/16px var(--f-num); text-align: right; padding-right: 5px; box-sizing: border-box; }
.dist li.now .barf { background: var(--ink); }
.dist li.zero .barf { background: var(--rule); color: var(--ink); }
.countdown { font: 500 13px var(--f-num); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.countdown:empty { display: none; }

/* share card */
.share { display: grid; gap: 6px; }
.share:empty { display: none; }
.share textarea { box-sizing: border-box; width: 100%; resize: none; border: 1px solid var(--rule); border-radius: 2px; background: rgba(255, 255, 255, 0.35); color: var(--ink); padding: 8px 10px;
  font: 12.5px/1.5 var(--f-num), "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.share textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.share .row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.share .msg { font-size: 12px; color: var(--ink-2); }

@media (max-width: 720px) {
  .top { flex-direction: column; align-items: stretch; gap: 8px; }
  .card { width: auto; padding: 9px 12px; gap: 8px; }
  .card .legend { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 4px 8px; }
  .stats dd { font-size: 13px; }
  .masthead { padding: 8px 10px 8px 8px; }
  .seal { width: 38px; height: 38px; font-size: 16px; }
  .masthead h1 { font-size: 18px; }
  .mast-body { flex: 1; }
  .nav { margin-top: 6px; }
  .hud-top { display: flex; gap: 14px; align-items: center; }
  .feed { max-height: 60px; }
  .btn { padding: 9px 10px; }
  .btn kbd { display: none; }
  .big { grid-template-columns: repeat(2, 1fr); gap: 12px 8px; }
  .result { padding: 18px 16px 14px; gap: 14px; }
  .emblem { width: 56px; height: 56px; }
  .result header { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
