:root {
  --bg: #000000;          /* true OLED black */
  --panel: #0a0a0f;
  --panel-2: #101019;
  --line: #1d1d2a;
  --ink: #e9e9f2;
  --muted: #8a8aa0;
  --accent: #ffcf6b;      /* warm amber */
  --accent-2: #6be3ff;    /* soft cyan */
  --pink: #ff7eb6;
  --radius: 14px;
  --pixel: 'Press Start 2P', monospace;
  --read: 'VT323', 'Courier New', monospace;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must beat the `display:flex` rules on .modal/.drawer/.typing.
   Author styles override the UA default for [hidden], so force it back. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--read);
  overflow: hidden;
}

body { -webkit-font-smoothing: antialiased; }

#app {
  height: 100vh;
  height: 100dvh; /* track the *visible* viewport as mobile chrome/keyboard slides */
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr);
  gap: 18px;
  padding: 18px;
}

/* ---------------- WAREHOUSE STAGE ---------------- */
#stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.screen-frame {
  position: relative;
  background:
    radial-gradient(120% 90% at 50% 0%, #14141f 0%, #08080d 55%, #050507 100%);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow:
    inset 0 0 0 2px #000,
    inset 0 0 60px rgba(0, 0, 0, 0.7),
    0 0 0 1px #000;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* CRT dressing: faint scanlines + a corner vignette over the scene. Sits under
   the room label / tooltip (z-index 4) and never intercepts clicks. */
.screen-frame::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px),
    radial-gradient(115% 100% at 50% 45%, transparent 62%, rgba(0, 0, 0, 0.32) 100%);
  pointer-events: none;
  z-index: 2;
}

#scene {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  /* When the frame is height-constrained (short/landscape screens) the CSS box
     may no longer be 16:9 — object-fit keeps the pixel art letterboxed instead
     of stretching it. Harmless when the box is already 16:9. */
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 8px;
  cursor: pointer;
}

.cabinet-tip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: linear-gradient(180deg, rgba(20, 20, 31, 0.92), rgba(10, 10, 15, 0.92));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid #2c2c40;
  padding: 5px 10px;
  font-size: 17px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  white-space: nowrap;
  color: var(--ink);
  z-index: 4;
}

.room-label {
  position: absolute;
  top: 22px;
  left: 22px;
  background: rgba(5, 5, 9, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid #2c2c40;
  color: var(--ink);
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.15s ease;
}

.cabinet-directory {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.dir-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: color-mix(in srgb, var(--chip-color, var(--line)) 6%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--chip-color, var(--line)) 28%, var(--line));
  border-radius: 999px;
  padding: 5px 10px 5px 8px;
  font-family: var(--read);
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.dir-chip:hover {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 60%, var(--line));
  transform: translateY(-1px);
}
.dir-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dir-chip .count { color: color-mix(in srgb, var(--chip-color, var(--ink)) 75%, var(--ink)); }

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  transition: margin-top 0.3s ease;
}
.brand h1 {
  font-family: var(--pixel);
  font-size: 16px;
  margin: 0;
  color: var(--accent);
  letter-spacing: 1px;
}
.tagline { color: var(--muted); font-size: 20px; margin: 0; }
.status {
  margin-left: auto;
  font-size: 16px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}
.status.live { color: #7cffa0; border-color: #1f3a26; }
.status.demo { color: var(--accent); border-color: #3a3320; }
.status.offline { color: #ff9a9a; border-color: #3a1f24; }

.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; transition: margin-top 0.3s ease; }

/* Mobile-only accordion toggle for the warehouse scene; irrelevant on desktop
   where there's room for the scene and chat side by side. */
.stage-toggle { display: none; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  font-family: var(--read);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--accent); transform: translateY(-1px); }

/* The one action we want users to find without hunting: start a new chat. */
.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(180deg, var(--accent), #e0a83f);
  color: #1a1407;
  border: 1px solid #a87c2a;
  border-radius: 10px;
  padding: 7px 14px;
  font-family: var(--read);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255, 207, 107, 0.25);
  transition: transform 0.12s ease, filter 0.12s ease;
}

