/* Tokens, layout and components. Animation lives in motion.css. */
:root {
  --night: #0d0b14;
  --wall: #1b1630;
  --wood: #2a2036;
  --candle: #ffb347;
  --candle-glow: #ffd98a;
  --ghost: #b9f2ff;
  --ink: #ece7f5;
  --muted: #a79fba;
  --danger: #ff6b8a;

  --frame: #4a3a5c;
  --frame-dark: #1f1829;
  --floor: #171021;
  --roof: #261b3b;
  --roof-line: #3a2c58;
  --brick: #3b2a3f;
  --moon: #f4efd8;
  --focus: #ffd98a;
  --display: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--night);
  color: var(--ink);
  font-family: var(--body);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(90, 60, 140, 0.28), transparent 70%),
    radial-gradient(ellipse 60% 30% at 50% 100%, rgba(255, 179, 71, 0.08), transparent 70%),
    var(--night);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -64px;
  z-index: 10;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--candle-glow);
  color: var(--night);
  font-weight: 700;
  border-radius: 6px;
}

.skip-link:focus {
  top: 8px;
}

.noscript {
  margin: 16px;
  color: var(--danger);
  text-align: center;
}

/* Header */
.masthead {
  max-width: 940px;
  margin: 0 auto;
  padding: 28px 16px 8px;
  text-align: center;
}

.title {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(2.2rem, 9vw, 3.6rem);
  letter-spacing: 0.12em;
  line-height: 1.1;
  color: var(--candle-glow);
  text-shadow: 0 0 18px rgba(255, 179, 71, 0.55), 0 0 2px rgba(255, 217, 138, 0.8);
}

.intro {
  margin: 10px auto 0;
  max-width: 34rem;
  color: var(--muted);
  font-size: 1rem;
}

.page {
  max-width: 940px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}

/* Stage */
.house-title {
  margin: 16px 0 4px;
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.08em;
  font-size: 1.5rem;
  color: var(--ink);
}

.house-title:focus-visible {
  outline-offset: 6px;
}

.summary {
  margin: 0 0 14px;
  text-align: center;
  color: var(--muted);
}

.summary strong {
  display: block;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.06em;
  font-size: 1.25rem;
  color: var(--candle-glow);
}

.summary-counts {
  font-size: 0.95rem;
}

/* The house: roof, a cutaway of rooms, a yard. */
.house {
  position: relative;
  isolation: isolate;
}

/* Art never widens the page, whatever an animation does. */
.roof-art,
.yard-art,
.room-art {
  overflow: hidden;
}

.house-title,
.diary-name {
  overflow-wrap: anywhere;
}

.roof-art {
  display: block;
  width: 104%;
  height: auto;
  margin: 0 -2% -2px;
  position: relative;
  z-index: 1;
}

.yard-art {
  display: block;
  width: 106%;
  height: auto;
  margin: -6px -3% 0;
}

.house-body {
  position: relative;
  padding: 8px;
  border: 7px solid var(--frame);
  border-top-width: 4px;
  border-radius: 3px 3px 6px 6px;
  background: var(--frame-dark);
  box-shadow:
    inset 0 0 0 2px #2a2036,
    0 0 40px rgba(255, 179, 71, 0.12),
    0 18px 40px rgba(0, 0, 0, 0.6);
}

