/* ═══════════════════════════════════════════════════════
   TANYO.ID — Design System
   ═══════════════════════════════════════════════════════ */

:root {
  /* Colors — aligned with TANYO brand (navy bg, cyan-teal-purple gradient) */
  --bg:             #0b0f1a;
  --surface:        #111827;
  --surface2:       #1a2235;
  --surface3:       #212d42;
  --surface-hover:  #1e2940;
  --border:         #263044;
  --border-light:   #2e3a52;

  /* Brand gradient: cyan #00d4ff → teal #00c49a → purple #7c5fff */
  --accent:         #3b82f6;
  --accent-light:   #60a5fa;
  --accent-dim:     #1d4ed8;
  --accent-glow:    rgba(0, 196, 154, 0.22);
  --accent-glow-sm: rgba(0, 212, 255, 0.10);

  /* Brand gradient stops */
  --grad-start:  #00d4ff;
  --grad-mid:    #00c49a;
  --grad-end:    #7c5fff;

  --text:           #ededf5;
  --text-muted:     #8080a0;
  --text-dim:       #50506a;

  --success:        #4ade80;
  --warning:        #fbbf24;
  --error:          #f87171;
  --error-bg:       rgba(248, 113, 113, 0.1);

  /* Layout */
  --nav-height:     56px;
  --sidebar-width:  260px;
  --radius-sm:      8px;
  --radius:         12px;
  --radius-lg:      16px;
  --radius-full:    9999px;

  /* Shadows */
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.6);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.7);
  --shadow-glow:0 0 40px var(--accent-glow);

  /* Transitions */
  --t-fast:   150ms ease;
  --t-base:   220ms ease;
  --t-slow:   380ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Typography */
  --font:     'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:'JetBrains Mono','Fira Code','Cascadia Code',monospace;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  line-height: 1.6;
}

/* ── App Shell ──────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--nav-height) 1fr;
  grid-template-columns: 0fr 1fr;
  height: 100dvh;
  transition: grid-template-columns var(--t-slow);
  overflow: hidden;
}

#mobile-bottom-nav { display: none; }

#app.sidebar-open {
  grid-template-columns: var(--sidebar-width) 1fr;
}

#app:not(.app-mode) #sidebar,
#app:not(.app-mode) #sidebar-toggle { display: none; }

/* ── Top Navigation ─────────────────────────────────── */
#top-nav {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 50;
}

#nav-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#sidebar-toggle {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-base), color var(--t-base);
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--surface2); color: var(--text); }
#sidebar-toggle svg { width: 18px; height: 18px; }

#logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  text-decoration: none;
}
#logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
}
#logo-text {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.03em;
  color: var(--text);
}
#logo-text span { color: var(--grad-start); }

#landing-nav-links {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  margin-left: auto;
  margin-right: 1.5rem;
}
#landing-nav-links a {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-decoration: none;
  transition: color var(--t-base);
}
#landing-nav-links a:hover { color: var(--text); }
#app.app-mode #landing-nav-links { display: none; }

#nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-base);
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}
.btn-nav.ghost {
  color: var(--text-muted);
  border-color: var(--border);
  background: transparent;
}
.btn-nav.ghost:hover {
  color: var(--text);
  border-color: var(--border-light);
  background: var(--surface2);
}
.btn-nav.solid {
  background: linear-gradient(135deg, var(--grad-start), var(--grad-end));
  color: #fff;
  box-shadow: 0 0 16px var(--accent-glow);
  border: none;
}
.btn-nav.solid:hover { opacity: 0.9; }
.btn-nav.danger {
  color: var(--error);
  border-color: var(--border);
  background: transparent;
}
.btn-nav.danger:hover { background: var(--error-bg); border-color: var(--error); }

#user-pill {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}
#user-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
#user-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
#user-name { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); }

/* ── Sidebar ────────────────────────────────────────── */
#sidebar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}

#sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#new-conv-btn {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--t-base);
}
#new-conv-btn:hover {
  border-color: var(--accent);
  color: var(--accent-light);
  background: var(--accent-glow-sm);
}
#new-conv-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
#conv-archive-toggle {
  width: 100%; margin-top: 7px; padding: 7px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim); font-size: .73rem; cursor: pointer;
}
#conv-archive-toggle:hover { background: var(--surface-hover); color: var(--text); }

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.conv-item {
  padding: 8px 8px 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  position: relative;
}
.conv-item-details { display: grid; gap: 2px; min-width: 0; flex: 1; }
.conv-item-actions { display: flex; gap: 3px; flex-shrink: 0; }
.conv-item-actions button {
  padding: 4px 5px; border: 0; border-radius: 5px; background: transparent;
  color: var(--text-dim); font-size: .58rem; cursor: pointer;
}
.conv-item-actions button:hover { background: var(--surface2); color: var(--text); }
.conv-item:hover { background: var(--surface-hover); }
.conv-item.active { background: var(--surface3); }
.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.conv-item-title {
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.conv-item.active .conv-item-title { color: var(--accent-light); }
.conv-item-meta {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.conv-item-agent {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(124, 106, 247, 0.14);
  color: var(--accent-light);
  border-radius: 10px;
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#conv-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ── Main Content ───────────────────────────────────── */
#main-content {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
  min-height: 0;
}

/* ── Landing Page ───────────────────────────────────── */
#landing-page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
#app.app-mode #landing-page { display: none; }
#app:not(.app-mode) #persona-space,
#app:not(.app-mode) #chat-inline { display: none; }

#landing-hero {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: min(760px, calc(100dvh - var(--nav-height)));
  padding: 3.5rem clamp(1.25rem, 5vw, 5rem) 2rem;
  overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,0.045);
}
#landing-hero::before {
  content: '';
  position: absolute;
  z-index: -1;
  width: min(820px, 85vw);
  height: min(820px, 85vw);
  right: -17%;
  top: 46%;
  transform: translateY(-50%);
  background: radial-gradient(circle, rgba(0,196,154,0.11), rgba(59,130,246,0.055) 38%, transparent 70%);
  pointer-events: none;
}
.landing-hero-inner {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(380px, 1.05fr);
  align-items: center;
  gap: clamp(2.5rem, 6vw, 6rem);
}
.landing-hero-copy { position: relative; z-index: 1; }
.landing-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--accent-light);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.landing-eyebrow > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grad-mid);
  box-shadow: 0 0 12px rgba(0,196,154,0.7);
}
.landing-hero h1 {
  max-width: 620px;
  margin: 1.25rem 0 1rem;
  font-size: clamp(2.8rem, 5.2vw, 4.7rem);
  font-weight: 700;
  letter-spacing: -0.065em;
  line-height: 1.04;
}
.landing-hero h1 span,
.landing-section-heading h2 span {
  background: linear-gradient(100deg, var(--grad-start), var(--grad-mid) 52%, #a494ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.landing-lede {
  max-width: 480px;
  color: var(--text-muted);
  font-size: 1.04rem;
  line-height: 1.8;
}
.landing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.8rem;
}
.landing-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.75rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--t-base), border-color var(--t-base), background var(--t-base), box-shadow var(--t-base);
}
.landing-button:hover { transform: translateY(-2px); }
.landing-button svg { width: 16px; height: 16px; }
.landing-button.primary {
  color: #07111a;
  background: linear-gradient(105deg, #70e7ee, #7be2c7 52%, #b4a1ff);
  box-shadow: 0 8px 28px rgba(0,196,154,0.16);
}
.landing-button.primary:hover { box-shadow: 0 10px 34px rgba(0,196,154,0.28); }
.landing-button.secondary {
  color: var(--text);
  border-color: var(--border-light);
  background: rgba(17,24,39,0.55);
}
.landing-button.secondary:hover { border-color: var(--accent-light); background: var(--surface2); }
.landing-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-top: 2rem;
  color: var(--text-dim);
  font-size: 0.72rem;
}
.landing-trust span { display: inline-flex; align-items: center; gap: 0.45rem; }
.landing-trust b { color: var(--accent-light); font-size: 0.65rem; letter-spacing: 0.06em; }

