:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: #f5efe3;
  background: #100e15;
  --panel: #17141e;
  --inset: #0d0c12;
  --line: #524957;
  --frame: #bfb3c1;
  --muted: #bdb4c4;
  --accent: #f2c485;
  --selection: #332a27;
  --green: #a4e3b8;
  --red: #ffb4b8;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }

body { margin: 0; isolation: isolate; }

.site-header {
  position: relative;
  z-index: 1;
  background: var(--inset);
  border-bottom: 1px solid var(--line);
}

.header-inner, #fullscreen-status, main {
  width: min(100% - 48px, 1240px);
  margin-inline: auto;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 6px clamp(8px, 2vw, 24px);
  justify-content: space-between;
  align-items: center;
  min-height: 60px;
  padding-block: 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-inline-start: auto;
}

.header-titles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px clamp(8px, 2vw, 18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: 700 .95rem var(--mono);
}

.brand::before {
  width: 7px;
  height: 7px;
  background: var(--green);
  content: "";
}

.header-titles h1 {
  margin: 0;
  padding-inline-start: 12px;
  border-inline-start: 1px solid var(--frame);
  color: var(--muted);
  font-size: .9rem;
  font-weight: 650;
}

main { padding: clamp(20px, 3vw, 36px) 0; }

body:has(:is(#quest-menu, #dungeon):not([hidden])) {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

main:has(> :is(#quest-menu, #dungeon):not([hidden])), #dungeon {
  display: flex;
  flex: 1;
  flex-direction: column;
}

main:has(> :is(#quest-menu, #dungeon):not([hidden])) {
  padding: 0;
}

main:has(> #dungeon:not([hidden])) { width: 100%; }

#dungeon { position: relative; }

body:has(main > #dungeon:not([hidden])) .site-header :is(.header-inner, #fullscreen-status) {
  width: calc(100% - 24px);
}

[hidden] { display: none !important; }

.quest-menu {
  width: min(100%, 440px);
  margin: clamp(28px, 12svh, 128px) auto 0;
  padding: clamp(24px, 5vw, 44px);
}

.quest-menu h1 {
  margin: 0 0 24px;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

#quest-menu {
  display: grid;
  flex: 1;
  grid-template-rows: minmax(min-content, 1.15fr) auto minmax(min-content, .85fr);
  width: min(100%, 960px);
  margin: 0 auto;
  padding: 0 0 min(61px, 8svh);
  text-align: center;
}

#dungeon-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--inset);
  overflow: hidden;
  pointer-events: none;
}

#dungeon-backdrop::after {
  position: absolute;
  inset: 0;
  background: #08060c66;
  content: "";
}

body:has(#dungeon:not([hidden])) > #dungeon-backdrop { visibility: hidden; }

body:has(#quest-menu:not([hidden])) > #dungeon-backdrop::after {
  background:
    linear-gradient(#0d0b119e, #0d0b11bd),
    radial-gradient(ellipse at 29% 31%, #ffa85038, transparent min(23vw, 210px)),
    radial-gradient(ellipse at 74% 31%, #ffa85038, transparent min(23vw, 210px)),
    radial-gradient(ellipse at 50% 45%, transparent 15%, #100e1580 100%);
}

.title-scene {
  --title-sprite-scale: 2.1;
  display: flex;
  align-self: start;
  justify-content: space-between;
  margin-top: clamp(16px, 4svh, 36px);
}

.title-character {
  display: grid;
  grid-template-rows: 1.5rem calc(54px * var(--title-sprite-scale) + 12px);
  width: min(42%, 210px);
}

.title-character-name {
  grid-row: 1;
  overflow: hidden;
  margin: 0;
  font-size: .9rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-character > .player, #title-guests > * {
  grid-area: 2 / 1;
  place-self: end center;
  position: relative;
  scale: var(--title-sprite-scale);
}

#title-guests > * {
  opacity: 0;
  pointer-events: none;
}

#title-guests > .host-sprite {
  width: 54px;
  height: 54px;
}

#title-guests > [data-active] { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  #title-guests > * { transition: opacity .45s ease-in-out; }
}

@media (min-width: 640px) {
  .title-scene { --title-sprite-scale: 3.2; }
}

#quest-menu-title {
  align-self: end;
  margin: 0 0 clamp(24px, 6svh, 48px);
  font: 900 clamp(1.5rem, 8.5vw, 6rem)/.95 var(--mono);
  letter-spacing: .015em;
  text-transform: uppercase;
}

#quest-menu-title span { display: block; }

#quest-menu .quest-menu-actions {
  width: min(100%, 284px);
  margin-inline: auto;
}

#quest-menu .quest-menu-actions button {
  position: relative;
  font-family: var(--mono);
}

#quest-menu .quest-menu-actions .button-secondary {
  border-color: var(--frame);
  background: var(--inset);
}

#quest-menu .quest-menu-actions .button-secondary:is(:hover, :focus-visible) {
  border-color: var(--accent);
  background: var(--selection);
}

#quest-menu .quest-menu-actions button::before {
  position: absolute;
  top: 50%;
  left: 20px;
  translate: 0 -50%;
  width: 7px;
  height: 7px;
  background: currentColor;
  rotate: 45deg;
  opacity: 0;
  content: "";
}

#quest-menu .quest-menu-actions button:is(:hover, :focus-visible, [data-menu-selected])::before { opacity: 1; }

#quest-picker {
  width: min(100%, 640px);
  margin: clamp(12px, 5svh, 48px) auto 0;
  padding: 16px;
}

#quest-picker h1 {
  margin: 0 0 8px;
  font-size: 1.3rem;
}

.quest-picker-chapter h2 {
  margin: 10px 0 2px;
  color: var(--accent);
  font-size: 1rem;
}

.quest-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.quest-picker-row :is(h3, h4) { margin: 0; font-size: .9rem; }
.quest-picker-tip h4 { padding-inline-start: 14px; }

.quest-picker-actions { display: flex; gap: 6px; flex-wrap: wrap; }

#quest-picker button {
  min-height: 32px;
  padding: 4px 9px;
  font-size: .8rem;
}

#quest-menu-back { margin-block-start: 10px; }

@media (max-width: 550px) {
  #quest-picker { padding: 12px; }
  .quest-picker-row { grid-template-columns: 1fr; }
}

.quest-menu-actions {
  display: grid;
  gap: 12px;
}

.quest-menu-actions button {
  min-height: 52px;
  font-size: 1rem;
}

.corridor {
  --sprite-scale: 1;
  --floor-height: 54%;
  position: relative;
  isolation: isolate;
  flex: 1;
  overflow: hidden;
  min-height: max(280px, 62svh);
  background: var(--inset);
}

