:root {
  color-scheme: light;
  --ink: #23251f;
  --paper: #f4e8c9;
  --paper-deep: #ddc38d;
  --vermillion: #a93424;
  --gold: #d39b32;
  --indigo: #264b58;
  --moss: #47634d;
  --town: #84513d;
  --shadow: rgba(42, 31, 20, .22);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; background: #302a23; color: var(--ink); }
body { min-height: 100svh; min-height: 100dvh; overflow: hidden; }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid #1269a0; outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 1180px);
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--paper);
  background-image: linear-gradient(90deg, rgba(117, 82, 42, .07) 1px, transparent 1px), radial-gradient(circle at 25% 18%, rgba(255,255,255,.56), transparent 32%);
  background-size: 31px 100%, auto;
  box-shadow: 0 0 50px #130e09;
  overflow: hidden;
}

.masthead {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 3px double #5e4a31;
  padding: 2px 2px 4px;
}
.title-lockup { display: flex; align-items: center; min-width: 0; gap: 7px; }
.title-lockup p { margin: 0; font-size: 14px; letter-spacing: .08em; color: #715b3c; white-space: nowrap; }
.title-lockup h1 { margin: 0; font-size: clamp(18px, 4.4vw, 27px); line-height: 1.05; white-space: nowrap; }
.crest { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 42px; border: 2px solid var(--vermillion); border-radius: 50%; color: var(--vermillion); font-weight: 900; transform: rotate(-4deg); }
.header-actions { display: flex; gap: 5px; }
.icon-button { min-width: 44px; min-height: 44px; border: 2px solid #57462f; border-radius: 3px; background: #f9efda; font-weight: 900; font-size: 20px; cursor: pointer; }
.icon-button[aria-pressed="true"] { background: #57462f; color: #fff6dc; }

.screen { min-height: 0; overflow: hidden; }
.start-screen { position: relative; display: grid; place-items: center; align-content: center; gap: clamp(8px, 2.5vh, 18px); padding: 12px 18px; isolation: isolate; }
.start-scroll { position: absolute; inset: 4% 3% 6%; border: 3px solid #604d32; background: #ebd7aa; overflow: hidden; z-index: -1; }
.start-scroll::before, .start-scroll::after { content: ""; position: absolute; inset-block: 0; width: 22px; background: #785533; border: 3px solid #463421; box-shadow: inset 0 0 0 4px #a77945; }
.start-scroll::before { left: 0; }.start-scroll::after { right: 0; }
.ink-mountain { position: absolute; bottom: 22%; width: 58%; height: 48%; background: #72806d; opacity: .72; clip-path: polygon(0 100%, 15% 53%, 28% 75%, 48% 16%, 65% 58%, 82% 30%, 100% 100%); }
.ink-mountain.left { left: 2%; }.ink-mountain.right { right: -10%; transform: scaleX(-1); opacity: .45; }
.history-river { position: absolute; left: 10%; right: 10%; bottom: 19%; height: 34px; border-top: 7px solid var(--indigo); transform: skewX(-12deg); }
.history-river i { position: absolute; top: -16px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold); border: 4px solid #fff0bc; box-shadow: 0 0 0 2px #644326; }
.history-river i:nth-child(1) { left: 4%; }.history-river i:nth-child(2) { left: 34%; }.history-river i:nth-child(3) { left: 65%; }.history-river i:nth-child(4) { right: 1%; }
.era-seals { position: absolute; left: 9%; right: 9%; bottom: 8%; display: flex; justify-content: space-between; font-weight: 900; }
.era-seals span { background: #f4e6c4; border: 2px solid #6c4b2d; padding: 4px 6px; transform: rotate(-2deg); }
.start-copy { text-align: center; max-width: 680px; padding: 12px; background: rgba(246, 233, 202, .82); border-block: 1px solid rgba(75,51,29,.45); }
.kicker { margin: 0 0 4px; color: var(--vermillion); font-weight: 900; letter-spacing: .1em; }
.start-copy h2 { margin: 2px 0 8px; font-size: clamp(24px, 6vw, 44px); line-height: 1.18; }
.start-copy p:last-child { margin: 0; font-family: system-ui, sans-serif; font-size: 15px; font-weight: 700; }
.seal-button { min-height: 48px; border: 2px solid #542d21; padding: 8px 18px; cursor: pointer; font-weight: 900; font-size: 17px; box-shadow: 3px 3px 0 #6a4a32; }
.seal-button.primary { background: var(--vermillion); color: #fff8e6; }
.seal-button.secondary { background: #f6e5bb; color: #392b20; }
.start-note { margin: 0; padding: 3px 8px; background: rgba(244,232,201,.88); font: 700 14px/1.2 system-ui, sans-serif; }

.play-screen { display: grid; grid-template-rows: auto minmax(160px, 1fr) auto; gap: 5px; padding-top: 5px; }
.hud { min-height: 48px; display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: stretch; gap: 5px; }
.hud > div { border: 1px solid #725c3d; background: rgba(255,248,226,.78); padding: 4px 7px; }
.era-hud { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.era-hud span, .score-hud span { font: 700 14px/1 system-ui, sans-serif; color: #705b40; }
.era-hud strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.score-hud { min-width: 76px; text-align: right; display: grid; align-content: center; }
.score-hud strong { font: 900 22px/1 system-ui, sans-serif; }
.danger-badge { min-width: 78px; display: flex; flex-direction: column; justify-content: center; align-items: center; font: 800 14px/1.15 system-ui, sans-serif; }
.danger-badge.steady { color: #22513c; }.danger-badge.warning { color: #7a4b00; background: #fff0bd; }.danger-badge.danger { color: #8f2018; background: #ffe1d6; animation: warning-pulse 1.1s ease-in-out infinite alternate; }

.game-field { position: relative; min-width: 0; min-height: 160px; border: 3px solid #5b472f; background: #e9d6aa; overflow: hidden; touch-action: pan-y; display: grid; grid-template-rows: auto minmax(62px,1fr) auto auto; }
.game-field::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 28px rgba(67,48,26,.25); }
.event-strip { z-index: 2; display: grid; grid-template-columns: auto minmax(0,1fr); gap: 8px; padding: 5px 7px; background: rgba(246,235,205,.93); border-bottom: 2px solid #80684a; }
.year-stamp { align-self: center; padding: 4px 7px; border: 2px solid var(--vermillion); color: var(--vermillion); font-weight: 900; font-size: 14px; transform: rotate(-1deg); white-space: nowrap; }
.event-copy { min-width: 0; display: grid; }
.event-copy strong { font-size: 15px; line-height: 1.25; }
.event-copy span { font: 600 14px/1.25 system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-world { position: relative; min-height: 0; overflow: hidden; background: linear-gradient(#dcc894 0 66%, #b89a67 66% 100%); }
.sun-disc { position: absolute; width: 60px; height: 60px; border-radius: 50%; background: #c6492e; right: 7%; top: 8%; opacity: .75; }
.land { position: absolute; bottom: 0; height: 64%; background: #61725c; opacity: .85; }
.land-west { left: -3%; width: 58%; clip-path: polygon(0 100%, 0 42%, 15% 32%, 22% 55%, 34% 20%, 44% 50%, 56% 0, 72% 45%, 100% 70%, 100% 100%); }
.land-east { right: -4%; width: 52%; clip-path: polygon(0 100%, 0 68%, 19% 48%, 31% 61%, 49% 17%, 65% 54%, 78% 35%, 100% 50%, 100% 100%); opacity: .62; }
.center-marker { position: absolute; z-index: 3; left: 55%; top: 7%; transform: translateX(-50%); display: grid; text-align: center; padding: 3px 8px; background: #f6e6ba; border: 2px solid #573d27; box-shadow: 3px 3px 0 rgba(55,38,23,.3); transition: left .65s ease; }
.center-marker span { font: 700 14px/1 system-ui, sans-serif; }.center-marker strong { color: var(--vermillion); font-size: 17px; }
.road { position: absolute; z-index: 2; left: 8%; right: 8%; height: 12px; border: 2px solid #4a3523; background: #f2d88b; transform-origin: left center; }
.road b { display: block; width: 25%; height: 100%; background: repeating-linear-gradient(90deg, var(--gold) 0 12px, #fff0bc 12px 18px); animation: road-flow 2.2s linear infinite; }
.road-a { top: 34%; transform: rotate(-5deg); }.road-b { top: 54%; transform: rotate(2deg); }.road-c { top: 73%; transform: rotate(-1deg); }
.lantern-row { position: absolute; z-index: 4; left: 9%; right: 9%; bottom: 9%; display: flex; justify-content: space-between; }
.lantern-row i { width: 18px; height: 24px; border-radius: 4px; background: #f5c24b; border: 2px solid #603a1f; box-shadow: 0 0 14px #ffe183; animation: lantern-bob 1.5s ease-in-out infinite alternate; }
.silhouette { position: absolute; z-index: 2; bottom: 0; background: #302b24; }
.silhouette.castle { left: 8%; width: 58px; height: 45px; clip-path: polygon(0 100%, 7% 48%, 20% 48%, 20% 33%, 35% 33%, 35% 14%, 50% 0, 65% 14%, 65% 33%, 80% 33%, 80% 48%, 93% 48%, 100% 100%); }
.silhouette.village { left: 44%; width: 78px; height: 26px; clip-path: polygon(0 100%, 0 40%, 16% 0, 32% 40%, 43% 40%, 59% 5%, 75% 40%, 87% 40%, 94% 20%, 100% 40%, 100% 100%); }
.silhouette.market { right: 8%; width: 72px; height: 29px; clip-path: polygon(0 100%, 0 35%, 10% 35%, 15% 0, 21% 35%, 38% 35%, 50% 8%, 62% 35%, 78% 35%, 85% 0, 91% 35%, 100% 35%, 100% 100%); }
.route-states { z-index: 3; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 3px; padding: 3px 4px; background: rgba(57,42,29,.9); color: white; }
.state { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; column-gap: 4px; }
.state span { grid-column: 1 / 3; font: 700 14px/1 system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state strong { font: 900 14px/1 system-ui, sans-serif; }
.meter { height: 7px; background: #1e1b17; border: 1px solid #d9c79f; }
.meter i { display: block; width: 50%; height: 100%; background: #ecd064; transition: width .5s ease, background .3s; }
.telegraph { z-index: 3; min-height: 43px; display: flex; align-items: center; gap: 7px; padding: 3px 7px; background: #fff1c9; border-top: 2px dashed #a93424; color: #50291f; }
.telegraph > span { font-size: 23px; }.telegraph p { margin: 0; display: grid; min-width: 0; }.telegraph strong { font-size: 14px; }.telegraph p span { font: 700 14px/1.2 system-ui, sans-serif; white-space: normal; overflow-wrap: anywhere; }
.release-banner { position: absolute; z-index: 8; inset: 17% 8% auto; padding: 10px; background: rgba(255,244,196,.96); border: 4px double #a93424; text-align: center; box-shadow: 0 8px 30px var(--shadow); animation: release-in .45s ease-out; }
.release-banner strong { display: block; color: var(--vermillion); font-size: 21px; }.release-banner span { font: 700 14px/1.3 system-ui, sans-serif; }

.control-deck { display: grid; grid-template-columns: minmax(0,1fr) minmax(130px, .34fr); grid-template-rows: auto auto auto; gap: 4px 6px; border-top: 3px double #61462c; padding-top: 4px; }
.dispatch-summary { grid-column: 1 / 3; display: flex; justify-content: center; gap: 15px; min-height: 20px; font: 800 14px/1.2 system-ui, sans-serif; }
.route-buttons { grid-column: 1; grid-row: 2; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 5px; }
.route-button { min-width: 0; min-height: 60px; padding: 3px; border: 2px solid #463621; background: #f6e8c2; display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; text-align: left; cursor: pointer; box-shadow: inset 0 -4px rgba(62,42,25,.13); }
.route-button > span { grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; margin-right: 4px; border: 2px solid currentColor; border-radius: 50%; font-weight: 900; }
.route-button b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.route-button em { font: normal 800 14px/1 system-ui, sans-serif; }
.route-button.authority { color: #82352c; }.route-button.regions { color: #254f5d; }.route-button.towns { color: #3d6245; }
.route-button.active { color: #fff9e9; background: currentColor; }
.route-button.authority.active { background: #82352c; }.route-button.regions.active { background: #254f5d; }.route-button.towns.active { background: #3d6245; }
.advance-button { grid-column: 2; grid-row: 2; min-height: 60px; border: 3px solid #51261d; background: var(--vermillion); color: #fff8e7; cursor: pointer; display: grid; place-content: center; text-align: center; box-shadow: inset 0 0 0 2px #d07852; }
.advance-button span { font-size: 14px; }.advance-button strong { font-size: 17px; }
.advance-button:disabled { filter: grayscale(.8); opacity: .58; cursor: not-allowed; }
.action-hint { grid-column: 1 / 3; margin: 0; min-height: 34px; padding-inline: 4px; text-align: center; font: 700 14px/1.2 system-ui, sans-serif; white-space: normal; overflow-wrap: anywhere; }

.quiz-screen { position: relative; display: grid; grid-template-rows: auto auto minmax(0,auto) auto auto; align-content: center; gap: 7px; padding: 10px max(10px, 6vw); background: #f0dfb7; }
.quiz-top { display: flex; justify-content: space-between; font: 900 16px/1.2 system-ui, sans-serif; color: var(--vermillion); }
.quiz-scroll-art { height: 8px; background: repeating-linear-gradient(90deg, #563c26 0 24px, #c69743 24px 44px); border-radius: 50%; }
.quiz-screen h2 { margin: 0; font-size: clamp(18px, 4.8vw, 27px); line-height: 1.3; }
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.quiz-choice { min-height: 48px; border: 2px solid #58452f; background: #fff7df; padding: 6px 8px; text-align: left; font: 700 16px/1.25 system-ui, sans-serif; cursor: pointer; }
.quiz-choice.correct { border-color: #245c40; background: #dff0d7; }.quiz-choice.wrong { border-color: #8c2c24; background: #f9d8cc; }
.quiz-choice:disabled { color: #2e2c27; opacity: 1; }
.quiz-feedback { padding: 7px 9px; border-left: 6px solid var(--gold); background: #fff3d0; font: 700 15px/1.3 system-ui, sans-serif; }
.quiz-feedback strong { color: var(--vermillion); }.quiz-feedback p { display: inline; margin: 0 0 0 7px; }
.quiz-screen > .seal-button { justify-self: center; min-width: 120px; }
.quiz-note { margin: 0; text-align: center; font: 700 14px/1.2 system-ui, sans-serif; }

.result-screen { position: relative; display: grid; align-content: center; justify-items: center; gap: 7px; padding: 10px 16px; text-align: center; background: #eddbad; overflow: hidden; }
.result-sun { position: absolute; top: 5%; width: min(65vw, 310px); aspect-ratio: 1; border-radius: 50%; background: rgba(192,67,40,.18); border: 3px solid rgba(147,48,31,.2); z-index: 0; }
.result-screen > *:not(.result-sun) { position: relative; z-index: 1; }
.result-screen h2 { margin: 0; font-size: clamp(22px, 5.5vw, 36px); }
.result-score { display: grid; min-width: min(90%, 320px); padding: 5px 12px; border-block: 3px double #684a2f; background: rgba(255,244,211,.7); }
.result-score span { font: 800 14px/1.2 system-ui, sans-serif; }.result-score strong { color: var(--vermillion); font: 900 clamp(32px, 9vw, 52px)/1 system-ui, sans-serif; }.result-score small { font: 800 14px/1.2 system-ui, sans-serif; }
.result-facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.result-facts span { padding: 5px 8px; border: 1px solid #715336; background: #f8eac7; font: 700 14px/1.2 system-ui, sans-serif; }
.result-screen > p:not(.kicker) { margin: 0; max-width: 580px; font: 700 15px/1.35 system-ui, sans-serif; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; width: min(100%, 440px); }

.paper-dialog { width: min(92vw, 660px); max-height: min(84svh, 720px); padding: 0; border: 4px double #5b412a; background: #f7e9c7; color: var(--ink); box-shadow: 0 20px 70px #17110d; }
.paper-dialog::backdrop { background: rgba(20,16,12,.72); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; background: #ead5a5; border-bottom: 2px solid #62492f; }
.dialog-head h2 { margin: 0; font-size: 20px; }.dialog-body { max-height: calc(84svh - 66px); overflow-y: auto; padding: 8px 18px 16px; font: 600 16px/1.65 system-ui, sans-serif; }.dialog-body li + li { margin-top: 7px; }
.ranking-dialog { width: min(96vw, 720px); }.ranking-host { min-height: 260px; max-height: calc(84svh - 66px); overflow-y: auto; padding: 10px; color: #222; background: #fff8e8; font-family: system-ui, sans-serif; }
.ranking-host button, .ranking-host a { color: #172838; }

@keyframes road-flow { to { transform: translateX(250%); } }
@keyframes lantern-bob { to { transform: translateY(-4px); } }
@keyframes release-in { from { transform: translateY(15px) scale(.94); opacity: 0; } }
@keyframes warning-pulse { to { box-shadow: inset 0 0 0 3px #c54b37; } }

@media (max-width: 580px) {
  .app-shell { padding-inline: max(4px, env(safe-area-inset-left)); }
  .title-lockup p { display: none; }
  .crest { width: 38px; height: 38px; flex-basis: 38px; }
  .hud { grid-template-columns: minmax(0,1fr) 66px 68px; }
  .score-hud { min-width: 0; }.danger-badge { min-width: 0; padding-inline: 2px !important; }
  .danger-badge span:first-child { display: none; }
  .event-copy span { display: none; }
  .center-marker { top: 5%; padding: 2px 5px; }.center-marker span { display: none; }
  .route-states { padding-inline: 2px; }.state span { font-size: 14px; }
  .telegraph { min-height: 41px; }.telegraph p span { font-size: 14px; }
  .control-deck { grid-template-columns: minmax(0,1fr) 112px; }
  .dispatch-summary { gap: 9px; }
  .route-button { min-height: 58px; grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .route-button > span { grid-row: auto; width: 26px; height: 26px; margin: 0; }.route-button b { display: none; }
  .advance-button { min-height: 58px; }.advance-button strong { font-size: 15px; }
  .quiz-screen { padding-inline: 8px; }.quiz-choices { grid-template-columns: 1fr; gap: 5px; }.quiz-choice { min-height: 44px; }
}

@media (max-height: 610px) {
  .masthead { min-height: 44px; }.crest { width: 36px; height: 36px; flex-basis: 36px; }.icon-button { min-height: 44px; }
  .play-screen { gap: 3px; padding-top: 3px; }.hud { min-height: 44px; }
  .event-strip { padding-block: 3px; }.route-states { padding-block: 2px; }.telegraph { min-height: 38px; }
  .control-deck { gap: 2px 5px; padding-top: 2px; }.route-button, .advance-button { min-height: 55px; }.dispatch-summary { min-height: 18px; }
  .start-screen { gap: 7px; }.start-copy { padding: 8px; }.start-copy h2 { font-size: 25px; }
  .result-screen { gap: 5px; }.result-score strong { font-size: 34px; }
}

@media (max-height: 567px), (max-width: 319px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 568px; overflow: visible; }
}

@media (min-width: 800px) {
  .play-screen { grid-template-columns: minmax(0,1fr) 360px; grid-template-rows: auto minmax(0,1fr); column-gap: 10px; }
  .hud { grid-column: 1 / 3; }.game-field { grid-column: 1; }.control-deck { grid-column: 2; display: grid; grid-template-columns: 1fr; grid-template-rows: auto 1fr auto auto; align-content: center; border: 3px double #61462c; padding: 12px; }
  .dispatch-summary, .route-buttons, .advance-button, .action-hint { grid-column: 1; grid-row: auto; }
  .route-buttons { grid-template-columns: 1fr; align-content: center; }.route-button { min-height: 72px; }.advance-button { min-height: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