/* inline SVG glyphs inside buttons — consistent across platforms, unlike emoji */
.btn-icon { width: 15px; height: 15px; flex: none; display: block; }
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  line-height: 1;
}

/* ---------------- CHAT ---------------- */
#chat {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0) 120px),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  min-height: 0;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 18px 48px rgba(0, 0, 0, 0.55);
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 8px 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  /* soft fade at the clipped edges instead of a hard cut */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%);
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.messages::-webkit-scrollbar-thumb:hover { background: #2c2c40; }

.msg {
  position: relative; /* anchors the hover timestamp beside the bubble */
  max-width: 82%;
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 19px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; } }

/* hover timestamp — floats in the gutter beside the bubble so it costs no
   vertical space; the day divider carries the date context. */
.msg-time {
  position: absolute;
  bottom: 6px;
  font-size: 14px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  white-space: nowrap;
}
.msg.pip .msg-time { left: calc(100% + 10px); }
.msg.user .msg-time { right: calc(100% + 10px); }
.msg:hover .msg-time { opacity: 1; }

.day-divider {
  align-self: center;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 8px 0 -2px;
  opacity: 0.85;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #3a3013, #241d0a);
  border: 1px solid rgba(255, 207, 107, 0.28);
  color: #ffe9b8;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.msg.pip {
  position: relative; /* anchors the mood avatar in the left gutter */
  align-self: flex-start;
  background: linear-gradient(180deg, #14141f, #0e0e16);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  margin-left: 36px; /* gutter for the avatar */
}

/* consecutive Pip bubbles read as one turn: tighter gap, the name only on the
   first of the run, the (bottom-anchored) avatar only on the last. Anything in
   between — a user bubble, a day divider — resets the run. */
.msg.pip + .msg.pip { margin-top: -8px; border-top-left-radius: 10px; }
.msg.pip + .msg.pip .who { display: none; }
.msg.pip:has(+ .msg.pip) .msg-avatar { display: none; }

/* Pip's mood avatar beside each of his messages (img asset or canvas fallback) */
.msg-avatar {
  position: absolute;
  left: -36px;
  bottom: 2px;
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  border-radius: 8px;
}

/* mood tint on Pip's bubbles (warm = none): the whole border picks up a faint
   wash of the mood color, the leading edge stays stronger, and the avatar gets
   a soft glow in the same hue — readable at a glance, never loud. */
.msg.pip[data-mood="happy"],
.msg.pip[data-mood="excited"],
.msg.pip[data-mood="proud"],
.msg.pip[data-mood="thoughtful"],
.msg.pip[data-mood="concerned"],
.msg.pip[data-mood="playful"] {
  border-color: color-mix(in srgb, var(--mood-color) 22%, var(--line));
  border-left: 2px solid color-mix(in srgb, var(--mood-color) 40%, transparent);
}
.msg.pip[data-mood] .msg-avatar {
  box-shadow: 0 0 12px color-mix(in srgb, var(--mood-color, transparent) 45%, transparent);
}
.msg.pip[data-mood="happy"]      { --mood-color: #ffd36b; }
.msg.pip[data-mood="excited"]    { --mood-color: #ff9e54; }
.msg.pip[data-mood="proud"]      { --mood-color: #ffcf6b; }
.msg.pip[data-mood="thoughtful"] { --mood-color: #6be3ff; }
.msg.pip[data-mood="concerned"]  { --mood-color: #ff7eb6; }
.msg.pip[data-mood="playful"]    { --mood-color: #7cffa0; }
/* tap-to-skip: while Pip's reply is typewriting in, the bubble is clickable
   to reveal it instantly — useful for fast readers or long replies. */
.msg.pip.typewriting { cursor: pointer; }

/* inline retry affordance on a failed send — reuses the message flow so it
   reads as part of the conversation rather than a separate error banner. */
.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  background: rgba(255, 126, 182, 0.12);
  border: 1px solid rgba(255, 126, 182, 0.4);
  color: #ff9a9a;
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--read);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.retry-btn:hover { background: rgba(255, 126, 182, 0.2); transform: translateY(-1px); }

.msg.pip .who {
  display: block;
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--accent-2);
  margin-bottom: 5px;
  letter-spacing: 1px;
}
/* "filed n notes" — a row of category chips that open their cabinet drawer */
.msg .note-flags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  animation: flag-in 0.3s ease;
}
@keyframes flag-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.note-flag-lead { font-size: 15px; color: var(--muted); }
.msg .note-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--read);
  font-size: 15px;
  line-height: 1;
  color: color-mix(in srgb, var(--chip-color) 70%, var(--ink));
  background: color-mix(in srgb, var(--chip-color) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip-color) 35%, transparent);
  border-radius: 999px;
  padding: 4px 10px 4px 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.msg .note-flag:hover {
  background: color-mix(in srgb, var(--chip-color) 20%, transparent);
  transform: translateY(-1px);
}
.msg .note-flag .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chip-color);
  flex: none;
}