.corridor :is(.player, .enemy-sprite, .dungeon-book, .dungeon-prop) {
  position: absolute;
  left: calc(6% + (var(--column, 0) + .5) * 88% / var(--grid-columns));
  bottom: calc(var(--floor-height) - 6% - (var(--row, 0) + .5) * (var(--floor-height) - 9%) / var(--grid-rows));
  z-index: calc(2 + var(--row, 1));
  translate: -50%;
  scale: var(--sprite-scale);
}

#dungeon-gate {
  bottom: var(--floor-height);
  width: clamp(46px, 6vw, 72px);
  height: clamp(62px, 8vw, 90px);
  border: 5px solid #827289;
  border-bottom-color: #504252;
  border-radius: 36% 36% 0 0;
  background: repeating-linear-gradient(90deg, #5a372b 0 8px, #38231d 8px 11px);
  box-shadow: inset 0 0 0 2px #21191d;
  transform-origin: bottom;
}

#dungeon[data-phase="entering-gate"] .player { bottom: calc(var(--floor-height) + 8px); }

.gate-lock {
  position: absolute;
  top: 53%;
  left: 50%;
  width: 15px;
  height: 13px;
  border: 2px solid #5c3f2e;
  background: #e5b75f;
  translate: -50%;
}

.gate-lock::before {
  position: absolute;
  inset: -10px 0 auto;
  height: 10px;
  border: 2px solid #e5b75f;
  border-radius: 6px 6px 0 0;
  content: "";
}

[data-cleared] #dungeon-gate {
  border-color: #b98a57;
  background: radial-gradient(ellipse at 50% 100%, #ffd18088, transparent 75%), #201921;
  box-shadow: 0 0 16px #efa64b59, inset 0 0 0 2px #35251f;
}

[data-cleared] .gate-lock { display: none; }

.enemy-sprite { transform-origin: bottom; }

.corridor .enemy-sprite {
  opacity: 0;
  transition: opacity .24s;
}

