@font-face {
  font-family: "Fira Code";
  src: url("../assets/fonts/FiraCode-VF.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #d8d5ce;
  color: #211f1b;
  font: 14px/1.4 Georgia, serif;
}

#house-app,
#viewport,
#game-interface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-interface {
  pointer-events: none;
}

#game-interface > .game-hud,
#game-interface > #journal-note {
  pointer-events: none;
}

#game-interface > .game-toolbar,
#game-interface > .touch-controls,
#game-interface > .intro-overlay,
#game-interface > .loading-overlay,
#game-interface > .error-overlay,
#game-interface > .house-dialog {
  pointer-events: auto;
}

#viewport canvas,
#game-interface canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.script-notice {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
  font-style: italic;
}

.intro-overlay,
.loading-overlay,
.error-overlay {
  position: absolute;
  inset: 0;
  background: #d8d5ce;
  z-index: 2;
}

.intro-overlay {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: clamp(0.75rem, 5vh, 2.5rem);
}

.loading-overlay,
.error-overlay {
  display: grid;
  place-items: center;
}

.loading-inner,
.error-inner {
  max-width: 24rem;
  padding: 2rem;
  text-align: center;
}

.intro-card {
  width: min(31rem, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(1.1rem, 4vw, 1.75rem);
  border: 1px solid rgba(33, 31, 27, 0.15);
  border-radius: 4px;
  background: #f2eee5;
  box-shadow: 0 12px 40px rgba(33, 31, 27, 0.14);
}

.loading-inner p,
.error-inner p {
  margin: 0 0 1rem;
  font-style: italic;
}
.loading-intro {
  color: rgba(33, 31, 27, 0.68);
  font-size: 0.85rem;
}


progress {
  width: 100%;
  height: 4px;
  appearance: none;
  border: none;
  background: rgba(33, 31, 27, 0.12);
}

progress::-webkit-progress-bar {
  background: rgba(33, 31, 27, 0.12);
}

progress::-webkit-progress-value {
  background: #211f1b;
}

progress::-moz-progress-bar {
  background: #211f1b;
}

.game-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.game-hud,
.game-toolbar,
.touch-controls {
  font-family: "Fira Code", ui-monospace, monospace;
}

.game-hud > * {
  pointer-events: none;
}

.hud-hall {
  position: absolute;
  top: 1rem;
  left: 1rem;
  max-width: 24rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 3px;
  background: rgba(242, 238, 229, 0.82);
  box-shadow: 0 1px 6px rgba(33, 31, 27, 0.12);
}

#hall-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.3;
}

.hud-growth {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  min-width: 10rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 3px;
  background: rgba(242, 238, 229, 0.82);
  box-shadow: 0 1px 6px rgba(33, 31, 27, 0.12);
}

.growth-numbers {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.9rem;
}

#diameter {
  font-weight: bold;
}

.hud-small {
  margin: 0.25rem 0 0;
  font-size: 0.72rem;
  color: rgba(33, 31, 27, 0.7);
}

.game-toolbar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.4rem;
  z-index: 1;
}

.tool-button {
  padding: 0.3rem 0.55rem;
  border: 1px solid rgba(33, 31, 27, 0.2);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.8);
  color: #211f1b;
  font: inherit;
  cursor: pointer;
}

.tool-button:hover {
  background: rgba(255, 255, 255, 0.95);
}

.tool-button:focus-visible,
.touch-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible {
  outline: 2px solid #f2eee5;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px #211f1b;
}
.touch-controls {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  left: 0.75rem;
  z-index: 1;
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  pointer-events: none;
}

.touch-move {
  display: grid;
  grid-template-columns: repeat(3, 3.2rem);
  grid-template-rows: repeat(2, 3.2rem);
}

.touch-up { grid-column: 2; grid-row: 1; }
.touch-left { grid-column: 1; grid-row: 2; }
.touch-down { grid-column: 2; grid-row: 2; }
.touch-right { grid-column: 3; grid-row: 2; }

.touch-turn {
  display: grid;
  gap: 0.45rem;
}

.touch-button {
  min-width: 3.2rem;
  min-height: 3.2rem;
  padding: 0.45rem;
  border: 1px solid rgba(33, 31, 27, 0.28);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.78);
  color: #211f1b;
  box-shadow: 0 2px 8px rgba(33, 31, 27, 0.12);
  font: 600 0.75rem/1.1 "Fira Code", ui-monospace, monospace;
  touch-action: none;
  user-select: none;
  pointer-events: auto;
}

.touch-button.pressed {
  background: #211f1b;
  color: #f2eee5;
  transform: translateY(1px);
}


#journal-note {
  position: absolute;
  top: 4rem;
  right: 1rem;
  max-width: min(22rem, calc(100% - 2rem));
  padding: 0.55rem 0.75rem;
  margin: 0;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(33, 31, 27, 0.08);
  font-size: 0.85rem;
  font-style: italic;
  pointer-events: none;
  z-index: 1;
}

#room-narration {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(70rem, calc(100% - 2rem));
  margin: 0;
  padding: clamp(1.25rem, 4vw, 2.5rem);
  transform: translate(-50%, -50%);
  border-radius: 2px;
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-style: italic;
  line-height: 1.15;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

