/* =====================================================================
   Escape room style sheet
   The same file is used by every escape room. Only the font at the top
   is different. Colors, sizes and fonts come from the "theme" section of
   the room's settings file (the -config.js file), so most changes are
   made there, not here.

   CONTENTS
     1. Heading font and default colors
     2. Page and text
     3. Header, room view and footer
     4. Markers in the room
     5. Pop-up windows (puzzles, clues, lists, door)
     6. Puzzle parts (choices, word order, answers)
     7. Jigsaw
     8. Mini-games (snowflakes, cats, maze)
     9. Ending scene
    10. Screen sizes and reduced motion
   ===================================================================== */

/* =====================================================================
   1. HEADING FONT AND DEFAULT COLORS
   ===================================================================== */

@font-face {
  font-family: "Creepster";
  src: url("../halloween-assets/halloween-heading-font.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

/* Default colors. The Halloween settings file replaces them with its dark theme. */
:root {
  color-scheme: light;

  --page-bg: #edf7fa; /* behind everything */
  --panel: #ffffff; /* header, footer and pop-up windows */
  --panel-soft: #edf7fa; /* hover color and soft boxes */
  --heading: #173d45; /* headings and strong text */
  --text: #253a3e; /* normal text */
  --muted: #546b71; /* small and Japanese text */
  --line: #c7dbe0; /* borders */
  --accent: #26634e; /* small buttons, labels, correct answers */
  --on-accent: #ffffff; /* text on the accent color */
  --accent-soft: #e5f2e9; /* chosen answer background */
  --button: #a93251; /* main buttons */
  --button-hover: #8e233b;
  --on-button: #ffffff; /* text on main buttons */
  --solved: #efc75e; /* solved markers and code letters */
  --on-solved: #173d45;
  --error: #a93251; /* "try again" messages */
  --stage: #173d45; /* behind the 360 picture while it loads */
  --on-stage: #ffffff;
  --on-stage-muted: #d9eef2;
  --field-bg: #ffffff; /* answer boxes and word buttons */
  --field-text: #253a3e;
  --field-border: #90a7a0;
  --focus: #cc7b20; /* keyboard focus ring */
  --backdrop: rgba(14, 39, 46, 0.62);
  --shadow: rgba(9, 30, 35, 0.4);
  --marker-tint: #c2eaff; /* the markers you click in the room */
  --marker-hover: #ffffff;
  --marker-shadow: #15363e;
  --marker-size: 40px;
  --jigsaw-bg: #dcedf3;
  --ending-bg: #173d45;
  --ending-card: rgba(255, 255, 255, 0.92);

  --heading-font: "Creepster", Georgia, serif;
  --body-font: "Trebuchet MS", Arial, sans-serif;
  --japanese-font: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  --heading-size: 28px;
  --body-size: 16px;
  --dialog-width: 620px;
  --corner-radius: 6px;
}

/* =====================================================================
   2. PAGE AND TEXT
   ===================================================================== */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--body-font);
  font-size: var(--body-size);
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2 {
  font-family: var(--heading-font);
  font-weight: 400;
}

h1 {
  font-size: var(--heading-size);
  line-height: 1.12;
  color: var(--heading);
}

h2 {
  font-size: 30px;
  line-height: 1.2;
  margin: 8px 0 18px;
  color: var(--heading);
  overflow-wrap: anywhere;
}

[hidden] {
  display: none !important;
}

/* Japanese help text. It is hidden when the 日本語 switch is off. */
.japanese {
  display: block;
  margin-top: 4px;
  font: 14px/1.7 var(--japanese-font);
  color: var(--muted);
  text-transform: none;
  font-weight: 400;
  overflow-wrap: anywhere;
}

body.japanese-off .japanese {
  display: none;
}

h2 .japanese {
  font-size: 17px;
  color: var(--heading);
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  font-weight: bold;
  color: var(--accent);
}

.no-script {
  position: fixed;
  inset: 40% 10% auto;
  padding: 20px;
  background: var(--panel);
}

/* =====================================================================
   3. HEADER, ROOM VIEW AND FOOTER
   ===================================================================== */

.room-shell {
  position: relative;
  height: 100svh;
  min-height: 510px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* ---- Header ---- */

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 3px solid var(--accent);
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand > svg {
  width: 36px;
  height: 36px;
  color: var(--button);
  flex-shrink: 0;
}

.brand p {
  font-size: 16px;
  text-transform: uppercase;
  font-weight: bold;
  color: var(--muted);
}

.brand h1 {
  overflow-wrap: anywhere;
}

.brand .japanese {
  font-size: 12px;
  line-height: 1.3;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--heading);
  flex-shrink: 0;
}

.icon-button:hover {
  background: var(--panel-soft);
}

.notebook-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--corner-radius);
  background: transparent;
  color: var(--heading);
  font-weight: bold;
}