.dungeon-book {
  width: 26px;
  height: 22px;
  border: 3px solid #80562f;
  border-left-color: #66412a;
  background:
    linear-gradient(#fff0c7, #fff0c7) center 5px / 9px 3px no-repeat,
    linear-gradient(#bd863c 75%, #f3d7a4 75%);
  box-shadow: 0 0 14px #f2c48580, 0 4px 0 #111015a0;
  animation: book-drop .4s ease-out both;
}

@keyframes book-drop {
  0% { opacity: 0; transform: translateY(-20px) rotate(-12deg); }
  68% { opacity: 1; transform: translateY(0) rotate(5deg); }
  100% { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dungeon-book { animation: none; }
}

.player {
  --coat-edge: #132e45;
  --coat-light: #a9d9c1;
  --coat-shade: #4f8276;
  --coat-back: #315450;
  --head-edge: #28243a;
  --head-light: #77628a;
  --head-front: #736189;
  --head-back-light: #85729b;
  --head-back: #584666;
  --face: #f4c19a;
  --head-shape: polygon(0 20%, 14% 20%, 14% 0, 86% 0, 86% 20%, 100% 20%, 100% 84%, 86% 84%, 86% 100%, 14% 100%, 14% 84%, 0 84%);
  transform-origin: bottom;
  width: 36px;
  height: 54px;
  transition: left .13s linear, bottom .13s linear;
}

.player[data-placing] { transition: none; }

.player[data-character="knight"] {
  --face: #a5b8cb;
  --head-shape: polygon(20% 5%, 33% 5%, 33% 0, 64% 0, 64% 6%, 77% 6%, 77% 22%, 89% 22%, 89% 34%, 100% 34%, 100% 77%, 91% 77%, 91% 90%, 74% 90%, 74% 100%, 24% 100%, 24% 92%, 10% 92%, 10% 76%, 0 76%, 0 34%, 10% 34%, 10% 22%, 20% 22%);
}

.player[data-character="mage"] {
  --coat-edge: #171b38;
  --coat-light: #505b99;
  --coat-shade: #363e70;
  --coat-back: #282f59;
  --head-edge: #171b38;
  --mage-gold: #efba56;
}

.player::before, .enemy-sprite::before {
  position: absolute;
  inset: auto 0 -3px;
  height: 9px;
  border-radius: 50%;
  background: #1219239c;
  content: "";
}

.player-coat {
  position: absolute;
  inset: 23px 7px 5px;
  border: 3px solid var(--coat-edge);
  background: linear-gradient(var(--coat-light) 65%, var(--coat-shade) 65%);
  box-shadow: -3px 6px 0 -2px #202034, 5px 6px 0 -2px #202034;
}

.player-head {
  position: absolute;
  inset: 3px 4px auto 5px;
  height: 27px;
  border: 3px solid var(--head-edge);
  background: linear-gradient(150deg, var(--head-light) 40%, var(--face) 40%);
  clip-path: var(--head-shape);
}

.player-head::after {
  position: absolute;
  inset: 10px 2px auto auto;
  width: 3px;
  height: 5px;
  background: var(--head-edge);
  content: "";
}

.player-gear {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.player-gear::before, .player-gear::after {
  position: absolute;
  content: "";
}

.player-gear::after {
  left: 25px;
  bottom: 15px;
  width: 5px;
  height: 5px;
  background: var(--face);
}

.player[data-character="knight"] .player-gear::before {
  left: 23px;
  bottom: 8px;
  width: 17px;
  height: 37px;
  background:
    linear-gradient(90deg, #768baa 36%, #f2f8ff 36% 56%, #b5c8df 56%) top / 100% 69% no-repeat,
    linear-gradient(#fee2a1 30%, #ad7038 30%) 0 76% / 100% 16% no-repeat,
    linear-gradient(#5e2939 0 82%, #e0a95c 82%) bottom / 100% 31% no-repeat;
  clip-path: polygon(50% 0, 74% 15%, 74% 69%, 100% 69%, 100% 80%, 62% 83%, 62% 94%, 67% 94%, 67% 100%, 33% 100%, 33% 94%, 38% 94%, 38% 83%, 0 80%, 0 69%, 26% 69%, 26% 15%);
  rotate: 21deg;
  transform-origin: 50% 85%;
}

.player[data-character="mage"] .player-gear::before {
  left: 21px;
  bottom: 5px;
  width: 15px;
  height: 42px;
  background:
    linear-gradient(135deg, #ffe6a0 25%, var(--mage-gold) 25% 72%, #c88437 72%) top / 100% 16px no-repeat,
    linear-gradient(90deg, #9e6950 8px, #674536 8px);
  clip-path: polygon(
    5px 0, 12px 0, 12px 2px, 9px 2px, 9px 4px, 7px 4px, 7px 9px,
    9px 9px, 9px 11px, 13px 11px, 13px 9px, 15px 9px, 15px 13px,
    12px 13px, 12px 15px, 9px 15px, 9px 100%, 6px 100%, 6px 16px,
    3px 16px, 3px 14px, 1px 14px, 1px 11px, 0 11px, 0 5px, 2px 5px, 2px 2px, 5px 2px
  );
  rotate: 12deg;
  transform-origin: 50% 65%;
}

.player:is([data-facing="left"], [data-facing="right"]) .player-coat {
  inset-inline: 9px;
  background: linear-gradient(90deg, var(--coat-shade) 25%, var(--coat-light) 25%);
}

.player[data-facing="left"] :is(.player-head, .player-coat, .player-gear) {
  transform: scaleX(-1);
}

.player[data-facing="up"] .player-head {
  background: linear-gradient(155deg, var(--head-back-light) 32%, var(--head-back) 35%);
}

.player[data-facing="up"] .player-head::after {
  content: none;
}

.player[data-facing="up"] .player-coat {
  background: linear-gradient(90deg, var(--coat-shade) 20%, var(--coat-back) 20% 80%, var(--coat-shade) 80%);
}

.player[data-facing="down"] .player-head {
  background: linear-gradient(var(--head-front) 31%, var(--face) 34%);
}

.player[data-facing="down"] .player-head::after {
  right: 5px;
  box-shadow: -7px 0 var(--head-edge);
}

.player[data-character="explorer"] > :is(.player-head, .player-coat, .player-gear) {
  display: none;
}

.player[data-character="explorer"]::after {
  position: absolute;
  inset: 0;
  /* The three frames show the front, right side, and back in that order. */
  background: url("./sprites/explorer.png") left center / 300% 100% no-repeat;
  image-rendering: pixelated;
  content: "";
}

.player[data-character="explorer"]:is([data-facing="left"], [data-facing="right"])::after {
  background-position: center;
}

.player[data-character="explorer"][data-facing="left"]::after {
  scale: -1 1;
}

.player[data-character="explorer"][data-facing="up"]::after {
  background-position: right center;
}

:is(.title-character, .character-preview) > .player[data-character="knight"] > :is(.player-head, .player-coat, .player-gear) {
  display: none;
}

:is(.title-character, .character-preview) > .player[data-character="knight"]::after {
  position: absolute;
  inset: 0;
  background: url("./sprites/knight-portrait.png") center / 100% no-repeat;
  image-rendering: pixelated;
  content: "";
}

.player[data-character="mage"] .player-head {
  inset: 0 auto auto -2px;
  width: 37px;
  height: 33px;
  border: 0;
  background:
    linear-gradient(135deg, #ffe6a0 40%, var(--mage-gold) 40%) 21px 13px / var(--mage-clasp-size, 5px) 5px no-repeat,
    linear-gradient(#232647, #232647) 0 14px / 100% 4px no-repeat,
    linear-gradient(115deg, #303662 32%, #555e9e 32% 55%, #39437d 55%) top / 100% 18px no-repeat,
    linear-gradient(#424c87 3px, #212646 3px) 0 18px / 100% 5px no-repeat,
    linear-gradient(90deg, #9d99bb 41%, var(--mage-face, var(--face)) 41% 86%, #bdb6d2 86%);
  clip-path: polygon(
    9px 0, 20px 0, 20px 3px, 25px 3px, 25px 7px, 28px 7px, 28px 12px,
    31px 12px, 31px 17px, 37px 17px, 37px 21px, 33px 21px, 33px 29px,
    30px 29px, 30px 33px, 12px 33px, 12px 30px, 9px 30px, 9px 23px,
    0 23px, 0 19px, 4px 19px, 4px 16px, 12px 16px, 12px 12px, 15px 12px,
    15px 6px, 10px 6px, 10px 9px, 5px 9px, 5px 4px, 9px 4px
  );
}

.player[data-character="mage"] .player-head::after {
  top: 25px;
  right: 8px;
  height: 4px;
}

.player[data-character="mage"][data-facing="up"] .player-head {
  --mage-clasp-size: 0px;
  --mage-face: #aaa5c6;
}

.player[data-character="mage"] .player-coat::after {
  position: absolute;
  inset: 7px auto 0 50%;
  width: 2px;
  background: linear-gradient(var(--mage-gold) 4px, #af7b43 4px);
  content: "";
}

.player[data-character="mage"][data-facing="up"] .player-coat::after {
  inset: auto 0 0;
  width: auto;
  height: 2px;
  background: #af7b43;
}

.player[data-character="knight"] .player-head {
  inset: 0 3px auto 4px;
  height: 32px;
  border: 0;
  background:
    linear-gradient(90deg, #812e43 30%, #db5269 30% 64%, #f58c91 64% 77%, #a63754 77%) top / 100% 7px no-repeat,
    linear-gradient(#eef5ff, #eef5ff) 10px 9px / 11px 2px no-repeat,
    linear-gradient(#52647f, #52647f) bottom / 100% 6px no-repeat,
    linear-gradient(90deg, #3b4a64 17%, #8295b0 17% 31%, #c0cddd 31% 69%, #98abc4 69% 85%, #63748f 85%);
}

.player[data-character="knight"] .player-head::after {
  inset: 15px 0 auto 9px;
  width: auto;
  height: 7px;
  background: linear-gradient(#182536 2px, transparent 2px 4px, #182536 4px), #d7a960;
  box-shadow: none;
  clip-path: polygon(0 0, 100% 0, 100% 72%, 76% 72%, 76% 100%, 20% 100%, 20% 72%, 0 72%);
}

.player[data-character="knight"][data-facing="down"] .player-head::after {
  inset-inline: 5px;
}

.player[data-character="knight"] .player-coat {
  inset: 24px 3px 1px;
  border: 0;
  background:
    linear-gradient(#f7d691 40%, #956432 40%) center 17px / 8px 5px no-repeat,
    linear-gradient(90deg, #61758f 22%, #b1c3d8 22% 53%, #8196b1 53% 79%, #526783 79%) top / 100% 14px no-repeat,
    linear-gradient(#263449, #263449) 0 15px / 100% 5px no-repeat,
    linear-gradient(90deg, #732d45 14%, #637790 14% 45%, #29394f 45% 57%, #92a6bd 57% 86%, #732d45 86%);
  clip-path: polygon(13% 0, 87% 0, 87% 10%, 100% 10%, 100% 46%, 84% 46%, 84% 78%, 93% 78%, 93% 100%, 57% 100%, 57% 86%, 43% 86%, 43% 100%, 7% 100%, 7% 78%, 16% 78%, 16% 46%, 0 46%, 0 10%, 13% 10%);
}

.player[data-character="knight"][data-facing="up"] .player-coat {
  background: linear-gradient(#b74359 10%, #94334c 62%, transparent 62%), linear-gradient(90deg, #667d99 44%, #29394f 44% 56%, #8196b1 56%);
}

[data-enemy-visible] .enemy-sprite { opacity: 1; }

[data-cleared] .enemy-sprite {
  animation: victory-hop .55s ease-out;
}

#dungeon[data-slime-defeated] .enemy-sprite,
#challenge[data-slime-defeated] .monster-arena .enemy-sprite { visibility: hidden; }

.dungeon-dialogue {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(50%, 22rem);
  grid-template-rows: minmax(0, 1fr);
  flex: none;
  align-items: center;
  gap: 12px;
  block-size: 10rem;
  padding: 16px clamp(14px, 4vw, 26px);
  border-top: 2px solid var(--frame);
  background: var(--inset);
}

.dungeon-dialogue p { margin: 0; }

.dungeon-speech {
  display: grid;
  grid-template-rows: minmax(min-content, 1fr) minmax(0, max-content) minmax(0, 1fr);
  align-self: stretch;
  min-block-size: 0;
}

.dungeon-text {
  grid-row: 2;
  min-block-size: 0;
  overflow: auto;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
  font-size: 1.25rem;
  line-height: 1.7;
}
.dungeon-text:focus-visible { outline-offset: -2px; }
.dungeon-text a { color: var(--green); }
#dungeon-message { white-space: pre-line; }
.dungeon-dialogue .speaker {
  grid-row: 1;
  align-self: start;
  width: fit-content;
  margin-bottom: 6px;
  padding: 1px 8px;
  background: var(--green);
  color: var(--inset);
  font-size: 1.0625rem;
  line-height: 1.35;
  font-weight: 750;
}
.dungeon-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: center;
  gap: 12px;
}

#dungeon-action {
  grid-column: 1;
  justify-self: end;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow-wrap: anywhere;
}

#dungeon-controls { grid-column: 2; }

#move-hint { margin-bottom: 6px; color: var(--muted); font-size: .8rem; text-align: center; }

#dungeon-action kbd { margin-inline-end: 4px; }

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.direction-pad button {
  min-height: 44px;
  padding: 0;
  border-color: var(--line);
  background: var(--inset);
  color: var(--accent);
  font-size: 1.15rem;
}

.direction-pad [data-key="ArrowUp"] { grid-column: 2; }
.direction-pad [data-key="ArrowLeft"] { grid-column: 1; }

@media (max-width: 640px) {
  .dungeon-dialogue {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    block-size: 14rem;
  }
}

.stage-clear {
  position: absolute;
  inset: clamp(12px, 4svh, 36px) 0 auto;
  z-index: 1;
  width: min(100% - 28px, 460px);
  margin-inline: auto;
  padding: 20px;
  border: 2px solid var(--green);
  background: var(--inset);
  color: var(--green);
  text-align: center;
  pointer-events: none;
}

.stage-clear h2 { font-size: clamp(1.5rem, 5vw, 2.25rem); }
.stage-clear p { margin: 6px 0 0; }

dialog {
  width: min(100% - 32px, 380px);
  padding: 24px;
  border: 2px solid var(--frame);
  background: var(--inset);
  color: inherit;
}

dialog::backdrop { background: #08060ccc; }
dialog h2 { font-size: 1.2rem; }
#options-title { margin-block-end: 24px; }
dialog form { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

#dungeon[data-quiz-arch] #go-quiz-stands::before {
  position: absolute;
  z-index: 1;
  inset: auto 23% 17%;
  height: 12%;
  border: 2px solid #aa825071;
  background: repeating-linear-gradient(90deg, #a8784129 0 14px, #25161b30 14px 16px);
  content: "";
}

.go-quiz-sign {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid #8a5a3b;
  background: #35251d;
  box-shadow: inset 0 0 0 2px #5d3d2d, 0 3px 0 #180e10;
  color: var(--accent);
  font: bold 22px var(--mono);
}

#go-quiz {
  width: min(100% - 24px, 600px);
  max-height: calc(100dvh - 24px);
  padding: clamp(16px, 4vw, 28px);
  border-color: var(--accent);
  background: var(--panel);
}

#go-quiz h2 { margin: 0; font-size: clamp(1.15rem, 4vw, 1.5rem); }
#go-quiz-progress { margin: 8px 0 18px; color: var(--accent); font-variant-numeric: tabular-nums; }
#go-quiz-round > p { margin: 0; }

#go-quiz pre {
  margin: 12px 0 16px;
  padding: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--accent);
  background: var(--inset);
  font: clamp(.875rem, 2.8vw, 1rem)/1.65 var(--mono);
}

#go-quiz pre code { color: inherit; }
#go-quiz pre mark { padding-inline: .2em; background: var(--selection); color: var(--accent); }

#go-quiz-hint { margin-block-end: 12px; }
#go-quiz-hint summary { cursor: pointer; color: var(--accent); }
#go-quiz-hint p { margin: 6px 0 0; line-height: 1.6; }

#go-quiz-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 135px), 1fr));
  gap: 8px;
}

#go-quiz-choices button { min-height: 44px; font-family: var(--mono); }
#go-quiz-choices [data-result] { opacity: 1; }
#go-quiz-choices [data-result="correct"] { border-color: var(--green); color: var(--green); }
#go-quiz-choices [data-result="incorrect"] { border-color: var(--red); color: var(--red); }

#go-quiz-feedback:not(:empty) { margin-block-start: 14px; white-space: pre-line; line-height: 1.6; }
#go-quiz-references { margin: 8px 0 0; padding-inline-start: 1.25em; line-height: 1.6; }
#go-quiz-references a { color: var(--accent); }
#go-quiz-score { margin: 0; color: var(--green); font-size: clamp(1.4rem, 5vw, 2rem); }

.go-quiz-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-block-start: 18px;
}

.book-reward-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-block: 8px;
  overflow-wrap: anywhere;
}

.book-reward-entry .book-cover { zoom: .6; }
.book-reward-entry button { margin-inline-start: auto; white-space: nowrap; }

body:has(#collection-page:not([hidden])) > .site-header { display: none; }

main:has(> #collection-page:not([hidden])) { width: 100%; padding: 0; }

#collection-page {
  display: grid;
  place-items: center;
  min-block-size: 100dvh;
  padding: 12px;
}

.collection-content {
  display: flex;
  flex-direction: column;
  inline-size: min(100%, 820px);
  block-size: min(100dvh - 24px, 740px);
  padding: clamp(12px, 3vw, 26px);
}

#collection-title {
  margin: 0 0 20px;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

#collection-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

#collection-categories button, #collection-entries button { background: var(--inset); }

#collection-categories button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--selection);
  color: var(--accent);
}

#collection-empty {
  margin: 0;
  color: var(--muted);
}

#collection-entries button { text-align: start; }

.collection-book-entry {
  display: flex;
  align-items: center;
  gap: clamp(8px, 3vw, 16px);
  padding-block: 10px;
}

.collection-book-summary {
  flex: 1;
  min-inline-size: 0;
  overflow-wrap: anywhere;
}

.book-cover {
  position: relative;
  flex: none;
  inline-size: 46px;
  block-size: 62px;
  border: 2px solid #28191d;
  border-radius: 3px 1px 1px 3px;
  background:
    linear-gradient(to right, #351c22 6px, #e1ac6533 6px 8px, transparent 8px),
    repeating-linear-gradient(to bottom, #e2bd88 0 1px, #a78764 1px 2px) bottom / 100% 5px no-repeat,
    #744035;
  box-shadow: 2px 3px #08070c;
}

.book-cover::before {
  position: absolute;
  inset: 6px 5px 11px 12px;
  border: 1px solid #d8af66;
  content: "";
}

.book-cover::after {
  position: absolute;
  inset: 20px 11px auto 17px;
  aspect-ratio: 1;
  background: #e8c180;
  rotate: 45deg;
  content: "";
}

.book-cover[data-cover="cloth"] {
  border-color: #162442;
  background:
    linear-gradient(to right, #172745 6px, #8da8db44 6px 8px, transparent 8px),
    repeating-linear-gradient(to bottom, #ece0bf 0 1px, #a79b83 1px 2px) bottom / 100% 5px no-repeat,
    repeating-linear-gradient(to right, #3f6490 0 2px, #3b5d86 2px 4px);
}

.book-cover[data-cover="cloth"]::before {
  inset: 12px 5px auto 12px;
  block-size: 20px;
  border-color: #f3dfb3;
  background: #dbc7a1;
}

.book-cover[data-cover="cloth"]::after {
  inset: 18px auto auto 16px;
  inline-size: 16px;
  block-size: 2px;
  background: #526582;
  box-shadow: 0 5px #526582;
  rotate: none;
}

.book-cover[data-cover="notebook"] {
  border-color: #182e25;
  border-radius: 4px 3px 3px 4px;
  background:
    linear-gradient(to right, #203c31 6px, #91ba8644 6px 8px, transparent 8px),
    repeating-linear-gradient(to bottom, #ead7a8 0 1px, #9f916d 1px 2px) bottom / 100% 5px no-repeat,
    #527753;
}

.book-cover[data-cover="notebook"]::before {
  inset: 23px -3px auto 17px;
  block-size: 12px;
  border-color: #162d24;
  background: #284637;
}

.book-cover[data-cover="notebook"]::after {
  inset: 27px 12px auto auto;
  inline-size: 4px;
  background: #edd390;
  rotate: none;
}

.collection-book-entry small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 400;
}

.collection-read-label {
  flex: none;
  color: var(--accent);
  font-size: .875rem;
}

#collection-list, #collection-details {
  flex: 1;
  min-block-size: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.collection-actions {
  display: flex;
  flex: none;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

#collection-details {
  overflow-wrap: anywhere;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  line-height: 1.75;
}

#collection-details h3 { font-size: 1.1rem; }

#collection-details h4 {
  margin: 16px 0 4px;
  color: var(--accent);
}

#collection-details p { margin: 0 0 8px; }
#collection-page:not([data-reading-book]) #collection-details p { font-size: 1.125rem; }
#collection-details pre {
  overflow-x: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
}
#collection-details a { color: var(--green); }

#collection-page[data-reading-book] { padding: 0; }

#collection-page[data-reading-book] .collection-content {
  inline-size: 100%;
  block-size: 100dvh;
  padding: clamp(8px, 1.25vw, 20px);
  padding-block-end: max(12px, env(safe-area-inset-bottom));
}

#collection-page[data-reading-book] .collection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

#collection-page[data-reading-book] #collection-title {
  margin: 0;
  padding: 4px 10px;
  background: var(--inset);
  font-size: 1.2rem;
}

#collection-page[data-reading-book] .collection-actions { margin-top: 14px; }
#collection-page[data-reading-book] .collection-actions button { background: var(--inset); }

#collection-page[data-reading-book] :is(#collection-details, #book-pagination) {
  --paper-edge: #d5b784;
  --paper-cover: #553627;
  color-scheme: light;
  color: #352719;
  background: linear-gradient(90deg, #caa878 0, #f4e5c5 24px, #fff7e5 56px, #fcf1d9 100%);
  border: solid var(--paper-cover);
  border-width: 0 7px;
  box-shadow: 0 8px 0 -4px var(--paper-edge), 0 12px 0 -4px var(--paper-cover), 0 18px 32px #0b070888;
}

#collection-page[data-reading-book] #collection-details {
  border-block: 7px solid var(--paper-cover);
  border-radius: 10px 10px 8px 8px;
  padding: clamp(22px, 6vw, 64px);
  font-size: clamp(1rem, 1.6vw, 1.125rem);
  line-height: 1.85;
}

#collection-page[data-reading-book] #collection-details:has(> .book-spread) {
  padding: 0;
  overflow: hidden;
}

#collection-page[data-reading-book] #collection-details:has(.book-leaf + .book-leaf),
#collection-page[data-reading-book] #collection-details:has(.book-leaf + .book-leaf) + #book-pagination {
  background: linear-gradient(90deg,
    #e9d1a8, #fff7e5 4%, #fcf1d9 calc(50% - 44px),
    #d8bc8d calc(50% - 2px), #b59466 50%,
    #debf91 calc(50% + 5px), #fff7e5 calc(50% + 42px),
    #fcf1d9 96%, #e9d1a8);
}

.book-spread {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  block-size: 100%;
}

.book-leaf {
  min-block-size: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(20px, 5vw, 64px) clamp(20px, 4vw, 60px);
}

.book-page-content {
  max-inline-size: 58ch;
  margin-inline: auto;
}

#collection-page[data-reading-book] #collection-details:has(+ #book-pagination:not([hidden])) {
  border-block-end: 0;
  border-end-start-radius: 0;
  border-end-end-radius: 0;
  box-shadow: none;
}

#collection-page[data-reading-book] #collection-details :is(h3, h4) {
  margin: 0 0 .8em;
  color: #503321;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  font-size: clamp(1.4rem, 2.6vw, 2.15rem);
  line-height: 1.35;
}

#collection-page[data-reading-book] #collection-details a {
  color: #245344;
  text-underline-offset: .18em;
}

#collection-page[data-reading-book] #collection-details code {
  color: #674022;
}

#collection-page[data-reading-book] #collection-details pre {
  border-color: #ccb488;
  background: #ebdbb5;
}

#book-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px clamp(12px, 4vw, 32px) 14px;
  border-radius: 0 0 8px 8px;
}

#collection-page[data-reading-book] #book-pagination { border-block-end-width: 7px; }

#book-pagination button {
  justify-self: start;
  min-height: 44px;
  border: 1px solid #a3845e;
  border-radius: 3px;
  background: #fffaee;
  color: #503321;
}

#book-pagination button:last-child { justify-self: end; }
#book-pagination button[aria-disabled="true"] { opacity: .55; cursor: default; }
#book-pagination button[aria-disabled="false"]:hover { background: #e9d5ac; }
#book-page-number {
  flex: none;
  margin: 0;
  padding: 4px 10px;
  background: var(--inset);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#collection-page[data-reading-book] :is(.book-leaf, #collection-details a, #book-pagination button):focus-visible {
  outline-color: #245344;
}

#collection-page[data-reading-book] :is(#collection-details, .book-leaf):focus-visible { outline-offset: -4px; }

@media (prefers-reduced-motion: no-preference) {
  .book-spread[data-turn] .book-page-content {
    transform-origin: left center;
    animation: turn-book-page 320ms ease-out both;
  }

  #collection-details [data-turn="next"] { --page-turn-angle: -32deg; }
  #collection-details [data-turn="previous"] { --page-turn-angle: 32deg; }

  @keyframes turn-book-page {
    from { opacity: .35; transform: perspective(900px) rotateY(var(--page-turn-angle)); }
    to { opacity: 1; transform: perspective(900px) rotateY(0); }
  }
}

#settings-dialog { width: min(100% - 32px, 440px); }
#settings-title { margin: 0 0 20px; }

.player-name-field {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.player-name-field input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: inherit;
  font: inherit;
}

.character-options {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.character-options legend { margin-bottom: 10px; }

.character-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.character-option {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 4px;
  border: 2px solid var(--line);
  background: var(--panel);
  text-align: center;
  font-size: .875rem;
  cursor: pointer;
}

.character-option:hover { background: var(--selection); }
.character-option:has(input:checked) { border-color: var(--accent); }

.character-option input {
  position: absolute;
  inset: 6px 6px auto auto;
  margin: 0;
  accent-color: var(--accent);
}

.character-preview .player {
  position: relative;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .player, .enemy-sprite { transition: none; }
  [data-cleared] .enemy-sprite { animation: none; }
}

.intro p {
  margin: 0;
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.7;
}

.intro h1 {
  margin: 0 0 6px;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
}

.intro {
  grid-area: prompt;
  margin: 0;
  padding: 12px 14px;
  border-inline-start: 4px solid var(--green);
  background: var(--panel);
}

code { font-family: var(--mono); color: var(--accent); }

#question-prompt { white-space: pre-line; }

.workspace {
  --editor-bg: var(--inset);
  --editor-fg: #f5efe3;
  --editor-caret: var(--green);
  --editor-accent: var(--accent);
  --editor-muted: var(--muted);
  --editor-error: var(--red);
  --editor-warning: var(--accent);
  --editor-option-active: var(--selection);
  --editor-selection: #43536c;
  --go-keyword: #e1b4fd;
  --go-string: #a4e3b8;
  --go-number: #f2c485;
  --go-builtin: #9bc9fa;
  --go-function: #7bdddf;
  --go-note: #8ecaff;
  --go-todo: #f8dc76;
  --go-space-bg: #62482b;
  --go-space-edge: #f2c485;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(270px, 28vw, 420px);
  grid-template-areas: "editor prompt" "editor output" "editor encounter" "editor hints";
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  min-height: calc(100dvh - 24px);
  align-items: start;
}

.workspace[data-editor-theme="light"] {
  --editor-bg: #f7f6f2;
  --editor-fg: #222936;
  --editor-caret: #005962;
  --editor-accent: #23569b;
  --editor-muted: #4c5666;
  --editor-error: #a31932;
  --editor-warning: #82521c;
  --editor-option-active: #e3ecfb;
  --editor-selection: #bfd8fb;
  --go-keyword: #74348f;
  --go-string: #286443;
  --go-number: #84521e;
  --go-builtin: #23569b;
  --go-function: #00676b;
  --go-note: #23569b;
  --go-todo: #745500;
  --go-space-bg: #ffe7ad;
  --go-space-edge: #84521e;
}

.workspace[data-editor-theme="navy"] {
  --editor-bg: #101f32;
  --editor-fg: #e6f0ff;
  --editor-caret: #86e4c1;
  --editor-accent: #90caff;
  --editor-muted: #acbfd9;
  --editor-option-active: #213850;
  --editor-selection: #375674;
}

body:has(#challenge:not([hidden])) > .site-header { display: none; }

main:has(> #challenge:not([hidden])) {
  width: 100%;
  padding: 12px;
}

.panel {
  min-width: 0;
  border: 2px solid var(--frame);
  background: var(--panel);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  min-height: 54px;
}

.panel-header label {
  color: var(--accent);
  font: 600 .95rem var(--mono);
}

h2, h3 { margin: 0; font-size: 1rem; }

.editor-actions, .editor-file-actions { display: flex; gap: 5px; }
.editor-actions { flex-wrap: wrap; }
.editor-actions button {
  padding: 3px 8px;
  min-height: 30px;
  font-size: .78rem;
  white-space: nowrap;
}

.editor-heading { min-width: 0; overflow-wrap: anywhere; }
#editor-read-only { margin-inline-start: 8px; color: var(--muted); font-size: .75rem; }
.editor { grid-area: editor; }
.editor .panel-header { flex-wrap: wrap; }

#local-output-title { color: var(--accent); }

#local-exercise {
  padding: 14px 16px 18px;
  line-height: 1.6;
}

#local-exercise ol {
  margin: 0 0 16px;
  padding-inline-start: 1.5em;
}

#local-exercise a { color: var(--accent); }
#local-exercise label { display: block; }

#local-output {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--frame);
  padding: 10px;
  background: var(--inset);
  color: inherit;
  font: .95rem/1.6 var(--mono);
  resize: vertical;
}

#open-editor-menu {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#open-editor-menu > span {
  color: var(--accent);
  font-size: .95rem;
  line-height: 1;
}

.editor-preferences {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.editor-preferences label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .875rem;
}

.editor-preferences select {
  min-width: 7rem;
  min-height: 36px;
  padding: 4px 6px;
  border: 1px solid var(--frame);
  background: var(--inset);
  color: inherit;
  font: inherit;
}

#go-version {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .8rem;
}

button {
  border: 2px solid var(--accent);
  padding: 6px 14px;
  min-height: 36px;
  background: var(--inset);
  color: var(--accent);
  font: 700 .9rem system-ui, sans-serif;
  cursor: pointer;
}

button:not(:disabled):hover { background: var(--selection); }

button:disabled {
  opacity: .6;
  cursor: default;
}

#run > [aria-hidden="true"] { font-size: .8em; margin-right: 4px; }

.button-secondary {
  border-color: var(--line);
  background: transparent;
  color: inherit;
  font-weight: 600;
}

.button-secondary:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent);
}

#menu {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-color: transparent;
}

body:has(#quest-menu:not([hidden])) #menu { display: none; }

#menu:hover { border-color: transparent; }

#fullscreen {
  display: grid;
  place-items: center;
  min-width: 36px;
  padding: 0;
  border-color: transparent;
}

.fullscreen-icon {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  grid-auto-rows: 7px;
  gap: 2px;
}

.fullscreen-icon > span {
  border-top: 2px solid currentColor;
  border-left: 2px solid currentColor;
}

.fullscreen-icon > :nth-child(2) { rotate: 90deg; }
.fullscreen-icon > :nth-child(3) { rotate: -90deg; }
.fullscreen-icon > :nth-child(4) { rotate: 180deg; }
#fullscreen[data-fullscreen] .fullscreen-icon > span { transform: rotate(180deg); }

#fullscreen-status {
  margin-block: 0;
  padding-bottom: 8px;
  color: var(--red);
  font-size: .875rem;
}

.menu-icon {
  width: 16px;
  height: 12px;
  border-block: 2px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
}

.dungeon-actions button:is(:active, [data-pressed]) {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--inset);
  box-shadow: 0 0 8px #f2c48566;
}

:focus-visible, [data-menu-selected] {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.dialog-content:focus-visible { outline: none; }

.editor-file-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--line);
}

.editor-file-tabs button { font-family: var(--mono); }
.editor-file-tabs [data-read-only] { color: var(--muted); }
.editor-file-tabs [aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.editor-file-tabs [data-read-only] span {
  font-family: system-ui, sans-serif;
  font-size: .75rem;
  white-space: nowrap;
}

.editor-source { position: relative; }

#source, #source-highlight {
  font: var(--editor-font-size, 1rem)/1.65 var(--mono);
  font-variant-ligatures: none;
  tab-size: 4;
  white-space: pre;
}

#source {
  position: relative;
  display: block;
  width: 100%;
  height: clamp(180px, 52dvh, 520px);
  border: 0;
  background: var(--editor-bg);
  color: var(--editor-fg);
  caret-color: var(--editor-caret);
  padding: 16px;
  resize: none;
}