.landing-preview-wrap {
  position: relative;
  width: min(100%, 500px);
  justify-self: end;
  padding: 1.25rem 0.5rem 1.5rem;
}
.landing-hero-video-frame {
  position: relative;
  width: min(100%, 270px);
  aspect-ratio: 9 / 16;
  margin-left: auto;
  overflow: hidden;
  border: 1px solid rgba(162,185,221,0.24);
  border-radius: 28px;
  background: #07111d;
  box-shadow: 0 30px 90px rgba(0,0,0,0.46), 0 0 42px rgba(0,196,154,0.08);
  transform: rotate(1deg);
}
.landing-hero-video-poster,
.landing-hero-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.landing-hero-video-poster { z-index: 0; }
.landing-hero-video {
  z-index: 1;
  opacity: 1;
  transition: opacity 480ms ease;
}
.landing-hero-video-frame.is-transitioning .landing-hero-video { opacity: 0; }
.landing-hero-video-frame.is-transitioning .landing-hero-video-poster {
  filter: blur(5px);
  transform: scale(1.035);
}
.landing-hero-video-poster { transition: filter 480ms ease, transform 480ms ease; }
.landing-hero-video-shade {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4,9,18,.18), transparent 35%, rgba(4,9,18,.12) 58%, rgba(4,9,18,.82));
}
.landing-hero-video-label {
  position: absolute;
  z-index: 3;
  top: 1rem;
  left: 1rem;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .7rem;
  border: 1px solid rgba(255,255,255,.17);
  border-radius: 999px;
  background: rgba(5,12,22,.58);
  color: #e8faff;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .12em;
  backdrop-filter: blur(12px);
}
.landing-hero-video-label i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #58e3cf;
  box-shadow: 0 0 12px rgba(88,227,207,.8);
}
.landing-hero-video-caption {
  position: absolute;
  z-index: 3;
  right: 1.15rem;
  bottom: 1.35rem;
  left: 1.15rem;
  display: grid;
  gap: .25rem;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,.6);
}
.landing-hero-video-caption strong { font-size: clamp(1.05rem, 2vw, 1.35rem); letter-spacing: -.025em; }
.landing-hero-video-caption span { color: rgba(236,245,255,.78); font-size: .78rem; }
.landing-hero-video[hidden] { display: none; }
.landing-orb {
  position: absolute;
  inset: 3% 7% 14% 12%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,212,255,0.12), rgba(124,95,255,0.1) 42%, transparent 72%);
  filter: blur(8px);
  animation: ambient-pulse 6s ease-in-out infinite;
}
.landing-preview {
  position: relative;
  padding: 1.1rem;
  border: 1px solid rgba(162,185,221,0.18);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(24,34,54,0.96), rgba(12,18,31,0.98));
  box-shadow: 0 30px 90px rgba(0,0,0,0.4), inset 0 1px rgba(255,255,255,0.05);
  transform: rotate(1deg);
}
.preview-topbar,
.preview-agent,
.preview-input,
.preview-caption { display: flex; align-items: center; }
.preview-topbar { justify-content: space-between; padding: 0.1rem 0.15rem 0.9rem; border-bottom: 1px solid rgba(255,255,255,0.07); }
.preview-agent { gap: 0.65rem; }
.preview-avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(118,218,234,0.38);
  border-radius: 12px;
  color: #c9fcff;
  background: linear-gradient(145deg, rgba(0,212,255,0.25), rgba(124,95,255,0.22));
  font-weight: 700;
}
.preview-agent b,
.preview-agent small { display: block; }
.preview-agent b { font-size: 0.82rem; letter-spacing: 0.04em; }
.preview-agent small { margin-top: 1px; color: var(--text-dim); font-size: 0.68rem; }
.preview-live { color: var(--text-dim); font-size: 0.58rem; letter-spacing: 0.08em; }
.preview-live i,
.preview-caption span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--success); margin-right: 0.3rem; }
.preview-conversation { display: flex; flex-direction: column; gap: 0.75rem; padding: 1rem 0.25rem; }
.preview-day { margin-bottom: 0.1rem; color: var(--text-dim); font-size: 0.58rem; font-weight: 700; letter-spacing: 0.13em; }
.preview-message {
  max-width: 88%;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(255,255,255,0.055);
  border-radius: 13px;
  font-size: 0.76rem;
  line-height: 1.6;
}
.preview-message.user { align-self: flex-end; color: #edf9ff; background: rgba(59,130,246,0.22); border-bottom-right-radius: 4px; }
.preview-message.assistant { align-self: flex-start; color: #d7dbea; background: rgba(255,255,255,0.045); border-bottom-left-radius: 4px; }
.preview-input {
  justify-content: space-between;
  min-height: 42px;
  padding: 0.4rem 0.45rem 0.4rem 0.8rem;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 0.7rem;
  background: rgba(7,12,22,0.62);
}
.preview-send { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: #07111a; background: #8be2dc; font-size: 1rem; font-weight: 700; }
.preview-caption { gap: 0.25rem; justify-content: center; padding-top: 0.8rem; color: var(--text-dim); font-size: 0.59rem; }
.preview-caption span { width: 5px; height: 5px; margin: 0; background: var(--accent-light); }
.preview-note {
  position: absolute;
  left: -1.5rem;
  bottom: 0.2rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(162,185,221,0.15);
  border-radius: var(--radius-full);
  color: #d9e2f2;
  background: rgba(17,24,39,0.94);
  box-shadow: var(--shadow-md);
  font-size: 0.68rem;
}
.preview-note span { color: #8ee6df; margin-right: 0.35rem; }
.landing-scroll-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 1.3rem;
  color: var(--text-dim);
  font-size: 0.59rem;
  letter-spacing: 0.12em;
  text-decoration: none;
}
.landing-scroll-hint span { width: 18px; height: 25px; border: 1px solid var(--border-light); border-radius: 10px; position: relative; }
.landing-scroll-hint span::after { content: ''; position: absolute; width: 2px; height: 5px; left: 7px; top: 5px; border-radius: 2px; background: var(--accent-light); animation: scroll-hint 1.5s ease infinite; }
@keyframes scroll-hint { 0% { opacity: 0; transform: translateY(0); } 35% { opacity: 1; } 100% { opacity: 0; transform: translateY(7px); } }

.landing-section {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 6.5rem clamp(1.25rem, 5vw, 3rem);
}
.landing-section-heading { max-width: 660px; margin: 0 auto 2.5rem; text-align: center; }
.landing-section-heading h2 { margin: 0.9rem 0 0.65rem; font-size: clamp(2rem, 4vw, 3.1rem); letter-spacing: -0.05em; line-height: 1.12; }
.landing-section-heading > p { color: var(--text-muted); font-size: 0.95rem; line-height: 1.75; }
.landing-feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.landing-feature-card {
  min-height: 275px;
  padding: 1.4rem;
  border: 1px solid rgba(162,185,221,0.12);
  border-radius: 17px;
  background: linear-gradient(145deg, rgba(21,31,49,0.9), rgba(14,20,33,0.88));
  transition: transform var(--t-base), border-color var(--t-base), background var(--t-base);
}
.landing-feature-card:hover { transform: translateY(-4px); border-color: rgba(96,165,250,0.38); background: linear-gradient(145deg, rgba(27,41,64,0.96), rgba(15,23,39,0.94)); }
.feature-index { color: var(--text-dim); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em; }
.feature-icon { width: 43px; height: 43px; display: flex; align-items: center; justify-content: center; gap: 3px; margin: 1.3rem 0 1rem; border: 1px solid rgba(96,165,250,0.22); border-radius: 13px; background: rgba(59,130,246,0.08); }
.conversation-icon span { width: 5px; height: 5px; border-radius: 50%; background: #7ddbe4; }
.conversation-icon span:nth-child(2) { background: #9b91ff; }
.conversation-icon span:nth-child(3) { background: #75d8be; }
.focus-icon span { width: 19px; height: 19px; border: 1.5px solid #8e9fff; border-radius: 50%; position: relative; }
.focus-icon span::after { content: ''; position: absolute; inset: 5px; border: 1px solid #75d8be; border-radius: 50%; }
.space-icon span { width: 6px; height: 17px; border-radius: 4px; background: linear-gradient(#73d8df, #7c6af7); transform: rotate(35deg); }
.space-icon span:nth-child(2) { height: 22px; transform: rotate(-35deg); opacity: 0.75; }
.space-icon span:nth-child(3) { height: 12px; opacity: 0.55; }
.landing-feature-card h3 { margin-bottom: 0.55rem; font-size: 1.02rem; letter-spacing: -0.02em; }
.landing-feature-card p { color: var(--text-muted); font-size: 0.81rem; line-height: 1.75; }
.feature-link { display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 1rem; color: var(--accent-light); font-size: 0.69rem; font-weight: 600; }
.feature-link b { font-size: 0.85rem; }

.landing-quote {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4.5rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.045);
  border-bottom: 1px solid rgba(255,255,255,0.045);
  text-align: center;
  background: radial-gradient(ellipse at 50% 100%, rgba(0,196,154,0.09), transparent 58%);
}
.quote-mark { height: 42px; color: var(--grad-mid); font-family: Georgia,serif; font-size: 4.6rem; line-height: 1; opacity: 0.8; }
.landing-quote p { margin: 0.65rem 0 1.4rem; font-size: clamp(1.4rem, 3.2vw, 2.25rem); font-weight: 600; letter-spacing: -0.04em; line-height: 1.4; }
.landing-quote p span { color: var(--text-muted); }
.landing-faq { max-width: 880px; padding-top: 6rem; padding-bottom: 6rem; }
.landing-faq .landing-section-heading { margin-bottom: 1.8rem; }
.faq-list { border-top: 1px solid var(--border); }
.faq-list details { border-bottom: 1px solid var(--border); }
.faq-list summary { position: relative; padding: 1.15rem 2rem 1.15rem 0; color: var(--text); font-size: 0.91rem; font-weight: 600; cursor: pointer; list-style: none; }
.faq-list summary::-webkit-details-marker { display: none; }
.faq-list summary::after { content: '+'; position: absolute; right: 0; top: 0.85rem; color: var(--accent-light); font-size: 1.3rem; font-weight: 400; }
.faq-list details[open] summary::after { content: '−'; }
.faq-list details p { max-width: 690px; padding: 0 2rem 1.15rem 0; color: var(--text-muted); font-size: 0.83rem; line-height: 1.8; }
.faq-list details a { color: var(--accent-light); text-underline-offset: 3px; }
.landing-footer {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1.25rem, 5vw, 3rem);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.7rem;
}
.footer-brand { color: var(--text); font-size: 0.88rem; font-weight: 800; letter-spacing: -0.03em; text-decoration: none; }
.footer-brand span { color: var(--grad-start); }
.landing-footer > div { display: flex; gap: 1rem; }
.landing-footer a:not(.footer-brand) { color: var(--text-muted); text-decoration: none; }
.landing-footer a:hover { color: var(--text); }

/* ── Persona Space ──────────────────────────────────── */
#persona-space {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  position: relative;
  overflow: hidden;
  transition: flex var(--t-slow), padding var(--t-slow);
}

/* Ambient background gradient */
#persona-space::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow-sm) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: ambient-pulse 6s ease-in-out infinite;
}

@keyframes ambient-pulse {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

#persona-space.chat-mode {
  flex: 0 0 80px;
  padding: 0 1rem;
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}
#persona-space.chat-mode::before { display: none; }

/* ── Character Stage ────────────────────────────────── */
#character-stage {
  width: min(300px, 75vw);
  height: min(300px, 75vw);
  position: relative;
  cursor: pointer;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
  transition: width var(--t-slow), height var(--t-slow), margin var(--t-slow);
}
#character-stage.has-assistant-portrait #character-canvas,
#character-stage.has-assistant-portrait #character-fallback { display: none !important; }
.assistant-portrait {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: 1px solid rgba(143, 229, 226, .35);
  border-radius: 48%;
  box-shadow: 0 20px 70px rgba(25, 68, 91, .3), 0 0 34px rgba(84, 201, 210, .12);
  animation: assistant-idle 4s ease-in-out infinite;
}
.assistant-portrait[hidden] { display: none; }
.assistant-portrait[data-visual-style="manga3d"] { filter: saturate(.72) contrast(1.12); }
.assistant-portrait[data-visual-style="stylized3d"] { filter: saturate(1.18) brightness(1.04); }
@keyframes assistant-idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

#persona-space.chat-mode #character-stage {
  width: 52px;
  height: 52px;
  margin: 0;
}

.orb-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0.2;
  animation: orb-ring-spin 8s linear infinite;
  pointer-events: none;
}
.orb-ring:nth-child(2) {
  inset: -16px;
  border-color: var(--accent-light);
  opacity: 0.1;
  animation-duration: 12s;
  animation-direction: reverse;
}

@keyframes orb-ring-spin {
  from { transform: rotate(0deg) rotateX(60deg); }
  to { transform: rotate(360deg) rotateX(60deg); }
}

#character-canvas {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: block;
}

#character-fallback {
  width: 100%; height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
}
#character-fallback svg { width: 100%; height: 100%; }

/* ── Greeting ───────────────────────────────────────── */
#greeting-text {
  text-align: center;
  max-width: 520px;
  transition: opacity var(--t-slow);
}
#persona-space.chat-mode #greeting-text { display: none; }

