/* OBVIOUS EXITS — the Ministry's house style. System fonts only (works offline). */
:root {
  --paper: #f3eedf;
  --paper-2: #e9e2cd;
  --ink: #1e2328;
  --ink-soft: #5b5f63;
  --rule: #cfc6ad;
  --green: #2f6b4f;
  --green-soft: #dce9dc;
  --brass: #b08a2e;
  --stamp: #b3362b;
  --pa: #24456b;
  --copy-bg: #1e2328;
  --copy-ink: #f3eedf;
  --fs: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", "Droid Serif", serif;
  --civic: "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  --plain: "Courier New", Courier, "Noto Mono", monospace;
  --stage-h: clamp(140px, 32vh, 300px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15181b;
    --paper-2: #1f2327;
    --ink: #ece5d3;
    --ink-soft: #a7a394;
    --rule: #3a3d3f;
    --green: #7cc29b;
    --green-soft: #22352b;
    --brass: #d5b05a;
    --stamp: #e0675a;
    --pa: #9cc0e8;
    --copy-bg: #ece5d3;
    --copy-ink: #15181b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
body { font-family: var(--serif); font-size: var(--fs); line-height: 1.5; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  position: fixed; left: 0; right: 0; top: 0;
  height: var(--vvh, 100dvh);
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: auto var(--stage-h) minmax(0, 1fr) auto;
  grid-template-areas: "bar" "stage" "log" "dock";
}
#app.no3d, #app.kbd { grid-template-rows: auto 0 minmax(0, 1fr) auto; }
#app.collapsed { grid-template-rows: auto 48px minmax(0, 1fr) auto; }

/* ---------- top bar ---------- */
#bar { grid-area: bar; display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 12px; padding-top: env(safe-area-inset-top); border-bottom: 1.5px solid var(--ink); background: var(--paper); min-height: 44px; }
#brand { font-family: var(--civic); font-weight: 700; letter-spacing: 0.18em; font-size: 14px; }
#barbtns { display: flex; gap: 4px; }
.hb { min-height: 44px; min-width: 44px; padding: 0 10px; background: none; border: 0; font-family: var(--civic); font-weight: 600; letter-spacing: 0.1em; font-size: 13px; cursor: pointer; }
.hb[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.hb:disabled { opacity: 0.3; }

/* ---------- stage ---------- */
#stage { grid-area: stage; position: relative; overflow: hidden; background: #c9d6dc; border-bottom: 1.5px solid var(--ink); }
#app.no3d #stage, #app.kbd #stage { display: none; }
#stage-canvas, #stage-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#btn-collapse { position: absolute; right: 2px; top: 2px; background: rgba(243, 238, 223, 0.85); color: #1e2328; border-radius: 6px; min-height: 44px; font-size: 11px; }
#app.collapsed #btn-collapse { top: 2px; }
#app.collapsed #stage-canvas { visibility: hidden; }

/* ---------- transcript ---------- */
#log { grid-area: log; overflow-y: auto; padding: 12px 16px 8px; scroll-behavior: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#log:focus { outline: none; }
#log p { margin: 0 0 0.6em; max-width: 40em; }
#log .echo { font-family: var(--civic); color: var(--ink-soft); margin-top: 1.1em; font-size: 0.82em; letter-spacing: 0.04em; }
#log .echo::before { content: "> "; }
#log .head { margin-top: 0.9em; margin-bottom: 0.25em; font-family: var(--civic); font-weight: 700; letter-spacing: 0.14em; font-size: 0.95em; }
#log .head .credit { font-family: var(--serif); font-weight: 400; font-style: italic; letter-spacing: 0; color: var(--ink-soft); margin-left: 0.4em; }
#log .exits, #log .small { font-family: var(--civic); font-size: 0.86em; letter-spacing: 0.02em; border-left: 3px solid var(--brass); padding-left: 0.6em; }
#log .small { font-size: 0.74em; color: var(--ink-soft); border-left-style: dotted; }
#log .pa { color: var(--pa); }
#log .pa .tag, #log .chime .tag { font-family: var(--civic); font-weight: 700; font-size: 0.72em; letter-spacing: 0.16em; border: 1.5px solid currentColor; border-radius: 3px; padding: 0 0.35em; margin-right: 0.45em; vertical-align: 0.12em; }
#log .chime { color: var(--pa); font-style: italic; }
#log .issued { display: inline-block; font-family: var(--civic); font-weight: 700; letter-spacing: 0.08em; color: var(--green); border: 2px solid var(--green); border-radius: 4px; padding: 0.05em 0.5em; transform: rotate(-1.2deg); }
#log .issued.lent { border-style: dashed; color: var(--brass); border-color: var(--brass); }
#log .copy { font-family: var(--civic); font-weight: 700; letter-spacing: 0.12em; background: var(--copy-bg); color: var(--copy-ink); padding: 0.4em 0.6em; font-size: 0.92em; }
#log .plain { }
#log .help-head, #log .help { font-family: var(--civic); letter-spacing: 0.03em; }
#log .help-head { font-weight: 700; letter-spacing: 0.12em; }
#log .unissued { font-family: var(--plain); font-size: 0.95em; text-transform: lowercase; letter-spacing: 0; }
#log .end { font-family: var(--civic); font-weight: 700; letter-spacing: 0.3em; font-size: 1.1em; margin-top: 1.2em; }
#log i.aside { color: var(--ink-soft); }
#log .choices { display: flex; flex-wrap: wrap; gap: 6px; }
#log .noun.live { text-decoration: underline; text-decoration-color: var(--brass); text-decoration-thickness: 2px; text-underline-offset: 3px; cursor: pointer; }
#log .noun.live:hover { background: var(--paper-2); }
#log .word.live { cursor: pointer; border-bottom: 2px dotted var(--green); padding: 0 1px; }
#log .word.live:hover, #log .word.live:focus { background: var(--green-soft); }
#log .turn-fade { opacity: 0.86; }

/* ---------- dock ---------- */
#dock { grid-area: dock; border-top: 1.5px solid var(--ink); background: var(--paper); padding-bottom: env(safe-area-inset-bottom); }
.row { display: flex; gap: 6px; padding: 5px 10px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.row::-webkit-scrollbar { display: none; }
.row.more-right { -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent); mask-image: linear-gradient(90deg, #000 82%, transparent); }
.row .rowlabel { font-family: var(--civic); font-size: 12px; letter-spacing: 0.1em; color: var(--ink-soft); white-space: nowrap; padding-right: 2px; }
#row-nouns, #row-talk { background: var(--paper-2); }
#row-exits:empty { display: none; }
/* exits wrap rather than scroll, so a new exit is never cut off at the edge */
#row-exits { flex-wrap: wrap; overflow-x: visible; }
#row-exits.weather-only { flex-wrap: nowrap; overflow-x: auto; }
#verbs-line { display: flex; align-items: center; }
#verbs-line #row-verbs { flex: 1 1 auto; min-width: 0; }
.pin { display: flex; gap: 6px; padding: 5px 10px 5px 2px; flex: 0 0 auto; }
.pin:empty { display: none; }

.chip {
  flex: 0 0 auto; min-height: 44px; min-width: 44px; padding: 0 12px;
  font-family: var(--civic); font-weight: 600; font-size: 15px; letter-spacing: 0.06em;
  background: var(--paper); color: var(--ink); border: 1.5px solid var(--ink); border-radius: 7px;
  cursor: pointer; white-space: nowrap; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.chip:active { transform: translateY(1px); }
.chip:focus-visible { outline: 3px solid var(--brass); outline-offset: 1px; }
.chip.small { min-height: 44px; font-size: 13px; padding: 0 10px; }
.chip.big { min-height: 52px; font-size: 18px; padding: 0 22px; }
.chip.on { background: var(--ink); color: var(--paper); }
.chip.exit b { font-weight: 800; }
.chip.exit .lbl { font-weight: 400; margin-left: 0.45em; font-size: 0.82em; letter-spacing: 0.02em; }
.chip.exit.weather { border-style: dashed; color: var(--ink-soft); }
.chip.issued { border-color: var(--green); color: var(--green); border-width: 2px; }
.chip.lent { border-style: dashed; border-color: var(--brass); color: var(--brass); }
.chip.lent::after { content: " lent"; font-size: 0.7em; font-weight: 400; letter-spacing: 0.02em; }
.chip.nudge { border-color: var(--ink-soft); color: var(--ink); font-size: 13px; }
.chip.more { border-style: dotted; }
.chip.new { animation: issue 900ms ease-out 1; }
@keyframes issue { 0% { transform: scale(1.6) rotate(-6deg); background: var(--green-soft); } 60% { transform: scale(0.96) rotate(1deg); } 100% { transform: none; } }
.chip.copy { background: var(--copy-bg); color: var(--copy-ink); border-color: var(--copy-bg); letter-spacing: 0.14em; }
.chip.copy.flipin { animation: flip 520ms ease-out 1 both; }
@keyframes flip { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.chip.falling { animation: fall 600ms ease-in 1 forwards; pointer-events: none; }
@keyframes fall { to { transform: translateY(70px) rotate(8deg); opacity: 0; } }
.chip.oldstyle.slidein { animation: slidein 500ms ease-out 1 both; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.chip.unissued { font-family: var(--plain); font-weight: 400; letter-spacing: 0; text-transform: lowercase; border-radius: 0; border-width: 1px; }

#inputline { display: flex; align-items: center; gap: 6px; padding: 6px 10px 8px; }
#prompt { font-family: var(--civic); font-weight: 700; }
#cmd { flex: 1 1 auto; min-width: 0; min-height: 44px; font-family: var(--serif); font-size: max(16px, 0.95em); color: var(--ink); background: var(--paper-2); border: 1.5px solid var(--rule); border-radius: 7px; padding: 0 10px; caret-color: var(--ink); }
#cmd:focus { outline: none; border-color: var(--ink); }
#cmd.described { caret-color: transparent; font-family: var(--civic); letter-spacing: 0.1em; }
#cmd.described::placeholder { color: var(--ink-soft); font-style: italic; }
#walking { display: flex; align-items: center; gap: 6px; font-family: var(--civic); font-size: 12px; color: var(--green); white-space: nowrap; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--green); animation: pulse 900ms ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.5); opacity: 0.4; } }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--paper); z-index: 20; padding: 24px; }
#endcard { background: rgba(21, 24, 27, 0.55); animation: fadein 900ms ease-out 1; }
@keyframes fadein { from { opacity: 0; } }
.title-card { max-width: 32em; text-align: center; background: var(--paper); padding: 28px 22px; border: 2px solid var(--ink); }
.title-card h1 { font-family: var(--civic); font-weight: 800; letter-spacing: 0.2em; font-size: clamp(30px, 9vw, 54px); margin: 0 0 0.3em; line-height: 1.05; }
.issued-by { font-style: italic; margin: 0 0 1.4em; }
.title-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.end-1 { font-family: var(--civic); font-weight: 700; letter-spacing: 0.12em; }
.sheet { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, 0.25); display: flex; align-items: flex-start; justify-content: flex-end; }
.sheet-inner { margin-top: calc(48px + env(safe-area-inset-top)); margin-right: 8px; background: var(--paper); border: 2px solid var(--ink); padding: 10px; display: grid; gap: 8px; max-width: calc(100vw - 16px); }
.sheet-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sheet-row span { font-family: var(--civic); letter-spacing: 0.06em; min-width: 7.5em; }
.pop { position: fixed; z-index: 12; background: var(--paper); border: 2px solid var(--ink); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; max-width: min(92vw, 380px); }
.pop .pop-title { width: 100%; font-family: var(--civic); font-size: 12px; letter-spacing: 0.12em; color: var(--ink-soft); padding: 0 2px; }

/* ---------- wide screens: diorama beside the text ---------- */
@media (min-width: 820px), (orientation: landscape) and (min-width: 600px) and (max-height: 600px) {
  :root { --fs: 19px; }
  #app {
    grid-template-columns: 45% 55%;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "bar bar" "stage log" "stage dock";
  }
  #app.no3d, #app.kbd { grid-template-columns: 0 100%; grid-template-rows: auto minmax(0, 1fr) auto; }
  #app.collapsed { grid-template-rows: auto minmax(0, 1fr) auto; }
  #app.collapsed #stage-canvas { visibility: visible; }
  #btn-collapse { display: none; }
  #stage { border-bottom: 0; border-right: 1.5px solid var(--ink); }
  #log { padding: 16px 28px 10px; }
  #dock { border-left: 0; }
  #app.no3d #log, #app.no3d #dock .row, #app.no3d #inputline { padding-left: max(16px, calc(50% - 22em)); padding-right: max(16px, calc(50% - 22em)); }
}
@media (max-width: 380px) { :root { --fs: 17px; } .chip { font-size: 14px; padding: 0 10px; } }
/* phones: each exit chip is two short lines, the direction over where it goes */
@media (max-width: 819px) {
  .chip.exit { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 9px; line-height: 1.1; }
  .chip.exit .lbl { margin-left: 0; font-size: 11px; }
  .pin .chip { padding: 0 9px; font-size: 13px; }
}
/* tall narrow screens: a slimmer picture, more room for the words */
@media (max-width: 819px) and (max-aspect-ratio: 2/3) { :root { --stage-h: clamp(130px, 27vh, 240px); } }
@media (prefers-reduced-motion: reduce) {
  .chip.new, .chip.flipin, .chip.falling, .chip.slidein, #endcard, .pulse { animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
}
@media (max-width: 400px) { #walking-label { display: none; } }