#progress-count {
  font-size: 13px;
  font-weight: normal;
  white-space: nowrap;
}

/* ---- Menu that opens from the header ---- */

.room-menu {
  position: absolute;
  top: 90px;
  right: 16px;
  z-index: 10;
  width: min(320px, calc(100% - 32px));
  max-height: 60svh;
  overflow: auto;
  padding: 8px;
  background: var(--panel);
  border-radius: var(--corner-radius);
  box-shadow: 0 8px 32px var(--shadow);
}

.room-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--heading);
  text-align: left;
  text-decoration: none;
}

.room-menu-item:hover {
  background: var(--panel-soft);
}

.room-menu-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.room-menu-item .japanese {
  font-size: 12px;
  margin-top: 0;
}

/* ---- The 360 room view ---- */

.room-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
}

#panorama {
  width: 100%;
  height: 100%;
}

.pnlm-about-msg {
  display: none !important;
}

.language-control {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--panel);
  color: var(--heading);
  font: 14px/1.4 var(--japanese-font);
  cursor: pointer;
}

.language-control input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.loading-message {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--stage);
  color: var(--on-stage);
}

.loading-message.error {
  flex-direction: column;
  gap: 12px;
}

.loading-message .japanese {
  color: var(--on-stage-muted);
}

.room-tools {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border-radius: 6px;
  background: var(--panel);
  opacity: 0.94;
}

/* ---- Footer ---- */

.room-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 24px;
  background: var(--panel);
  border-top: 3px solid var(--accent);
}

.mission p:first-child {
  font:
    700 19px/1.3 Georgia,
    serif;
  color: var(--heading);
}

.mission p:last-child {
  max-width: 380px;
  margin-top: 3px;
  font-size: 16px;
  color: var(--muted);
}

.mission .japanese {
  font-size: 14px;
  line-height: 1.5;
}

/* The row of code letters (? until solved) */
.letter-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  max-width: 560px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.letter-strip li {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 35px;
  height: 42px;
  border-bottom: 2px solid var(--line);
  background: var(--panel-soft);
  font:
    700 23px Georgia,
    serif;
  color: var(--accent);
}

.letter-strip li.empty {
  color: var(--muted);
}

.letter-strip.long {
  gap: 4px;
}

.letter-strip.long li {
  width: 24px;
  height: 32px;
  font-size: 17px;
}

/* ---- Buttons used everywhere ---- */

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 44px;
  padding: 11px 17px;
  border: 0;
  border-radius: var(--corner-radius);
  background: var(--button);
  color: var(--on-button);
  font-weight: bold;
  text-decoration: none;
}

.primary-button:hover {
  background: var(--button-hover);
}

.primary-button .japanese {
  margin: 0;
  font-size: 12px;
  color: var(--on-button);
}

.door-button {
  flex-shrink: 0;
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
}

.text-button:hover {
  background: var(--panel-soft);
}

.text-button .japanese {
  margin: 0;
  font-size: 12px;
  color: var(--accent);
}

/* =====================================================================
   4. MARKERS IN THE ROOM
   Every marker looks the same: puzzle, clue or door. The shape comes
   from the marker picture in the settings; the color comes from the theme.
   ===================================================================== */

.marker-hotspot {
  width: var(--marker-size);
  height: var(--marker-size);
  margin-left: calc(var(--marker-size) / -2);
  margin-top: calc(var(--marker-size) / -2);
  border: 0;
  background: none;
}

.marker-button {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  filter: drop-shadow(0 1px 2px var(--marker-shadow)) drop-shadow(0 0 2px var(--marker-shadow));
}

/* The picture is small, but the area you can click or tap is a little larger. */
.marker-button::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}

.marker-shape {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--marker-tint);
  -webkit-mask: var(--marker-mask) center / contain no-repeat;
  mask: var(--marker-mask) center / contain no-repeat;
  transition: transform 0.18s;
}

.marker-button:hover .marker-shape,
.marker-button:focus-visible .marker-shape {
  transform: scale(1.15);
  background: var(--marker-hover);
}

.marker-button:focus-visible {
  outline: 0;
}

.marker-button:focus-visible .marker-shape {
  outline: 3px solid var(--solved);
  outline-offset: 3px;
  border-radius: 50%;
}

.marker-button.solved .marker-shape {
  background: var(--marker-solved, var(--solved));
}

