:root {
  --bg: #030305;
  --ink: #e9dccb;
  --ink-dim: #9c8f80;
  --ember: #ff8a3d;
  --blood: #d8453a;
  --line: rgba(233, 220, 203, 0.22);
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Frost creeping in from the edges; --cold is set from body warmth. */
#frost {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: calc(var(--cold, 0) * 0.9);
  background: radial-gradient(ellipse at center, transparent 55%, rgba(120, 160, 210, 0.04) 78%, rgba(170, 205, 245, 0.13) 100%);
  transition: opacity 1.2s linear;
}

#ui {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
#ui > * { pointer-events: auto; }
/* Scrims keep text legible when daylight brightens the scene. */
#ui { isolation: isolate; }
#ui::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(3, 3, 5, 0.75), rgba(3, 3, 5, 0.35) 30%, transparent 50%),
    linear-gradient(to bottom, rgba(3, 3, 5, 0.6), transparent 20%);
  opacity: calc(0.6 + var(--day, 0) * 0.4);
}

/* ---------- reveal: elements fade into existence as the story unlocks them ---------- */
.reveal:not(.shown) { display: none; }
.reveal.shown { animation: emerge 2.4s ease-out both; }

@keyframes emerge {
  from { opacity: 0; filter: blur(6px); transform: translateY(4px); }
  to   { opacity: 1; filter: blur(0); transform: none; }
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.clock {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  text-align: center;
  white-space: nowrap;
}
.clock.tick { animation: say 1.6s ease-out; }
@media (max-width: 560px) {
  .hud { flex-wrap: wrap; }
  .clock { order: 3; flex-basis: 100%; margin-top: -4px; }
}

.meters { display: grid; gap: 8px; width: min(220px, 45vw); }
.meter { display: grid; gap: 3px; font-size: 13px; letter-spacing: 0.08em; color: var(--ink-dim); }
.meter .bar {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.meter .bar i {
  display: block;
  height: 100%;
  transform-origin: left;
  transform: scaleX(var(--v, 0));
  transition: transform 0.5s ease-out;
  border-radius: inherit;
}
[data-meter="health"] .bar i { background: linear-gradient(90deg, #8e2a24, var(--blood)); }
[data-meter="warmth"] .bar i { background: linear-gradient(90deg, #a2501f, var(--ember)); }
[data-meter="food"] .bar i { background: linear-gradient(90deg, #6b6a2a, #b9b45a); }
.meter.critical .bar i { animation: pulse 1.1s ease-in-out infinite; }
.meter.critical span { color: var(--blood); }

@keyframes pulse {
  50% { opacity: 0.35; }
}

.inventory {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  font-size: 14px;
  min-width: 110px;
}
.inventory li { display: flex; justify-content: space-between; gap: 18px; color: var(--ink-dim); }
.inventory b { color: var(--ink); font-weight: normal; font-variant-numeric: tabular-nums; }
.inventory b.bump { animation: bump 0.5s ease-out; }

@keyframes bump {
  30% { color: #fff; transform: scale(1.35); text-shadow: 0 0 10px var(--ember); }
}
.inventory b { display: inline-block; }

.side { display: grid; justify-items: stretch; min-width: 120px; }
.known {
  list-style: none;
  margin: 10px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid rgba(233, 220, 203, 0.12);
  font-size: 13px;
  color: var(--ink-dim);
  display: grid;
  gap: 3px;
}
.known li { animation: say 1.6s ease-out both; }
.known li::before { content: attr(data-kind) " "; opacity: 0.55; font-size: 11px; letter-spacing: 0.1em; }

/* ---------- log + actions ---------- */
.bottom {
  display: grid;
  gap: 18px;
  justify-items: center;
  width: min(820px, 100%);
  margin: 0 auto;
}

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(560px, 100%);
  min-height: 7.5em;
  max-height: 9em;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  text-align: center;
  font-size: 16px;
  line-height: 1.5;
  mask-image: linear-gradient(to bottom, transparent, #000 60%);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 60%);
}
#log li { animation: say 1.6s ease-out both; }
#log li:not(:last-child) { color: var(--ink-dim); }
#log li.warn { color: #f0a08a; }

@keyframes say {
  from { opacity: 0; filter: blur(4px); letter-spacing: 0.06em; }
  to   { opacity: 1; filter: blur(0); }
}

/* Groups flow side by side when there's room, so a long list stays short. */
#actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 10px 28px;
}
.group { display: grid; gap: 6px; justify-items: center; }
.group[hidden] { display: none; }
.group h2 {
  margin: 0;
  font-size: 11px;
  font-weight: normal;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-dim);
  opacity: 0.7;
}
#actions:not(.grouped) .group h2 { display: none; }
.group .buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.action {
  position: relative;
  overflow: hidden;
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(10, 8, 7, 0.55);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition: border-color 0.25s, background 0.25s, color 0.25s, transform 0.1s;
}
.action.reveal.shown { animation-duration: 1.6s; }
.action:hover:not(:disabled) { border-color: rgba(255, 170, 110, 0.6); background: rgba(40, 20, 10, 0.6); }
.action:active:not(:disabled) { transform: scale(0.97); }
.action:focus-visible { outline: 1px solid var(--ember); outline-offset: 3px; }
.action:disabled { cursor: default; color: var(--ink-dim); border-color: rgba(233, 220, 203, 0.1); }
.action kbd {
  font: inherit;
  font-size: 11px;
  color: var(--ink-dim);
  margin-left: 8px;
  opacity: 0.6;
}
@media (hover: none) { .action kbd { display: none; } }

/* Cooldown sweep: --cd goes 1 -> 0 while the action recovers. */
.action::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: var(--ember);
  transform-origin: left;
  transform: scaleX(var(--cd, 0));
  opacity: 0.8;
}
.action.busy { border-color: rgba(255, 170, 110, 0.45); }

/* ---------- death ---------- */
#death {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: #000;
  animation: fade-in 4s ease-in both;
}
#death[hidden] { display: none; }
#death > * { animation: emerge 2s ease-out 3s both; }
#death button { animation-delay: 4.5s; margin-top: 20px; }
.death-title { font-size: 22px; margin: 0; }
.death-sub { color: var(--ink-dim); margin: 0; }

@keyframes fade-in { from { opacity: 0; } }

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

/* ---------- people: name, task toggle, health underline ---------- */
.people {
  list-style: none;
  margin: 10px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid rgba(233, 220, 203, 0.12);
  display: grid;
  gap: 2px;
  font-size: 13px;
}
.people li {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 3px;
  animation: say 1.6s ease-out both;
}
.people li i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, #8e2a24, var(--blood));
  transform-origin: left;
  transform: scaleX(var(--v, 0));
  transition: transform 0.5s ease-out;
  opacity: 0.7;
}
.people button {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  background: none;
  border: 1px solid rgba(233, 220, 203, 0.14);
  border-radius: 3px;
  padding: 2px 8px;
  min-width: 4.5em;
  cursor: pointer;
  transition: border-color 0.25s, color 0.25s;
}
.people button:hover { color: var(--ink); border-color: rgba(255, 170, 110, 0.6); }
.people button:focus-visible { outline: 1px solid var(--ember); outline-offset: 2px; }
.people button.weak { color: #f0a08a; border-style: dashed; }

/* ---------- narrow screens: keep the essentials, tighten the rest ---------- */
@media (max-width: 560px) {
  .known { display: none; }
  .people { margin-top: 6px; padding-top: 6px; }
  .bottom { gap: 12px; }
  #log { font-size: 15px; min-height: 6em; max-height: 7.5em; }
  #actions { gap: 6px 14px; }
  .group { gap: 4px; }
  .group .buttons { gap: 6px; }
  .action { font-size: 14px; padding: 8px 12px; min-height: 40px; }
}
