/* JARVIS — the look, v2 "game mode" (Aaron's launch-day ruling 2026-08-26:
   "less hospital room, more video-game homescreen you can't wait to play").
   Layout is UNCHANGED from v1 — same selectors, same drawer, same quality
   floor (360px, visible focus, reduced-motion, 44px targets). What changed
   is the skin: committed dark cosmic theme (no light mode — a game console
   doesn't go beige at noon), aurora backdrop, glow accents, gradient
   wordmark. Each install still personalizes ONLY through --accent, set at
   runtime from users.accent_color, which now also drives the glows. */

:root {
  --accent: #6B7DB3;
  --bg: #070b18;
  --bg-deep: #04060f;
  --bg-panel: rgba(16, 22, 44, 0.72);
  --bg-input: rgba(22, 30, 58, 0.85);
  --bg-user: rgba(38, 52, 96, 0.55);
  --bg-hover: rgba(56, 72, 128, 0.35);
  --text: #e8ecf8;
  --text-dim: #8b94b3;
  --line: rgba(110, 130, 190, 0.22);
  --code-bg: #0c1020;
  --code-text: #dfe4f5;
  --danger: #ff6b57;
  --glow: 0 0 18px;
  --radius: 16px;
  --sidebar-w: 288px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* the CHOREFIRE precedence law: an element with its own display: rule
   will beat the hidden attribute unless this exists */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.55;
}
.display { font-family: "Fraunces", Georgia, "Times New Roman", serif; }
code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ===== the aurora: two slow drifting glow fields behind everything.
   pure CSS, GPU-cheap (transform+opacity only), killed by reduced-motion */