/* =====================================================================
   5. POP-UP WINDOWS (puzzles, clues, lists, door)
   ===================================================================== */

dialog {
  width: min(var(--dialog-width), calc(100% - 24px));
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  padding: 26px;
  border: 0;
  border-radius: var(--corner-radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 15px 80px var(--shadow);
}

dialog::backdrop {
  background: var(--backdrop);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: -9px;
}

.reading {
  margin-bottom: 20px;
  line-height: 1.65;
}

.reading .japanese {
  padding-top: 8px;
}

.place-line {
  margin: -10px 0 14px;
  font-size: 14px;
  color: var(--muted);
}

.place-line .japanese {
  margin-top: 0;
  font-size: 13px;
}

.hint {
  margin-top: 18px;
  padding: 12px;
  border-radius: 4px;
  background: var(--panel-soft);
}

.clue-text {
  margin-top: 6px;
  font-size: 18px;
  border-left: 4px solid var(--solved);
}

.feedback {
  min-height: 24px;
  margin: 16px 0 12px;
  color: var(--error);
}

.feedback.correct {
  color: var(--accent);
  font-weight: bold;
}

.puzzle-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ---- Check List and Room Locations ---- */

#notebook-list,
#locations-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

#notebook-list li,
#locations-list li {
  border-top: 1px solid var(--line);
}

.notebook-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 13px 0;
  border: 0;
  background: transparent;
  color: var(--heading);
  text-align: left;
}

#locations-list .notebook-entry {
  min-height: 52px;
  padding: 8px 0;
}

.notebook-entry:hover {
  background: var(--panel-soft);
}

.notebook-entry .entry-text {
  flex: 1;
  min-width: 0;
}

.notebook-entry strong {
  display: block;
  overflow-wrap: anywhere;
}

.notebook-entry small {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.notebook-entry small .japanese {
  margin-top: 0;
  font-size: 12px;
  line-height: 1.5;
}

.notebook-entry .entry-status {
  color: var(--accent);
}

#notebook-list li:not(.done) .entry-status {
  color: var(--muted);
}

.notebook-entry .entry-clue {
  margin-top: 4px;
  padding: 6px 8px;
  border-left: 3px solid var(--solved);
  background: var(--panel-soft);
  color: var(--text);
}

.entry-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 37px;
  height: 40px;
  flex-shrink: 0;
  background: var(--panel-soft);
  font:
    700 23px Georgia,
    serif;
  color: var(--accent);
}

.entry-letter.empty {
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--field-bg);
}

#notebook-list li.done .entry-letter {
  border-radius: 4px;
  background: var(--solved);
  color: var(--on-solved);
}

.door-dialog .letter-strip {
  margin: 22px 0;
}

/* =====================================================================
   6. PUZZLE PARTS (choices, word order, answers)
   ===================================================================== */

label {
  display: block;
  margin: 14px 0 7px;
  font-weight: bold;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  background: var(--field-bg);
  color: var(--field-text);
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border: 2px solid var(--error);
}

fieldset {
  min-width: 0;
  margin: 20px 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 9px;
  font-weight: bold;
}

.choices {
  display: grid;
  gap: 8px;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-weight: normal;
  cursor: pointer;
}

.choice-label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice-label input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.field-error {
  margin-top: 6px;
  font-size: 14px;
  color: var(--error);
}

/* ---- Word order ---- */

.sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  min-height: 76px;
  padding: 12px;
  border-bottom: 2px solid var(--accent);
  background: var(--panel-soft);
}

.sentence:empty::before {
  content: "...";
  color: var(--muted);
}

.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 46px;
  margin: 16px 0;
}

.word-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--field-bg);
  color: var(--field-text);
}

.word-button:hover {
  background: var(--accent-soft);
}

.sentence .word-button {
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
}

/* =====================================================================
   7. JIGSAW
   ===================================================================== */

.jigsaw-dialog {
  --dialog-width: 1100px;
}

.jigsaw-dialog .reading {
  margin-bottom: 12px;
}

.picture-jigsaw {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--jigsaw-bg);
}

.jigsaw-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.jigsaw-toolbar button,
.jigsaw-toolbar select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  background: var(--field-bg);
  color: var(--field-text);
}

.jigsaw-toolbar button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.jigsaw-status {
  margin: 0 0 0 auto;
  font-size: 14px;
  font-weight: bold;
  color: var(--accent);
  text-align: right;
}

.jigsaw-status .japanese {
  margin-top: 0;
  font-size: 12px;
}

.jigsaw-error {
  margin: 0;
  padding: 12px;
  color: var(--error);
}

.jigsaw-workspace {
  width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

.picture-jigsaw canvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  touch-action: none;
}

