:root {
  --bg: #0b0b0b;
  --bg-elevated: #121212;
  --bg-sidebar: #0f0f0f;
  --bg-card: #161616;
  --bg-hover: #1c1c1c;
  --fg: #f5f5f5;
  --muted: #9a9a9a;
  --faint: #6b6b6b;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #00ccb1;
  --accent-soft: rgba(0, 204, 177, 0.12);
  --cite: #9b87ff;
  --outside: #f0b429;
  --danger: #f87171;
  --gradient: linear-gradient(90deg, #00ccb1, #7b61ff, #ff61dc);
  --gradient-soft: linear-gradient(
    135deg,
    rgba(0, 204, 177, 0.16),
    rgba(123, 97, 255, 0.14),
    rgba(255, 97, 220, 0.1)
  );
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --sidebar-w: 280px;
  --topbar-h: 3.85rem;
  --composer-h: 6.5rem;
  --max-chat: 46rem;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

/* ── Shell ── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(123, 97, 255, 0.12), transparent 55%),
    radial-gradient(900px 500px at 10% 110%, rgba(0, 204, 177, 0.08), transparent 50%),
    var(--bg);
}

/* ── Sidebar ── */

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: color-mix(in srgb, var(--bg-sidebar) 92%, #000);
  border-right: 1px solid var(--border);
  padding: 0.85rem 0.75rem;
  z-index: 40;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.25rem 0.35rem 0.85rem;
}

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--fg);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: -0.01em;
}

.sidebar-brand-home {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  color: var(--fg);
}

.sidebar-brand-home svg {
  flex-shrink: 0;
  color: var(--muted);
}

.sidebar-brand-home strong {
  font-size: 0.92rem;
  font-weight: 700;
}

.sidebar-brand:hover .sidebar-brand-home svg {
  color: var(--fg);
}

.btn-gradient {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.65rem 1rem;
  color: #fff;
  background: var(--gradient);
  background-size: 180% 100%;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}

.btn-gradient:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-gradient:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sidebar-new {
  width: 100%;
}

.sidebar-section-label {
  padding: 0.35rem 0.65rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0 0.65rem 0.75rem;
  max-height: 11.5rem;
  overflow: auto;
  flex-shrink: 0;
}

.episode-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

.episode-item:hover {
  background: var(--bg-hover);
}

.episode-item-meta {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
}

.episode-item-title {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.msg-action {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.msg-action:hover {
  color: var(--fg);
  border-color: var(--border-strong);
}

.notes-tools {
  padding: 0 0.65rem 0.35rem;
}

.notes-search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.78rem;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0 0.65rem 0.75rem;
  max-height: 12rem;
  overflow: auto;
  flex-shrink: 0;
}

.note-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  position: relative;
}

.note-item:hover {
  background: var(--bg-hover);
}

.note-item-meta {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}