.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.5;
  padding: 24px;
}
.empty-hint b { color: var(--accent); }
.hint-pip {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 10px;
  image-rendering: pixelated;
}

/* typing indicator — an incoming bubble wrapped in the same spinning AI
   gradient as the composer, so "Pip is thinking" reads unmistakably as AI. */
.typing {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 14px;
  color: var(--muted);
  border: 1px solid transparent;
  --glow-alpha: 0.75;
  background:
    linear-gradient(180deg, #14141f, #0e0e16) padding-box,
    conic-gradient(from var(--glow-angle),
      rgba(255, 207, 107, var(--glow-alpha)),
      rgba(107, 227, 255, var(--glow-alpha)),
      rgba(255, 126, 182, var(--glow-alpha)),
      rgba(255, 207, 107, var(--glow-alpha))) border-box;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  box-shadow: 0 0 18px rgba(107, 227, 255, 0.14);
  animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2), glow-spin 2.4s linear infinite;
}

/* loading skeletons — ghost bubbles with the composer's AI gradient (amber →
   cyan → pink) drifting through them, plus the light-reflection sweep on top,
   so a slow fetch clearly reads as "the AI is bringing something in". */
.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background-color: #0e0e16;
  background-image: linear-gradient(115deg,
    rgba(255, 207, 107, 0.14),
    rgba(107, 227, 255, 0.14),
    rgba(255, 126, 182, 0.14),
    rgba(255, 207, 107, 0.14));
  background-size: 300% 100%;
  animation: skel-gradient 3s linear infinite;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 35%, rgba(233, 233, 242, 0.10) 50%, transparent 65%);
  background-size: 220% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes skel-gradient {
  from { background-position: 100% 0; }
  to { background-position: -200% 0; }
}
@keyframes shimmer {
  from { background-position: 130% 0; }
  to { background-position: -90% 0; }
}
.skeleton.pip { align-self: flex-start; border-bottom-left-radius: 6px; }
.skeleton.user { align-self: flex-end; border-bottom-right-radius: 6px; }
.skeleton.note { border-radius: 10px; }
.pip-avatar { width: 28px; height: 28px; image-rendering: pixelated; border-radius: 8px; }
img.pip-avatar { object-fit: contain; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-2);
  animation: bounce 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* composer — one unified pill: textarea + mic + send live inside a single
   field. No hard divider line: the edge is an AI gradient (amber → cyan →
   pink, à la Gemini) painted as the border-box layer, barely-there at rest,
   glowing on focus and animating while Pip is thinking. */