.picture-jigsaw.jigsaw-enlarged canvas {
  width: max(100%, 1000px);
  max-width: none;
}

/* =====================================================================
   8. MINI-GAMES (snowflakes, cats, maze)
   ===================================================================== */

.game-dialog {
  --dialog-width: 920px;
}

.game-dialog .reading {
  margin-bottom: 10px;
}

.game-dialog h2 {
  margin: 4px 0 12px;
  font-size: 26px;
}

.game-dialog .feedback {
  min-height: 0;
  margin: 8px 0;
}

.room-game {
  display: block;
}

.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.game-toolbar .text-button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  font-weight: bold;
}

.game-status {
  min-height: 24px;
  margin: 10px 0 0;
  font-weight: bold;
  color: var(--accent);
}

.game-area {
  position: relative;
  width: 100%;
}

/* ---- Catch the snowflakes ---- */

.game-snowflakes {
  aspect-ratio: 16 / 9;
  min-height: 260px;
  max-height: 52svh;
  overflow: hidden;
  border: 3px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--line);
  background:
    radial-gradient(
      circle at 86% 17%,
      #fffbe0 0 5%,
      #ffe98a 5.4% 7.4%,
      rgba(255, 233, 138, 0.35) 7.8% 11%,
      transparent 11.4%
    ),
    radial-gradient(ellipse 62% 26% at 18% 104%, #ffffff 0 99%, transparent 100%),
    radial-gradient(ellipse 72% 30% at 78% 108%, #eef9ff 0 99%, transparent 100%),
    linear-gradient(#2488e0, #6fc0fb 62%, #c4e9ff);
}

.game-flake {
  position: absolute;
  aspect-ratio: 1;
  min-width: 64px;
  padding: 7px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.14));
  cursor: pointer;
  touch-action: manipulation;
}

.game-flake svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 0 2px #0d4f8c) drop-shadow(0 1px 1px #0d4f8c);
}

.game-flake:hover {
  border-color: #ffffff;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0.3));
}

.game-flake:focus-visible,
.game-cat:focus-visible {
  outline: 4px solid var(--solved);
  outline-offset: 2px;
}

/* ---- Catch the cats ---- */

.game-cats {
  aspect-ratio: 16 / 9;
  min-height: 260px;
  max-height: 52svh;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #1b2330 center / cover no-repeat;
}

.game-cat {
  position: absolute;
  aspect-ratio: 1.6;
  min-width: 84px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.game-cat:hover {
  background: rgba(255, 255, 255, 0.12);
}

.game-cat-sprite {
  display: block;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: 400% 200%;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

/* ---- Maze ---- */

.game-maze {
  text-align: center;
}

.game-maze canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 52svh;
  margin: auto;
  border-radius: 6px;
  touch-action: none;
  cursor: pointer;
}

.game-directions {
  display: grid;
  grid-template-columns: repeat(4, 52px);
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.game-arrow {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  color: var(--field-text);
  font-size: 22px;
  font-weight: bold;
}

.game-arrow:hover {
  background: var(--panel-soft);
}

/* =====================================================================
   9. ENDING SCENE
   ===================================================================== */

dialog.ending-dialog {
  width: 100vw;
  max-width: 100vw;
  height: 100svh;
  max-height: 100svh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 0;
  background: var(--ending-bg);
}

#ending-host {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ending-bg);
}

/* The drawn scene, used only when no ending picture is set */
.ending-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ending-snow span {
  position: absolute;
  top: -24px;
  border-radius: 50%;
  background: #ffffff;
  animation: ending-fall linear infinite;
}

@keyframes ending-fall {
  to {
    transform: translate(36px, 112svh);
  }
}

/* The ending picture and the moving effect (snow, fog, bats) on top of it */
.ending-picture,
.ending-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ending-picture {
  object-fit: cover;
}

.ending-canvas {
  pointer-events: none;
}

/* The message card */
.ending-card {
  position: absolute;
  top: 9%;
  left: 50%;
  transform: translateX(-50%);
  width: min(580px, calc(100% - 28px));
  max-height: 82%;
  overflow: auto;
  padding: 22px 24px;
  border-radius: 12px;
  background: var(--ending-card);
  text-align: center;
  box-shadow: 0 10px 40px var(--shadow);
}

.ending-card h2 {
  margin: 0 0 10px;
  font-size: 34px;
  color: var(--ending-title, var(--button));
}

.ending-card h2 .japanese {
  font-size: 18px;
  color: var(--heading);
}

.ending-time {
  margin-top: 6px;
  font-weight: bold;
  color: var(--accent);
}

.ending-time .japanese {
  margin-top: 0;
  color: var(--accent);
}

.ending-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.ending-actions a {
  text-decoration: none;
}

.ending-actions .text-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--field-bg);
}

