:root {
  --paper: #efe9dc;
  --paper2: #e4ddcb;
  --ink: #151412;
  --ink2: #4a453c;
  --seal: #8a1f1f;
  --line: rgba(21, 20, 18, 0.26);
  --glass: rgba(239, 233, 220, 0.88);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body {
  height: 100%; margin: 0;
  background: #cfc8bb; color: var(--ink);
  font: 14px/1.5 "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }

.hud { position: fixed; pointer-events: none; z-index: 5; }
.hud * { pointer-events: auto; }
.panel {
  background: var(--glass);
  border: 1.5px solid var(--ink);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
button { font: inherit; color: inherit; }

/* Top-left chapter enamel badge */
#story-card {
  left: 16px; top: calc(14px + env(safe-area-inset-top, 0px));
  max-width: min(410px, calc(100vw - 32px));
  padding: 11px 16px;
  display: grid; grid-template-columns: auto 1fr; gap: 2px 14px;
}
#st-num {
  grid-row: 1/4;
  font: 700 42px/1 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: -0.02em;
  color: var(--seal);
}
#st-zh { font: 700 19px/1.25 "Noto Serif SC", "Songti SC", serif; }
#st-en { font: italic 13.5px/1.3 Georgia, serif; color: var(--ink2); }
#st-yr { font: 600 11.5px/1.4 "IBM Plex Mono", monospace; letter-spacing: 0.08em; color: var(--seal); text-transform: uppercase; }
#world-tag {
  grid-column: 1/3; margin-top: 7px; padding-top: 6px;
  border-top: 1px solid var(--line);
  font: 600 11.5px/1.3 "IBM Plex Mono", monospace; color: var(--ink2);
}

/* Top-right controls */
#controls {
  right: 16px; top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center;
}
#road-switcher, #lang-switcher {
  display: flex; gap: 3px;
}
#road-switcher button, #lang-switcher button {
  padding: 7px 9px; font: 700 11.5px "IBM Plex Mono", "Noto Sans SC", monospace;
}
#road-switcher button.vis { background: #e1d8c5; }
#road-switcher button.cur, #lang-switcher button.cur {
  background: var(--seal); border-color: var(--seal); color: var(--paper);
}
#btn-lantern.on {
  background: #c97d28; border-color: #151412; color: #fff;
}

/* Visitor Contribution Modal */
#trace-modal {
  inset: 0; z-index: 25;
  background: rgba(21, 20, 18, 0.58);
  display: none; align-items: center; justify-content: center; padding: 18px;
  pointer-events: auto;
}
#trace-modal.on { display: flex; }
#trace-modal .box {
  background: var(--paper); border: 2px solid var(--ink);
  width: min(520px, 100%); max-height: 90vh; overflow: auto;
  padding: 20px 22px; display: flex; flex-direction: column; gap: 10px;
}
#trace-modal header { display: flex; justify-content: space-between; align-items: center; }
#trace-modal h2 { margin: 0; font: 700 19px "Noto Serif SC", serif; }
#trace-modal header button { border: 0; background: none; font-size: 24px; cursor: pointer; }
#trace-modal .sub { margin: 0; font-size: 12.5px; color: var(--ink2); }
#trace-modal select, #trace-modal textarea {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--ink);
  background: #fbf9f3; font: 13.5px/1.5 "Noto Sans SC", sans-serif; color: var(--ink);
}
#trace-modal .consent { font-size: 12px; color: var(--ink2); display: flex; gap: 7px; align-items: center; }
#trace-modal .submit {
  padding: 10px 16px; background: var(--seal); color: var(--paper);
  border: 0; font-weight: 700; cursor: pointer;
}
#trace-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.trace-item { background: #e8e1d2; border-left: 4px solid var(--seal); padding: 8px 10px; }
.trace-item small { font: 600 10.5px "IBM Plex Mono", monospace; color: var(--seal); }
.trace-item p { margin: 3px 0 0; font-size: 13px; }
.trace-empty { margin: 4px 0 0; font-size: 12px; color: var(--ink2); }
#controls button {
  padding: 8px 12px; background: var(--glass);
  border: 1.5px solid var(--ink); cursor: pointer;
  font-weight: 600; font-size: 12.5px;
  transition: background 0.15s, color 0.15s;
}
#controls button:hover { background: var(--ink); color: var(--paper); }
#controls button.on { background: var(--ink); color: var(--paper); }
#controls button.vr { background: var(--seal); color: var(--paper); border-color: var(--seal); }

/* Center-bottom bilingual narration caption (sleek museum-subtitle proportions) */
#caption {
  left: 50%; transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  width: min(680px, calc(100vw - 32px));
  padding: 9px 18px; text-align: center;
  background: rgba(239, 233, 220, 0.80);
  border-left: 4px solid var(--seal);
  opacity: 0; transition: opacity 0.45s;
  pointer-events: none;
}
#caption * { pointer-events: none; }
#caption.on { opacity: 1; }
#cap-who { font: 700 10px/1 "IBM Plex Mono", monospace; letter-spacing: 0.14em; color: var(--seal); text-transform: uppercase; }
#cap-zh { font: 600 17px/1.38 "Noto Serif SC", "Songti SC", serif; margin-top: 4px; }
#cap-en { font: italic 13px/1.35 Georgia, serif; color: var(--ink2); margin-top: 2px; }