#greeting-headline {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 0.35rem;
  line-height: 1.2;
}

#greeting-tagline {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  background: linear-gradient(90deg, var(--grad-start), var(--grad-mid), var(--grad-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.6rem;
}

#greeting-sub {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 1.5rem;
}

#chat-mode-name {
  display: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
#persona-space.chat-mode #chat-mode-name { display: block; }

#chat-mode-status {
  display: none;
  font-size: 0.75rem;
  color: var(--text-dim);
}
#persona-space.chat-mode #chat-mode-status { display: block; }

#open-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.75rem;
  background: linear-gradient(135deg, var(--grad-start), var(--grad-mid), var(--grad-end));
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 28px var(--accent-glow), var(--shadow-sm);
  transition: all var(--t-base);
}
#open-chat-btn:hover {
  opacity: 0.92;
  box-shadow: 0 0 40px var(--accent-glow), var(--shadow-md);
  transform: translateY(-1px);
}
#open-chat-btn:active { transform: translateY(0); }
#open-chat-btn svg { width: 16px; height: 16px; }

/* ── Chat Inline ────────────────────────────────────── */
#chat-inline {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  width: min(1120px, calc(100% - 2.5rem));
  align-self: center;
  margin: 1.25rem auto 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(17, 24, 39, 0.62);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--t-slow), transform var(--t-slow);
  pointer-events: none;
  position: relative;
  isolation: isolate;
}
#chat-inline::before {
  content: '';
  position: absolute;
  inset: 44px 0 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 96% 86%, rgba(53, 117, 139, .11), transparent 38%),
    linear-gradient(140deg, rgba(15, 23, 38, .2), rgba(11, 16, 27, .16));
}
#chat-inline > #chat-toolbar,
#chat-inline > #messages-area,
#chat-inline > #quota-bar,
#chat-inline > #input-wrapper { position: relative; z-index: 1; }
#chat-avatar-backdrop {
  position: absolute;
  z-index: 0;
  inset: 44px 0 94px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 650ms ease;
}
#chat-avatar-backdrop.visible { opacity: 1; }
#chat-avatar-background-image {
  position: absolute;
  right: 2%;
  bottom: 0;
  width: min(42%, 340px);
  height: 100%;
  object-fit: cover;
  object-position: center 24%;
  opacity: .24;
  filter: saturate(.78);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0,0,0,.2) 28%, #000 100%);
  mask-image: linear-gradient(90deg, transparent 0%, rgba(0,0,0,.2) 28%, #000 100%);
  transition: transform 650ms ease, filter 650ms ease;
}
#chat-avatar-backdrop[data-turn="1"] img { transform: translateX(-8px) scale(1.04); filter: saturate(.9) hue-rotate(-8deg); }
#chat-avatar-backdrop[data-turn="2"] img { transform: translateY(-5px) scale(1.07); filter: saturate(.72) hue-rotate(7deg); }
#chat-avatar-backdrop[data-turn="3"] img { transform: translateX(7px) scale(1.03); filter: saturate(.88) hue-rotate(14deg); }
#chat-inline[hidden] { display: none; }
#chat-inline.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

#chat-toolbar {
  padding: 0 1rem;
  height: 44px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 0.75rem;
}
#conv-title-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
#chat-status-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: 0.5rem;
}
.btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-base), color var(--t-base);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon svg { width: 16px; height: 16px; }

/* ── Messages ───────────────────────────────────────── */
#messages-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
  background: transparent;
}
#chat-inline.has-assistant-companion #messages-area { padding-bottom: 125px; }
.assistant-chat-companion {
  position: absolute;
  z-index: 2;
  left: 1rem;
  bottom: 86px;
  display: flex;
  align-items: flex-end;
  gap: .55rem;
  pointer-events: none;
  animation: companion-enter .35s ease both;
}
.assistant-chat-companion[hidden] { display: none; }
.assistant-chat-companion img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border: 1px solid rgba(143, 229, 226, .38);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25), 0 0 12px rgba(84, 201, 210, .1);
  animation: assistant-idle 4s ease-in-out infinite;
}
.assistant-chat-companion[data-visual-style="manga3d"] img { filter: saturate(.72) contrast(1.12); }
.assistant-chat-companion[data-visual-style="stylized3d"] img { filter: saturate(1.18) brightness(1.04); }
.assistant-chat-companion span {
  margin-bottom: .25rem;
  padding: .32rem .55rem;
  border: 1px solid rgba(202, 195, 255, .12);
  border-radius: 999px;
  background: rgba(16, 17, 27, .8);
  color: #d7d5e5;
  font-size: .68rem;
  backdrop-filter: blur(8px);
}
@keyframes companion-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  #chat-avatar-backdrop,
  #chat-avatar-background-image { transition: none; }
  .assistant-chat-companion img { animation: none; }
}

.msg-wrap {
  display: flex;
  gap: 0.6rem;
  animation: msg-in 0.2s ease forwards;
}
.msg-wrap.user { flex-direction: row-reverse; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 2px;
}
.msg-wrap.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--grad-start), var(--grad-end));
  color: #fff;
  font-size: 0.8rem;
  overflow: hidden;
  padding: 2px;
}
.msg-wrap.assistant .msg-avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.msg-wrap.user .msg-avatar {
  background: var(--surface3);
  color: var(--text-muted);
}