.ending-actions .ending-icon {
  width: 44px;
  min-height: 44px;
  padding: 0;
}

/* With an ending picture, the message sits along the bottom */
.ending-with-picture .ending-card {
  top: auto;
  bottom: 14px;
  width: min(680px, calc(100% - 24px));
  max-height: 46%;
  padding: 14px 20px;
}

.ending-with-picture .ending-card h2 {
  margin-bottom: 4px;
  font-size: 30px;
}

.ending-with-picture .ending-card > p {
  font-size: 14px;
  line-height: 1.4;
}

.ending-with-picture .ending-card .japanese {
  margin-top: 2px;
  line-height: 1.4;
}

.ending-with-picture .ending-actions {
  gap: 6px;
  margin-top: 10px;
}

.ending-with-picture .ending-actions .text-button,
.ending-with-picture .ending-actions .primary-button {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 14px;
}

.ending-with-picture .ending-actions .ending-icon {
  width: 40px;
  padding: 0;
}

/* =====================================================================
   10. SCREEN SIZES AND REDUCED MOTION
   ===================================================================== */

/* Tablets and phones */
@media (max-width: 780px) {
  h1 {
    font-size: 23px;
  }

  h2 {
    font-size: 27px;
  }

  .room-header {
    padding: 10px;
  }

  .brand > svg {
    display: none;
  }

  /* Phones: keep "Professor Outlaw" on one line */
  .brand p {
    font-size: 14px;
    white-space: nowrap;
  }

  .header-actions {
    gap: 0;
  }

  .notebook-button {
    padding: 7px;
    border: 0;
  }

  #notebook-button > span:first-of-type {
    display: none;
  }

  .room-footer {
    gap: 8px;
    padding: 12px 14px;
  }

  .mission {
    flex-basis: 100%;
  }

  .mission p:first-child {
    font-size: 17px;
  }

  .mission p:last-child {
    max-width: none;
    font-size: 16px;
  }

  .room-footer > .letter-strip {
    flex: 1;
    justify-content: flex-start;
  }

  .letter-strip li {
    width: 25px;
    height: 34px;
    font-size: 19px;
  }

  .door-button {
    padding: 10px;
    font-size: 14px;
  }

  .room-tools {
    right: 10px;
    bottom: 10px;
  }

  .room-menu {
    top: 95px;
  }

  dialog {
    padding: 20px;
  }

  .jigsaw-dialog {
    padding: 14px;
  }
}

/* Phones */
@media (max-width: 600px) {
  .game-snowflakes,
  .game-cats {
    aspect-ratio: 4 / 5;
    max-height: 56svh;
  }

  .ending-card {
    top: 6%;
    padding: 16px;
  }

  .ending-card h2 {
    font-size: 27px;
  }

  .ending-with-picture .ending-card {
    bottom: 6px;
    max-height: none;
    padding: 10px 12px;
  }

  .ending-with-picture .ending-card > p {
    font-size: 12.5px;
    line-height: 1.35;
  }

  .ending-with-picture .ending-card h2 {
    margin-bottom: 2px;
    font-size: 22px;
  }

  .ending-with-picture .ending-card h2 .japanese {
    font-size: 15px;
  }

  .ending-with-picture .ending-actions {
    margin-top: 6px;
  }
}

/* Small phones */
@media (max-width: 380px) {
  h1 {
    font-size: 20px;
  }

  .icon-button {
    width: 36px;
    height: 44px;
  }

  .room-footer .letter-strip {
    flex-basis: 100%;
  }

  .door-button {
    margin-left: auto;
  }
}

/* Wide but short screens (phones held sideways) */
@media (max-height: 530px) and (min-width: 600px) {
  .room-shell {
    min-height: 390px;
  }

  .room-header {
    padding: 6px 14px;
  }

  .room-footer {
    padding: 6px 14px;
  }

  .room-menu {
    top: 75px;
  }

  .mission p:last-child {
    display: none;
  }
}

@media (max-height: 520px) {
  .ending-with-picture .ending-card > p {
    display: none;
  }

  .ending-with-picture .ending-card h2 {
    font-size: 22px;
  }
}

/* Phones held upright: a wooden frame around the drawn ending scene */
@media (orientation: portrait) {
  #ending-host:not(.ending-with-picture) {
    box-shadow: inset 0 0 0 14px #8a4f24;
  }

  .ending-snow,
  .ending-card {
    z-index: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