.rooms {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.rooms > li {
  display: flex;
}

@media (min-width: 720px) {
  .rooms {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .rooms--many {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* A room is one button: art on top, plain text underneath. */
.room {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 2px solid #0a0710;
  border-radius: 4px;
  overflow: hidden;
  background: var(--wall);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.room:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

.room:focus-visible {
  outline-offset: 2px;
  z-index: 2;
}

.room-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 6 / 5;
}

.room-caption {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 8px 10px 10px;
  background: var(--night);
  border-top: 2px solid #0a0710;
}

.room-name {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.room-status {
  font-size: 0.875rem;
  color: var(--muted);
}

.room[data-status='up'] .room-status {
  color: var(--candle-glow);
}

.room[data-status='degraded'] .room-status {
  color: var(--candle);
}

.room[data-status='down'] .room-status {
  color: var(--ghost);
}

.room[data-status='down'] {
  border-color: #38243f;
}

/* Mood of the whole house shows in the attic window and the sky. */
.house[data-mood='peace'] .attic-glow {
  opacity: 1;
}

.house[data-mood='uneasy'] .attic-glow {
  opacity: 0.55;
}

.house[data-mood='haunted'] .attic-glow {
  opacity: 0.15;
}

.house[data-mood='peace'] .art-attic {
  fill: var(--candle-glow);
}

.house[data-mood='uneasy'] .art-attic {
  fill: var(--candle);
}

.house[data-mood='haunted'] .art-attic {
  fill: #1c2a3c;
}

.house[data-mood='haunted'] .house-body {
  box-shadow:
    inset 0 0 0 2px #2a2036,
    0 0 50px rgba(185, 242, 255, 0.12),
    0 18px 40px rgba(0, 0, 0, 0.6);
}

.house[data-mood='peace'] .house-body {
  box-shadow:
    inset 0 0 0 2px #2a2036,
    0 0 60px rgba(255, 179, 71, 0.28),
    0 18px 40px rgba(0, 0, 0, 0.6);
}

/* ---- Art colors (classes used by src/ui/art.js) ---- */
.art-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.stop-warm-a {
  stop-color: var(--candle-glow);
  stop-opacity: 0.85;
}

.stop-warm-b {
  stop-color: var(--candle);
  stop-opacity: 0.35;
}

.stop-warm-c {
  stop-color: var(--candle);
  stop-opacity: 0;
}

.stop-cold-a {
  stop-color: var(--ghost);
  stop-opacity: 0.5;
}

.stop-cold-b {
  stop-color: var(--ghost);
  stop-opacity: 0.18;
}

.stop-cold-c {
  stop-color: var(--ghost);
  stop-opacity: 0;
}

.stop-moon-a {
  stop-color: var(--moon);
  stop-opacity: 0.35;
}

.stop-moon-b {
  stop-color: var(--moon);
  stop-opacity: 0.1;
}

.stop-moon-c {
  stop-color: var(--moon);
  stop-opacity: 0;
}

.art-wall { fill: var(--wall); }
.art-stripe { fill: #ffffff; opacity: 0.035; }
.art-floor { fill: var(--floor); }
.art-baseboard { fill: #2d2240; }
.art-plank { fill: none; stroke: #0a0710; stroke-width: 0.6; opacity: 0.8; }
.art-dim { fill: var(--night); opacity: 0.5; }

.art-frame { fill: #4a3a5c; }
.art-glass { fill: #0f1530; }
.art-moon { fill: var(--moon); }
.art-star { fill: #fff6d6; }
.art-crater { fill: #cfc8a8; opacity: 0.6; }

.art-furn { fill: #34264a; }
.art-furn-inner { fill: #251b36; }
.art-furn-dark { fill: #1a1325; }
.art-book-a { fill: #8a3556; }
.art-book-b { fill: #3c6379; }
.art-book-c { fill: #7a6830; }
.art-bone { fill: #d8d0c0; }
.art-brass { fill: #b98a3f; }
.art-clock-face { fill: #efe6d2; }
.art-clock-hand { fill: none; stroke: #1a1325; stroke-width: 1; stroke-linecap: round; }
.art-blanket { fill: #5a2a52; }
.art-pillow { fill: #d9d2e6; }
.art-bubble { fill: #8fe3a4; opacity: 0.85; }
.art-keys { fill: #e8e1d0; }
.art-key-line { fill: none; stroke: #1a1325; stroke-width: 1.2; }
.art-web { fill: none; stroke: var(--ghost); stroke-width: 0.5; opacity: 0.4; }

.art-table { fill: #3b2b4d; }
.art-wax { fill: #efe6d2; }
.art-wick { fill: #2a2230; }
.art-flame { fill: var(--candle); }
.art-flame-core { fill: var(--candle-glow); }
.art-ember { fill: #ff7a3c; }
.art-smoke { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-linecap: round; opacity: 0.6; }

.glow {
  pointer-events: none;
}

.glow--steady,
.glow--flicker {
  fill: url(#hh-warm);
}

.glow--flicker {
  opacity: 0.8;
}

.glow--cold {
  fill: url(#hh-cold);
}

.flame--flicker {
  transform: rotate(-4deg) scale(0.9, 1.06);
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.ghost-glow {
  fill: url(#hh-cold);
}

.art-ghost {
  fill: var(--ghost);
  opacity: 0.93;
}

.art-ghost-eye {
  fill: var(--night);
}

/* Roof and yard */
.moon-halo { fill: url(#hh-moon); }
.art-roof { fill: var(--roof); stroke: var(--roof-line); stroke-width: 3; stroke-linejoin: round; }
.art-shingle {
  fill: none;
  stroke: var(--roof-line);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}
.art-eave { fill: var(--frame); }
.art-brick { fill: var(--brick); }
.art-brick-cap { fill: #4b3750; }
.art-puff { fill: var(--muted); opacity: 0; }
.art-bat { fill: #07050c; }
.attic-glow { fill: url(#hh-attic); transition: opacity 0.6s ease; }
.art-attic { fill: var(--candle-glow); transition: fill 0.6s ease; }
.art-attic-bar { fill: none; stroke: var(--roof); stroke-width: 3; }

.art-ground { fill: #120d1b; }
.art-stone { fill: #3a3150; stroke: #1c1528; stroke-width: 1.5; }
.art-stone-mark { fill: none; stroke: #1c1528; stroke-width: 2; }
.art-fence { fill: none; stroke: #07050c; stroke-width: 3; stroke-linecap: round; }
.art-tree { fill: none; stroke: #07050c; stroke-width: 4; stroke-linecap: round; }
.art-pumpkin { fill: #d9772b; }
.art-stem { fill: #3d5a30; }
.art-pumpkin-face { fill: var(--candle-glow); stroke: var(--candle-glow); stroke-width: 1.4; }

/* ---- Death diary dialog ---- */
.diary {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 2px solid var(--frame);
  border-radius: 10px;
  background: linear-gradient(180deg, #19132a, var(--night));
  color: var(--ink);
  box-shadow: 0 0 0 1px #0a0710, 0 24px 70px rgba(0, 0, 0, 0.75), 0 0 60px rgba(255, 179, 71, 0.12);
}

.diary[data-status='down'] {
  box-shadow: 0 0 0 1px #0a0710, 0 24px 70px rgba(0, 0, 0, 0.75), 0 0 60px rgba(185, 242, 255, 0.16);
}

.diary::backdrop {
  background: rgba(6, 4, 12, 0.78);
  backdrop-filter: blur(2px);
}

.diary-body {
  padding: 16px 16px 20px;
}

.diary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.diary-name {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.05em;
  font-size: 1.6rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.diary-status {
  margin: 2px 0 0;
  font-weight: 700;
}

.diary[data-status='up'] .diary-status { color: var(--candle-glow); }
.diary[data-status='degraded'] .diary-status { color: var(--candle); }
.diary[data-status='down'] .diary-status { color: var(--ghost); }

.diary-close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--frame);
  border-radius: 6px;
  background: var(--wood);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.diary-close:hover {
  background: #3a2c4c;
}

.diary-art {
  position: relative;
  margin: 12px 0;
  border: 2px solid #0a0710;
  border-radius: 6px;
  overflow: hidden;
}

.diary-art .room-art {
  aspect-ratio: 12 / 7;
}

.ritual-glow {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 60%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 217, 138, 0.9), rgba(255, 179, 71, 0.35) 40%, transparent 70%);
  opacity: 0;
  pointer-events: none;
}

.diary-description {
  margin: 0 0 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.ritual-box {
  padding: 12px;
  border: 1px dashed var(--frame);
  border-radius: 8px;
  background: rgba(42, 32, 54, 0.55);
}

.ritual {
  min-height: 48px;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #7a5418;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd98a, #ffb347);
  color: #1a1020;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255, 179, 71, 0.35);
}

.ritual:hover {
  filter: brightness(1.06);
}

.ritual:active {
  transform: translateY(1px);
}

.ritual-note,
.ritual-result {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.ritual-result:empty {
  display: none;
}

.ritual-result {
  color: var(--ink);
  font-style: italic;
}

.diary-heading {
  margin: 18px 0 8px;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.06em;
  font-size: 1.2rem;
}

.diary-entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.entry {
  padding: 10px 12px;
  border-left: 3px solid var(--muted);
  border-radius: 0 6px 6px 0;
  background: rgba(27, 22, 48, 0.85);
}

.entry--up { border-left-color: var(--candle-glow); }
.entry--degraded { border-left-color: var(--candle); }
.entry--down { border-left-color: var(--ghost); }

.entry p {
  margin: 0;
  overflow-wrap: anywhere;
}

.entry-time {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.entry-title {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.05rem;
}

.entry-status {
  font-size: 0.875rem;
  font-weight: 700;
}

.entry-detail {
  margin-top: 4px !important;
  font-size: 0.9rem;
  color: var(--muted);
}

.diary-quiet {
  margin: 0;
  padding: 12px;
  border-radius: 6px;
  background: rgba(27, 22, 48, 0.85);
  color: var(--muted);
  font-style: italic;
}

[hidden] {
  display: none !important;
}

/* ---- Controls ---- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.controls {
  margin: 0 auto 18px;
  max-width: 560px;
  text-align: center;
}

.mode-note {
  margin: 0 0 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.control {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 18px;
  border: 1px solid var(--frame);
  border-radius: 999px;
  background: var(--wood);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.control:hover {
  background: #3a2c4c;
}

.sound-state {
  display: inline-block;
  min-width: 2.2em;
  margin-left: 2px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--night);
  font-size: 0.8rem;
  color: var(--muted);
}

.control--sound[aria-pressed='true'] .sound-state {
  background: var(--candle);
  color: var(--night);
}

.control--sound[aria-pressed='true'] {
  border-color: var(--candle);
  color: var(--candle-glow);
}

.control[data-paused='true'] {
  background: var(--ink);
  color: var(--night);
  border-color: var(--ink);
}

.control--storm {
  border-color: #5d7fa8;
  background: #1c2440;
  color: #d6e8ff;
}

.control--storm:hover {
  background: #26315a;
}

/* The "all residents are at peace" state gets a warm, calm banner. */
.summary.is-peace strong {
  color: var(--candle-glow);
  text-shadow: 0 0 14px rgba(255, 179, 71, 0.6);
}

.summary.is-haunted strong {
  color: var(--ghost);
  text-shadow: 0 0 14px rgba(185, 242, 255, 0.45);
}

.summary.is-uneasy strong {
  color: var(--candle);
}

/* ---- Loader ---- */
.loader {
  margin: 36px auto 0;
  max-width: 720px;
  padding: 18px 16px 20px;
  border: 1px solid var(--frame);
  border-radius: 10px;
  background: rgba(27, 22, 48, 0.7);
}

.loader-title {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.06em;
  font-size: 1.35rem;
}

.loader-intro {
  margin: 6px 0 14px;
  color: var(--muted);
}

a {
  color: var(--candle-glow);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--ink);
}

.loader-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: -6px 0 12px;
}

.link-pill {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.loader-grid {
  display: grid;
  gap: 14px;
}

@media (min-width: 720px) {
  .loader-grid {
    grid-template-columns: auto 1fr;
    align-items: end;
  }
}

.control--file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-input:focus-visible + .control--file {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.url-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.url-row {
  display: flex;
  gap: 8px;
}

.url-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--frame);
  border-radius: 8px;
  background: var(--night);
  color: var(--ink);
  font: inherit;
}

.url-input::placeholder {
  color: #8a82a0;
}

.control[aria-disabled='true'] {
  opacity: 0.6;
  cursor: progress;
}

.load-feedback {
  margin-top: 12px;
  color: var(--muted);
}

.load-feedback:empty {
  display: none;
}

.load-feedback.is-ok {
  color: var(--candle-glow);
}

.load-feedback.is-error {
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  border-radius: 0 6px 6px 0;
  background: rgba(255, 107, 138, 0.08);
  color: var(--ink);
}

.load-error-title {
  margin: 0;
  font-weight: 700;
  color: var(--danger);
}

.load-errors {
  margin: 6px 0 0;
  padding-left: 18px;
}

.load-errors li {
  overflow-wrap: anywhere;
}

.load-errors code {
  color: var(--ghost);
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

#back-to-demo {
  margin-top: 12px;
}