.msg {
  max-width: min(560px, 78%);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.7;
  word-break: break-word;
}
.msg.user {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  background: var(--surface2);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.msg.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.msg.system-note {
  background: transparent;
  color: var(--text-dim);
  font-size: 0.78rem;
  text-align: center;
  max-width: 100%;
  border: none;
  padding: 0.25rem;
}

/* Markdown in assistant messages */
.msg.assistant p { margin-bottom: 0.5rem; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant pre {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin: 0.6rem 0;
  line-height: 1.5;
}
.msg.assistant code {
  font-family: var(--font-mono);
  background: var(--surface3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent-light);
}
.msg.assistant pre code {
  background: none;
  padding: 0;
  color: var(--text);
}
.msg.assistant ul, .msg.assistant ol {
  padding-left: 1.4rem;
  margin: 0.4rem 0;
}
.msg.assistant li { margin-bottom: 0.2rem; }
.msg.assistant h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0.75rem 0 0.25rem;
  color: var(--text);
}
.msg.assistant strong { color: var(--text); font-weight: 600; }
.msg.assistant em { color: var(--text-muted); }
.msg.assistant a { color: var(--accent-light); text-underline-offset: 2px; }
.msg.assistant blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
  font-style: italic;
}
.msg.assistant hr { border: none; border-top: 1px solid var(--border); margin: 0.75rem 0; }

/* Typing indicator */
.typing-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0.75rem 0.9rem;
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.4s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input Area ─────────────────────────────────────── */
#input-wrapper {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#chat-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0 0 0.55rem;
  scrollbar-width: thin;
}
.chat-tool-btn {
  flex: 0 0 auto;
  min-height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.65rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.chat-tool-btn:hover,
.chat-tool-btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-light);
  background: var(--accent-glow-sm);
}
.translate-target-label {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 0.72rem;
}
#translate-target {
  flex: 0 0 auto;
  min-height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  padding: 0.25rem 0.4rem;
  font: inherit;
  font-size: 0.75rem;
}

#input-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.5rem 0.5rem 0.85rem;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
#input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  outline: none;
  line-height: 1.6;
  padding: 0.2rem 0;
  align-self: center;
}
#chat-input::placeholder { color: var(--text-dim); }

#send-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-base);
  box-shadow: 0 0 12px var(--accent-glow);
}
#send-btn:hover { background: var(--accent-light); transform: scale(1.05); }
#send-btn:active { transform: scale(0.97); }
#send-btn:disabled { background: var(--surface3); box-shadow: none; cursor: not-allowed; opacity: 0.5; }
#send-btn svg { width: 16px; height: 16px; }

#image-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#image-btn:hover { color: var(--accent-light); background: var(--surface3); }
#image-btn svg { width: 19px; height: 19px; }

.reminders-box { width: min(560px, 100%); }
.reminders-box h2 { margin: 0 0 0.4rem; color: var(--text); }
.reminders-box .subtitle { color: var(--text-muted); line-height: 1.5; }
#reminders-form { display: grid; gap: 0.5rem; }
#reminders-form label { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
#reminders-form input {
  min-width: 0;
  width: 100%;
  min-height: 2.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
}
#reminders-status { margin-top: 0.5rem; color: var(--text-dim); font-size: 0.8rem; }
#reminders-list { display: grid; gap: 0.5rem; margin-top: 0.75rem; }
.reminder-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.4rem 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.reminder-item-title { color: var(--text); overflow-wrap: anywhere; }
.reminder-item-time { color: var(--text-dim); font-size: 0.75rem; }
.reminder-item.completed { opacity: 0.65; }
.reminder-item-actions { display: flex; gap: 0.35rem; }
.reminder-item-actions button { min-height: 2.2rem; }
.reminder-item.completed .reminder-item-title { text-decoration: line-through; }

#quota-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.3rem 0.1rem 0;
  min-height: 18px;
}
#quota-badge {
  padding: 0.25rem 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  font: inherit;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: color var(--t-base), background var(--t-base), border-color var(--t-base);
}
#quota-badge:hover { color: var(--text); background: var(--surface2); border-color: var(--border); }
#quota-badge.warn { color: var(--warning); }
#quota-badge.danger { color: var(--error); }

/* ── Status Bar ─────────────────────────────────────── */
#status-bar {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  color: var(--text-muted);
  z-index: 20;
  opacity: 0;
  transition: opacity var(--t-base);
  pointer-events: none;
  white-space: nowrap;
}
#status-bar.visible { opacity: 1; }

/* ── Builder and Plan Modals ────────────────────────── */
.workspace-modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--t-base), visibility 0s linear var(--t-base);
}
.workspace-modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  transition: opacity var(--t-base), visibility 0s;
}
.workspace-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(7px);
}
.workspace-box {
  position: relative;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: scale(0.97) translateY(8px);
  transition: transform var(--t-slow);
}
.workspace-modal.open .workspace-box { transform: scale(1) translateY(0); }
.workspace-box h2 { margin: 0 2rem 0.35rem 0; font-size: 1.3rem; letter-spacing: -0.03em; }
.workspace-box > .subtitle { margin: 0 0 1.25rem; color: var(--text-muted); font-size: 0.83rem; line-height: 1.6; }
.workspace-box .form-group input,
.workspace-box .form-group textarea,
.builder-field-card input:not([type=checkbox]),
.builder-field-card select,
.builder-field-card textarea,
.builder-share input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text);
  background: var(--surface2);
  font: inherit;
  font-size: 0.86rem;
}
.workspace-box .form-group textarea,
.builder-field-card textarea { resize: vertical; }
.workspace-box .form-group input:focus,
.workspace-box .form-group textarea:focus,
.builder-field-card input:focus,
.builder-field-card select:focus,
.builder-field-card textarea:focus { border-color: var(--accent-light); }
.builder-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.builder-list-info { display: flex; flex: 1; flex-direction: column; gap: 0.2rem; min-width: 0; }
.builder-list-info strong { overflow: hidden; color: var(--text); font-size: 0.86rem; text-overflow: ellipsis; white-space: nowrap; }
.builder-list-info span { color: var(--text-dim); font-size: 0.7rem; }
.builder-empty { padding: 1rem; color: var(--text-muted); text-align: center; font-size: 0.82rem; }
.builder-editor-toolbar { display: flex; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.builder-fields-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin: 1.25rem 0 0.65rem; }
.builder-fields-heading h3 { margin: 0; font-size: 0.92rem; }
.builder-fields-heading p { margin: 0.15rem 0 0; color: var(--text-dim); font-size: 0.7rem; }
.builder-field-card { margin: 0.65rem 0; padding: 0.9rem; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(26,34,53,0.65); }
.builder-field-card > .builder-field-label,
.builder-field-card > .builder-field-type { display: block; margin-bottom: 0.65rem; }
.builder-field-card > div > label { display: block; margin-bottom: 0.3rem; color: var(--text-muted); font-size: 0.7rem; }
.builder-field-card select { appearance: auto; }
.builder-field-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 0.7rem; }
.builder-required { display: inline-flex !important; align-items: center; gap: 0.4rem; margin: 0 !important; color: var(--text-muted); font-size: 0.74rem !important; }
.builder-required input { accent-color: var(--accent); }
.builder-publish-row { display: flex; gap: 0.65rem; margin: 0.8rem 0 1.2rem; }
.builder-publish-row .btn-primary { flex: 1; margin: 0; }
.builder-share { margin: 1rem 0; padding: 0.9rem; border: 1px solid rgba(74,222,128,0.2); border-radius: var(--radius); background: rgba(74,222,128,0.04); }
.builder-share > label { display: block; margin-bottom: 0.45rem; color: var(--success); font-size: 0.75rem; font-weight: 600; }
.builder-share > div { display: flex; gap: 0.5rem; }
.builder-share input { min-width: 0; }
.builder-responses { padding-top: 0.6rem; border-top: 1px solid var(--border); }
.builder-response-empty { color: var(--text-dim); font-size: 0.78rem; }
.builder-response-item { margin-top: 0.55rem; padding: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: rgba(26,34,53,0.5); }
.builder-response-item > time { display: block; margin-bottom: 0.5rem; color: var(--text-dim); font-size: 0.66rem; }
.builder-response-item > div { display: grid; grid-template-columns: minmax(120px, 0.5fr) 1fr; gap: 0.5rem; padding: 0.25rem 0; font-size: 0.75rem; }
.builder-response-item strong { color: var(--text-muted); }
.builder-response-item span { overflow-wrap: anywhere; }
.plan-eyebrow { color: var(--accent-light); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.13em; }
.plan-box { width: min(600px, 100%); }
.plan-usage { padding: 0.7rem 0.85rem; border-radius: var(--radius-sm); background: var(--surface2); color: var(--text); font-size: 0.82rem; }
.plan-tier { display: grid; grid-template-columns: 0.7fr 1fr 1.5fr 2fr; align-items: center; gap: 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.plan-tier.current { color: var(--success); }
.plan-tier h3 { margin: 0; font-size: 0.86rem; }
.plan-tier > span,
.plan-tier p { margin: 0; color: var(--text-muted); font-size: 0.7rem; line-height: 1.5; }
.plan-tier.current > span { color: var(--success); }
.plan-note { margin-top: 1rem; padding: 0.75rem; border: 1px solid rgba(251,191,36,0.18); border-radius: var(--radius-sm); color: var(--text-muted); background: rgba(251,191,36,0.04); font-size: 0.72rem; line-height: 1.6; }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.status-dot.thinking { background: var(--accent); animation: status-blink 0.8s ease infinite; }
.status-dot.speaking { background: var(--success); animation: status-blink 0.5s ease infinite; }
@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ── Auth Modal ─────────────────────────────────────── */
#auth-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
#auth-modal.open { opacity: 1; pointer-events: all; }

#auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#auth-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  width: min(420px, 100%);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent-glow-sm);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--t-slow), opacity var(--t-base);
}
#auth-modal.open #auth-box {
  transform: scale(1) translateY(0);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.auth-logo-img {
  width: 36px; height: 36px;
  border-radius: 9px;
  object-fit: cover;
}
.auth-logo-text { font-weight: 800; font-size: 1rem; }
.auth-logo-text span { color: var(--grad-start); }

