:root {
  --bg: #14120f; --panel: #1c1915; --line: #3a332a; --ink: #e6dcc8; --dim: #9a8d77;
  --accent: #d9a441; --cmd: #8fb7a6;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; height: 100dvh; background: var(--bg); color: var(--ink);
  font: 17px/1.5 Georgia, "Iowan Old Style", "Times New Roman", serif;
}
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 2px 12px;
  font-size: 15px; cursor: pointer;
}
button:hover, button:focus-visible { border-color: var(--accent); }

/* --- status bar ------------------------------------------------------------ */

#status {
  flex: none; display: flex; align-items: center; gap: 16px; padding: 6px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
#room { flex: 1; min-width: 0; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status nav { display: flex; gap: 6px; }
#score { flex: 1; text-align: right; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- main column ----------------------------------------------------------- */

#body { flex: 1; min-height: 0; display: flex; justify-content: center; }
/* One column exactly as wide as the picture, so the picture, the text and the
   input line share their left and right edges. */
main {
  --col: min(100%, calc(48dvh * 16 / 9));
  flex: 1 1 1100px; max-width: 1100px; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; padding: 0 16px;
}
#scene, #text, #form, #over, #auto { width: var(--col); margin-left: auto; margin-right: auto; }

/* --- picture --------------------------------------------------------------- */

#scene {
  flex: none; position: relative; overflow: hidden; margin-top: 12px; aspect-ratio: 16 / 9;
  background: #000; border-radius: 4px; cursor: zoom-in; transition: filter 1s;
}
#scene.ghost { filter: grayscale(.85) brightness(1.15) contrast(.85); }
.pane { position: absolute; inset: 0; opacity: 0; transition: opacity .6s ease-in-out; }
.pane.slow { transition-duration: 1.1s; }
.pane.on { opacity: 1; }
/* A picture is the room's image with any layers stacked exactly over it. */
.picture { position: relative; height: 100%; }
.picture img { width: 100%; height: 100%; object-fit: cover; display: block; }
.picture img + img { position: absolute; inset: 0; }
.placeholder {
  height: 100%; display: grid; place-items: center; padding: 16px; text-align: center;
  background: radial-gradient(ellipse at center, #3a3226, #16130f 75%);
  color: var(--dim); font-size: clamp(18px, 4vw, 34px); font-style: italic;
}
.placeholder.dark { background: #050505; color: #3b362e; }
/* A wandering character, inset over the lower left of the picture. Its edges
   fade away so that it sits in the scene rather than on top of it. */
#overlay {
  position: absolute; z-index: 3; left: 1%; bottom: 2%; width: 44%; aspect-ratio: 16 / 9; pointer-events: none;
  opacity: 0; transform: translateX(-12%); transition: opacity .7s ease, transform .7s ease;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 45%, transparent 70%);
  mask-image: radial-gradient(ellipse at center, #000 45%, transparent 70%);
}
#overlay.on { opacity: 1; transform: none; }
#overlay img { width: 100%; height: 100%; object-fit: cover; display: block; }
#facing {
  position: absolute; z-index: 2; left: 50%; bottom: 8px; transform: translateX(-50%); pointer-events: none;
  padding: 1px 10px; border-radius: 3px; background: rgba(15, 13, 10, .62);
  font-size: 13px; letter-spacing: .04em;
}

/* --- transcript and input -------------------------------------------------- */

#text { flex: 1; min-height: 0; position: relative; margin-top: 6px; }
/* The text fades out at an edge it can scroll past, so no line is ever cut off
   without a sign. game.js sets the classes. */
#log {
  --top: 0px; --bottom: 0px;
  height: 100%; overflow-y: auto; padding: 8px 4px 14px; overflow-wrap: anywhere; line-height: 1.45; cursor: text;
  mask-image: linear-gradient(to bottom, transparent, #000 var(--top), #000 calc(100% - var(--bottom)), transparent);
}
#log.above { --top: 34px; }
#log.below { --bottom: 48px; }
#log p { margin: 0 0 10px; white-space: pre-wrap; }
#log .cmd { margin-top: 14px; color: var(--cmd); }
#log .cmd::before { content: "> "; }
#log .title { margin-bottom: 0; font-weight: bold; color: var(--accent); }
#log .notice { color: #e08a6a; font-style: italic; }
#more {
  position: absolute; z-index: 1; bottom: 4px; left: 50%; transform: translateX(-50%);
  color: var(--accent); border-color: var(--accent); font-size: 14px;
}

