:root {
  color-scheme: dark;
  --bg: #1b1420;
  --panel: #241a2b;
  --panel-2: #2f2338;
  --ink: #f4e9f0;
  --muted: #b49fae;
  --accent: #e87fa9;
  --accent-ink: #2a0f1c;
  --danger: #ff8a8a;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

body { overflow: hidden; }

.view { height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* ---------- login ---------- */
#view-login { align-items: center; justify-content: center; padding: 1.5rem; }

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* The mark is the SVG icon, not an emoji — emoji fonts aren't guaranteed. */
.pig-big { width: 96px; height: 96px; margin: 0 auto; display: block; border-radius: 22px; }
.brand { display: inline-flex; align-items: center; gap: .4rem; }
.brand-pig { border-radius: 6px; vertical-align: middle; }
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p { margin: 0 0 .5rem; font-size: .92rem; }

input[type="password"], textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: .85rem 1rem;
  font: inherit;
  resize: none;
}

input[type="password"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: .85rem 1.1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

button:disabled { opacity: .55; cursor: default; }

.ghost {
  background: transparent;
  color: var(--muted);
  padding: .5rem .7rem;
  font-weight: 500;
}

.ghost:hover { color: var(--ink); }

/* ---------- chrome ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: max(.6rem, env(safe-area-inset-top)) .8rem .6rem;
  background: var(--panel);
  border-bottom: 1px solid #00000040;
  flex: none;
}

.brand { font-weight: 650; }

/* ---------- messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem .9rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  overscroll-behavior: contain;
}

.msg {
  max-width: 85%;
  padding: .7rem .9rem;
  border-radius: var(--radius);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 5px; }
.msg.pending { opacity: .7; font-style: italic; }
.msg.failed { background: #4a2230; color: #ffd7d7; }

.empty-hint { margin: auto; text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty-hint .pig-big { margin-bottom: .5rem; }

/* ---------- composer ---------- */
.composer {
  flex: none;
  display: flex;
  gap: .5rem;
  padding: .6rem .7rem calc(.6rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #00000040;
}

.composer { align-items: flex-end; }

/* The text field leads with the duck. */
.field {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: .55rem .7rem;
}

.field:focus-within { border-color: var(--accent); }

.duck { flex: none; margin-top: 2px; }

.field textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: .3rem 0;
  max-height: 40vh;
}

.field textarea:focus { outline: none; border: none; }

.attach {
  flex: none;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
  padding: .6rem .8rem;
  font-weight: 400;
}

.attach:hover { background: #3a2b45; }

/* ---------- attachment tray (pending uploads) ---------- */
.tray {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .5rem .7rem 0;
  background: var(--panel);
}

.chip {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--panel-2);
  border-radius: 10px;
  padding: .35rem .5rem;
  font-size: .85rem;
  max-width: 100%;
}

.chip img { width: 32px; height: 32px; object-fit: cover; border-radius: 6px; flex: none; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9rem; }
.chip .x { background: transparent; color: var(--muted); padding: 0 .25rem; font-size: 1rem; }
.chip .x:hover { color: var(--danger); }
.chip.err { color: var(--danger); }

/* ---------- attachments inside a message ---------- */
.msg .atts { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .45rem; }
.msg .atts img { max-width: 220px; max-height: 220px; border-radius: 10px; display: block; }

.filecard {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: #00000030;
  border-radius: 10px;
  padding: .4rem .6rem;
  font-size: .85rem;
  text-decoration: none;
  color: inherit;
}

/* ---------- memory ---------- */
.memory-wrap { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .8rem; }

.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.facts li {
  background: var(--panel-2);
  border-radius: 12px;
  padding: .7rem .85rem;
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  line-height: 1.4;
}

.facts li span { flex: 1; overflow-wrap: anywhere; }

.forget {
  background: transparent;
  color: var(--muted);
  padding: .15rem .5rem;
  border-radius: 8px;
  font-size: .85rem;
  flex: none;
}

.forget:hover { color: var(--danger); }
.forget.confirm-delete {
  background: var(--danger);
  color: #2a0f1c;
  font-weight: 700;
  white-space: nowrap;
}

.danger { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding-top: 1rem; }

.danger-btn { background: transparent; color: var(--danger); border: 1px solid #ff8a8a55; font-weight: 500; }
.danger-btn:hover { background: #ff8a8a18; }

/* ---------- conversations ---------- */
.facts li.current { outline: 1px solid var(--accent); }

.thread-open {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .15rem;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  font-weight: 500;
}

.thread-open .t { overflow-wrap: anywhere; }
.small { font-size: .8rem; }

/* ---------- settings row ---------- */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  background: var(--panel-2);
  border-radius: 12px;
  padding: .8rem .9rem;
}

.setting p { margin: .2rem 0 0; }
.setting .ghost { border: 1px solid #ffffff22; flex: none; }

/* ---------- voice ---------- */
/* SVG, not an emoji: emoji fonts aren't guaranteed (the pig and duck are SVG for
   the same reason — 🎤 rendered as a tofu box on a machine without them). */
.mic { display: inline-flex; align-items: center; justify-content: center; padding: .65rem .8rem; }
.mic img { display: block; }

.mic.listening {
  background: var(--accent);
  color: var(--accent-ink);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

@media (prefers-reduced-motion: reduce) {
  .mic.listening { animation: none; }
}

/* Voice unavailable in this browser: still visible and tappable (it explains
   itself), just visually de-emphasised so it doesn't promise more than it can do. */
.mic.unsupported { opacity: .45; }
.mic.unsupported:hover { opacity: .7; }

/* ---------- timestamps ---------- */
.msg { position: relative; }

.stamp {
  display: block;
  margin-top: .25rem;
  font-size: .68rem;
  opacity: .55;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.day-sep {
  align-self: center;
  font-size: .75rem;
  color: var(--muted);
  background: #00000035;
  padding: .2rem .7rem;
  border-radius: 999px;
  margin: .3rem 0;
}

/* ---------- conversation picker (discoverability) ---------- */
.chatpicker {
  background: transparent;
  color: var(--ink);
  padding: .3rem .5rem;
  text-align: left;
  min-width: 0;
  flex: 1;
}

.chatpicker:hover { background: var(--panel-2); }
.chatpicker .stack { display: flex; flex-direction: column; gap: 0; min-width: 0; }

.chatpicker .kicker {
  font-size: .68rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.chatpicker .cur {
  font-size: .95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 42vw;
}

.bar nav { display: flex; align-items: center; gap: .15rem; flex: none; }
.bar nav .ghost { padding: .5rem .45rem; font-size: .85rem; white-space: nowrap; }

/* pending-reminder count on the clock button */
#to-reminders { position: relative; }

.badge {
  position: absolute;
  top: .15rem;
  right: .05rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: .6rem;
  font-weight: 700;
  min-width: 1.1em;
  padding: 0 .25em;
  line-height: 1.3;
}


.primary-wide { width: 100%; text-align: center; }

/* Icon-only header button. SVG, not an emoji — see the .mic note above; ⏰
   rendered as a tofu box on a machine without emoji fonts. */
.iconbtn { display: inline-flex; align-items: center; justify-content: center; padding: .5rem .5rem; }
.iconbtn img { display: block; }

/* ---------- "you're running an old copy" bar ---------- */
#update-bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  padding: .6rem .8rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .9rem;
  font-weight: 600;
}

#update-bar button {
  background: var(--accent-ink);
  color: var(--accent);
  padding: .35rem .8rem;
  font-size: .85rem;
}

/* ---------- starting up / couldn't load ---------- */
#view-boot, #view-trouble { align-items: center; justify-content: center; padding: 1.5rem; }

/* Revealed by a pure CSS delay, not a timer: the CSP forbids inline scripts, so
   if app.js itself fails to load there is no JS available to show this. */
#boot-slow {
  opacity: 0;
  animation: boot-slow-reveal 0s linear 8s forwards;
}

@keyframes boot-slow-reveal { to { opacity: 1; } }

#boot-slow a { color: var(--accent); }

/* ---------- passkeys ---------- */
.codes {
  background: var(--panel-2);
  border-radius: 12px;
  padding: .8rem;
  font-size: .95rem;
  line-height: 1.9;
  letter-spacing: .04em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: .4rem 0;
}

#view-recover { align-items: center; justify-content: center; padding: 1.5rem; }

#recover-code {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: .85rem 1rem;
  font: inherit;
  text-align: center;
}

#recover-code:focus { outline: none; border-color: var(--accent); }

/* ---------- two-step sign-in ---------- */
.totp-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .95rem;
  letter-spacing: .08em;
  background: var(--panel-2);
  border-radius: 10px;
  padding: .6rem .7rem;
  overflow-wrap: anywhere;
  user-select: all;      /* so she can select the whole key in one tap */
}

#twofactor-step input, #twofactor-setup input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: .85rem 1rem;
  font: inherit;
  letter-spacing: .15em;
  text-align: center;
}

#twofactor-setup { display: flex; flex-direction: column; gap: .5rem; }