#auth-box h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
#auth-box .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
  line-height: 1.5;
}

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.form-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}
.form-group input::placeholder { color: var(--text-dim); }

.btn-primary {
  width: 100%;
  padding: 0.7rem;
  background: linear-gradient(135deg, var(--grad-start), var(--grad-mid), var(--grad-end));
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all var(--t-base);
  margin-top: 0.25rem;
  box-shadow: 0 0 20px var(--accent-glow);
}
.btn-primary:hover { opacity: 0.9; box-shadow: 0 0 28px var(--accent-glow); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  color: var(--text-dim);
  font-size: 0.8rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#google-btn-container {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 44px;
}
#google-btn-container > div {
  width: 100% !important;
  max-width: 360px;
}
.auth-toggle {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.83rem;
  color: var(--text-muted);
}
.auth-toggle a {
  color: var(--accent-light);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
}
.auth-toggle a:hover { text-decoration: underline; }

.auth-legal {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.auth-legal a { color: var(--text-dim); text-decoration: none; }
.auth-legal a:hover { color: var(--text-muted); }

.form-error {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 0.4rem;
  min-height: 1.1em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* ── Sidebar Overlay (mobile) ───────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--nav-height) 0 0 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* ── Scrollbars ─────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Utility ────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Tablet ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }

  #greeting-headline { font-size: clamp(1.4rem, 3.5vw, 2rem); }
}

@media (max-width: 900px) {
  .landing-hero-inner { grid-template-columns: minmax(0, 0.9fr) minmax(330px, 1.1fr); gap: 2rem; }
  .landing-preview-wrap { padding-right: 0; }
  .preview-note { left: -0.5rem; }
  .landing-feature-card { padding: 1.2rem; }
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 767px) {
  #input-wrapper { padding: 0.5rem 0.65rem max(0.65rem, env(safe-area-inset-bottom)); }
  #chat-tools { margin: 0 -0.15rem; }
  .chat-tool-btn { min-height: 2.25rem; }
  #translate-target { min-height: 2.25rem; }
  .reminders-box { padding: 1.35rem 1rem; }
  :root { --mobile-tab-height: 68px; }
  #app {
    grid-template-columns: 0 1fr !important;
    grid-template-rows: var(--nav-height) minmax(0, 1fr) calc(var(--mobile-tab-height) + env(safe-area-inset-bottom, 0px));
    transition: none;
  }
  #landing-nav-links { display: none; }
  #top-nav { padding: 0 0.75rem; }
  #nav-left { gap: 0.25rem; }
  #logo-text { font-size: 0.95rem; }
  #sidebar-toggle { display: none !important; }
  #nav-actions { gap: 0.25rem; }
  #nav-actions > :not(#user-pill) { display: none !important; }
  #user-pill { border: 0; background: transparent; padding: 0.2rem; }
  #user-avatar { width: 31px; height: 31px; }
  #main-content { grid-column: 1 / -1; grid-row: 2; }
  #mobile-bottom-nav {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    position: relative;
    z-index: 60;
    min-height: calc(var(--mobile-tab-height) + env(safe-area-inset-bottom, 0px));
    padding: 0.35rem 0.45rem max(0.35rem, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(13, 18, 30, 0.88);
    -webkit-backdrop-filter: blur(24px) saturate(1.35);
    backdrop-filter: blur(24px) saturate(1.35);
    box-shadow: 0 -12px 32px rgba(0,0,0,0.2);
  }
  .mobile-tab {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.18rem;
    min-width: 0;
    min-height: 3rem;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 0.62rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 180ms ease, transform 180ms ease, background 180ms ease;
  }
  .mobile-tab svg { width: 21px; height: 21px; }
  .mobile-tab[aria-current="page"] { color: #b6a8ff; }
  .mobile-tab[aria-current="page"]::before {
    content: '';
    position: absolute;
    top: -0.38rem;
    width: 22px;
    height: 3px;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--grad-start), var(--grad-end));
    box-shadow: 0 0 12px rgba(124,95,255,.55);
    animation: mobile-tab-enter 260ms cubic-bezier(.2,.8,.2,1) both;
  }
  .mobile-tab:active { transform: scale(.92); }
  .mobile-tab-primary { color: var(--text-muted); }
  .mobile-tab-primary[aria-current="page"] { color: #fff; }
  .mobile-chat-orb {
    display: grid;
    place-items: center;
    width: 48px;
    height: 42px;
    margin-top: -1.05rem;
    border: 1px solid rgba(255,255,255,.26);
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, #7161f5 0%, #507ef6 52%, #20b9c9 100%);
    box-shadow: 0 8px 22px rgba(83, 102, 235, .38), inset 0 1px 0 rgba(255,255,255,.28);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1), box-shadow 220ms ease;
    animation: mobile-orb-breathe 3.2s ease-in-out infinite;
  }
  .mobile-chat-orb svg { width: 22px; height: 22px; }
  .mobile-tab-primary:active .mobile-chat-orb { transform: translateY(2px) scale(.93); }
  .mobile-tab-primary[aria-current="page"] .mobile-chat-orb {
    box-shadow: 0 0 0 5px rgba(111, 106, 250, .12), 0 9px 28px rgba(83, 102, 235, .48), inset 0 1px 0 rgba(255,255,255,.3);
  }
  .mobile-account-avatar {
    display: grid;
    place-items: center;
    width: 21px;
    height: 21px;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 50%;
    background: linear-gradient(145deg, #363354, #1d7f91);
    color: #f1efff;
    font-size: 0.62rem;
    font-weight: 700;
  }
  #mobile-account-tab[aria-current="page"] .mobile-account-avatar { box-shadow: 0 0 0 2px rgba(182,168,255,.35); }
  .mobile-account-sheet {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    visibility: hidden;
    pointer-events: none;
  }
  .mobile-account-sheet.open { visibility: visible; pointer-events: auto; }
  .mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(2, 5, 12, .68);
    opacity: 0;
    transition: opacity 240ms ease;
    -webkit-backdrop-filter: blur(0);
    backdrop-filter: blur(0);
  }
  .mobile-account-sheet.open .mobile-sheet-backdrop { opacity: 1; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
  .mobile-sheet-panel {
    position: relative;
    width: min(100%, 560px);
    padding: 0.55rem 1.15rem max(1.2rem, env(safe-area-inset-bottom, 0px));
    border: 1px solid rgba(255,255,255,.12);
    border-bottom: 0;
    border-radius: 24px 24px 0 0;
    background: linear-gradient(150deg, rgba(28,36,57,.98), rgba(15,21,35,.99));
    box-shadow: 0 -18px 60px rgba(0,0,0,.4);
    transform: translateY(30px);
    opacity: .8;
    transition: transform 300ms cubic-bezier(.2,.8,.2,1), opacity 240ms ease;
  }
  .mobile-account-sheet.open .mobile-sheet-panel { transform: translateY(0); opacity: 1; }
  .mobile-sheet-handle { width: 38px; height: 4px; margin: 0 auto 1rem; border-radius: 99px; background: rgba(255,255,255,.23); }
  .mobile-account-heading { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.1rem; }
  .mobile-account-avatar.large { width: 46px; height: 46px; font-size: 1rem; }
  .mobile-account-heading h2 { color: var(--text); font-size: 1rem; }
  .mobile-account-heading p { color: var(--text-muted); font-size: .75rem; }
  .mobile-sheet-close { margin-left: auto; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 50%; background: rgba(255,255,255,.04); color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
  .mobile-account-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .55rem; }
  .mobile-account-grid[hidden] { display: none; }
  .mobile-account-grid button {
    display: grid;
    justify-items: center;
    gap: .38rem;
    min-width: 0;
    min-height: 72px;
    padding: .65rem .2rem;
    border: 1px solid rgba(255,255,255,.075);
    border-radius: 15px;
    background: rgba(255,255,255,.035);
    color: var(--text-muted);
    font: inherit;
    font-size: .65rem;
    cursor: pointer;
    transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
  }
  .mobile-account-grid button:active { transform: scale(.95); background: rgba(124,95,255,.12); border-color: rgba(124,95,255,.4); }
  .mobile-account-grid button span { color: #b4a7ff; font-size: 1.2rem; line-height: 1; }
  .mobile-account-footer { display: flex; align-items: center; gap: .9rem; margin-top: 1rem; color: var(--text-dim); font-size: .72rem; }
  .mobile-account-footer a { color: var(--text-dim); text-decoration: none; }
  .mobile-account-footer button { margin-left: auto; border: 0; background: transparent; color: #ff8a98; font: inherit; font-size: .75rem; cursor: pointer; }
  @keyframes mobile-tab-enter { from { opacity: 0; transform: scaleX(.35); } to { opacity: 1; transform: scaleX(1); } }
  @keyframes mobile-orb-breathe {
    0%, 100% { box-shadow: 0 8px 22px rgba(83, 102, 235, .38), inset 0 1px 0 rgba(255,255,255,.28); }
    50% { box-shadow: 0 10px 28px rgba(83, 102, 235, .52), inset 0 1px 0 rgba(255,255,255,.32); }
  }
  #sidebar {
    top: var(--nav-height);
    bottom: calc(var(--mobile-tab-height) + env(safe-area-inset-bottom, 0px));
  }
  #sidebar-overlay { bottom: calc(var(--mobile-tab-height) + env(safe-area-inset-bottom, 0px)); }

  #sidebar {
    position: fixed;
    left: 0;
    top: var(--nav-height);
    bottom: 0;
    width: min(80vw, 280px);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--t-slow);
    box-shadow: var(--shadow-lg);
  }
  #app.sidebar-open #sidebar { transform: translateX(0); }
  #app.sidebar-open #sidebar-overlay { display: block; }

  #landing-hero {
    min-height: auto;
    padding: 3.5rem 1.25rem 1.6rem;
  }
  .landing-hero-inner { grid-template-columns: minmax(0, 1fr); gap: 2.1rem; }
  .landing-hero h1 { max-width: 560px; margin-top: 1rem; font-size: clamp(2.65rem, 11vw, 4rem); }
  .landing-lede { font-size: 0.95rem; }
  .landing-trust { gap: 0.8rem; margin-top: 1.5rem; }
  .landing-preview-wrap { width: min(100%, 500px); justify-self: center; padding: 0.25rem 0.25rem 1.3rem; }
  .landing-preview { padding: 0.9rem; border-radius: 18px; transform: none; }
  .landing-hero-video-frame { width: min(270px, 70vw); margin: 0 auto; transform: none; }
  .preview-note { left: 0; bottom: 0; }
  .landing-scroll-hint { margin-top: 1.1rem; }
  .landing-section { padding: 4.5rem 1.25rem; }
  .landing-section-heading { margin-bottom: 1.7rem; }
  .landing-feature-grid { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
  .landing-feature-card { min-height: auto; padding: 1.25rem; }
  .feature-icon { margin: 1rem 0 0.75rem; }
  .landing-quote { padding: 3.5rem 1.25rem; }
  .landing-faq { padding-top: 4.5rem; padding-bottom: 4.5rem; }
  .landing-footer { align-items: flex-start; flex-wrap: wrap; }
  .landing-footer > span { order: 3; width: 100%; }

  /* Nav — hide username, shrink actions */
  #user-name { display: none; }
  #user-pill { padding: 0.3rem 0.5rem; }
  .btn-nav { padding: 0.38rem 0.65rem; font-size: 0.78rem; }
  #builder-btn { width: 34px; height: 34px; justify-content: center; padding: 0; }
  #builder-btn span { display: none; }
  #builder-btn svg { width: 16px; height: 16px; }
  .workspace-box { padding: 1.5rem 1rem; max-height: 94dvh; }
  .builder-fields-heading { align-items: flex-start; }
  .builder-fields-heading .btn-ghost { white-space: nowrap; }
  .plan-tier { grid-template-columns: 0.6fr 1fr; }
  .plan-tier p { grid-column: span 2; }
  .builder-publish-row { flex-direction: column; }

  /* Persona space */
  #persona-space { padding: 1.25rem 1rem; }
  #character-stage {
    width: min(200px, 60vw);
    height: min(200px, 60vw);
    margin-bottom: 1rem;
  }
  #greeting-headline { font-size: clamp(1.3rem, 6vw, 1.7rem); }
  #greeting-tagline { font-size: 0.68rem; }
  #greeting-sub { font-size: 0.88rem; line-height: 1.6; margin-bottom: 1.25rem; }
  #greeting-sub br { display: none; }
  #open-chat-btn { padding: 0.65rem 1.4rem; font-size: 0.88rem; }

  /* Chat */
  #conv-title-display { max-width: calc(100vw - 120px); }
  .msg { max-width: 90%; }
  #chat-toolbar { padding: 0 0.75rem; }
  #chat-inline { width: calc(100% - 1rem); margin: 0.75rem auto 1rem; border-radius: 14px; }
  #messages-area { padding: 0.85rem 0.75rem 0.5rem; }
  #chat-inline.has-assistant-companion #messages-area { padding-bottom: 105px; }
  .assistant-chat-companion { left: .65rem; bottom: 76px; gap: .35rem; }
  .assistant-chat-companion img { width: 40px; height: 40px; border-radius: 50%; }
  #chat-avatar-backdrop { bottom: 88px; }
  #chat-avatar-background-image { right: 0; width: min(52%, 240px); opacity: .18; }
  .assistant-chat-companion span { font-size: .62rem; }
  #input-wrapper { padding: 0.55rem 0.65rem; }

  /* Auth modal — full screen friendly */
  #auth-modal { padding: 0.75rem; align-items: flex-end; }
  #auth-box {
    padding: 1.75rem 1.5rem;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-sm);
    max-height: 92dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Status bar */
  #status-bar { font-size: 0.72rem; padding: 0.3rem 0.75rem; bottom: 0.75rem; }
}

