:root {
  --paper: #fffdf6;
  --ink: #20342a;
  --muted: #667267;
  --line: #d6d9cb;
  --gold: #785b2c;
  --glass: #fffcf4f5;
  --edge: #5d746348;
  --gutter: clamp(14px, 2.5vw, 42px);
  --left: max(var(--gutter), env(safe-area-inset-left));
  --right: max(var(--gutter), env(safe-area-inset-right));
  --top: max(12px, env(safe-area-inset-top));
  --bottom: max(12px, env(safe-area-inset-bottom));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: #c6e2ef;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, select, input { font: inherit; }
button, a { color: inherit; touch-action: manipulation; }
button { padding: 0; border: 0; cursor: pointer; background: transparent; }
button:disabled { opacity: .38; cursor: default; }
a { text-decoration: none; }
:focus-visible, .era-picker:focus-within { outline: 3px solid #c29238; outline-offset: -3px; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.world { position: relative; isolation: isolate; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; color: var(--ink); }
.stage { position: absolute; inset: 0; overflow: hidden; isolation: isolate; touch-action: none; background-color: #c6e2ef;
  background-image: linear-gradient(#62899a0c 1px, transparent 1px), linear-gradient(90deg,#62899a0c 1px,transparent 1px), linear-gradient(160deg,#c0dfef,#daeaf0 60%,#bdd8de);
  background-size: 60px 60px, 60px 60px, 100% 100%; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.scene-exit { pointer-events: none; animation: dissolve 220ms ease-out forwards; }
@keyframes dissolve { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .scene-exit { animation-duration: 1ms; } }
#loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); padding: 12px 18px; border-radius: 6px; background: var(--glass); }
.pin { position: absolute; z-index: 1; transform: translate(-50%,-100%); display: flex; align-items: center; gap: 5px; padding: 5px 7px; white-space: nowrap; color: #204134; background: #fffdf5f5; border: 1px solid #698571a6; border-radius: 4px; font-size: 12px; line-height: 1.15; box-shadow: 0 2px 8px #11201948; }
.pin b { font: 10px ui-monospace, monospace; color: #456250; }
.pin:after { content: ""; position: absolute; top: 100%; left: 50%; width: 1px; height: var(--stem,13px); background: #365f48; pointer-events: none; }
.pin:before { content: ""; position: absolute; left: calc(50% - 2px); top: calc(100% + var(--stem,13px)); width: 4px; height: 4px; border-radius: 50%; background: #365f48; pointer-events: none; }
.pin[aria-pressed="true"] { z-index: 2; background: #235340; color: #fffdf6; border-color: #e4eddf; font-weight: 700; }
.pin[aria-pressed="true"] b { color: #f4e3b1; }
.pin.compact span { display: none; }
.structure-pin { background: #fff0cf; border-color: #a58850; }
.glass, #screen-mode { border: 1px solid var(--edge); background: var(--glass); box-shadow: 0 3px 12px #10201824; border-radius: 7px; }
.map-header { position: absolute; inset: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: var(--top) var(--right) 20px var(--left); background: linear-gradient(#f5f9f4ed, #f5f9f495 61%, transparent); pointer-events: none; }
.map-header a, .map-header button { pointer-events: auto; }
.brand { display: inline-flex; align-items: center; gap: 5px; color: #365246; font-size: 12px; min-height: 32px; }
.brand .icon { width: 15px; }
.identity h1 { margin: 0; font-size: clamp(30px,3vw,46px); font-weight: 680; letter-spacing: -.07em; line-height: 1.15; }
.map-header nav { display: flex; gap: 6px; align-items: center; }
.map-header nav > * { min-height: 44px; padding: 0 12px; border-radius: 6px; display: flex; align-items: center; justify-content: center; gap: 7px; font-size: 13px; }
#screen-mode { margin-left: 5px; }
.map-switch { position: absolute; left: var(--left); top: calc(var(--top) + clamp(78px, 6vw, 102px)); display: flex; padding: 3px; }
.map-switch button { display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 13px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.map-switch [aria-pressed="true"] { background: #295540; color: #fffdf5; }
.map-switch .icon { width: 15px; }
.map-tools { position: absolute; right: var(--right); top: 48%; transform: translateY(-50%); display: grid; gap: 9px; }
.tool-set { display: flex; flex-direction: column; padding: 2px; }
.tool-set button, .play-tools button, .dialog-head button { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 4px; }
.tool-set button[aria-pressed="true"] { background: #e4eddf; color: #2b5038; }
.lower-hud { position: absolute; left: var(--left); right: var(--right); bottom: var(--bottom); display: grid; gap: 10px; pointer-events: none; }
.map-readouts { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.mouse-hint { display: none; }
@media (hover: hover) and (pointer: fine) and (min-width: 920px) {
  .mouse-hint { display: block; margin: 0 auto 0 0; align-self: end; padding: 6px 10px; border-radius: 4px; color: var(--ink); background: var(--glass); font-size: 11px; }
  .mouse-hint span { margin: 0 8px; }
}
.place-card, .time-panel { pointer-events: auto; }
.place-card { display: inline-flex; align-items: stretch; }
.place-card button { display: flex; align-items: center; justify-content: center; }
#places-open { gap: 10px; padding: 8px 12px; text-align: left; }
#places-open > .icon { color: var(--gold); }
#places-open span { display: grid; gap: 2px; }
#places-open small { font-size: 10px; color: #516451; }
#places-open strong { font-size: 15px; }
#visit-next { width: 44px; border-left: 1px solid var(--edge); }
.map-key { display: flex; align-items: end; gap: 12px; padding: 2px 7px; border-radius: 6px; background: #fffdf4d6; }
.compass { width: 48px; height: 49px; }
.compass svg { width: 100%; height: 100%; }
.compass text { fill: #234433; font: 8px sans-serif; text-anchor: middle; dominant-baseline: middle; }
.scale { display: grid; justify-items: center; gap: 3px; padding-bottom: 4px; }
.scale span { display: block; height: 5px; border: 1px solid #365647; border-top: 0; }
.scale b { font: 10px ui-monospace, monospace; color: #2b4635; }
.time-panel { display: grid; grid-template-columns: minmax(115px,auto) minmax(100px,1fr) auto; align-items: center; column-gap: clamp(12px,3vw,54px); padding: 10px clamp(13px,2vw,33px) 14px; border-radius: 9px; border: 1px solid #f1f0de; color: var(--ink); background: var(--paper); box-shadow: 0 5px 22px #15291f40; }
.yearbox { position: relative; display: grid; justify-items: start; }
.era-picker { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; font-size: 12px; font-weight: 650; color: #576143; }
.era-picker .icon { width: 12px; height: 12px; }
.era-picker select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.yearbox output { white-space: nowrap; font-size: 15px; line-height: 1.15; }
.yearbox b { font: 34px/.94 Georgia,serif; letter-spacing: -.04em; }
.ruler { min-width: 0; }
.range-box { position: relative; height: 38px; display: grid; align-items: center; }
.ticks { position: absolute; inset: 55% 6px auto; height: 6px; background: repeating-linear-gradient(90deg,#acb1a0 0 1px,transparent 1px 2%); }
input[type="range"] { margin: 0; width: 100%; height: 100%; position: relative; appearance: none; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: linear-gradient(to right,#a88a44 var(--progress,99%),#d1d4c5 var(--progress,99%)); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 17px; height: 17px; margin-top: -6.5px; border-radius: 50%; border: 4px solid #786431; background: #fffbea; }
input[type="range"]::-moz-range-track { height: 4px; background: #d1d4c5; }
input[type="range"]::-moz-range-progress { height: 4px; background: #a88a44; }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; border: 4px solid #786431; background: #fffbea; }
.tick-labels { display: flex; justify-content: space-between; font-size: 10px; color: #616d5f; }
.play-tools { display: flex; gap: 2px; align-items: center; }
.play-tools .icon { width: 15px; height: 15px; }
#play { display: inline-flex; justify-content: center; align-items: center; gap: 8px; width: auto; padding: 0 14px; background: #2c4937; color: #fffbed; font-size: 13px; font-weight: 650; }
#speed { font: 14px ui-monospace,monospace; }
dialog { width: min(460px,calc(100% - 24px)); max-height: calc(100dvh - var(--top) - var(--bottom)); padding: 0; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); box-shadow: 0 12px 60px #10221866; }
dialog::backdrop { background: #10201978; }
.dialog-head { position: sticky; top: 0; z-index: 1; background: var(--paper); padding: 8px 12px 8px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; letter-spacing: -.04em; }
#dialog-body, .notes, .period-notes { padding: 0 18px 16px; font-size: 14px; line-height: 1.65; }
#dialog-body a, .notes a, #point-evidence { color: #365a3d; text-decoration: underline; text-underline-offset: 3px; }
#dialog-body article, .notes { border-bottom: 1px solid var(--line); }
#dialog-body article { padding: 9px 0; }
#dialog-body article small { display: block; color: var(--muted); }
#dialog-body p { margin: 5px 0 12px; }
#stops { display: grid; grid-template-columns: 1fr 1fr; padding: 10px 14px; gap: 4px; }
.stop { display: flex; align-items: center; min-height: 44px; gap: 7px; padding: 5px 8px; border-radius: 4px; text-align: left; }
.stop b, .stop small { font: 10px ui-monospace,monospace; color: var(--muted); }
.stop strong { font-size: 13px; }
.stop small { margin-left: auto; }
.stop .icon { width: 13px; }
.stop[aria-pressed="true"], #eras [aria-pressed="true"] { background: #e3e7d9; color: #24402c; }
.notes { padding-top: 12px; background: #eef0e4; }
.notes-head, .note-foot { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.notes-head { font-size: 12px; }
.notes a .icon { width: 13px; height: 13px; }
.notes h3, .period-notes h3 { margin: 7px 0 0; }
.notes p, #era-story { margin: 5px 0; }
#point-evidence { min-height: 36px; font-size: 12px; }
#point-evidence:after { content: " · 근거"; }
.period-notes { padding-top: 8px; }
#eras { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
#eras button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; font-size: 12px; min-height: 34px; }
noscript { position: fixed; inset: 40% 5% auto; text-align: center; color: white; background: #23352c; padding: 1em; }
noscript a { text-decoration: underline; }
@media (hover:hover) and (pointer:fine) {
  .map-header nav > :hover, .tool-set button:hover, .place-card button:hover { background-color: #e2eada; }
  .map-switch button:not([aria-pressed="true"]):hover { color: var(--gold); }
  .pin:hover { border-color: var(--gold); }
  .stop:hover, .play-tools button:not(#play):hover { background-color: #e6e8d9; }
}
button:active:not(:disabled) { filter: brightness(.88); }
@media (max-width: 700px) {
  .map-header nav { gap: 1px; }
  .map-header nav > * { padding: 0 7px; font-size: 12px; }
  .map-header nav > a .icon, .map-header nav > [data-dialog] .icon { display: none; }
  #screen-mode { min-width: 44px; }
  #screen-mode span { display: none; }
  .map-switch { top: calc(var(--top) + 74px); }
  .map-tools { right: max(8px,env(safe-area-inset-right)); }
  .tool-set button { width: 40px; height: 44px; }
  .map-key { gap: 6px; }
  .time-panel { grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "year play" "ruler ruler"; gap: 0 6px; padding: 8px 12px 10px; }
  .yearbox { grid-area: year; }
  .yearbox b { font-size: 29px; }
  .ruler { grid-area: ruler; }
  .play-tools { grid-area: play; gap: 0; }
  .play-tools button { width: 38px; }
  #play { padding: 0 9px; }
  .range-box { height: 30px; }
  .pin { font-size: 10px; padding: 4px 5px; }
  .lower-hud { gap: 7px; }
}
@media (max-width: 368px) {
  .play-tools button { width: 33px; }
  #play { width: 42px; }
  #play span { position: absolute; clip-path: inset(50%); }
}
@media (max-width: 700px) and (orientation: portrait) {
  .map-tools { top: calc(var(--top) + 74px); right: var(--right); transform: none; gap: 5px; }
  .tool-set { flex-direction: row; }
}
@media (max-height: 540px) and (orientation: landscape) {
  :root { --top: max(4px,env(safe-area-inset-top)); --bottom: max(5px,env(safe-area-inset-bottom)); }
  .identity { display: flex; align-items: center; gap: 12px; min-height: 44px; }
  .identity h1 { font-size: 25px; }
  .map-switch { top: calc(var(--top) + 48px); }
  .map-tools { top: calc(var(--top) + 48px); transform: none; display: flex; gap: 5px; }
  .tool-set { flex-direction: row; }
  .tool-set button { width: 36px; height: 36px; }
  .lower-hud { gap: 3px; }
  .time-panel { grid-template-columns: auto minmax(50px,1fr) auto; grid-template-areas: "year ruler play"; gap: 12px; padding: 4px 11px 6px; }
  .yearbox b { font-size: 25px; }
  #places-open { padding: 4px 9px; }
  .compass { width: 37px; height: 39px; }
}
:root[data-map-only] :is(.identity,#temple-nav,[data-dialog="sources"],.map-switch,.map-tools,.lower-hud) { display: none; }
:root[data-map-only] .map-header { justify-content: flex-end; background: none; }

#walk-mode { position: absolute; top: calc(var(--top) + clamp(78px, 6vw, 102px) + 51px); left: var(--left); min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; gap: 7px; background: #255740; color: #fffdf5; font-size: 13px; font-weight: 650; }
#walk-mode:hover { background: #1b4735; }
.walk-readouts { display: none; }
:root[data-walking] :is(.map-switch,.map-tools,.map-readouts,#markers,#structures) { display: none; }
:root[data-walking] #walk-mode { top: calc(var(--top) + clamp(78px, 6vw, 102px)); background: var(--glass); color: var(--ink); }
:root[data-walking] .walk-readouts { display: flex; align-items: end; gap: 12px; }
#walk-hint { margin: 0; padding: 7px 12px; font-size: 12px; line-height: 1.4; background: var(--glass); color: var(--ink); border-radius: 6px; }
#walk-pad { display: none; }
@media (pointer: coarse) {
  #walk-pad { display: grid; grid-template-columns: repeat(3, 44px); gap: 3px; pointer-events: auto; }
  #walk-pad button { touch-action: none; user-select: none; -webkit-touch-callout: none; width: 44px; height: 44px; background: var(--glass); border: 1px solid var(--edge); border-radius: 8px; color: var(--ink); font-size: 21px; }
  #walk-pad button:first-child { grid-column: 2; }
  #walk-pad button:nth-child(2) { grid-column: 1; }
}
@media (max-width: 700px) {
  #walk-mode { top: calc(var(--top) + 125px); }
  :root[data-walking] #walk-mode { top: calc(var(--top) + 74px); }
}
@media (max-height: 540px) and (orientation: landscape) {
  #walk-mode { top: calc(var(--top) + 98px); }
  :root[data-walking] #walk-mode { top: calc(var(--top) + 48px); }
}
:root[data-map-only]:not([data-walking]) #walk-mode { display: none; }
:root[data-map-only][data-walking] #walk-mode { top: var(--top); }
:root[data-map-only][data-walking] .lower-hud { display: grid; }
:root[data-map-only][data-walking] .time-panel { display: none; }