/* Gradients don't interpolate (mask-image snaps between keyframes), so animate
   registered percentages that position a fixed soft-edged band instead.
   --a: left edge of the solid band (erase); --b: right edge (reveal). */
@property --narration-a { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
@property --narration-b { syntax: '<percentage>'; inherits: false; initial-value: 100%; }

#room-narration.is-playing {
  mask-image: linear-gradient(90deg,
    transparent calc(var(--narration-a) - 18%), #000 var(--narration-a),
    #000 var(--narration-b), transparent calc(var(--narration-b) + 18%));
  /* both: hold the hidden end state until the 7s JS timer sets [hidden], no end-frame flash. */
  animation: room-narration 7s ease-in-out both;
}

/* Band sweeps left→right to reveal, holds, then sweeps left→right again to erase. */
@keyframes room-narration {
  0% { --narration-a: -18%; --narration-b: -18%; }
  28%, 62% { --narration-a: 0%; --narration-b: 100%; }
  100% { --narration-a: 118%; --narration-b: 118%; }
}

@media (prefers-reduced-motion: reduce) {
  #room-narration.is-playing { animation: none; }
}

.house-dialog {
  max-width: 34rem;
  max-height: 90vh;
  padding: 1.5rem;
  border: 1px solid rgba(33, 31, 27, 0.15);
  border-radius: 4px;
  background: #f2eee5;
  color: #211f1b;
  box-shadow: 0 12px 40px rgba(33, 31, 27, 0.18);
  overflow: auto;
}

.house-dialog::backdrop {
  background: rgba(33, 31, 27, 0.35);
  backdrop-filter: blur(2px);
}

.house-dialog .eyebrow,
.intro-card .eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(33, 31, 27, 0.6);
}

.house-dialog h2,
.intro-card h1 {
  margin: 0 0 1rem;
  font-size: 1.6rem;
  font-weight: normal;
}

.house-dialog .dialog-intro,
.intro-card .dialog-intro {
  margin: 0 0 1.2rem;
  line-height: 1.5;
}

.house-dialog .controls-list,
.intro-card .controls-list {
  display: grid;
  grid-template-columns: 6rem 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 1.2rem;
}

.house-dialog .controls-list dt,
.intro-card .controls-list dt {
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 0.85rem;
}

.house-dialog .controls-list dd,
.intro-card .controls-list dd {
  margin: 0;
}

.house-dialog .keyboard-notice {
  margin: 0 0 1.2rem;
  font-size: 0.85rem;
  font-style: italic;
  color: rgba(33, 31, 27, 0.6);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.primary-button,
.secondary-button {
  padding: 0.45rem 0.75rem;
  border: 1px solid rgba(33, 31, 27, 0.2);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.85);
  color: #211f1b;
  font: 500 0.78rem/1.2 "Fira Code", ui-monospace, monospace;
  cursor: pointer;
}

.primary-button {
  background: #211f1b;
  color: #f2eee5;
  border-color: #211f1b;
}

.ending-line {
  font-size: 1.15rem;
  font-style: italic;
  margin: 0 0 1.2rem;
}

#ending-stats,
#collection-stats {
  margin: 0 0 1.2rem;
  color: rgba(33, 31, 27, 0.7);
}
.controls-summary {
  margin: 0 0 1.2rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.48);
  line-height: 1.5;
}


.collection-dialog {
  max-width: 44rem;
}

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.collection-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  max-height: 50vh;
  overflow: auto;
}

.collection-entry {
  display: grid;
  grid-template-columns: 2rem 6rem 1fr;
  gap: 0.75rem;
  align-items: start;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(33, 31, 27, 0.08);
}

.collection-empty {
  display: block;
}

.collection-entry h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.collection-entry h3 a {
  color: inherit;
}

.work-thumbnail {
  display: block;
  width: 6rem;
  height: 6rem;
  object-fit: cover;
  border-radius: 2px;
  background: #eee9de;
}

.work-meta {
  margin: 0 0 0.15rem;
  font-size: 0.8rem;
  color: rgba(33, 31, 27, 0.65);
}

.work-rights {
  font: 0.72rem/1.3 "Fira Code", ui-monospace, monospace;
  color: rgba(33, 31, 27, 0.7);
}

.collection-attribution {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(33, 31, 27, 0.1);
  font-size: 0.8rem;
  color: rgba(33, 31, 27, 0.6);
}

.collection-attribution p {
  margin: 0;
}

@media (max-width: 40rem) {
  .hud-hall {
    top: 3.6rem;
    right: 0.6rem;
    left: 0.6rem;
    width: max-content;
    max-width: calc(100% - 1.2rem);
  }

  .hud-growth {
    left: 0.6rem;
  }

  .game-toolbar {
    top: 0.6rem;
    right: 0.6rem;
  }

  #journal-note {
    top: 6.6rem;
    right: 0.6rem;
  }

  .collection-entry {
    grid-template-columns: 1.5rem 4.5rem 1fr;
    gap: 0.55rem;
  }

  .work-thumbnail {
    width: 4.5rem;
    height: 4.5rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls:not([hidden]) {
    display: flex;
  }

  .hud-growth {
    bottom: 7.4rem;
  }

  .game-toolbar {
    top: 0.6rem;
    right: 0.6rem;
  }

  .tool-button {
    min-height: 2.6rem;
  }
}

[hidden] {
  display: none !important;
}