body::before, body::after {
  content: ""; position: fixed; z-index: 0; pointer-events: none;
  width: 90vmax; height: 90vmax; border-radius: 50%;
  filter: blur(90px); opacity: 0.32;
}
body::before {
  background: radial-gradient(circle, var(--accent) 0%, transparent 62%);
  top: -45vmax; left: -25vmax;
  animation: drift1 26s ease-in-out infinite alternate;
}
body::after {
  background: radial-gradient(circle, #2b7fff 0%, transparent 62%);
  bottom: -50vmax; right: -30vmax;
  animation: drift2 32s ease-in-out infinite alternate;
}
@keyframes drift1 { to { transform: translate(10vmax, 8vmax) scale(1.15); } }
@keyframes drift2 { to { transform: translate(-8vmax, -10vmax) scale(1.1); } }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button, a, input, textarea, [role="button"] { min-height: 44px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* the glowing gradient wordmark, everywhere it appears */
.wordmark {
  background: linear-gradient(120deg, #9fd4ff 0%, var(--accent) 45%, #b48cff 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(90, 160, 255, 0.45));
  font-weight: 600;
}

/* ============ LOGIN ============ */
.login {
  height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 24px;
  text-align: center; position: relative; z-index: 1;
}
.login .wordmark { font-size: 52px; letter-spacing: 0.08em; }
.login p { color: var(--text-dim); max-width: 340px; }
.login form { display: flex; flex-direction: column; gap: 10px; width: min(340px, 100%); }
.login input {
  padding: 13px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-input); color: var(--text); font-size: 16px;
}
.login .go {
  background: linear-gradient(120deg, var(--accent), #5a8dee);
  color: #fff; border-radius: var(--radius);
  padding: 13px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: var(--glow) rgba(90, 141, 238, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.login .go:hover { transform: translateY(-1px); box-shadow: 0 0 26px rgba(90, 141, 238, 0.55); }
.login .note { font-size: 14px; min-height: 22px; }
.login .coderow { display: flex; gap: 8px; width: 100%; }
.login .coderow input {
  flex: 1; min-width: 0; /* flex inputs default min-width:auto and refuse to
  shrink — this is what pushed the button off the iPhone screen */
  text-align: center; letter-spacing: 0.2em; font-size: 17px;
  padding: 11px 8px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-input); color: var(--text);
}
.login .coderow .go.alt { flex-shrink: 0; white-space: nowrap; }
.login .go.alt {
  background: none; color: #8ec2ff; border: 1px solid var(--accent);
  box-shadow: none; padding: 11px 16px; font-weight: 600;
}
.login .codehint { font-size: 12.5px; color: var(--text-dim); }
.login .note.err { color: var(--danger); }

/* ============ APP FRAME ============ */
.app { display: none; height: 100dvh; position: relative; z-index: 1; }
.app.on { display: flex; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding-top: var(--sat);
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 8px; }
.side-head .wordmark { font-size: 22px; letter-spacing: 0.06em; flex: 1; }
.newchat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 4px 10px 8px; padding: 11px 12px; border-radius: var(--radius);
  color: #fff; font-weight: 700; letter-spacing: 0.02em;
  background: linear-gradient(120deg, var(--accent), #5a8dee);
  box-shadow: 0 0 14px rgba(90, 141, 238, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.newchat:hover { transform: translateY(-1px); box-shadow: 0 0 22px rgba(90, 141, 238, 0.5); }
.searchrow { margin: 0 10px 8px; }
.searchrow input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-input); color: var(--text); font-size: 14px;
}
.convlist { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.convgroup { margin-top: 10px; }
.convgroup h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); padding: 4px 10px; font-weight: 600;
}
.convitem {
  display: flex; align-items: center; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; gap: 8px; font-size: 14px;
  color: var(--text); transition: background 0.1s ease;
}
.convitem .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convitem:hover { background: var(--bg-hover); }
.convitem.on {
  background: var(--bg-hover);
  box-shadow: inset 2px 0 0 var(--accent), 0 0 12px rgba(90, 141, 238, 0.15);
}
.convitem .pin { font-size: 11px; color: var(--accent); }
.side-foot {
  border-top: 1px solid var(--line); padding: 10px 14px calc(10px + var(--sab));
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5a8dee);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
  box-shadow: 0 0 10px rgba(90, 141, 238, 0.4);
}
.side-foot .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot a { color: var(--text-dim); text-decoration: none; font-size: 13px; display: flex; align-items: center; }

/* mobile drawer */
.scrim { display: none; }
@media (max-width: 760px) {
  .sidebar {
    position: fixed; z-index: 30; left: 0; top: 0; bottom: 0;
    transform: translateX(-105%); transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5); width: min(320px, 86vw);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.on {
    display: block; position: fixed; inset: 0; z-index: 29;
    background: rgba(2, 4, 10, 0.55);
  }
}

/* ============ MAIN ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--sat)) 14px 8px; border-bottom: 1px solid var(--line);
  min-height: 52px;
  background: rgba(7, 11, 24, 0.6);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.menubtn { display: none; font-size: 20px; padding: 4px 10px; }
@media (max-width: 760px) { .menubtn { display: block; } }
.topbar .title {
  flex: 1; font-size: 15px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.notice {
  font-size: 12px; color: var(--text-dim); white-space: nowrap;
}

/* ============ MESSAGES ============ */
.msgs { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { .msgs { scroll-behavior: auto; } }
.msgs-inner { max-width: 760px; margin: 0 auto; padding: 18px 16px 8px; }
.msg { margin-bottom: 18px; animation: rise 0.22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: linear-gradient(135deg, var(--bg-user), rgba(90, 141, 238, 0.22));
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 10px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .bubble { max-width: 100%; }
.msg .att-img {
  max-width: min(300px, 100%); border-radius: 10px; display: block; margin-top: 8px;
  border: 1px solid var(--line);
}
.msg .att-pdf {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; color: var(--text-dim); background: var(--bg-panel);
}
.cursor {
  display: inline-block; width: 8px; height: 17px; vertical-align: text-bottom;
  background: var(--accent); border-radius: 2px; animation: blink 1s steps(2) infinite;
  box-shadow: 0 0 8px var(--accent);
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ===== the empty state: reactor ring + greeting + quest chips ===== */
.empty {
  text-align: center; color: var(--text-dim); padding: 9vh 20px 0;
}
.empty .wordmark { font-size: 40px; margin-bottom: 10px; }
.reactor {
  width: 96px; height: 96px; margin: 0 auto 18px; border-radius: 50%;
  border: 3px solid rgba(100, 190, 255, 0.9);
  box-shadow: 0 0 24px rgba(80, 170, 255, 0.55), inset 0 0 18px rgba(80, 170, 255, 0.35);
  display: flex; align-items: center; justify-content: center;
  animation: breathe 3.2s ease-in-out infinite;
}
.reactor::before {
  content: ""; width: 66px; height: 66px; border-radius: 50%;
  border: 2px dashed rgba(120, 200, 255, 0.7);
  animation: spin 24s linear infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 18px rgba(80, 170, 255, 0.4), inset 0 0 14px rgba(80, 170, 255, 0.25); }
  50% { box-shadow: 0 0 34px rgba(80, 170, 255, 0.7), inset 0 0 22px rgba(80, 170, 255, 0.45); }
}
@keyframes spin { to { transform: rotate(360deg); } }
#emptyHello { font-size: 17px; color: var(--text); }
.chips {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  margin-top: 22px;
}
.chip {
  border: 1px solid var(--line); border-radius: 20px; padding: 10px 16px;
  background: var(--bg-panel); color: var(--text); font-size: 14px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.chip:hover {
  transform: translateY(-2px); border-color: var(--accent);
  box-shadow: 0 0 14px rgba(90, 141, 238, 0.35);
}

/* markdown */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h2, .bubble h3, .bubble h4, .bubble h5 { margin: 16px 0 8px; line-height: 1.3; }
.bubble ul, .bubble ol { margin: 0 0 10px 22px; }
.bubble li { margin-bottom: 4px; }
.bubble blockquote {
  border-left: 3px solid var(--accent); padding: 2px 0 2px 12px;
  color: var(--text-dim); margin: 0 0 10px;
}
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.bubble a { color: #8ec2ff; }
.bubble code {
  background: rgba(90, 141, 238, 0.12); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; font-size: 0.88em;
}
.tablewrap { overflow-x: auto; margin: 0 0 10px; }
.bubble table { border-collapse: collapse; font-size: 14px; min-width: 50%; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.bubble th { background: var(--bg-panel); }

/* code blocks */
.codeblock {
  border-radius: 10px; overflow: hidden; margin: 0 0 12px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
.codebar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--code-bg); color: #8b94b3; padding: 4px 6px 4px 12px;
  border-bottom: 1px solid rgba(120, 150, 255, 0.12);
}
.codelang { font-size: 12px; letter-spacing: 0.04em; color: #7fb2ff; }
.copybtn {
  font-size: 12px; color: #c9d2ea; padding: 6px 10px; border-radius: 6px;
  min-height: 32px;
}
.copybtn:hover { background: rgba(130, 160, 255, 0.14); }
.codeblock pre {
  background: var(--code-bg); color: var(--code-text); padding: 12px 14px;
  overflow-x: auto; font-size: 13.5px; line-height: 1.5;
}
.codeblock code { background: none; border: none; padding: 0; font-size: inherit; }
.tok-kw { color: #c792ea; }
.tok-str { color: #a5d6a7; }
.tok-num { color: #f5b971; }
.tok-com { color: #6f7796; font-style: italic; }
.tok-fn { color: #82aaff; }

/* ============ COMPOSER ============ */
.composer {
  padding: 8px 12px calc(12px + var(--sab)); max-width: 792px; margin: 0 auto; width: 100%;
}
.attrow { display: flex; gap: 8px; padding: 0 4px 6px; flex-wrap: wrap; }
.attchip {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; min-height: 32px;
}
.attchip img { width: 26px; height: 26px; object-fit: cover; border-radius: 5px; }
.attchip button { min-height: 24px; padding: 0 4px; color: var(--text-dim); }
.inputrow {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-input);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 24px; padding: 6px 8px 6px 6px;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.inputrow:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(90, 141, 238, 0.3), 0 4px 22px rgba(0, 0, 0, 0.35);
}
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 19px; color: var(--text-dim); flex-shrink: 0;
  min-height: 40px;
}
.iconbtn:hover { background: var(--bg-hover); }
.inputrow textarea {
  flex: 1; resize: none; border: none; background: none; color: var(--text);
  font: inherit; padding: 8px 4px; max-height: 200px; outline: none;
  min-height: 24px;
}
.inputrow textarea::placeholder { color: var(--text-dim); }
.sendbtn {
  width: 40px; height: 40px; min-height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5a8dee);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  box-shadow: 0 0 12px rgba(90, 141, 238, 0.45);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.sendbtn:not(:disabled):hover { transform: scale(1.08); box-shadow: 0 0 20px rgba(90, 141, 238, 0.65); }
.sendbtn:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
.sendbtn.stop { background: var(--danger); box-shadow: 0 0 12px rgba(255, 107, 87, 0.5); }
.capnote {
  text-align: center; font-size: 13px; color: var(--text-dim); padding: 6px 0 0;
}

/* ===== iOS install banner (shown by fun.js when not standalone) ===== */
.installbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(14px + var(--sab));
  z-index: 55; display: flex; align-items: center; gap: 12px;
  background: linear-gradient(120deg, rgba(24, 34, 68, 0.97), rgba(34, 26, 66, 0.97));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(90, 141, 238, 0.2);
  font-size: 14px; animation: rise 0.3s ease;
}
.installbar .ico { font-size: 24px; }
.installbar .txt { flex: 1; line-height: 1.4; }
.installbar .txt b { color: #9fd4ff; }
.installbar .close { color: var(--text-dim); font-size: 18px; padding: 4px 8px; min-height: 32px; }

/* ============ SEARCH RESULTS ============ */
.searchresults { padding: 4px 6px; }
.sr {
  display: block; width: 100%; text-align: left; padding: 8px 10px;
  border-radius: 10px; font-size: 13px;
}
.sr:hover { background: var(--bg-hover); }
.sr .c { font-weight: 600; }
.sr .s { color: var(--text-dim); display: block; margin-top: 2px; }

/* ============ CONTEXT MENU (long-press / ⋯) ============ */
.menu {
  position: fixed; z-index: 50; background: #141b33;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5); min-width: 180px;
}
.menu button { display: block; width: 100%; text-align: left; padding: 11px 16px; font-size: 14px; }
.menu button:hover { background: var(--bg-hover); }
.menu button.danger { color: var(--danger); }

/* ============ ADMIN ============ */
.admin-wrap { height: 100dvh; overflow-y: auto; padding: calc(16px + var(--sat)) 16px 40px; position: relative; z-index: 1; }
.admin-inner { max-width: 860px; margin: 0 auto; }
.admin-inner > h1 { font-size: 26px; margin-bottom: 4px; }
.admin-sub { color: var(--text-dim); margin-bottom: 20px; font-size: 14px; }
.ucard {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-panel); padding: 16px; margin-bottom: 16px;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.ucard .uhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ucard .uhead h2 { font-size: 18px; flex: 1; }
.badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px;
  color: var(--text-dim);
}
.badge.live { color: #5fdd8a; border-color: #5fdd8a; }
.badge.off { color: var(--danger); border-color: var(--danger); }
.ustats { font-size: 13px; color: var(--text-dim); margin: 6px 0 10px; }
.ucard textarea {
  width: 100%; min-height: 140px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-input); color: var(--text); padding: 10px 12px;
  font-size: 13.5px; font-family: ui-monospace, Menlo, monospace; line-height: 1.5;
}
.urow { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.urow label { font-size: 13px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; }
.urow input[type="number"], .urow input[type="text"] {
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-input);
  color: var(--text); padding: 8px 10px; font-size: 14px; width: 130px;
}
.btn {
  background: linear-gradient(120deg, var(--accent), #5a8dee);
  color: #fff; border-radius: 10px; padding: 10px 18px;
  font-weight: 600; font-size: 14px;
  box-shadow: 0 0 10px rgba(90, 141, 238, 0.3);
}
.btn.ghost { background: none; color: #8ec2ff; border: 1px solid var(--accent); box-shadow: none; }
.btn:disabled { opacity: 0.4; }
.reports { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.report { margin-bottom: 10px; }
.report summary { cursor: pointer; font-size: 14px; font-weight: 600; padding: 6px 0; }
.report .bubble { font-size: 14px; padding: 8px 0 0 14px; border-left: 2px solid var(--line); }
.savednote { font-size: 13px; color: #5fdd8a; min-width: 60px; }

.toast {
  position: fixed; bottom: calc(18px + var(--sab)); left: 50%; transform: translateX(-50%);
  background: #141b33; color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 18px; font-size: 14px; z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 16px rgba(90, 141, 238, 0.2);
}