/* Bottom spatial story ribbon */
#bottom-bar {
  left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 5px; align-items: center;
}
#story-ribbon {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
}
#story-ribbon button {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 11px; background: var(--glass);
  border: 1.5px solid var(--ink); cursor: pointer;
  font-size: 12px; font-weight: 600;
}
#story-ribbon button b {
  font: 700 11px "IBM Plex Mono", monospace;
  color: var(--seal);
}
#story-ribbon button.vis { background: #e1d8c5; }
#story-ribbon button.cur { background: var(--seal); border-color: var(--seal); color: var(--paper); }
#story-ribbon button.cur b { color: var(--paper); }
#story-ribbon button:hover:not(.cur) { background: var(--ink); color: var(--paper); }
#story-ribbon button:hover:not(.cur) b { color: #e9b08a; }

#splat-stat {
  font: 500 11px/1.3 "IBM Plex Mono", monospace;
  color: var(--ink); background: rgba(239, 233, 220, 0.78);
  padding: 2px 8px;
}

#toast {
  left: 50%; top: calc(74px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  padding: 8px 15px; background: var(--ink); color: var(--paper);
  font: 600 12.5px/1.4 "IBM Plex Mono", "Noto Sans SC", monospace;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center;
}
#toast.on { opacity: 1; }

#align-hud {
  left: 16px; bottom: calc(108px + env(safe-area-inset-bottom, 0px));
  padding: 10px 14px; background: rgba(21, 20, 18, 0.9); color: var(--paper);
  font: 12px/1.55 "IBM Plex Mono", monospace; white-space: pre-wrap;
  display: none; pointer-events: none;
}
#align-hud.on { display: block; }

/* Entry Splash Overlay (Paper & Enamel Plate Aesthetic) */
#start-overlay {
  inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center; padding: 18px;
  background: linear-gradient(180deg, rgba(21, 20, 18, 0.55), rgba(239, 233, 220, 0.78));
  pointer-events: auto;
}
#start-overlay.on { display: flex; }
#start-overlay .box {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  outline: 3px solid var(--paper);
  padding: 24px 28px;
  width: min(740px, 100%);
  max-height: 94vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
#road-plates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.road-plate {
  position: relative;
  display: flex; flex-direction: column; text-align: left;
  padding: 12px 12px 10px;
  background: #f6f4ed;
  border: 2px solid var(--ink);
  outline: 2px solid #f6f4ed;
  border-radius: 6px;
  cursor: pointer;
  transform: rotate(var(--r, 0deg));
  transition: transform 0.18s ease, background 0.15s, color 0.15s;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}
.road-plate:hover {
  transform: rotate(0deg) scale(1.04);
  background: var(--ink); color: var(--paper);
}
.road-plate .rp-no {
  font: 700 10.5px "IBM Plex Mono", monospace;
  color: var(--seal); letter-spacing: 0.08em;
}
.road-plate:hover .rp-no { color: #e9b08a; }
.road-plate .rp-zh {
  font: 900 16px/1.25 "Noto Sans SC", sans-serif;
  margin-top: 4px;
}
.road-plate .rp-en {
  font: italic 11.5px/1.3 Georgia, serif;
  opacity: 0.78; margin-top: 2px;
}
#start-overlay .kicker {
  font: 700 11px/1 "IBM Plex Mono", monospace;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--seal);
}
#start-overlay h1 {
  margin: 8px 0 4px;
  font: 900 30px/1.2 "Noto Serif SC", "Songti SC", serif;
}
#start-overlay h1 small {
  display: block; font: italic 16px Georgia, serif; font-weight: 400;
  color: var(--ink2); margin-top: 4px;
}
#start-overlay p { margin: 12px 0 0; font-size: 14px; line-height: 1.65; }
#start-overlay .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
#start-overlay .actions button {
  padding: 12px 22px; border: 2px solid var(--ink);
  background: var(--paper); font-weight: 700; font-size: 15px; cursor: pointer;
}
#start-overlay .actions button.primary { background: var(--ink); color: var(--paper); }
#start-overlay .actions button.vr-go { background: var(--seal); border-color: var(--seal); color: var(--paper); }
#start-overlay .actions button:hover { background: var(--seal); border-color: var(--seal); color: #fff; }
#start-overlay ul {
  margin: 16px 0 0; padding: 0 0 0 1.15em;
  font-size: 12.5px; color: var(--ink2); line-height: 1.65;
}

body:not(.live) .hud:not(#start-overlay):not(#toast) { opacity: 0; pointer-events: none; }
body.live .hud { transition: opacity 0.4s; }

@media (max-width: 640px) {
  #st-num { font-size: 30px; }
  #st-zh { font-size: 16px; }
  #cap-zh { font-size: 16px; }
  #story-ribbon button span { display: none; }
}
