/* Keep Nigel Alive — phone UI.
   Visual system from design/nigel-identity.html: a Prussian-blue cyanotype ground,
   an amber life-thread, per-product hues. Single committed theme (a blueprint under
   glass), painted explicitly so it holds on any host. */

:root {
  --ground: #0a1a2f;
  --ground-2: #0c2138;
  --surface: #102a45;
  --surface-2: #143453;
  --line: #23486e;
  --line-soft: #1b3a5c;
  --ink: #eaf2ff;
  --ink-dim: #a7bcd9;
  --ink-faint: #87a0c0;

  --amber: #ff9e1b; /* life-thread + Durable Object */
  --amber-soft: #ffb84d;
  --cyan: #59d2ff;
  --coral: #ff5d73; /* danger / death */
  --olive: #aeb79a;

  /* per-need hues */
  --hunger: #ffb84d;
  --fun: #ff5d73;
  --clean: #59d2ff;
  --energy: #b7d33b;
  --health: #ff9e1b;

  /* per-product hues (peek-behind) */
  --p-phone: #7cf0ff;
  --p-workers: #7cf0ff;
  --p-relay: #ff9e1b;
  --p-nigel: #ff9e1b;
  --p-sqlite: #ffd27a;
  --p-ai: #ff5d73;
  --p-gateway: #17bfa6;
  --p-queue: #45d0e0;
  --p-d1: #3da5ff;

  --r-lg: 22px;
  --r-md: 15px;
  --r-sm: 10px;
  --gap: 14px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);

  color-scheme: dark;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -10%, #123252 0%, rgba(18, 50, 82, 0) 60%),
    radial-gradient(900px 500px at 90% 110%, #0e2b47 0%, rgba(14, 43, 71, 0) 55%),
    var(--ground);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.eyebrow {
  font: 600 0.72rem/1 var(--font-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan);
  margin: 0 0 14px;
}

/* ---------------- Join gate ---------------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
  background:
    radial-gradient(1000px 600px at 50% -5%, #16385c 0%, rgba(10, 26, 47, 0) 60%),
    var(--ground);
}
.gate[hidden] { display: none; }
.gate-card {
  max-width: 420px;
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.gate-title {
  font: 800 clamp(2.6rem, 12vw, 3.6rem) / 0.95 var(--font-display);
  margin: 0 0 16px;
  letter-spacing: -0.02em;
  text-wrap: balance;
  background: linear-gradient(180deg, #fff 0%, var(--amber-soft) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gate-sub {
  color: var(--ink-dim);
  font-size: 1.02rem;
  line-height: 1.5;
  margin: 0 auto 26px;
  max-width: 33ch;
}
.turnstile-slot { display: flex; justify-content: center; min-height: 0; margin-bottom: 18px; }
.turnstile-slot:empty { margin-bottom: 0; }
.gate-btn {
  font: 700 1.15rem var(--font-display);
  color: #21160a;
  background: linear-gradient(180deg, var(--amber-soft), var(--amber));
  border: none;
  border-radius: 999px;
  padding: 17px 40px;
  cursor: pointer;
  box-shadow: 0 12px 30px -10px rgba(255, 158, 27, 0.6);
  transition: transform 0.12s ease, filter 0.2s ease, opacity 0.2s ease;
}
.gate-btn:disabled { opacity: 0.45; box-shadow: none; }
.gate-btn:not(:disabled):active { transform: scale(0.96); }
.gate-fine { color: var(--ink-faint); font-size: 0.82rem; margin: 20px auto 0; max-width: 30ch; }

/* ---------------- App shell ---------------- */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  gap: var(--gap);
}
.app[hidden] { display: none; }

.top { display: flex; align-items: center; justify-content: space-between; padding-top: 4px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-glyph { font-size: 1.1rem; }
.brand-name {
  font: 700 0.82rem var(--font-mono);
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}
.conn { display: flex; align-items: center; gap: 7px; font: 500 0.72rem var(--font-mono); color: var(--ink-faint); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); transition: background 0.3s; }
.conn-dot.live { background: #4be08a; box-shadow: 0 0 0 4px rgba(75, 224, 138, 0.16); }
.conn-dot.down { background: var(--coral); }

/* ---------------- Stage / pet ---------------- */
.stage { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; position: relative; }
.halo {
  position: absolute;
  top: -6px;
  width: min(78vw, 300px);
  height: min(78vw, 300px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 158, 27, 0.22) 0%, rgba(255, 158, 27, 0) 66%);
  filter: blur(6px);
  z-index: 0;
  transition: opacity 0.6s, background 0.6s;
  pointer-events: none;
}
.pet-frame {
  position: relative;
  width: min(66vw, 260px);
  height: min(66vw, 260px);
  border-radius: 30px;
  overflow: hidden;
  background: linear-gradient(180deg, var(--surface-2), var(--ground-2));
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 1;
  transform-origin: center 62%;
  will-change: transform;
}
.portrait { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.8s ease, filter 0.6s ease; }
.portrait.ready { opacity: 1; }
.pet-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 5.5rem;
  color: var(--amber);
  opacity: 0.9;
}
.portrait.ready ~ .pet-glyph { opacity: 0; }
.deadmark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 6rem var(--font-display);
  color: var(--coral);
  background: rgba(10, 26, 47, 0.55);
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}
.app.dead .pet-frame { animation: none !important; transform: none !important; }
.app.dead .portrait { filter: grayscale(0.85) brightness(0.6); }
.app.dead .deadmark { opacity: 1; }
.app.dead .halo { opacity: 0; }