@property --glow-angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 135deg;
}
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 14px;
  border: 1px solid transparent;
  border-radius: 26px;
  padding: 6px 6px 6px 4px;
  --glow-alpha: 0.18;
  background:
    linear-gradient(#050509, #050509) padding-box,
    conic-gradient(from var(--glow-angle),
      rgba(255, 207, 107, var(--glow-alpha)),
      rgba(107, 227, 255, var(--glow-alpha)),
      rgba(255, 126, 182, var(--glow-alpha)),
      rgba(255, 207, 107, var(--glow-alpha))) border-box;
  transition: box-shadow 0.25s ease;
}
.composer:focus-within {
  --glow-alpha: 0.65;
  box-shadow:
    0 0 18px rgba(107, 227, 255, 0.10),
    0 0 26px rgba(255, 207, 107, 0.10);
}
.composer.thinking {
  --glow-alpha: 0.9;
  animation: glow-spin 2.4s linear infinite;
  box-shadow:
    0 0 22px rgba(107, 227, 255, 0.16),
    0 0 32px rgba(255, 126, 182, 0.12);
}
@keyframes glow-spin {
  to { --glow-angle: 495deg; }
}
#input {
  flex: 1;
  resize: none;
  background: transparent;
  color: var(--ink);
  border: none;
  border-radius: 20px;
  padding: 11px 8px 11px 16px;
  font-family: var(--read);
  font-size: 19px;
  line-height: 1.3;
  max-height: 140px;
  outline: none;
}
#input::placeholder { color: #56566a; font-size: 17px; }

#send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), #e0a83f);
  color: #1a1407;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  flex: none;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(255, 207, 107, 0.3);
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}
#send svg { width: 19px; height: 19px; display: block; transform: translate(-1px, 1px); }
#send:hover { transform: scale(1.06); filter: brightness(1.08); box-shadow: 0 4px 16px rgba(255, 207, 107, 0.4); }
#send:active { transform: scale(0.96); }
#send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.mic-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  flex: none;
  cursor: pointer;
  transition: transform 0.12s ease, color 0.15s ease, background 0.15s ease;
}
.mic-btn svg { width: 20px; height: 20px; display: block; }
.mic-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.mic-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.mic-btn.recording {
  background: rgba(255, 92, 92, 0.16);
  color: #ff9a9a;
  animation: mic-pulse 1.1s infinite ease-in-out;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 92, 92, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(255, 92, 92, 0); }
}

.mic-status {
  margin: 10px 2px 0;
  font-size: 14px;
  color: #ff9a9a;
}

.disclaimer {
  margin: 10px 2px 0;
  font-size: 14px;
  color: #565668;
  text-align: center;
}

/* ---------------- DRAWER + MODAL ---------------- */
.drawer, .modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  z-index: 20;
  animation: fade 0.18s ease;
}
.drawer { align-items: flex-end; justify-content: center; }
.modal { align-items: center; justify-content: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer-card, .modal-card {
  background: rgba(10, 10, 15, 0.92);
  border: 2px solid var(--line);
  width: min(560px, 92vw);
  padding: 18px 20px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.drawer-card {
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 70vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}
.modal-card { border-radius: var(--radius); animation: pop 0.2s ease; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: translateY(0); } }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.drawer-head h2 {
  font-family: var(--pixel);
  font-size: 13px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ink);
  font-family: var(--read);
  font-size: 17px;
  margin-bottom: 12px;
}
.drawer-search:focus { outline: none; border-color: var(--accent); }

.drawer-count { font-size: 14px; color: var(--muted); font-family: var(--read); font-weight: normal; }
.drawer-empty-icon { font-size: 32px; margin-bottom: 6px; }

.drawer-notes { display: flex; flex-direction: column; gap: 10px; }
.note-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 19px;
  line-height: 1.4;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: pop 0.18s ease;
}
.note-card time { display: block; font-size: 14px; color: var(--muted); margin-top: 5px; }

.note-card-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex: none;
}
.note-card .edit,
.note-card .del {
  background: none;
  border: none;
  color: #565668;
  cursor: pointer;
  font-size: 18px;
  padding: 0 2px;
}
.note-card .edit:hover { color: var(--accent-2); }
.note-card .del:hover { color: var(--pink); }