#source-highlight {
  position: absolute;
  inset: 0;
  min-height: 0;
  max-height: none;
  margin: 0;
  overflow: hidden;
  background: var(--editor-bg);
  color: var(--editor-fg);
  pointer-events: none;
}

#source-highlight code {
  display: block;
  inline-size: max-content;
  padding: 16px;
  font: inherit;
  color: inherit;
}

.editor-source[data-highlighted]:not([data-composing]) #source {
  background: transparent;
  color: transparent;
}

:is(.go-keyword, .source-keyword) { color: var(--go-keyword); }
:is(.go-string, .source-string) { color: var(--go-string); }
:is(.go-number, .source-number) { color: var(--go-number); }
:is(.go-builtin, .source-builtin) { color: var(--go-builtin); }
:is(.go-function, .source-function) { color: var(--go-function); }
:is(.go-comment, .source-comment) { color: var(--editor-muted); }
.go-note { color: var(--go-note); }
.go-todo { color: var(--go-todo); }
.go-diagnostic {
  text-decoration: underline wavy var(--editor-error);
  text-underline-offset: .15em;
  text-decoration-skip-ink: none;
}
.go-diagnostic.diagnostic-warning { text-decoration-color: var(--editor-warning); }
.go-fullwidth-space {
  background: var(--go-space-bg);
  box-shadow: inset 0 0 0 1px var(--go-space-edge);
}

