:root {
  --ink: #f3ead9;
  --dim: rgba(243, 234, 217, 0.62);
  --amber: #e9b363;
  --glass: rgba(18, 12, 8, 0.52);
  --line: rgba(255, 228, 190, 0.14);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0906; color: var(--ink); font: 400 15px/1.5 var(--sans); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.nest-canvas { cursor: pointer; }

/* Film grain and vignette over everything: the documentary look. */
#grain { position: fixed; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.5) 100%); }
#grain::after { content: ""; position: absolute; inset: -50%; opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.9s steps(4) infinite; }
@keyframes grain { 0% { transform: translate(0, 0); } 25% { transform: translate(-3%, 2%); } 50% { transform: translate(2%, -3%); } 75% { transform: translate(-2%, -1%); } }

.btn { appearance: none; border: 1px solid var(--line); background: rgba(255, 240, 220, 0.06);
  padding: 0.75rem 1.4rem; border-radius: 999px; cursor: pointer; letter-spacing: 0.02em;
  transition: background 0.2s, border-color 0.2s, transform 0.1s; backdrop-filter: blur(8px); }
.btn:hover { background: rgba(255, 240, 220, 0.14); border-color: rgba(255, 228, 190, 0.3); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--amber); color: #1d1208; border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #f3c47c; }
.btn.danger { background: #a3361c; border-color: transparent; }
.btn.small { padding: 0.45rem 0.95rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.4; cursor: default; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.32em; font-size: 0.72rem; color: var(--amber); margin: 0 0 0.8rem; }
.muted { color: var(--dim); }

/* Screens */
.screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; text-align: center; padding: 2rem; }
#title { background: radial-gradient(ellipse at 50% 120%, rgba(120, 70, 25, 0.35), transparent 60%), linear-gradient(#0d0906cc, #0d0906ee); }
#title h1 { font: 400 clamp(4rem, 16vw, 10rem)/0.9 var(--serif); letter-spacing: 0.18em; margin: 0 0 2.4rem 0.18em;
  background: linear-gradient(180deg, #fff5e2, #d59a4e); -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 60px rgba(233, 179, 99, 0.15); }
.title-actions { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }
.hint { color: var(--dim); font-size: 0.85rem; margin-top: 2rem; }
.loading { position: absolute; bottom: 2rem; color: var(--dim); font-style: italic; font-family: var(--serif); }

.card { background: rgba(8, 5, 3, 0.78); backdrop-filter: blur(6px); animation: fadein 0.8s ease; }
.card-inner { max-width: 34rem; }
.card h2 { font: 400 clamp(1.9rem, 5vw, 3rem)/1.1 var(--serif); margin: 0 0 1.4rem; }
.card #card-text { font: 400 1.15rem/1.7 var(--serif); color: rgba(243, 234, 217, 0.85); margin: 0 0 1.6rem; }
.stats-line { color: var(--amber); letter-spacing: 0.08em; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 20; transition: opacity 0.45s ease; }
#fade.on { opacity: 1; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: max(1rem, env(safe-area-inset-top)); left: 1rem; right: 1rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; pointer-events: none; }
.clock { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 1rem 0.55rem 0.7rem; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(10px); }
.clock .sun { width: 26px; height: 26px; fill: var(--amber); transition: fill 1s; }
.season { font: 400 1.05rem/1.1 var(--serif); }
.day { font-size: 0.78rem; color: var(--dim); }
.stats { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.stat { display: flex; align-items: center; gap: 0.45rem; padding: 0.45rem 0.8rem; background: var(--glass); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(10px); }
.stat svg { width: 18px; height: 18px; fill: var(--amber); opacity: 0.9; }
.stat b { font-variant-numeric: tabular-nums; font-weight: 600; }
.stat span { font-size: 0.75rem; color: var(--dim); }
.stat.warn b { color: #ff8a6a; }

.health { position: absolute; top: calc(max(1rem, env(safe-area-inset-top)) + 4.2rem); left: 1rem; display: flex; align-items: center; gap: 0.6rem; font-size: 0.75rem; color: var(--dim); }
.health .bar { width: 120px; height: 5px; background: rgba(255, 255, 255, 0.12); border-radius: 3px; overflow: hidden; }
.health i { display: block; height: 100%; background: linear-gradient(90deg, #c9502c, #e9b363); transition: width 0.2s; }

.alert { position: absolute; top: 5rem; left: 50%; transform: translateX(-50%); padding: 0.5rem 1rem; border-radius: 999px; background: rgba(163, 54, 28, 0.85); font-weight: 600; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

#toasts { position: absolute; top: 8.5rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; width: min(92vw, 30rem); }
.toast { padding: 0.55rem 1.1rem; background: var(--glass); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(10px); font-family: var(--serif); font-style: italic; text-align: center; animation: toast 4.5s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.objective { position: absolute; left: 1rem; bottom: max(1rem, env(safe-area-inset-bottom)); max-width: min(24rem, 60vw); padding: 0.8rem 1rem; background: var(--glass); border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 12px; backdrop-filter: blur(10px); }
.objective .label { text-transform: uppercase; letter-spacing: 0.24em; font-size: 0.65rem; color: var(--amber); }
.objective p { margin: 0.2rem 0 0; font: 400 1.02rem/1.35 var(--serif); }
.obj-bar { margin-top: 0.55rem; height: 3px; background: rgba(255, 255, 255, 0.1); border-radius: 2px; overflow: hidden; }
.obj-bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width 0.4s; }
.objective.done { animation: done 0.9s ease; }
@keyframes done { 30% { border-left-color: #9fd36a; background: rgba(60, 90, 30, 0.55); } }

.prompt { position: absolute; left: 50%; bottom: 7.5rem; transform: translateX(-50%); display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 1rem 0.55rem 0.6rem; background: var(--glass); border: 1px solid var(--line); border-radius: 999px; backdrop-filter: blur(10px); white-space: nowrap; }
kbd { display: inline-grid; place-items: center; min-width: 1.8rem; height: 1.8rem; border-radius: 7px; background: var(--ink); color: #1d1208; font: 700 0.85rem var(--sans); }

.nest-actions { position: absolute; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
.nest-actions .btn small { opacity: 0.7; margin-left: 0.4rem; font-size: 0.75rem; }
.nest-actions .room { width: 100%; text-align: center; font: 400 1.25rem var(--serif); margin-bottom: 0.2rem; text-shadow: 0 2px 10px #000; pointer-events: none; }

.corner { position: absolute; right: 1rem; bottom: max(1rem, env(safe-area-inset-bottom)); display: flex; gap: 0.4rem; }
.keys { position: absolute; right: 1rem; bottom: 4rem; padding: 0.7rem 0.9rem; background: var(--glass); border: 1px solid var(--line); border-radius: 12px; font-size: 0.75rem; color: var(--dim); backdrop-filter: blur(10px); transition: opacity 1s; }
.keys p { margin: 0.1rem 0; }
.keys.gone { opacity: 0; pointer-events: none; }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; background: rgba(5, 3, 2, 0.6); backdrop-filter: blur(4px); padding: 1rem; }
.panel { width: min(30rem, 100%); max-height: 90dvh; overflow: auto; padding: 1.6rem; background: rgba(24, 17, 11, 0.92); border: 1px solid var(--line); border-radius: 18px; display: flex; flex-direction: column; gap: 0.7rem; }
.panel.narrow { width: min(20rem, 100%); }
.panel h2 { font: 400 1.7rem var(--serif); margin: 0 0 0.2rem; }
.panel p { margin: 0; }
.slider label { display: flex; justify-content: space-between; font-weight: 600; }
.slider b { color: var(--amber); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--amber); }
.slider small { color: var(--dim); display: block; }
.colony-stats { font-size: 0.85rem; color: var(--dim); border-top: 1px solid var(--line); padding-top: 0.7rem; display: grid; gap: 0.2rem; }
#m-confirm { display: grid; gap: 0.5rem; }

/* Touch */
.touch { position: absolute; inset: auto 0 0 0; height: 0; }
.stick { position: absolute; left: 1.4rem; bottom: 7.5rem; width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 240, 220, 0.08); border: 1px solid var(--line); touch-action: none; }
.stick.active { background: rgba(255, 240, 220, 0.14); }
.knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 240, 220, 0.35); }
.touch-buttons { position: absolute; right: 1.2rem; bottom: 4.5rem; display: flex; gap: 0.6rem; align-items: flex-end; }
.tbtn { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); font-size: 0.72rem; touch-action: none; }
.tbtn.main { width: 80px; height: 80px; background: var(--amber); color: #1d1208; font-weight: 700; font-size: 1.1rem; }

@media (max-width: 700px) {
  .stat span { display: none; }
  .stat { padding: 0.35rem 0.55rem; }
  .objective { max-width: calc(100vw - 2rem); bottom: auto; top: 7.6rem; padding: 0.6rem 0.8rem; }
  .health { top: calc(max(1rem, env(safe-area-inset-top)) + 4.8rem); }
  .nest-actions { bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 3.2rem); }
  .nest-actions .btn small { display: block; margin: 0; }
  .keys { display: none; }
  #toasts { top: 13rem; }
  .prompt { bottom: 13rem; }
}