/* inline edit: the note's own text swaps for a textarea, in place */
.note-card.editing { align-items: stretch; flex-direction: column; }
.note-edit-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  font-family: var(--read);
  font-size: 19px;
  line-height: 1.4;
  resize: vertical;
  min-height: 60px;
}
.note-edit-textarea:focus { outline: none; }
.note-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.note-edit-cancel,
.note-edit-save {
  border-radius: 999px;
  padding: 5px 14px;
  font-family: var(--read);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.note-edit-cancel {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
}
.note-edit-cancel:hover { color: var(--ink); border-color: var(--accent); }
.note-edit-save {
  background: linear-gradient(180deg, var(--accent), #e0a83f);
  border: 1px solid #a87c2a;
  color: #1a1407;
}
.note-edit-save:hover { filter: brightness(1.08); }
.note-edit-save:disabled { opacity: 0.5; cursor: not-allowed; }

.drawer-empty { color: var(--muted); font-size: 20px; text-align: center; padding: 20px; }

/* ---------------- CHATS PANEL ---------------- */
.chat-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  animation: pop 0.18s ease;
}
.chat-card.current { border-color: var(--accent); }
.chat-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: var(--ink);
  font-family: var(--read);
  font-size: 20px;
  line-height: 1.35;
  padding: 11px 13px;
  cursor: pointer;
}
.chat-open .chat-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-card.current .chat-title::after {
  content: '· open now';
  color: var(--accent);
  font-size: 14px;
  margin-left: 8px;
}
.chat-open time { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; }
.chat-card .del {
  background: none;
  border: none;
  color: #565668;
  cursor: pointer;
  font-size: 18px;
  padding: 11px 13px;
}
.chat-card .del:hover { color: var(--pink); }

.resources { font-size: 20px; line-height: 1.6; padding-left: 20px; }
.resources a { color: var(--accent-2); }
.modal-card p { font-size: 20px; line-height: 1.4; }
.muted { color: var(--muted); }

/* ---------------- AUTH GATE + ACCOUNT ---------------- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(120% 90% at 50% 0%, #14141f 0%, #08080d 55%, #050507 100%);
  animation: fade 0.2s ease;
}
.auth-card {
  width: min(420px, 100%);
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 26px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.auth-emblem { font-size: 40px; line-height: 1; }
.auth-card h1 {
  font-family: var(--pixel);
  font-size: 20px;
  color: var(--accent);
  letter-spacing: 1px;
  margin: 14px 0 10px;
}
.auth-sub {
  color: var(--ink);
  font-size: 19px;
  line-height: 1.45;
  margin: 0 auto 22px;
  max-width: 32ch;
}
.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  background: #ffffff;
  color: #1f1f1f;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-family: var(--read);
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.google-btn:hover { transform: translateY(-1px); filter: brightness(0.97); }
.g-icon { width: 20px; height: 20px; flex: none; }
.auth-error { color: #ff9ea0; font-size: 16px; margin: 14px 0 0; line-height: 1.4; }
.auth-fine { color: var(--muted); font-size: 15px; margin: 18px 0 0; }

.account { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.account-pic {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  object-fit: cover;
}
.account-name {
  color: var(--ink);
  font-size: 16px;
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- RESPONSIVE ---------------- */

/* Tablets & phones: collapse the two columns into one app-like column that
   fills the visible viewport. The page itself never scrolls — only the message
   list does — so the composer stays pinned above the keyboard / home indicator. */