@media (forced-colors: active) {
  #source-highlight { display: none; }
  .editor-source[data-highlighted]:not([data-composing]) #source {
    background: Field;
    color: FieldText;
  }
}

#source:focus-visible {
  outline-color: var(--editor-accent);
  outline-offset: -3px;
}

#source::selection {
  background: var(--editor-selection);
  color: var(--editor-fg);
}

#editor-shortcuts {
  margin: 0;
  border-top: 1px solid var(--line);
  padding: 8px 16px;
  color: var(--muted);
  font-size: .875rem;
}

kbd { font-family: var(--mono); }

#completions {
  max-height: 205px;
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: var(--editor-bg);
  color: var(--editor-fg);
}

#completions li {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
  padding: 6px 12px;
  font: var(--editor-font-size, 1rem)/1.5 var(--mono);
  overflow-wrap: anywhere;
  cursor: pointer;
}

#completions li[aria-selected="true"],
#completions li:hover {
  background: var(--editor-option-active);
  box-shadow: inset 3px 0 var(--editor-accent);
}

#completions small {
  font-size: inherit;
  color: var(--editor-muted);
}

#completion-status, #editor-status, #editor-diagnostics {
  margin: 0;
  padding: 5px 16px;
  color: var(--muted);
  font-size: .875rem;
}