/* ── Button label swap on mobile ─────────────────────── */
.btn-short { display: none; }
@media (max-width: 380px) {
  .btn-full { display: none; }
  .btn-short { display: inline; }
}

/* ── Small phones ────────────────────────────────────── */
@media (max-width: 380px) {
  #auth-box { padding: 1.5rem 1.25rem; }
  #auth-box h2 { font-size: 1.15rem; }
}

/* ── iOS safe area (bottom nav bar) ─────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Persona Modal ──────────────────────────────────── */
#persona-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
#persona-modal.open { opacity: 1; pointer-events: all; }
#persona-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#persona-modal .modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent-glow-sm);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--t-slow);
}
#persona-modal.open .modal-box { transform: scale(1) translateY(0); }
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  transition: color var(--t-base), background var(--t-base);
}
.modal-close:hover { color: var(--text); background: var(--surface2); }
#persona-modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
#persona-modal .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.form-group select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}

@media (max-width: 767px) {
  #persona-modal { padding: 0.75rem; align-items: flex-end; }
  #persona-modal .modal-box {
    width: 100%;
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
  }
  .form-row { grid-template-columns: 1fr; gap: 0; }
}

/* ── Memory Modal ───────────────────────────────────── */
#memory-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
#memory-modal.open { opacity: 1; pointer-events: all; }
#memory-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#memory-modal .modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent-glow-sm);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--t-slow);
}
#memory-modal.open .modal-box { transform: scale(1) translateY(0); }
#memory-modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
#memory-modal .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
#memory-form { margin-bottom: 1.25rem; }
#memory-form .form-row { margin-bottom: 1rem; }
#memory-form .btn-primary { margin-top: 0.5rem; }
#memory-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.memory-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}
.memory-cat {
  display: inline-block;
  background: var(--accent-glow-sm);
  color: var(--accent-light);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.memory-fact {
  flex: 1;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}
.memory-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t-base), background var(--t-base);
}
.memory-del:hover { color: #ff6a7a; background: rgba(255,106,122,0.1); }

@media (max-width: 767px) {
  #memory-modal { padding: 0.75rem; align-items: flex-end; }
  #memory-modal .modal-box {
    width: 100%;
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
  }
}

/* ── Dictionary Modal ───────────────────────────────── */
#dict-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
#dict-modal.open { opacity: 1; pointer-events: all; }
#dict-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#dict-modal .modal-box {
  width: min(720px, 100%);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--t-slow);
}
#dict-modal.open .modal-box { transform: scale(1) translateY(0); }
#dict-modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
#dict-modal .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

#dict-search-wrap {
  position: relative;
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#dict-search {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
#dict-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}
#dict-counter {
  color: var(--text-dim);
  font-size: 0.75rem;
  white-space: nowrap;
}

