/* A Day on the Bian River (汴河一日) — paper and ink. The diorama floats on the scroll's silk; the
   interface stays small and quiet like marginal inscriptions. */
:root {
  --paper: #f2e9d4; --paper-2: #e9dcc0; --ink: #2f2923; --muted: #7b6a55; --line: #b8a17c; --red: #a33b2c; --red-2: #c45a3f;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --track: .14em; --track-wide: .28em;
}
/* interface language (src/i18n.js): English by default, 中文, 日本語 */
:root:lang(en) { --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Hoefler Text", Georgia, "Songti SC", serif; --track: .02em; --track-wide: .16em; }
:root:lang(ja) { --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Source Han Serif JP", "Noto Serif CJK JP", serif; --track: .08em; --track-wide: .2em; }
:root:lang(en) .eyebrow { text-transform: uppercase; }
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body.bian-game { --halo: #efe5cf; background: #efe5cf; color: var(--ink); font: 13px/1.7 var(--serif); -webkit-tap-highlight-color: transparent; --sky-ink: var(--ink); --halo: #efe5cf; }
/* inscriptions keep a soft paper halo so they stay legible over a zoomed street */
.header-actions button, .view-tools button, #hint, body.interior #location-card { text-shadow: 0 0 2px var(--halo), 0 0 5px var(--halo), 0 0 9px var(--halo), 0 0 14px var(--halo); }
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 6px 10px; min-height: 34px; touch-action: manipulation; letter-spacing: .04em; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }
[hidden] { display: none !important; }

/* ---------- stage ---------- */
body.bian-game #stage { position: fixed; inset: 0; z-index: 1; transform: none; overflow: hidden; }
#canvas-wrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#c { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; outline: none; cursor: grab; }
#c:active { cursor: grabbing; }
#room-markers { position: absolute; inset: 0; pointer-events: none; }
/* the scroll's margin: paper fades in at the top and bottom edges */
#stage::before, #stage::after { content: ''; position: absolute; left: 0; right: 0; z-index: 2; pointer-events: none; }
#stage::before { top: 0; height: 64px; background: linear-gradient(var(--halo) 10%, transparent); }
#stage::after { bottom: 0; height: 70px; background: linear-gradient(transparent, var(--halo) 82%); }
body.night #stage::before, body.night #stage::after { opacity: .85; }
.marker-exit { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; font-size: 12px; padding: 3px 10px; min-height: 26px; color: #fff4df; background: #2f2923d9; border: 1px solid #f2e9d455; }
.marker-exit:hover { background: var(--red); }
.selected-tag { position: absolute; transform: translate(-50%, -130%); pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 0; font: 15px/1 var(--serif); padding: 6px 12px 5px; color: #fff4df; background: var(--red); box-shadow: 0 0 0 1px #f2e9d4aa; white-space: nowrap; }
.selected-tag b { font-weight: 600; letter-spacing: var(--track-wide); }
.selected-tag small { font: 10px/1 var(--serif); letter-spacing: var(--track); opacity: .78; }
.selected-tag:hover { background: var(--red-2); }
.selected-tag::after { content: ''; position: absolute; left: 50%; top: 100%; width: 1px; height: 14px; background: var(--red); }
#hover-tip { position: fixed; z-index: 6; pointer-events: none; transform: translate(14px, -50%); padding: 5px 10px 6px; background: #2f2923e6; color: #f6ecd6; display: flex; flex-direction: column; line-height: 1.35; white-space: nowrap; }
#hover-tip b { font: 15px var(--serif); font-weight: 600; letter-spacing: var(--track-wide); }
#hover-tip span { font-size: 11px; color: #d8c7a6; }
#hover-tip em { font-style: normal; font-size: 10px; color: #c9a26f; margin-top: 2px; letter-spacing: var(--track); }

/* ---------- masthead (top) ---------- */
.masthead { position: fixed; top: max(20px, env(safe-area-inset-top)); left: 28px; right: 24px; z-index: 4; display: flex; justify-content: flex-end; align-items: flex-start; pointer-events: none; }
.header-actions { pointer-events: auto; }
h2, .loading-title { font-family: var(--serif); font-weight: 600; }
.eyebrow { font-size: 11px; letter-spacing: var(--track-wide); color: var(--muted); }
.header-actions { display: flex; gap: 2px; align-items: center; }
.header-actions > button { font-size: 13px; padding: 6px 12px; border-bottom: 1px solid transparent; }
.header-actions > button:hover, .header-actions > button[aria-expanded="true"] { border-bottom-color: var(--ink); }
#visit-count { margin-left: 6px; color: var(--red); font-variant-numeric: tabular-nums; }
#clock-num { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 4px; }
#sun-moon { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: 0; }
#sun-moon.sun { background: #e6a43a; box-shadow: 0 0 0 3px #e6a43a33; }
#sun-moon.moon { background: #e8e2cf; box-shadow: inset -3px 0 0 #9aa3b8, 0 0 0 3px #e8e2cf22; }
#help-open { font-size: 14px; width: 34px; }
/* language: three quiet words, the current one underlined in red */
#lang-switch { display: flex; align-items: center; margin-right: 10px; padding-right: 10px; border-right: 1px solid #2f292333; }
#lang-switch button { font-size: 12px; padding: 4px 6px; min-height: 30px; color: var(--muted); border-bottom: 1px solid transparent; letter-spacing: .04em; }
#lang-switch button:hover { color: var(--ink); }
#lang-switch button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--red); }
#lang-switch button[lang="zh-CN"] { font-family: "Songti SC", "STSong", "Noto Serif SC", serif; }
#lang-switch button[lang="ja"] { font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; }
body.night #lang-switch { border-right-color: #efe6d244; }

/* ---------- paper slips ---------- */
.interface { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.interface button, .interface input, .interface select { pointer-events: auto; }
.paper { color: var(--ink); background: #f4ecd9f2; border: 1px solid #2f292326; box-shadow: 0 1px 0 #fff8 inset, 0 10px 30px -18px #3a2a1466; }
.paper h2 { margin: 2px 0 6px; font-size: 22px; line-height: 1.3; letter-spacing: var(--track); }
.paper p { font-size: 13px; margin: 0 0 12px; color: #5d5040; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.card-actions button, #activity, #time-flow { font-size: 13px; padding: 6px 12px; min-height: 34px; border: 1px solid #2f292340; background: #fbf5e7; }
.card-actions button:hover, #activity:hover, #time-flow:hover { border-color: var(--ink); }
.card-actions .primary, button.primary { color: #fff4df; background: var(--red); border-color: var(--red); }
.card-actions .primary:hover, button.primary:hover { background: var(--red-2); }

/* indoors: a quiet inscription at the top left, no slip (on the street the hover tip and name seal do this) */
#location-card { position: absolute; left: 28px; top: max(20px, env(safe-area-inset-top)); width: min(360px, 34vw); pointer-events: auto; display: flex; flex-direction: column; align-items: flex-start; }
#location-card.empty { display: none; }
#location-card .back { padding: 0 0 8px; min-height: 0; font-size: 13px; color: var(--muted); text-align: left; }
#location-card .back:hover { color: var(--red); }
#location-card h2 { margin: 4px 0 2px; font-size: 30px; line-height: 1.15; letter-spacing: var(--track-wide); color: var(--ink); }
#location-card .tag { font-size: 14px; color: var(--red); letter-spacing: var(--track); margin: 0 0 10px; }
#location-card .tag:empty { display: none; }
#room-list { display: flex; flex-wrap: wrap; gap: 0 14px; margin: 0 0 6px; }
#room-list:empty { display: none; }
#room-list::before { content: attr(data-label); width: 100%; font-size: 11px; letter-spacing: var(--track-wide); color: var(--muted); }
:root:lang(en) #room-list::before { text-transform: uppercase; }
#room-list button { padding: 2px 0; min-height: 26px; font-size: 14px; color: var(--ink); border-bottom: 1px dotted #2f292366; }
#room-list button:hover, #room-list button.active { color: var(--red); border-bottom-color: var(--red); }
#location-card .card-actions { gap: 4px 14px; }
#location-card .card-actions button { padding: 2px 0; min-height: 26px; font-size: 13px; border: 0; border-bottom: 1px solid #2f292355; background: none; color: var(--ink); }
#location-card .card-actions button:hover { color: var(--red); border-bottom-color: var(--red); }
#activity::after { content: ' →'; }
body.night #room-list button { border-bottom-color: #efe6d266; }

/* the boat: no slip — seals on the river (see game.js placeBoatUI) */
#boat-markers { position: absolute; inset: 0; pointer-events: none; }
#boat-markers > * { position: absolute; left: 0; top: 0; pointer-events: auto; }
/* a small 舟 seal over the moored boat: take the helm */
.boat-board { margin: -38px 0 0 -13px; width: 26px; height: 26px; min-height: 0; padding: 0; display: grid; place-items: center; font: 15px/1 "Songti SC", "STSong", "Noto Serif SC", serif; color: #fff1e0; background: var(--red); border-radius: 3px; transform-origin: 50% 100%; box-shadow: 0 0 0 1px #f2e9d4aa, inset 0 0 0 2px #fff1e033; animation: boat-bob 2.6s ease-in-out infinite; }
.boat-board::after { content: ''; position: absolute; left: 50%; top: 100%; width: 1px; height: 12px; background: var(--red); }
.boat-board:hover { background: var(--red-2); }
@keyframes boat-bob { 50% { margin-top: -41px; } }
/* aboard: one seal naming the next step, two quiet ink words under it */
.boat-ui { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: -8px; translate: -50% -100%; }
.boat-seal { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 0; padding: 6px 12px 5px; font: 14px/1.1 var(--serif); color: #fff4df; background: var(--red); box-shadow: 0 0 0 1px #f2e9d4aa; white-space: nowrap; }
.boat-seal b { font-weight: 600; letter-spacing: var(--track); }
.boat-seal small { font: 10px/1 var(--serif); letter-spacing: .06em; opacity: .82; }
.boat-seal:hover { background: var(--red-2); }
.boat-aux { display: flex; gap: 10px; padding: 2px 8px; background: #f4ecd9e8; box-shadow: 0 0 0 1px #2f292322; }
.boat-aux button { min-height: 0; padding: 1px 0; font: 11px/1.3 var(--serif); color: #2f2923; border-bottom: 1px solid transparent; }
.boat-aux button:hover { color: var(--red); border-bottom-color: var(--red); }
.boat-ui::after { content: ''; order: 3; width: 1px; height: 10px; background: var(--red); }
/* the destination dock: a pennant seal with the cargo's character (栈 for the warehouse) */
.dock-mark { margin: -30px 0 0 -11px; width: 22px; min-height: 0; padding: 3px 0 5px; font: 13px/1 "Songti SC", "STSong", "Noto Serif SC", serif; color: var(--red); background: #f4ecd9; border: 1px solid var(--red); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); }
.dock-mark:hover { color: #fff4df; background: var(--red); }
/* off screen: the pennant waits at the edge with a small ink pointer toward the dock */
.dock-mark.edge::before { content: ''; position: absolute; left: 50%; top: 45%; width: 0; height: 0; border: 5px solid transparent; border-left: 8px solid var(--red); transform: translate(-50%, -50%) rotate(var(--a)) translateX(20px); }
.dock-mark.edge { clip-path: none; border-radius: 2px; }
@media (prefers-reduced-motion: reduce) { .boat-board { animation: none; } }

/* bottom inscriptions */
.bottom { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 28px; right: 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
#hint { margin: 0; font-size: 12px; letter-spacing: var(--track); color: var(--muted); }
.view-tools { display: flex; gap: 0; pointer-events: auto; }
.view-tools button { font-size: 13px; padding: 4px 10px; color: var(--ink); border-bottom: 1px solid transparent; }
.view-tools button:hover { border-bottom-color: var(--ink); }
#zoom-in, #zoom-out { font-size: 17px; padding: 2px 9px; }

#toast { position: absolute; left: 50%; top: 86px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); width: max-content; padding: 8px 18px; background: #2f2923e8; color: #f6ecd6; font-size: 13px; letter-spacing: .06em; pointer-events: none; }

/* tour drawer */
.drawer { position: fixed; right: 22px; top: 76px; bottom: 70px; width: 340px; z-index: 8; padding: 20px 22px; overflow: auto; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.drawer-head h2 { margin: 2px 0 0; }
.drawer-head button { font-size: 24px; min-width: 36px; padding: 0; line-height: 1; }
.muted { color: var(--muted); font-size: 12px !important; }
#building-list { display: grid; gap: 0; margin-top: 8px; }
#building-list button { text-align: left; padding: 9px 2px; border-top: 1px solid #2f29231c; display: grid; grid-template-columns: 30px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: baseline; min-height: 0; }
#building-list button:hover span { color: var(--red); }
#building-list small { grid-row: span 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#building-list span { font-size: 18px; letter-spacing: var(--track); }
#building-list i { grid-column: 2; font-style: normal; font-size: 12px; color: var(--muted); }
#building-list em { grid-row: 1; grid-column: 3; font-style: normal; color: var(--red); font-size: 11px; letter-spacing: .1em; }
#building-list button.visited small { color: var(--red); }

/* sky panel */
#sky-panel { position: fixed; right: 22px; top: 76px; width: 300px; z-index: 9; padding: 18px 20px; }
#sky-panel label { display: block; font-size: 12px; margin-top: 14px; letter-spacing: .1em; }
#sky-panel input, #sky-panel select { width: 100%; accent-color: var(--red); }
#sky-panel select { padding: 7px; border: 1px solid #2f292340; background: #fbf5e7; }
#sky-panel output { float: right; font-variant-numeric: tabular-nums; }
#moon-info { margin: 10px 0 !important; font-size: 12px !important; }
.time-buttons { display: flex; gap: 4px; }
.time-buttons button { font-size: 13px; padding: 5px 10px; border: 1px solid #2f292333; background: #fbf5e7; }
.time-buttons button:hover { border-color: var(--ink); }
#time-flow { margin-top: 10px; }

/* move pad */
#move-pad { position: absolute; right: 24px; bottom: 74px; text-align: center; pointer-events: auto; }
#move-pad button { width: 44px; height: 44px; background: #f4ecd9ee; color: #2f2923; border: 1px solid #2f292333; font-size: 18px; margin: 2px; touch-action: none; }
body.boating #move-pad { right: auto; left: 24px; bottom: 74px; }
body.bian-game #pp-weather-open { display: none; }

dialog { width: min(540px, calc(100vw - 32px)); padding: 30px 34px; border: 1px solid #2f292340; background: #f4ecd9; color: var(--ink); max-height: 85dvh; overflow: auto; }
dialog::backdrop { background: #2d291f55; }
dialog h2 { font-size: 28px; margin: 6px 0 18px; letter-spacing: var(--track); }
dialog p { font-size: 14px; line-height: 1.95; }
dialog button { margin-right: 6px; border: 1px solid #2f292340; }
.fine { font-size: 12px !important; color: var(--muted) !important; line-height: 1.8; }
.primary { padding: 8px 16px; }

#loading { position: fixed; inset: 0; z-index: 20; background: #efe5cf; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink); }
.loading-title { font-size: 46px; letter-spacing: .5em; margin-left: .5em; }
:root:lang(en) .loading-title { font-size: 40px; letter-spacing: .06em; margin-left: 0; }
:root:lang(ja) .loading-title { letter-spacing: .3em; }
#loading p { font-size: 13px; letter-spacing: var(--track-wide); color: var(--muted); }
#baking-note { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; padding: 10px 22px; background: #2f2923e0; color: #f6ecd6; letter-spacing: var(--track-wide); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s; }
body.baking #baking-note { opacity: 1; }

/* ---------- night: ink-blue sky, pale lettering ---------- */
body.night { --ink: #efe6d2; --muted: #b9ae9a; --halo: #161a2c; }
body.night .header-actions button, body.night .view-tools button, body.night #hint { color: var(--ink); }
body.night .header-actions > button:hover, body.night .view-tools button:hover { border-bottom-color: var(--ink); }
body.night .paper { --ink: #2f2923; --muted: #7b6a55; }
body.night .paper .eyebrow { color: #7b6a55; }

@media (max-width: 1000px) {
  #hint { display: none; }
  #location-card { width: 300px; }
}
@media (max-width: 700px) {
  .masthead { top: max(12px, env(safe-area-inset-top)); left: 14px; right: 8px; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  #lang-switch { margin-right: 4px; padding-right: 4px; }
  #lang-switch button { padding: 4px 4px; font-size: 11px; }
  .header-actions > button { font-size: 12px; padding: 4px 7px; min-height: 30px; }
  #clock-num { display: none; }
  #location-card { left: 14px; right: 14px; top: calc(max(12px, env(safe-area-inset-top)) + 44px); width: auto; }
  #location-card h2 { font-size: 22px; margin: 2px 0; }
  #location-card .tag { margin-bottom: 6px; font-size: 13px; }
  .bottom { left: 8px; right: 8px; bottom: max(10px, env(safe-area-inset-bottom)); }
  .view-tools button { padding: 4px 7px; font-size: 12px; }
  #toast { top: 96px; font-size: 12px; }
  .drawer { right: 10px; left: 10px; width: auto; top: 86px; bottom: 60px; }
  #sky-panel { right: 10px; top: 86px; width: min(300px, calc(100vw - 20px)); }
  #move-pad { right: 10px; bottom: auto; top: 46vh; }
  body.interior:not(.boating) #move-pad { display: none; }
  body.boating #move-pad { left: 10px; right: auto; bottom: auto; top: 30vh; }
  #move-pad button { width: 40px; height: 40px; }
  #hover-tip { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { #baking-note { transition: none; } }
@media (hover: hover) and (pointer: fine) { body.boating #move-pad { display: none; } } /* the river is steered by clicking it */