#completion-status:empty, #editor-status:empty, #editor-diagnostics:empty { padding: 0; }
#editor-status { overflow-wrap: anywhere; }
#editor-diagnostics {
  color: var(--red);
  white-space: pre-line;
  overflow-wrap: anywhere;
  max-height: 8rem;
  overflow: auto;
}
#editor-diagnostics span { display: block; }
#editor-diagnostics .diagnostic-warning { color: var(--accent); }

.output { grid-area: output; }

.output-body { padding: 14px 16px 16px; }

.output-body h3 {
  color: var(--muted);
  font-size: .875rem;
  font-weight: 550;
}

#run-status { color: var(--muted); font-size: .875rem; }
#run-status[data-state="success"] { color: var(--green); }
#run-status[data-state="error"], #diagnostics pre { color: var(--red); }

pre {
  min-height: 26px;
  max-height: 220px;
  overflow: auto;
  margin: 6px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: inherit;
  font: .95rem/1.6 var(--mono);
}

pre[data-placeholder] { color: var(--muted); }

#diagnostics { margin-top: 14px; }

.quest-hints {
  grid-area: hints;
  padding: 18px;
  font-size: 1.0625rem;
  line-height: 1.65;
}

.question-host {
  grid-area: encounter;
  margin: 0;
  padding: 12px;
  background: linear-gradient(180deg, #10171a, #141518);
}

.question-host figcaption {
  color: var(--green);
  font-size: 1rem;
  font-weight: 700;
}

#question-speech {
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-height: 3.1em;
  margin: 8px auto 0;
  padding: 6px 10px;
  border: 1px solid var(--frame);
  background: #161d21;
  color: #f5efe3;
  font-size: 1rem;
  line-height: 1.5;
}