#dict-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 55vh;
  overflow-y: auto;
}
.dict-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
}
.dict-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}
.dict-term {
  font-weight: 600;
  color: var(--text);
  font-size: 0.98rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dict-pair {
  font-size: 0.68rem;
  color: var(--accent);
  background: var(--accent-glow-sm);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.dict-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t-base), background var(--t-base);
}
.dict-del:hover { color: #ff6a7a; background: rgba(255,106,122,0.1); }
.dict-meaning {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}
.dict-example {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 0.3rem;
  font-style: italic;
  line-height: 1.4;
}

@media (max-width: 767px) {
  #dict-modal { padding: 0.5rem; align-items: flex-end; }
  #dict-modal .modal-box {
    width: 100%;
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 94vh;
  }
}

/* ── Data (Spreadsheet) Modal ───────────────────────── */
#data-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
#data-modal.open { opacity: 1; pointer-events: all; }
#data-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#data-modal .modal-box,
.modal-box-wide {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: min(960px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent-glow-sm);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--t-slow);
}
#data-modal.open .modal-box { transform: scale(1) translateY(0); }
#data-modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}
#data-modal .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

#data-sheets {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}
.data-import-form {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.data-import-form > div { display: grid; gap: 0.4rem; min-width: 0; }
.data-import-form label,
.data-table-controls label,
.data-ai-form > label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.data-import-form input[type="file"] {
  max-width: 100%;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}
.data-import-form small { color: var(--text-dim); font-size: 0.75rem; }
.sheet-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.sheet-info { flex: 1; min-width: 0; }
.sheet-name {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-meta {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-top: 0.15rem;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: border-color var(--t-base), background var(--t-base), color var(--t-base);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost.danger:hover { border-color: #ff6a7a; color: #ff6a7a; }

#data-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
#data-sheet-title {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  min-width: 0;
}
#data-sheet-title:focus,
#data-sheet-title:hover { border-color: var(--border); outline: none; }
#data-editor-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.data-analysis {
  display: grid;
  gap: 0.8rem;
  margin: 0.85rem 0;
}
.data-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem;
}
.data-metric {
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.data-metric span,
.data-metric strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-metric span { color: var(--text-dim); font-size: 0.72rem; }
.data-metric strong { margin-top: 0.2rem; color: var(--text); font-size: 0.95rem; }
.data-table-controls {
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr) auto minmax(120px, 0.75fr);
  align-items: center;
  gap: 0.5rem;
}
.data-table-controls input,
.data-table-controls select,
.data-chart-heading select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.82rem;
}
.data-chart-panel {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.data-chart-heading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.data-chart-heading strong { margin-right: auto; font-size: 0.82rem; }
.data-chart-heading label { color: var(--text-dim); font-size: 0.75rem; }
.data-chart-heading select { width: auto; max-width: 45%; }
.data-chart {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}
.data-chart-row {
  display: grid;
  grid-template-columns: minmax(60px, 1fr) minmax(50px, 2fr) auto;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.data-chart-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-chart-track {
  display: block;
  height: 0.45rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}
.data-chart-track > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.data-chart-row strong { color: var(--text); font-size: 0.75rem; }
.data-ai-form {
  display: grid;
  gap: 0.5rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.data-ai-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 0.6rem;
  font: inherit;
  font-size: 0.85rem;
}
.data-ai-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
#data-ai-status { color: var(--text-dim); font-size: 0.8rem; }
.data-ai-result,
.data-ai-proposal {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}
.data-ai-result p,
.data-ai-proposal p { margin: 0; line-height: 1.55; }
.data-ai-result small,
.data-ai-proposal small { color: var(--text-dim); }
.data-ai-proposal ul { margin: 0; padding-left: 1.2rem; }

#data-grid-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 60vh;
}
#data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
#data-grid th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  z-index: 1;
  white-space: nowrap;
}
#data-grid th:last-child { border-right: none; }
#data-grid th .col-name {
  cursor: pointer;
  display: inline-block;
  padding-right: 0.4rem;
}
#data-grid th .col-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 0.3rem;
  font-size: 1rem;
  line-height: 1;
}
#data-grid th .col-del:hover { color: #ff6a7a; }
#data-grid td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  vertical-align: middle;
}
#data-grid td:last-child { border-right: none; }
#data-grid td input[type="text"],
#data-grid td input[type="number"],
#data-grid td input[type="date"] {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
}
#data-grid td input:focus {
  background: var(--surface2);
  box-shadow: inset 0 0 0 1px var(--accent);
}
#data-grid td input[type="checkbox"] {
  margin: 0.5rem 0.6rem;
}
#data-grid .cell-pad { width: 2rem; text-align: center; }
#data-grid .col-pad { width: 2rem; }
#data-grid .row-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  line-height: 1;
}
#data-grid .row-del:hover { color: #ff6a7a; }
#data-grid .row-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 1.25rem;
  font-size: 0.85rem;
}

@media (max-width: 767px) {
  #data-modal { padding: 0; align-items: stretch; }
  #data-modal .modal-box {
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    padding: max(1rem, env(safe-area-inset-top)) 0.85rem max(1rem, env(safe-area-inset-bottom));
    border-radius: 0;
  }
  #data-modal .modal-close { top: 0.75rem; right: 0.75rem; }
  #data-editor-toolbar { flex-wrap: wrap; align-items: stretch; }
  #data-sheet-title { min-width: calc(100% - 3rem); padding-right: 2.7rem; }
  #data-editor-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #data-editor-actions > * { justify-content: center; min-height: 2.6rem; }
  #data-grid-wrap { max-height: 50dvh; overflow: auto; }
  .data-import-form { align-items: stretch; flex-direction: column; }
  .data-import-form .btn-ghost { justify-content: center; min-height: 2.7rem; }
  .data-table-controls { grid-template-columns: 1fr 1fr; }
  .data-table-controls .data-search-label { grid-column: 1 / -1; }
  .data-chart-heading { flex-wrap: wrap; }
  .data-chart-heading strong { width: 100%; }
  .data-chart-heading select { max-width: 60%; }
  #data-grid,
  #data-grid tbody { display: block; width: 100%; }
  #data-grid thead { display: none; }
  #data-grid tbody tr:not(:has(.row-empty)) {
    display: grid;
    gap: 0.35rem;
    margin: 0.55rem;
    padding: 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
  }
  #data-grid td:not(.row-empty) {
    display: grid;
    grid-template-columns: minmax(70px, 34%) minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    border: 0;
    padding: 0.25rem 0;
  }
  #data-grid td:not(.row-empty)::before {
    content: attr(data-label);
    overflow: hidden;
    color: var(--text-dim);
    font-size: 0.75rem;
    text-overflow: ellipsis;
  }
  #data-grid td input[type="text"],
  #data-grid td input[type="number"],
  #data-grid td input[type="date"] {
    min-width: 0;
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    background: var(--surface);
    font-size: 16px;
  }
  #data-grid td.cell-pad { grid-template-columns: 1fr; justify-items: end; }
  #data-grid td.cell-pad::before { content: ''; }
  #data-grid .row-del { min-width: 2.4rem; min-height: 2.4rem; }
  #data-grid .row-empty { display: block; }
}

/* ── Agent Pill (toolbar) ───────────────────────────── */
.agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.26rem 0.55rem 0.26rem 0.45rem;
  background: rgba(124, 106, 247, 0.12);
  color: var(--accent-light);
  border: 1px solid rgba(124, 106, 247, 0.28);
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.agent-pill:hover {
  background: rgba(124, 106, 247, 0.2);
  border-color: rgba(124, 106, 247, 0.45);
}
.agent-pill-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
}
.agent-pill-icon svg { width: 14px; height: 14px; }
.agent-pill-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Agent Modal ────────────────────────────────────── */
#agent-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(var(--nav-height) + 3.25rem) 1rem 1rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--t-base), visibility 0s linear var(--t-base);
}
#agent-modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  transition: opacity var(--t-base), visibility 0s;
}
#agent-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3,8,18,0.42);
}
#agent-modal .modal-box {
  position: relative;
  width: min(520px, 100%);
  max-height: min(78vh, 680px);
  overflow-y: auto;
  padding: 1.35rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: rgba(17,24,39,0.98);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(96,165,250,0.06);
  transform: translateY(-8px) scale(0.98);
  transition: transform var(--t-base);
}
#agent-modal.open .modal-box { transform: translateY(0) scale(1); }
#agent-modal h2 {
  margin-bottom: 0.3rem;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}