.note-item-quote {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-delete {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.15rem 0.3rem;
}

.note-delete:hover {
  color: var(--danger);
}

.source-save {
  border: 1px solid rgba(0, 204, 177, 0.28);
  background: rgba(0, 204, 177, 0.08);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  margin-left: 0.25rem;
  letter-spacing: 0.01em;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.source-save:hover {
  background: rgba(0, 204, 177, 0.16);
  border-color: rgba(0, 204, 177, 0.55);
  color: #b8fff4;
}

.source-save.saved {
  background: rgba(0, 204, 177, 0.2);
  border-color: rgba(0, 204, 177, 0.65);
  color: var(--accent);
  pointer-events: none;
}

.save-clip-card {
  width: min(100%, 28rem);
  text-align: left;
}

.save-clip-kicker {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.save-clip-meta {
  margin: 0.35rem 0 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.save-clip-quote {
  margin: 0 0 1.1rem;
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 10px 10px 0;
  color: #e8e8e8;
  font-size: 0.9rem;
  line-height: 1.45;
  max-height: 8.5rem;
  overflow: auto;
}

.save-clip-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.save-clip-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg);
}

.save-clip-label span {
  font-weight: 400;
  color: var(--faint);
}

.save-clip-input {
  width: 100%;
  margin-bottom: 0.55rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 16px; /* avoid iOS focus zoom */
  resize: vertical;
}

.save-clip-input:focus {
  outline: none;
  border-color: rgba(0, 204, 177, 0.55);
  box-shadow: 0 0 0 3px rgba(0, 204, 177, 0.12);
}

.save-clip-note {
  min-height: 4.5rem;
}

.save-clip-error {
  margin: 0 0 0.35rem;
  color: var(--danger);
  font-size: 0.8rem;
}

.save-clip-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.save-clip-cancel {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.save-clip-cancel:hover {
  color: var(--fg);
  border-color: var(--border-strong);
}

.save-clip-submit {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 0.55rem 1.15rem;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
  color: #0b0b0b;
}

.save-clip-submit:disabled {
  opacity: 0.55;
  cursor: wait;
}

.fidelity-banner {
  margin-top: 0.65rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(240, 180, 41, 0.35);
  background: rgba(240, 180, 41, 0.08);
  border-radius: 10px;
  font-size: 0.78rem;
  color: #f0d78c;
  line-height: 1.4;
}

.fidelity-banner strong {
  color: var(--outside);
}

mark.ungrounded-quote {
  background: rgba(240, 180, 41, 0.22);
  color: inherit;
  border-bottom: 1px dashed rgba(240, 180, 41, 0.7);
  padding: 0 0.1em;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-right: 0.15rem;
}

.history-empty {
  margin: 0.5rem 0.65rem;
  color: var(--faint);
  font-size: 0.8rem;
  line-height: 1.45;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.55rem 0.45rem 0.55rem 0.65rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.history-item:hover,
.history-item.is-active {
  background: var(--bg-hover);
  color: var(--fg);
}

.history-item-body {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  display: block;
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--faint);
}

.history-item-delete {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}

.history-item:hover .history-item-delete,
.history-item:focus-within .history-item-delete {
  opacity: 1;
}

.history-item-delete:hover {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}

.sidebar-foot {
  padding: 0.65rem 0.25rem 0.25rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.signin-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  border-radius: 14px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.signin-chip:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.signin-chip.is-signed-in {
  border-color: rgba(0, 204, 177, 0.5);
  background: linear-gradient(
    135deg,
    rgba(0, 204, 177, 0.12),
    rgba(123, 97, 255, 0.14)
  );
  box-shadow:
    0 0 0 1px rgba(0, 204, 177, 0.18),
    0 8px 22px rgba(0, 0, 0, 0.28);
}

.signin-chip.is-signed-in:hover {
  border-color: rgba(0, 204, 177, 0.7);
  background: linear-gradient(
    135deg,
    rgba(0, 204, 177, 0.16),
    rgba(123, 97, 255, 0.18)
  );
}

.signin-avatar {
  display: grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  background: var(--gradient-soft);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  overflow: hidden;
}

.signin-avatar.has-initial {
  border: none;
  background: var(--gradient);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.signin-avatar.has-photo {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  padding: 0;
}

.signin-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.signin-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.signin-copy strong {
  font-size: 0.86rem;
  font-weight: 600;
}

.signin-copy small {
  color: var(--muted);
  font-size: 0.72rem;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 50;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg-elevated) 90%, transparent);
  color: var(--fg);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent;
}

.sidebar-scrim {
  display: none;
}

/* ── Main ── */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  position: relative;
  animation: page-in 0.28s ease;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  padding: 0 1.25rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  border-bottom: 1px solid transparent;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-afplus {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  min-width: 0;
  max-width: min(100%, 17rem);
  padding: 0.25rem 0.55rem;
  margin: -0.25rem -0.55rem;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}

.topbar-afplus:hover {
  background: rgba(255, 255, 255, 0.05);
}

.topbar-afplus:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar-afplus-kicker {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-afplus-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.topbar-afplus-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  border-radius: 5px;
}

.topbar-afplus-wordmark {
  display: block;
  height: 0.7rem;
  width: auto;
  max-width: min(9.5rem, 28vw);
}

.topbar-afplus-short {
  display: none;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.topbar-logo {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 7px;
  object-fit: cover;
}

.topbar-title {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

.usage-meters {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.usage-meter {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #d4d4d8;
  white-space: nowrap;
}

.usage-meter.is-empty {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.45);
}

.usage-meter.is-unlimited {
  color: #fafafa;
}

.plan-pill {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: #e4e4e7;
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.plan-pill.is-pro,
.plan-pill.is-ultra {
  color: #fff;
  border: none; /* transparent border + gradient bleeds cyan/magenta at the pill edges */
  background-image: var(--gradient);
  background-color: #7b61ff;
  background-origin: border-box;
  background-clip: padding-box;
}

.mode-pill {
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: var(--gradient);
  letter-spacing: 0.02em;
}

.answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.answer-action {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: #a1a1aa;
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.answer-action:hover {
  color: #fafafa;
  border-color: rgba(255, 255, 255, 0.28);
}

.plans-card {
  max-width: 52rem;
  width: min(52rem, calc(100vw - 2rem));
}

.billing-toggle {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.2rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  margin: 0.5rem 0 1rem;
}

.billing-toggle-btn {
  border: 0;
  background: transparent;
  color: #a1a1aa;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.billing-toggle-btn.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.plans-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

@media (max-width: 800px) {
  .plans-grid {
    grid-template-columns: 1fr;
  }
}

.plan-tile {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 1rem;
  padding: 1rem;
  text-align: left;
}

.plan-tile.is-current {
  border-color: rgba(249, 115, 22, 0.55);
}

.plan-tile h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.plan-tile .price {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 0.35rem 0;
}

.plan-tile ul {
  margin: 0.5rem 0 0.9rem;
  padding-left: 1.1rem;
  color: #a1a1aa;
  font-size: 0.85rem;
}

.plan-tile .btn-gradient {
  width: 100%;
  border: 0;
  cursor: pointer;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
}

.share-actions {
  display: grid;
  gap: 0.5rem;
}

.share-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: #f4f4f5;
  border-radius: 0.75rem;
  padding: 0.7rem 0.9rem;
  font-weight: 650;
  cursor: pointer;
  text-align: left;
}

.share-url {
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: #a1a1aa;
  word-break: break-all;
}

.coupon-form {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
}

.coupon-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.coupon-row .save-clip-input {
  flex: 1;
  min-width: 0;
}

.coupon-redeem {
  border: 0;
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.coupon-status {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: #a1a1aa;
}

.coupon-status.is-ok {
  color: #86efac;
}

.coupon-status.is-err {
  color: #fca5a5;
}

/* ── Stage ── */

.stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem 3rem;
  gap: 1.25rem;
  animation: fade-up 0.45s ease;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.welcome-hero {
  text-align: center;
  max-width: 34rem;
}

.welcome-mark {
  width: 4.25rem;
  height: 4.25rem;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border), 0 12px 40px rgba(123, 97, 255, 0.18);
  margin-bottom: 1rem;
}

.welcome-title {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.welcome-sub {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.welcome-stats {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.landing-composer {
  width: min(100%, 40rem);
}

.landing-box {
  box-shadow: var(--shadow);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  margin-bottom: 0.05rem;
}

.research-mode {
  display: flex;
  align-items: center;
}

.research-mode-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg) 70%, transparent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239a9a9a' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 0.55rem center;
  color: var(--fg);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.45rem 1.55rem 0.45rem 0.7rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  min-height: 2.25rem;
  max-width: 7.5rem;
}

.research-mode-select:hover,
.research-mode-select:focus {
  border-color: color-mix(in srgb, #7b61ff 40%, var(--border));
  outline: none;
}

.mode-hint {
  margin: 0.4rem 0 0;
  text-align: center;
  font-size: 0.68rem;
  color: var(--faint);
  letter-spacing: 0.02em;
}

.composer-mode-hint {
  margin-top: 0.35rem;
}

.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;
}

@media (max-width: 520px) {
  .composer-box {
    flex-wrap: wrap;
    border-radius: 1.25rem;
    padding: 0.55rem 0.55rem 0.55rem 0.85rem;
  }

  .composer-actions {
    width: 100%;
    justify-content: flex-end;
    padding-left: 1.6rem;
  }

  .research-mode-select {
    max-width: none;
    flex: 1;
  }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  max-width: 40rem;
}

.pill {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--fg);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

.pill:hover {
  border-color: transparent;
  background: var(--gradient-soft);
  transform: translateY(-1px);
}

/* ── Messages ── */

.messages {
  width: min(100%, var(--max-chat));
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  animation: fade-up 0.3s ease;
}

.message.user {
  align-items: flex-end;
}

.msg-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.message.user .msg-label {
  text-align: right;
}

.bubble {
  line-height: 1.6;
  word-break: break-word;
}

.message.user .bubble {
  max-width: 85%;
  padding: 0.8rem 1.05rem;
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(180deg, #1a1a1a, #151515);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

.message.assistant .bubble {
  padding: 0.15rem 0.1rem;
  color: var(--fg);
  font-size: 0.97rem;
  white-space: pre-wrap;
}

.bubble .ans-heading {
  margin: 1rem 0 0.45rem;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.bubble .ans-heading:first-child {
  margin-top: 0;
}

.bubble .cite {
  display: inline;
  margin: 0 0.1rem;
  padding: 0 0.25rem;
  border: none;
  border-radius: 5px;
  background: color-mix(in srgb, var(--cite) 20%, transparent);
  color: var(--cite);
  font: inherit;
  font-size: 0.85em;
  font-weight: 700;
  cursor: pointer;
}

.bubble .cite:hover {
  background: color-mix(in srgb, var(--cite) 35%, transparent);
}

.bubble .ans-link {
  color: var(--cite);
  font-weight: 600;
  text-decoration: none;
}

.bubble .ans-link:hover {
  text-decoration: underline;
}

.bubble .ans-quote {
  display: block;
  margin: 0.85rem 0;
  padding: 0.7rem 0.95rem 0.65rem;
  border-left: 3px solid color-mix(in srgb, var(--cite) 70%, transparent);
  background: color-mix(in srgb, var(--cite) 10%, #141414);
  border-radius: 0 8px 8px 0;
}

.bubble .ans-quote p {
  display: inline;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: #e4e4e4;
  font-style: italic;
}

/* Citation chip sits in the same offset box, after the quote text. */
.bubble .ans-quote-cite {
  display: inline;
  margin-left: 0.35rem;
  font-style: normal;
  vertical-align: baseline;
}

.bubble .ans-quote-cite .cite {
  margin-left: 0;
}

.bubble .outside-label {
  color: var(--outside);
  font-weight: 700;
}

/* ── Citations ── */

.sources {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.sources-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 0.35rem;
}

.source-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  background: var(--bg-elevated);
  scroll-margin-top: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.source-card:hover {
  border-color: var(--border-strong);
}

.source-card.is-flash {
  animation: source-flash 1.4s ease;
}

@keyframes source-flash {
  0% {
    border-color: var(--cite);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--cite) 45%, transparent);
  }
  100% {
    border-color: var(--border);
    box-shadow: none;
  }
}

.source-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.55rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.source-num {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--cite) 22%, transparent);
  color: var(--cite);
  font-size: 0.72rem;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 5px;
  padding: 0.12rem 0.4rem;
}

.badge-archive {
  color: var(--accent);
  background: var(--accent-soft);
}

.badge-x {
  color: #7dd3fc;
  background: rgba(125, 211, 252, 0.12);
}

.source-ep {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.source-ep-link {
  color: inherit;
  text-decoration: none;
}

.source-ep-link:hover {
  color: var(--cite);
  text-decoration: underline;
}

.source-meta {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
  line-height: 1.4;
}

.source-ts {
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  padding: 0.15rem 0.55rem;
  font-variant-numeric: tabular-nums;
}

.source-quote {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #d0d0d0;
  border-left: 2px solid color-mix(in srgb, var(--cite) 50%, transparent);
  padding-left: 0.75rem;
}

.source-link {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--cite);
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.sources-more-btn {
  margin: 0.1rem 0 0;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

.sources-more-btn:hover {
  color: var(--fg);
  border-color: color-mix(in srgb, var(--cite) 40%, var(--border));
}

.sources-extra {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* ── Composer ── */

.composer-wrap {
  width: min(100%, var(--max-chat));
  margin: 0 auto;
  padding: 0.5rem 1.25rem calc(1.1rem + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 28%);
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--bg-elevated) 88%, #000);
  backdrop-filter: blur(14px);
  padding: 0.65rem 0.65rem 0.65rem 1.1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-box:focus-within {
  border-color: color-mix(in srgb, #7b61ff 45%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, #7b61ff 20%, transparent), 0 10px 36px rgba(0, 0, 0, 0.35);
}

.composer-icon {
  flex-shrink: 0;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

#query-input,
#landing-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-size: 16px; /* iOS Safari: <16px zooms the page on focus */
  line-height: 1.45;
  max-height: 8rem;
  min-height: 1.4em;
  padding: 0.3rem 0;
}

#query-input::placeholder,
#landing-input::placeholder {
  color: var(--faint);
}

.send-btn {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.05);
}

.composer-foot {
  margin: 0.5rem 0 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--faint);
}

/* ── Loading / error ── */

.typing {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.35rem 0;
}

.typing span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.error-text {
  color: var(--danger);
  font-size: 0.92rem;
}

.status-line {
  color: var(--muted);
  font-size: 0.92rem;
}

.followups {
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}

.followups-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.followups-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.followup-pill {
  max-width: 100%;
  text-align: left;
  font-size: 0.82rem;
  line-height: 1.25;
  white-space: normal;
}

.status-dots::after {
  content: "";
  animation: status-dots 1.2s steps(4, end) infinite;
}

@keyframes status-dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
}

/* ── Auth modal ── */

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(100%, 24rem);
  max-height: min(92dvh, 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: linear-gradient(180deg, #151515, #101010);
  padding: 1.75rem 1.5rem 1.35rem;
  box-shadow: var(--shadow);
  text-align: center;
  animation: fade-up 0.28s ease;
}

.modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.85rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-sub {
  margin: 0.45rem 0 1.15rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.auth-providers {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--fg);
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: not-allowed;
  opacity: 0.55;
}

.auth-btn.is-enabled {
  cursor: pointer;
  opacity: 1;
}

.auth-btn.is-enabled:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: #171717;
}

.auth-logout {
  margin-top: 0.85rem;
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: var(--radius-pill);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.auth-logout:hover {
  background: rgba(248, 113, 113, 0.14);
}

.auth-error {
  margin: 0.65rem 0 0;
  color: #ff8e8e;
  font-size: 0.8rem;
}

.auth-icon {
  width: 1.25rem;
  text-align: center;
  font-weight: 800;
}

.auth-guest {
  width: 100%;
}

.modal-note {
  margin: 0.75rem 0 0;
  font-size: 0.72rem;
  color: var(--faint);
  line-height: 1.4;
}

.source-play {
  margin-left: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}

.source-play:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.playback-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(24rem, 92vw);
  z-index: 60;
  background: linear-gradient(180deg, #121212 0%, #0b0b0b 100%);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
  padding: 1.25rem 1.15rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: fade-up 0.22s ease;
}

/* display:flex above would otherwise ignore the HTML hidden attribute */
.playback-panel[hidden] {
  display: none !important;
}

.playback-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.playback-kicker {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.playback-title {
  margin: 0.2rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.playback-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.playback-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.playback-quote {
  margin: 0;
  padding: 0.9rem 1rem;
  border-left: 3px solid #7c5cff;
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg);
  font-size: 0.92rem;
  line-height: 1.5;
}

.playback-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.playback-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.88rem;
}

.playback-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--faint);
  line-height: 1.4;
}

body.has-playback .main {
  margin-right: min(24rem, 92vw);
}

@media (max-width: 860px) {
  body.has-playback .main {
    margin-right: 0;
  }
}

/* ── Responsive ── */

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, var(--sidebar-w));
    max-width: calc(100vw - 3rem);
    height: 100dvh;
    padding-top: max(0.85rem, env(safe-area-inset-top));
    padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  body.sidebar-open {
    overscroll-behavior: none;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .stage,
  body.sidebar-open .composer-wrap {
    pointer-events: none;
  }

  .sidebar-toggle {
    display: grid;
    place-items: center;
  }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.55);
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  .topbar {
    padding-left: max(3.85rem, calc(3.4rem + env(safe-area-inset-left)));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
  }

  .topbar-afplus-wordmark {
    display: none;
  }

  .topbar-afplus-short {
    display: inline;
  }

  .topbar-afplus {
    max-width: none;
    padding: 0.3rem 0.5rem;
    gap: 0.12rem;
  }

  .topbar-afplus-kicker {
    font-size: 0.58rem;
    letter-spacing: 0.03em;
  }

  .topbar-afplus-icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .usage-meters {
    gap: 0.25rem;
  }

  .usage-meter {
    padding: 0.28rem 0.5rem;
    font-size: 0.68rem;
  }

  .mode-pill {
    display: none;
  }

  .welcome {
    padding-top: 1.25rem;
    padding-inline: 1rem;
  }

  .composer-wrap {
    padding-inline: 0.85rem;
  }

  .composer-box {
    border-radius: 1.35rem;
    padding: 0.55rem 0.55rem 0.55rem 0.9rem;
  }

  .send-btn {
    width: 2.75rem;
    height: 2.75rem;
  }

  .message.user .bubble {
    max-width: 92%;
  }

  .modal {
    place-items: end center;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-card {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 100%);
    border-radius: 18px 18px 0 0;
    padding: 1.35rem 1.1rem calc(1.25rem + env(safe-area-inset-bottom));
  }

  .plans-card .plans-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .plan-pill {
    display: none;
  }

  .topbar-right .icon-btn {
    width: 2.4rem;
    height: 2.4rem;
  }

  .welcome-af-badge,
  .welcome-mark {
    width: 4.25rem;
    height: 4.25rem;
  }
}

@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .welcome-af-badge,
  .welcome-mark {
    width: 3.25rem;
    height: 3.25rem;
  }

  .welcome-sub {
    display: none;
  }

  .modal {
    place-items: center;
    padding: 0.75rem;
  }

  .modal-card {
    border-radius: 16px;
    max-height: 90dvh;
  }
}

@media (hover: none) and (pointer: coarse) {
  .episode-item,
  .history-item {
    min-height: 2.75rem;
  }

  .icon-btn {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }

  a,
  button {
    -webkit-tap-highlight-color: transparent;
  }
}