#question-speech:not(:has(> span:not(:empty))) { opacity: 0; }

#question-speech::after {
  position: absolute;
  inset: auto auto -5px calc(50% - 4px);
  width: 8px;
  height: 8px;
  border-inline-end: 1px solid var(--frame);
  border-block-end: 1px solid var(--frame);
  background: inherit;
  rotate: 45deg;
  content: "";
}

.monster-arena, .victory-scene {
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.monster-arena {
  min-height: 170px;
  background:
    radial-gradient(ellipse 47% 16% at 50% 82%, #293c3d, transparent 72%);
}

.monster-arena .enemy-sprite, .victory-scene .enemy-sprite {
  position: relative;
  inset: auto;
  opacity: 1;
  translate: none;
}

.object-sprite,
.host-sprite {
  object-fit: contain;
  object-position: bottom;
  image-rendering: pixelated;
}

.object-sprite { width: 52px; height: 54px; }
.host-sprite { width: 58px; height: 64px; }

#question-host-avatar > :is(.enemy-sprite, .elder-sprite, .timekeeper-sprite) {
  display: block;
  scale: 2.5;
}

#question-host-avatar > .host-sprite { width: 116px; height: 116px; }
#question-host-avatar > .timekeeper-sprite { position: relative; }

:is(.title-scene, .monster-arena) .enemy-body,
[data-enemy-visible]:is([data-phase="walking"], [data-phase="welcome"]) .corridor .enemy-body,
.title-scene :is(.player, .elder-sprite, .timekeeper-sprite, .host-sprite),
.monster-arena :is(.elder-sprite, .timekeeper-sprite, .host-sprite) {
  transform-origin: bottom;
  animation: sprite-idle 1.8s ease-in-out infinite;
}

.title-scene .player { animation-delay: -.45s; }
.monster-arena :is(.elder-sprite, .timekeeper-sprite, .host-sprite) { transform-origin: center; }

@keyframes sprite-idle {
  50% { transform: translateY(-3px) scale(1.07, .93); }
}

#reopen-victory { margin-top: 12px; }

#next-dialog {
  width: min(100% - 32px, 500px);
  border-color: var(--accent);
  text-align: center;
  box-shadow: 0 0 40px #f2c48530;
}