.mood {
  font: 500 clamp(1.15rem, 4.6vw, 1.5rem) / 1.25 var(--font-display);
  color: var(--amber-soft);
  margin: 2px 0 0;
  min-height: 1.9em;
  max-width: 24ch;
  text-wrap: balance;
  transition: color 0.4s;
}
.app.dead .mood { color: var(--coral); }

/* vitals */
.vitals { width: 100%; max-width: 340px; display: grid; gap: 7px; margin-top: 4px; }
.vital { display: grid; grid-template-columns: 58px 1fr 30px; align-items: center; gap: 10px; }
.vital-key { font: 500 0.68rem var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); text-align: left; }
.vital-track { height: 8px; border-radius: 6px; background: #0a1f36; overflow: hidden; border: 1px solid var(--line-soft); }
.vital-fill { height: 100%; border-radius: 6px; transition: width 0.5s cubic-bezier(0.3, 0.8, 0.3, 1); }
.vital-val { font: 500 0.72rem var(--font-mono); color: var(--ink-dim); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- Actions ---------------- */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.act {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 15px 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--surface), var(--ground-2));
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, border-color 0.2s;
}
.act:active { transform: scale(0.95); border-color: var(--amber); }
.act-glyph { font-size: 1.5rem; line-height: 1; }
.act-label { font: 600 0.82rem var(--font-body); }
.act::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 158, 27, 0.5), transparent 60%);
  opacity: 0;
  transform: scale(0.4);
}
.act.pulse::after { animation: ripple 0.5s ease-out; }
/* When dead, actions become revival votes — still tappable, visibly urgent. */
.app.dead .actions { opacity: 0.9; }
.app.dead .act { border-color: var(--coral); animation: revive-pulse 1.4s ease-in-out infinite; }
@keyframes revive-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 115, 0); } 50% { box-shadow: 0 0 0 3px rgba(255, 93, 115, 0.25); } }

/* ---------------- You row ---------------- */
.you { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.you-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font: 600 0.86rem var(--font-body);
  min-width: 0;
}
.you-glyph { font-size: 1rem; }
.you-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.you-metric { text-align: center; padding: 4px 6px; }
.you-metric-val { display: block; font: 600 1.05rem var(--font-mono); color: var(--cyan); font-variant-numeric: tabular-nums; }
.you-metric-key { display: block; font: 500 0.62rem var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); margin-top: 2px; }

/* ---------------- Peek behind ---------------- */
.peek { border: 1px solid var(--line); border-radius: var(--r-md); background: linear-gradient(180deg, var(--ground-2), rgba(12, 33, 56, 0.4)); overflow: hidden; }
.peek-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  background: none;
  border: none;
  color: var(--ink);
  font: 600 0.98rem var(--font-display);
  cursor: pointer;
}
.peek-caret { transition: transform 0.3s; color: var(--cyan); }
.peek-toggle[aria-expanded="true"] .peek-caret { transform: rotate(180deg); }
.peek-body { padding: 0 16px 18px; }
.peek-intro { color: var(--ink-dim); font-size: 0.86rem; line-height: 1.5; margin: 0 0 14px; }
.pipe { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.hop {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}
.hop::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 26px;
  bottom: -9px;
  width: 2px;
  background: var(--line-soft);
}
.hop:last-child::before { display: none; }
.hop-dot {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--hue, var(--cyan));
  z-index: 1;
  transition: box-shadow 0.25s, border-color 0.25s, background 0.25s;
}
.hop.lit .hop-dot {
  border-color: var(--hue);
  background: color-mix(in srgb, var(--hue) 22%, var(--surface));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--hue) 20%, transparent);
}
.hop-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.hop-title { display: block; font: 600 0.9rem var(--font-body); }
.hop-sub { display: block; font: 400 0.76rem/1.35 var(--font-body); color: var(--ink-faint); }
.hop-meta { font: 500 0.74rem var(--font-mono); color: var(--hue, var(--ink-dim)); font-variant-numeric: tabular-nums; opacity: 0; transition: opacity 0.25s; white-space: nowrap; }
.hop.lit .hop-meta { opacity: 1; }
.peek-foot { margin: 12px 0 0; font: 500 0.78rem var(--font-mono); color: var(--ink-faint); }

/* ---------------- Footer ---------------- */
.foot { margin-top: auto; padding-top: 8px; display: flex; align-items: center; justify-content: space-between; font: 500 0.74rem var(--font-mono); color: var(--ink-faint); }
.bill em { font-style: normal; color: var(--ink-faint); }
.madeon { color: var(--ink-faint); }

.revive-hint { margin: 0; text-align: center; font: 600 0.92rem var(--font-body); color: var(--coral); padding: 4px 8px; }
.revive-hint[hidden] { display: none; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: 999px;
  font: 500 0.86rem var(--font-body);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 30;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Animations ---------------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes ripple { from { opacity: 0.8; transform: scale(0.4); } to { opacity: 0; transform: scale(1.6); } }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.08s !important; }
  .pet-frame { animation: none !important; }
}