@media (max-width: 860px) {
  #app {
    /* minmax(0, …) — not a bare 1fr — so the column can't be blown wider than
       the viewport by its content's min-content width. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #stage { min-height: 0; min-width: 0; }
  #chat { min-width: 0; }
  .screen-frame {
    padding: 10px;
    border-radius: 12px;
    max-height: 40vh; /* keep the scene from swallowing the screen */
  }

  .brand { margin-top: 10px; }
  .brand h1 { font-size: 13px; }
  .tagline { display: none; } /* recover vertical room for the conversation */
  .stage-actions { margin-top: 10px; }

  /* One horizontally-swipeable row of chips instead of a tall wrapping block. */
  .cabinet-directory {
    margin-top: 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .cabinet-directory::-webkit-scrollbar { display: none; }
  .dir-chip { flex: 0 0 auto; }

  #chat { padding: 12px; }

  /* Roomier tap targets for touch. */
  .ghost-btn { padding: 10px 14px; }
  .primary-btn { padding: 10px 16px; }
  #send, .mic-btn { width: 46px; height: 46px; }
  #input { padding: 11px 6px 11px 14px; }

  /* Accordion toggle: collapses the scene + cabinet strip down to just the
     brand/status bar so the chat gets the screen once a conversation starts.
     Tapping it (or sending a first message) reveals/hides the room again. */
  .stage-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: none;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.25s ease, color 0.15s ease;
  }
  /* Collapsed = arrow points at the (hidden) content to say "tap to reveal". */
  #stage.collapsed .stage-toggle { transform: rotate(-90deg); }

  /* Animated accordion: a wrapper around the scene (whose own border/padding
     stay put) plus the directory strip both tween max-height + opacity
     instead of snapping via display:none. */
  .stage-scene-wrap {
    max-height: 40vh;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.32s ease, opacity 0.22s ease;
  }
  .cabinet-directory {
    transition: max-height 0.32s ease, opacity 0.22s ease, margin-top 0.32s ease;
    max-height: 60px;
  }
  #stage.collapsed .stage-scene-wrap {
    max-height: 0;
    opacity: 0;
  }
  #stage.collapsed .cabinet-directory {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    overflow: hidden;
  }
  #stage.collapsed .brand { margin-top: 0; }
  #stage.collapsed .stage-actions { margin-top: 8px; }
}

/* Portrait phones: tighten type + chrome so the chat keeps real estate. */
@media (max-width: 560px) {
  .screen-frame { max-height: 32vh; }
  .msg { max-width: 90%; font-size: 18px; }
  .msg-time { display: none; } /* no hover on touch — the day divider suffices */
  .msg.pip { margin-left: 28px; }
  .msg-avatar { width: 22px; height: 22px; left: -28px; }
  .room-label { top: 15px; left: 15px; font-size: 14px; }
  .brand { gap: 8px; }
  .status { font-size: 14px; }
  .disclaimer { font-size: 13px; }
  .account-name { display: none; } /* keep just the avatar + sign-out on phones */
  .auth-card h1 { font-size: 17px; }
  .auth-sub { font-size: 17px; }
}

/* Landscape phones / very short viewports: the scene shrinks and the
   conversation takes priority; drop the secondary stage chrome. */
@media (max-height: 480px) and (max-width: 860px) {
  #app { padding: 8px; gap: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .screen-frame { max-height: 46vh; }
  .brand, .stage-actions { display: none; }
  .cabinet-directory { margin-top: 0; }
}

/* Fine pointers (mouse) keep hover affordances; on touch, neutralize the
   sticky :hover lift so tapped buttons don't stay raised. */
@media (hover: none) {
  .ghost-btn:hover,
  .primary-btn:hover,
  .dir-chip:hover,
  .note-flag:hover,
  #send:hover { transform: none; }
}

/* Respect reduced-motion: still every looping animation (composer glow,
   skeleton shimmer, typing dots, mic pulse) and the entrance transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .messages { scroll-behavior: auto; }
}

/* ---------------- QUICK-FIRE PROMPT CARDS ---------------- */
.quickfire {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  animation: flag-in 0.25s ease;
}
.qf-card {
  flex: 1;
  min-width: 118px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font-family: var(--read);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}
.qf-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.qf-card .qf-label { font-size: 17px; }
.qf-card .qf-hint { font-size: 14px; color: var(--muted); }

