:root {
  --bg0: #070a0d;
  --bg1: #10161c;
  --fog: #1c2830;
  --ink: #d5cdb8;
  --ink-dim: #9a927e;
  --mold: #7e8f5c;
  --mold-deep: #4a5634;
  --blood: #6e3030;
  --lamp: #c4a45a;
  --line: rgba(213, 205, 184, 0.14);
  --font-display: "Alice", "Times New Roman", serif;
  --font-body: "Spectral", "Georgia", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #1a3030 0%, transparent 55%),
    radial-gradient(ellipse 90% 60% at 80% 100%, #152018 0%, transparent 50%),
    linear-gradient(165deg, var(--bg1), var(--bg0) 55%, #050708);
  overflow-x: hidden;
}

#fog {
  pointer-events: none;
  position: fixed;
  inset: -10%;
  background:
    radial-gradient(circle at 20% 40%, rgba(140, 160, 150, 0.12), transparent 40%),
    radial-gradient(circle at 75% 60%, rgba(100, 120, 110, 0.1), transparent 45%);
  opacity: 0.35;
  animation: fog-drift 18s ease-in-out infinite alternate;
  transition: opacity 0.8s ease;
  z-index: 0;
}

#grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.07;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#app {
  position: relative;
  z-index: 2;
  max-width: 42rem;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 1.25rem 1.25rem 2.5rem;
}

.hidden {
  display: none !important;
}

.screen {
  animation: fade-rise 0.7s ease both;
}

.boot-msg,
.boot-error {
  margin-top: 40vh;
  text-align: center;
  color: var(--ink-dim);
}

.title-hero {
  padding: 12vh 0 2rem;
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.75rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--mold);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  letter-spacing: 0.02em;
  line-height: 1.05;
  text-shadow: 0 0 40px rgba(126, 143, 92, 0.25);
  animation: title-breathe 6s ease-in-out infinite;
}

.tag {
  margin: 0.85rem 0 0;
  color: var(--ink-dim);
  font-style: italic;
}

.lede {
  margin: 1.75rem auto 0;
  max-width: 26rem;
  color: var(--ink-dim);
  line-height: 1.55;
}

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  margin-top: 2.5rem;
}

.btn {
  font-family: var(--font-body);
  font-size: 1rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 0.75rem 1.4rem;
  cursor: pointer;
  min-width: 12rem;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.btn:hover,
.btn:focus-visible {
  border-color: var(--mold);
  outline: none;
}

.btn.primary {
  background: linear-gradient(180deg, var(--mold), var(--mold-deep));
  border-color: transparent;
  color: #0d120c;
  font-weight: 600;
}

.btn.primary:hover,
.btn.primary:focus-visible {
  filter: brightness(1.08);
}

.btn.ghost.compact {
  min-width: 0;
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.play-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.sanity {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--ink-dim);
}

.sanity-label {
  display: none;
}

@media (min-width: 480px) {
  .sanity-label {
    display: inline;
  }
}

.sanity-track {
  height: 0.35rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  overflow: hidden;
}

#sanity-fill {
  height: 100%;
  width: 78%;
  background: linear-gradient(90deg, var(--mold-deep), var(--mold));
  transition: width 0.45s ease, background 0.45s ease;
}

#screen-play[data-sanity="frayed"] #sanity-fill {
  background: linear-gradient(90deg, #6a5a30, var(--lamp));
}

#screen-play[data-sanity="critical"] #sanity-fill {
  background: linear-gradient(90deg, #3a1818, var(--blood));
}

#screen-play[data-sanity="critical"] .scene-body {
  animation: tremor 2.8s ease-in-out infinite;
}

.scene h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.85rem;
  color: var(--ink);
}

.scene-body {
  color: var(--ink);
  line-height: 1.7;
  font-size: 1.08rem;
}

.scene-body p {
  margin: 0 0 1rem;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.75rem;
}

.choice {
  text-align: left;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.4;
  color: var(--ink);
  background: rgba(16, 22, 28, 0.55);
  border: 1px solid var(--line);
  border-left: 3px solid var(--mold-deep);
  padding: 0.85rem 1rem;
  cursor: pointer;
  animation: choice-in 0.45s ease both;
  animation-delay: calc(var(--i, 0) * 70ms);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.choice:hover,
.choice:focus-visible {
  border-color: var(--mold);
  border-left-color: var(--mold);
  background: rgba(30, 40, 36, 0.75);
  outline: none;
  transform: translateX(3px);
}

.no-choices {
  color: var(--ink-dim);
  font-style: italic;
}

.journal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(3, 5, 7, 0.72);
  display: grid;
  place-items: end center;
  padding: 1rem;
}

.journal-panel {
  width: min(36rem, 100%);
  max-height: min(80dvh, 36rem);
  overflow: auto;
  background:
    linear-gradient(180deg, #1a1610, #12100c);
  border: 1px solid rgba(196, 164, 90, 0.25);
  padding: 1rem 1.1rem 1.4rem;
  animation: fade-rise 0.35s ease both;
}

.journal-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid rgba(196, 164, 90, 0.2);
  padding-bottom: 0.6rem;
}

.journal-panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--lamp);
}

.clue {
  padding: 0.85rem 0;
  border-bottom: 1px solid rgba(213, 205, 184, 0.1);
}

.clue h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--lamp);
}

.clue p {
  margin: 0;
  color: var(--ink-dim);
  line-height: 1.5;
}

.journal-empty {
  color: var(--ink-dim);
  font-style: italic;
}

#screen-play[data-kind="ending"] .scene h2 {
  color: var(--mold);
}

@keyframes fog-drift {
  from { transform: translate3d(-2%, 0, 0) scale(1.05); }
  to { transform: translate3d(3%, 1%, 0) scale(1.1); }
}

@keyframes fade-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes choice-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes title-breathe {
  0%, 100% { text-shadow: 0 0 30px rgba(126, 143, 92, 0.15); }
  50% { text-shadow: 0 0 48px rgba(126, 143, 92, 0.35); }
}

@keyframes tremor {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-0.5px); }
  60% { transform: translateX(0.6px); }
}

@media (max-width: 480px) {
  #app {
    padding: 1rem 1rem 2rem;
  }

  .title-hero {
    padding-top: 8vh;
  }

  .choice {
    font-size: 0.98rem;
  }
}