#next-title {
  margin-top: 14px;
  color: var(--accent);
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.15;
}

#next-dialog p { margin: 8px 0 0; }
#victory-message { font-size: 1.125rem; line-height: 1.6; }

#victory-actions {
  flex-wrap: wrap;
  justify-content: center;
}

[data-celebrating] #victory-actions { visibility: hidden; }

.victory-scene {
  min-height: 148px;
  border: 1px solid var(--line);
  background: radial-gradient(ellipse at center, #76573366 0%, transparent 65%), var(--panel);
}

.victory-scene .enemy-sprite { scale: 1.45; }
[data-slime-defeated] .victory-scene .enemy-sprite { opacity: 0; }

.victory-sparks {
  position: absolute;
  width: 9px;
  height: 9px;
  color: var(--accent);
  box-shadow:
    -106px -20px currentColor, -79px 31px currentColor, -51px -49px #fff1c2,
    33px -45px currentColor, 75px 28px #fff1c2, 109px -17px currentColor;
  opacity: .8;
}

[data-celebrating] #next-title { animation: victory-title 1.05s both; }
[data-celebrating] .victory-scene .enemy-sprite { animation: victory-hop .85s both; }
[data-celebrating][data-slime-defeated] .victory-scene .enemy-sprite { animation-name: slime-melt; }
[data-celebrating] .victory-sparks { animation: victory-sparks 1.05s both; }

@keyframes victory-title {
  0%, 22% { opacity: 0; transform: scale(.8); }
  60% { opacity: 1; transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes victory-hop {
  35% { transform: translateY(-16px); }
  65% { transform: translateY(0) scaleY(.92); }
}

@keyframes slime-melt {
  0%, 12% { opacity: 1; transform: scale(1); }
  62% { opacity: .88; transform: scale(1.45, .16); }
  100% { opacity: 0; transform: scale(1.65, .03); }
}

@keyframes victory-sparks {
  0%, 22% { opacity: 0; transform: scale(.2); }
  54% { opacity: 1; transform: scale(1.2); }
  100% { opacity: .8; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  :is(.title-scene, .monster-arena) .enemy-body,
  [data-enemy-visible]:is([data-phase="walking"], [data-phase="welcome"]) .corridor .enemy-body,
  .title-scene :is(.player, .elder-sprite, .timekeeper-sprite, .host-sprite),
  .monster-arena :is(.elder-sprite, .timekeeper-sprite, .host-sprite),
  [data-celebrating] :is(#next-title, .victory-scene .enemy-sprite, .victory-sparks) { animation: none; }
}

#source-download-status {
  margin: 0;
  padding: 8px 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

#source-download-status:empty { padding: 0; }

#question-hints {
  margin: 8px 0 16px;
  padding-inline-start: 24px;
  overflow-wrap: anywhere;
}

#question-hints a { color: var(--accent); }

li + li { margin-top: 8px; }

#copy-agent-prompt {
  display: block;
  margin-block-start: 8px;
}

#agent-prompt-status:empty { margin: 0; }

@media (min-width: 900px) and (min-height: 650px) {
  .corridor { --sprite-scale: 1.35; }
}

@media (min-width: 1440px) and (min-height: 850px) {
  .corridor { --sprite-scale: 1.65; }
}

@media (max-width: 760px) {
  .header-inner, #fullscreen-status, main { width: calc(100% - 28px); }
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "prompt" "editor" "output" "encounter" "hints";
    grid-template-rows: auto;
    min-height: 0;
  }
  #source { height: clamp(180px, 44dvh, 420px); }
  .panel-header { padding-inline: 10px; }
  button { padding-inline: 8px; }
}