#agent-modal .subtitle {
  max-width: 340px;
  color: var(--text-muted);
  font-size: 0.77rem;
  line-height: 1.5;
}
#agent-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
.agent-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.7rem 0.8rem;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.agent-item:hover { border-color: var(--accent); background: rgba(124, 106, 247, 0.08); }
.agent-item.active {
  border-color: var(--accent);
  background: rgba(124, 106, 247, 0.12);
}
.agent-item-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(124, 106, 247, 0.14);
  color: var(--accent-light);
  border-radius: 10px;
}
.agent-item-icon svg { width: 18px; height: 18px; }
.agent-item-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.agent-item-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.agent-item-short {
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.agent-item-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}
.skill-meta {
  display: block;
  color: var(--text-dim);
  font-size: 0.68rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.skill-meta b { color: var(--text-muted); font-weight: 600; }
@media (max-width: 767px) {
  .agent-pill-name { max-width: 70px; }
  #agent-modal { align-items: center; padding: 1rem; }
  #agent-modal .modal-box { max-height: min(82dvh, 680px); padding: 1.2rem; }
}

/* ── Reduced Motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .landing-hero-video { display: none !important; }
}

/* ── Unified layout refresh ─────────────────────────── */
:root {
  --bg: #080d17;
  --surface: #101827;
  --surface2: #172235;
  --surface3: #202d43;
  --border: #26364d;
  --border-light: #34445e;
  --accent-glow: rgba(0, 196, 154, 0.18);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
}

body {
  background:
    radial-gradient(ellipse at 48% -15%, rgba(0, 196, 154, 0.075), transparent 42%),
    var(--bg);
}

#top-nav {
  min-height: var(--nav-height);
  border-bottom-color: rgba(180, 203, 231, 0.1);
  background: rgba(8, 13, 23, 0.88);
}

#sidebar {
  background: rgba(13, 20, 33, 0.98);
  border-right-color: rgba(180, 203, 231, 0.1);
}

.landing-hero-inner { width: min(1180px, 100%); }
.landing-preview {
  border-color: rgba(174, 206, 232, 0.2);
  border-radius: 26px;
  box-shadow: 0 34px 100px rgba(0, 0, 0, 0.46), inset 0 1px rgba(255,255,255,0.07);
}
.landing-feature-card {
  border-color: rgba(174, 206, 232, 0.14);
  border-radius: 20px;
  background: linear-gradient(150deg, rgba(20, 31, 49, 0.96), rgba(11, 18, 30, 0.94));
}
.landing-feature-card:hover { border-color: rgba(115, 218, 223, 0.38); }
.landing-section { width: min(1180px, 100%); }
.landing-quote { background: radial-gradient(ellipse at 50% 100%, rgba(0, 196, 154, 0.11), transparent 62%); }

#chat-toolbar {
  min-height: 58px;
  border-bottom-color: rgba(180, 203, 231, 0.1);
  background: rgba(9, 15, 26, 0.74);
}
#input-box {
  border-color: rgba(174, 206, 232, 0.2);
  border-radius: 18px;
  background: rgba(16, 24, 39, 0.96);
  box-shadow: 0 12px 38px rgba(0,0,0,0.22);
}
#input-box:focus-within {
  border-color: rgba(115, 218, 223, 0.48);
  box-shadow: 0 0 0 3px rgba(0, 196, 154, 0.08), 0 12px 38px rgba(0,0,0,0.22);
}

/* Keep dialogs outside the app grid and center them on every viewport. */
.workspace-modal {
  position: fixed !important;
  inset: 0 !important;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100dvh;
  padding: clamp(0.75rem, 3vw, 2rem);
  isolation: isolate;
}
.workspace-backdrop { background: rgba(3, 8, 17, 0.76); }
.workspace-box {
  width: min(800px, 100%);
  max-height: min(90dvh, 880px);
  padding: clamp(1.25rem, 3vw, 2rem);
  border-color: rgba(174, 206, 232, 0.18);
  border-radius: 22px;
  background: linear-gradient(155deg, #121d2e, #0d1523);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.58), inset 0 1px rgba(255,255,255,0.045);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.plan-box { width: min(620px, 100%); }
.image-generation-box { width: min(560px, 100%); }
.image-generation-box .form-group textarea {
  width: 100%;
  min-height: 110px;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text);
  background: var(--surface2);
  font: inherit;
  resize: vertical;
}
.image-generation-note,
.image-generation-status { color: var(--text-muted); font-size: 0.82rem; line-height: 1.5; }
.image-generation-status:empty { display: none; }
.image-generation-result { margin: 0.75rem 0 1rem; text-align: center; }
.image-generation-result img { display: block; width: min(100%, 420px); height: auto; margin: 0 auto 0.6rem; border-radius: 14px; }
.image-generation-result a { color: var(--accent-light); font-size: 0.85rem; }
.chat-generated-image-link { display: block; width: min(100%, 420px); margin-top: .5rem; }
.chat-generated-image { display: block; width: 100%; max-height: 420px; border-radius: 12px; object-fit: contain; }
.documents-box { max-width: 640px; overflow-y: auto; }
#documents-form { display: flex; align-items: end; gap: .75rem; margin-bottom: 1rem; }
.documents-upload { display: grid; flex: 1; gap: .4rem; color: var(--text-muted); font-size: .78rem; }
.documents-upload input { width: 100%; color: var(--text); font: inherit; }
#documents-upload-btn { flex: 0 0 auto; }
#documents-status { min-height: 1.2em; }
#documents-status:empty { display: none; }
.documents-item { display: flex; align-items: center; gap: .75rem; padding: .8rem 0; border-top: 1px solid var(--border); }
.documents-item > span { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--text); font-size: .84rem; }
.documents-item small { display: block; margin-top: .2rem; color: var(--text-dim); font-size: .7rem; }
.documents-delete { flex: 0 0 auto; border: 0; background: transparent; color: var(--danger, #f87171); font: inherit; cursor: pointer; }
.documents-empty { padding: 1rem 0; color: var(--text-muted); font-size: .84rem; text-align: center; }
#documents-btn svg { width: 16px; height: 16px; }
#mic-btn.voice-active { color: var(--accent-light); border-color: var(--accent-light); }
@media (max-width: 520px) {
  #documents-form { align-items: stretch; flex-direction: column; }
}
.avatar-settings-box { max-height: min(88vh, 780px); overflow-y: auto; }
.avatar-settings-preview { display: flex; align-items: center; gap: .75rem; margin: .8rem 0 1rem; color: var(--text-muted); font-size: .82rem; }
.avatar-settings-preview img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--surface2); }
.avatar-settings-group { margin: .9rem 0; }
.avatar-settings-group > strong { display: block; margin-bottom: .45rem; color: var(--text-muted); font-size: .75rem; }
.avatar-settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: .5rem; }
.avatar-settings-option { display: grid; justify-items: center; gap: .25rem; padding: .35rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); color: var(--text); font: inherit; font-size: .62rem; cursor: pointer; }
.avatar-settings-option:hover, .avatar-settings-option.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow-sm); }
.avatar-settings-option img { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; }
.avatar-settings-actions { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: 1rem; }
.avatar-settings-actions > span { color: var(--text-muted); font-size: .72rem; }
.avatar-settings-actions [hidden], .avatar-settings-group[hidden] { display: none; }
@media (max-width: 520px) {
  .avatar-settings-actions { align-items: stretch; flex-direction: column; }
  .avatar-settings-grid { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
}
.workspace-box .modal-close {
  top: 0.9rem;
  right: 0.9rem;
  z-index: 1;
}
.builder-field-card,
.builder-response-item,
.builder-list-item {
  border-color: rgba(174, 206, 232, 0.13);
  border-radius: 14px;
  background: rgba(255,255,255,0.025);
}
.plan-usage { border: 1px solid rgba(174, 206, 232, 0.12); }
.plan-note { border-radius: 12px; }

button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 3px;
}

@media (max-width: 767px) {
  #top-nav { min-height: var(--nav-height); }
  .landing-hero-inner { gap: 1.8rem; }
  .landing-preview { transform: none; }
  .workspace-modal { padding: 0.75rem; }
  .workspace-box {
    width: 100%;
    max-height: min(90dvh, 860px);
    padding: 1.25rem 1rem;
    border-radius: 20px;
  }
  .builder-response-item > div { grid-template-columns: minmax(0, 0.75fr) 1fr; }
}

.character-box { width: min(880px, 100%); }
.character-template-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
}
.character-template-select {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface2);
  font: inherit;
}
.character-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1rem;
}
.character-form-grid .form-group { min-width: 0; margin-bottom: 0.75rem; }
.character-form-grid input,
.character-form-grid textarea {
  width: 100%;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface2);
  font: inherit;
  font-size: 0.83rem;
}
.character-form-grid textarea { resize: vertical; }
.character-full { grid-column: 1 / -1; }
.character-safety-note {
  margin: 0.15rem 0 0.85rem;
  color: var(--text-dim);
  font-size: 0.7rem;
  line-height: 1.6;
}
.character-consent {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.55;
}
.character-consent input { flex: 0 0 auto; margin-top: 0.18rem; accent-color: var(--accent-light); }
.character-consent a { color: var(--accent-light); text-underline-offset: 2px; }
.character-actions { display: flex; justify-content: flex-end; gap: 0.65rem; margin-top: 0.75rem; }
.character-actions > * { width: auto; min-width: 120px; margin: 0; }
.character-settings-link { margin: 0 0 1rem; }

@media (max-width: 600px) {
  .character-form-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .character-full { grid-column: auto; }
  .character-actions { flex-direction: column-reverse; }
  .character-actions > * { width: 100%; }
}