#form {
  flex: none; display: flex; gap: 8px; align-items: center; padding: 8px 4px;
  border-top: 1px solid var(--line); cursor: text;
}
#form label { color: var(--accent); font-weight: bold; }
#line { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 18px; }
#over { flex: none; display: flex; gap: 12px; justify-content: center; padding: 12px; border-top: 1px solid var(--line); }
#auto {
  flex: none; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  padding: 8px 4px; border-top: 1px solid var(--accent); color: var(--accent);
}
#auto-pos { min-width: 9em; font-variant-numeric: tabular-nums; }
#auto.paused #auto-pos::after { content: "  (paused)"; color: var(--dim); }

/* --- side panels: map and items ------------------------------------------- */

#map, #inv { display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
#map { flex: 0 1 460px; min-width: 300px; }
#inv { flex: 0 1 380px; min-width: 280px; }

#map-head { display: flex; justify-content: space-between; gap: 8px; padding: 10px; }
#map-body { flex: 1; min-height: 0; overflow: auto; }
#map svg { display: block; margin: 0 auto; }
#map .exit { stroke: var(--dim); stroke-width: 2; fill: none; }
#map .stub { stroke-dasharray: 4 4; }
#map .arrow { fill: var(--dim); }
#map rect { fill: #2a251e; stroke: var(--line); rx: 4px; }
#map .here rect { fill: #5b4519; stroke: var(--accent); stroke-width: 2; }
#map text { fill: var(--ink); font-size: 12px; text-anchor: middle; dominant-baseline: middle; }
#map .stub-label { fill: var(--dim); font-size: 10px; font-style: italic; }

#inv .panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 0; }
#inv h2 { margin: 0; font-size: 17px; font-weight: normal; letter-spacing: .03em; color: var(--accent); }
#inv h2.sub { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
#inv-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 8px; }
.tile { text-align: center; font-size: 12px; line-height: 1.2; }
.tile img, .tile .noicon {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  border: 1px solid var(--line); border-radius: 4px; background: #efe7d3;
}
.tile .noicon { display: grid; place-items: center; color: #8a7d66; font-size: 22px; }
.tile span { display: block; margin-top: 3px; }
/* What is inside a container, indented below it. */
.inside { grid-column: 1 / -1; margin: -2px 0 4px; padding: 6px 8px; border-left: 2px solid var(--line); }
.inside > small { color: var(--dim); }
.inside .tiles { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; margin-top: 4px; }
.inside .tile { font-size: 11px; }
.empty-note { margin: 8px 0 0; color: var(--dim); font-style: italic; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; margin-top: 8px; }
.slot { aspect-ratio: 1; border: 1px dashed var(--line); border-radius: 4px; background: rgba(255, 255, 255, .02); }
.slot.full { border: 1px solid var(--accent); }
.slot img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }

/* --- dialogs --------------------------------------------------------------- */

dialog { max-width: min(480px, 92vw); background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; }
dialog::backdrop { background: rgba(0, 0, 0, .75); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
#slots-list button { display: block; width: 100%; margin-bottom: 6px; padding: 8px 12px; text-align: left; }
#slots-list small { display: block; color: var(--dim); }
#slots-form { display: flex; gap: 8px; margin: 10px 0; }
#slots-form input { flex: 1; min-width: 0; padding: 4px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
#about a { color: var(--accent); }
#zoom { max-width: none; padding: 0; border: 0; background: none; }
#zoom .picture { cursor: zoom-out; }
#zoom .picture img:first-child { width: auto; height: auto; max-width: 98vw; max-height: 96dvh; }

/* --- phones ---------------------------------------------------------------- */

@media (max-width: 800px) {
  body { font-size: 16px; }
  #status { flex-wrap: wrap; gap: 2px 4px; padding: 6px 10px; }
  #room { flex: 1 0 100%; }
  #status nav { gap: 4px; }
  #status button { padding: 2px 6px; font-size: 13px; }
  #score { font-size: 13px; }
  main { --col: 100%; padding: 0 10px; }
  #scene { width: auto; max-height: 36dvh; margin: 0 -10px; border-radius: 0; }
  #map, #inv { position: fixed; inset: 0; z-index: 5; border: 0; }
}

/* --- wide, short windows: the picture beside the text ---------------------- */

@media (min-width: 1000px) and (max-height: 700px) {
  main { display: grid; grid-template: minmax(0, 1fr) auto / minmax(0, 3fr) minmax(0, 2fr); gap: 0 16px; max-width: none; }
  #scene { grid-row: 1 / 3; align-self: start; width: min(100%, calc((100dvh - 80px) * 16 / 9)); margin: 12px 0 0; }
  #text, #form, #over, #auto { width: auto; margin-left: 0; margin-right: 0; }
  #text { grid-area: 1 / 2; }
  #form, #over, #auto { grid-area: 2 / 2; }
}

@media (prefers-reduced-motion: reduce) {
  .pane, #scene, #overlay { transition: none; }
}