/* ---------------- FLASHBACK MEMORY CARD ---------------- */
.msg.pip.flashback { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.memory-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 9px 12px;
  margin: 6px 0 10px;
}
.memory-card .memory-head { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.memory-card p { margin: 0; font-size: 17px; line-height: 1.4; color: var(--ink); }

/* ---------------- MOOD MAP ---------------- */
.moodmap-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: var(--read);
  font-size: 16px;
  color: var(--muted);
}
.stat-chip b { color: var(--accent); font-size: 19px; font-weight: normal; }
.moodmap-next { width: 100%; color: var(--muted); font-size: 15px; margin: 0; }

.moodmap-chart-wrap {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 10px 6px;
  margin-bottom: 14px;
}
.moodmap-chart-title {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
#moodmap-chart { display: block; width: 100%; height: 150px; }
.moodmap-tip { position: absolute; z-index: 5; }

.mood-day {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 17px;
  animation: pop 0.18s ease;
}
.mood-day .mood-emoji { font-size: 19px; flex: none; }
.mood-day time { color: var(--muted); font-size: 15px; flex: none; min-width: 74px; }
.mood-day .mood-cats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
  justify-content: flex-end;
}
/* category chips inside the Mood Map reuse the note-flag look */
.mood-cats .note-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--read);
  font-size: 15px;
  line-height: 1;
  color: color-mix(in srgb, var(--chip-color) 70%, var(--ink));
  background: color-mix(in srgb, var(--chip-color) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip-color) 35%, transparent);
  border-radius: 999px;
  padding: 4px 10px 4px 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mood-cats .note-flag:hover {
  background: color-mix(in srgb, var(--chip-color) 20%, transparent);
  transform: translateY(-1px);
}
.mood-cats .note-flag .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chip-color);
  flex: none;
}

/* ---------------- MIND MAP ---------------- */
/* A graph needs far more room than the 70vh bottom-sheet .drawer gives, so this
   one is a .modal and sizes itself to the viewport. */
.mindmap-card {
  width: min(1040px, 96vw);
  height: min(78vh, 720px);
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}
/* .screen-frame is built for the warehouse scene (centred, padded). Here it's
   just the CRT dressing around a canvas that fills it. */
.mindmap-stage {
  padding: 0;
  overflow: hidden;
  align-items: stretch;
  min-height: 180px;
}
#mindmap-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--radius) - 2px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: grab;
  touch-action: none; /* pan/pinch are handled in mindmap.js */
}
#mindmap-canvas.dragging { cursor: grabbing; }
.mindmap-tip { position: absolute; z-index: 5; }

.mindmap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  max-height: 64px;
  overflow-y: auto;
}
.mindmap-hint {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: #565668;
  text-align: center;
  margin: 10px 0 0;
}
.mindmap-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 19px;
  padding: 24px;
}
/* The drill-down list only appears once a tag is clicked, and never eats the
   canvas's height when it does. */
#mindmap-notes {
  max-height: 34vh;
  overflow-y: auto;
  margin-top: 12px;
}
#mindmap-notes:empty { display: none; }

/* Tag pills on note cards. Same --chip-color mechanic as the category flags. */
.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.tag-chip {
  font-family: var(--read);
  font-size: 14px;
  line-height: 1;
  color: color-mix(in srgb, var(--chip-color) 70%, var(--ink));
  background: color-mix(in srgb, var(--chip-color) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip-color) 30%, transparent);
  border-radius: 999px;
  padding: 4px 9px;
}
button.tag-chip { cursor: pointer; transition: all 0.15s ease; }
button.tag-chip:hover {
  background: color-mix(in srgb, var(--chip-color) 22%, transparent);
  transform: translateY(-1px);
}

@media (max-width: 860px) {
  .mindmap-card { width: 96vw; height: 88vh; }
  .mindmap-legend { max-height: 48px; }
}
@media (hover: none) {
  button.tag-chip:hover { transform: none; }
}

/* ---------------- TOASTS ---------------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 15, 22, 0.95);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  font-family: var(--read);
  font-size: 16px;
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: min(90vw, 420px);
}
.toast.out { animation: toast-out 0.18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
.toast-action {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--read);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  white-space: nowrap;
}
.toast-action:hover { text-decoration: underline; }
