:root {
  --bg: #141414;
  --sidebar: #191919;
  --line: #2e2e2e;
  --row: #2a2a2a;
  --hover: #242424;
  --composer: rgba(48, 48, 50, 0.46);
  --glass-line: rgba(255, 255, 255, 0.18);
  --glass-blur: blur(22px) saturate(1.7);
  --ink: #f2f2f2;
  --secondary: #c2c2c2;
  --muted: #b0b0b0;
  --ask: #f2f2f2;
  --ask-ink: #141414;
  --user: #2e2e32;
  --cite: #243044;
  --national: #d6e4f5;
  --atlantic: #b7ddd2;
  --danger: #ffb4b4;
  --focus: #9eb6ff;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  caret-color: var(--focus);
}

::selection {
  background: #3d5278;
  color: var(--ink);
}

svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html:not(.is-signed-in) .app { display: none; }
html.is-signed-in .gate { display: none; }

.gate {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 22.5rem);
  align-items: center;
  column-gap: clamp(2rem, 6vw, 5rem);
  min-height: 100dvh;
  padding: clamp(1.75rem, 4vw, 3.25rem);
  padding-bottom: calc(clamp(1.75rem, 4vw, 3.25rem) + env(safe-area-inset-bottom));
  background:
    linear-gradient(100deg, rgba(12, 8, 5, 0.18) 0%, rgba(8, 6, 4, 0.05) 42%, rgba(6, 6, 6, 0.5) 100%),
    url("door.jpg") left center / cover no-repeat;
  background-color: #0c0a08;
}

.gate-copy,
.gate-card { position: relative; z-index: 1; }

.gate-copy {
  align-self: start;
  max-width: 22rem;
  padding-top: clamp(0.5rem, 6vh, 3.5rem);
}

.gate-card { align-self: center; }

.gate .lockup { filter: drop-shadow(0 2px 16px rgba(0, 0, 0, 0.72)); }

.lockup { margin: 0; line-height: 0; }

.lockup-img {
  display: block;
  width: min(19.5rem, 100%);
  height: auto;
}

.brand-mark {
  display: block;
  width: auto;
  height: 1.85rem;
}

.gate-plan {
  margin: 0.9rem 0 0;
  color: var(--secondary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.gate-card {
  background: rgba(22, 22, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 1rem;
  padding: 1.35rem 1.3rem 1.15rem;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}

.gate-card h2 { margin: 0; }

.providers { display: grid; gap: 0.55rem; margin-top: 1rem; }

.provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.9rem;
  border: 1px solid #3a3a3a;
  border-radius: 999px;
  background: #1a1a1a;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
}

.provider:hover { background: #242424; }

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

.provider:disabled { opacity: 0.55; }

.provider svg,
.provider svg path {
  width: 1.05rem;
  height: 1.05rem;
  stroke: none;
}

.provider[data-provider="apple"] svg path { fill: currentColor; }

.provider-or {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.7rem;
  margin: 0.95rem 0 0;
  color: var(--secondary);
  font-size: 0.78rem;
}

.provider-or::before,
.provider-or::after {
  content: "";
  height: 1px;
  background: #3a3a3a;
}

.gate-plan { margin-top: 1rem; }

.app {
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
  padding: 0.65rem;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

#new-chat,
.chat,
.chat-remove,
.scope-button,
#send,
#chats,
#top-new,
#settings-open,
#settings-back,
.settings-menu button,
#plan-upgrade,
#plan-credits,
#account-button,
#account-mode,
#switch-cancel,
#switch-confirm,
.book-menu [role="option"] {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#new-chat {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
}

#new-chat[aria-current="true"],
.chat[aria-current="true"] { background: var(--row); }

#new-chat:hover,
.chat:hover { background: var(--hover); }

.history {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #4a4a4a transparent;
}

.group {
  margin: 0.85rem 0.7rem 0.3rem;
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 600;
}

.chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.chat {
  display: grid;
  gap: 0.05rem;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  text-align: left;
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.chat-book {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--secondary);
  font-size: 0.78rem;
}

.chat-remove {
  margin-right: 0.2rem;
  padding: 0.25rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--secondary);
  opacity: 0;
}

.chat-row:hover .chat-remove,
.chat-row:focus-within .chat-remove,
.chat-remove.is-armed { opacity: 1; }

.chat-remove:hover,
.chat-remove.is-armed { color: var(--danger); background: #3a2424; }

.brand {
  display: flex;
  align-items: center;
  margin: 0.35rem 0.7rem 0.35rem;
  line-height: 0;
}

.brand .brand-mark { height: 1.85rem; }

.account {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.35rem 0.2rem;
}

.avatar {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  background: #2e2e2e;
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.account-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#settings-open {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.55rem;
  color: var(--secondary);
}

#settings-open:hover,
#settings-open[aria-expanded="true"] { background: var(--hover); color: var(--ink); }

#settings-open svg { width: 1.15rem; height: 1.15rem; stroke-width: 1.75; }

#account-button,
#account-mode,
#chats,
#top-new {
  border: 0;
  background: transparent;
  color: inherit;
}

#account-button {
  margin-top: 0.9rem;
  padding: 0.4rem 0.75rem;
  border-radius: 0.55rem;
  background: var(--row);
  font-size: 0.9rem;
  font-weight: 600;
}

#account-button:hover { background: var(--hover); }

.topbar { display: none; }

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.65rem;
  color: var(--ink);
}

.topbar-btn:hover,
.topbar-btn:active { background: var(--hover); }

.topbar-btn svg { width: 1.25rem; height: 1.25rem; }

.term {
  margin: auto 0.55rem 0.15rem;
  color: var(--secondary);
  font-size: 0.78rem;
  line-height: 1.35;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.workspace.is-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.workspace.is-empty .thread { display: none; }

.thread {
  min-height: 0;
  overflow: auto;
  padding: 1.5rem 1.25rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: #4a4a4a transparent;
}

.turn, .dock {
  width: min(42rem, 100%);
  margin-inline: auto;
}

.turn + .turn { margin-top: 1.6rem; }

.reply-status, .reply-error, .reply-notice { margin: .9rem 0 0; color: var(--secondary); }
.reply-status { min-height: 1.5em; }
.streaming-prose::after {
  content: "";
  display: inline-block;
  width: .4em;
  height: .8em;
  margin-left: .2em;
  border-radius: .15em;
  background: currentColor;
  animation: sip-thinking 1.8s ease-in-out infinite;
}
.thinking-text { display: inline-block; animation: sip-thinking 1.8s ease-in-out infinite; }
@keyframes sip-thinking { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }
.reply-error { color: var(--danger); }
.reply-notice { font-size: .85rem; }
.retry-reply { margin-top: .65rem; padding: .4rem .75rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--row); color: var(--ink); font: inherit; font-size: .85rem; cursor: pointer; }
.retry-reply:hover { background: var(--hover); }
.retry-reply:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.bubble {
  width: fit-content;
  max-width: min(68ch, 88%);
  margin: 0 0 0 auto;
  padding: 0.7rem 0.95rem;
  border-radius: 1rem 1rem 0.3rem 1rem;
  background: var(--user);
  white-space: pre-wrap;
}

.prose {
  max-width: 68ch;
  margin-top: 0.9rem;
  white-space: pre-wrap;
}

.table-scroll {
  max-width: 100%;
  margin-top: 0.95rem;
  overflow-x: auto;
  white-space: normal;
  scrollbar-width: thin;
  scrollbar-color: #4a4a4a transparent;
}

.answer table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.35;
}

.answer th,
.answer td {
  padding: 0.48rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: bottom;
  white-space: nowrap;
}

.answer th:first-child,
.answer td:first-child {
  white-space: normal;
  min-width: 11rem;
  max-width: 18rem;
}

.answer th {
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.answer td.num,
.answer th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.answer tbody tr:last-child td { border-bottom: 0; }

.table-note {
  margin: 0.35rem 0 0;
  color: var(--secondary);
  font-size: 0.78rem;
}



.source-reference {
  margin-left: 0.15em;
  color: var(--secondary);
  font-size: 0.72em;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}



.cite {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr);
  column-gap: 0.85rem;
  max-width: 68ch;
  margin-top: 1.05rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--line);
}

.page {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.cite.national .page { color: var(--national); }
.cite.atlantic .page { color: var(--atlantic); }

.cite h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-wrap: balance;
}

.where {
  margin: 0.28rem 0 0;
  color: var(--secondary);
  font-size: 0.9rem;
}

.cite blockquote {
  margin: 0.55rem 0 0;
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.45;
}

.miss {
  margin: 0.45rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.dock { padding: 0 1.25rem 1rem; }



.workspace.is-empty .dock {
  width: min(42rem, calc(100% - 2.5rem));
  padding-bottom: 8vh;
}

.composer {
  position: relative;
  padding: 0.7rem 0.75rem 0.6rem;
  border: 1px solid var(--glass-line);
  border-radius: 1.15rem;
  background: var(--composer);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), var(--shadow);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

.composer:focus-within {
  border-color: #6d84b8;
  box-shadow: var(--shadow), 0 0 0 3px rgba(158, 182, 255, 0.28);
}

.scope { position: relative; width: fit-content; }

.scope-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.35rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--secondary);
  font-size: 0.92rem;
}

.scope-button:hover,
.scope-button[aria-expanded="true"] {
  background: var(--row);
  color: var(--ink);
}

.chevron { width: 0.85rem; height: 0.85rem; }

.book-menu {
  position: absolute;
  z-index: 3;
  bottom: calc(100% + 0.35rem);
  left: 0;
  min-width: 16rem;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  border: 1px solid #3a3a3a;
  border-radius: 0.7rem;
  background: #222;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

.book-menu [role="option"] {
  display: block;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  text-align: left;
  font-size: 0.92rem;
}

.book-menu [role="option"][aria-selected="true"] { background: var(--row); }
.book-menu [role="option"]:hover { background: #303030; }

textarea {
  display: block;
  width: 100%;
  min-height: 1.6rem;
  max-height: 9rem;
  margin: 0.35rem 0 0;
  padding: 0.35rem 0.35rem 0.15rem;
  overflow: auto;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
}

textarea:focus { outline: none; }
textarea::placeholder { color: #c8c8c8; }

.composer-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.15rem 0.1rem;
}

#send {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  padding: 0.42rem 0.85rem 0.42rem 0.7rem;
  border: 0;
  border-radius: 999px;
  background: #f3eee4;
  color: #171717;
  font-size: 0.92rem;
  font-weight: 650;
  transition: background 0.12s ease, transform 0.12s ease;
}

#send:hover { background: #fff8ee; }
#send:active { transform: scale(0.96); }
#send:disabled { opacity: 0.45; cursor: default; }

.send-icon {
  display: block;
  width: 0.95rem;
  height: 0.95rem;
  fill: currentColor;
  stroke: none;
}

.status {
  position: absolute;
  z-index: 3;
  top: .8rem;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: 0;
  padding: .55rem .85rem;
  border: 1px solid var(--line);
  border-radius: .7rem;
  background: var(--sidebar);
  color: var(--secondary);
  font-size: 0.82rem;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
}

.status:empty { display: none; }
.status.is-error { color: var(--danger); }

dialog {
  width: min(24rem, calc(100% - 2rem));
  border: 1px solid #3a3a3a;
  border-radius: 1rem;
  padding: 1.25rem 1.3rem 1.15rem;
  color: var(--ink);
  background: #222;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.62); }

dialog h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

dialog p {
  margin: 0.7rem 0 0;
  color: var(--secondary);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

#switch-cancel,
#switch-confirm {
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  font-size: 0.92rem;
  font-weight: 650;
}

#switch-cancel {
  background: transparent;
  color: var(--ink);
  border: 1px solid #3a3a3a;
}

#switch-cancel:hover { background: var(--row); }

#switch-confirm {
  background: var(--ask);
  color: var(--ask-ink);
  border: 0;
}

#new-chat:focus-visible,
.chat:focus-visible,
.chat-remove:focus-visible,
.scope-button:focus-visible,
.book-menu [role="option"]:focus-visible,
#chats:focus-visible,
#top-new:focus-visible,
#settings-open:focus-visible,
#settings-back:focus-visible,
.settings-menu button:focus-visible,
#plan-upgrade:focus-visible,
#plan-credits:focus-visible,
#account-button:focus-visible,
#account-submit:focus-visible,
#account-mode:focus-visible,
#send:focus-visible,
#switch-cancel:focus-visible,
#switch-confirm:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

@media (prefers-reduced-motion: no-preference) {
  .page { animation: page-in 0.55s cubic-bezier(0.16, 1, 0.3, 1); }
}

@keyframes page-in {
  from { transform: translateY(6px); filter: blur(2px); }
  to { transform: none; filter: none; }
}

.field {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.85rem;
  color: var(--secondary);
  font-size: 0.82rem;
}

.field input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid #3a3a3a;
  border-radius: 0.6rem;
  background: #1a1a1a;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  caret-color: var(--focus);
}

.field input::placeholder { color: #c8c8c8; }

.field input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.field[hidden],
.password-rules[hidden] { display: none; }

.password-rules {
  --rule-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' d='M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6'/%3E%3C/svg%3E");
  --rule-ok: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M3.2 8.3l3.1 3.1 6.5-7'/%3E%3C/svg%3E");
  margin: 0.65rem 0 0;
  padding: 0;
  list-style: none;
  color: #d2d2d2;
  font-size: 0.78rem;
  line-height: 1.35;
}

.password-rules li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.password-rules li + li { margin-top: 0.28rem; }

.password-rules li::before {
  content: "";
  flex: none;
  width: 0.85rem;
  height: 0.85rem;
  background: #ff5c5c;
  -webkit-mask: var(--rule-x) center / contain no-repeat;
  mask: var(--rule-x) center / contain no-repeat;
}

.password-rules li.is-met::before {
  background: #3dce8e;
  -webkit-mask: var(--rule-ok) center / contain no-repeat;
  mask: var(--rule-ok) center / contain no-repeat;
}

.settings-email.is-secondary {
  margin-top: 0.15rem;
  color: var(--secondary);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0;
}

#account-submit {
  width: 100%;
  margin-top: 1rem;
  padding: 0.55rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--ask);
  color: var(--ask-ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  cursor: pointer;
}

#account-submit:hover { background: #ffffff; }
#account-submit:disabled { opacity: 0.45; cursor: default; }

.account-error {
  min-height: 1.2rem;
  margin: 0.7rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

#account-mode {
  margin-top: 0.85rem;
  padding: 0;
  color: var(--secondary);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 0.15rem;
}

.settings {
  position: fixed;
  z-index: 6;
  inset: 0;
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
}

.settings[hidden] { display: none; }

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
  min-width: 0;
  padding: 0.75rem;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.settings-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.settings-back svg { width: 1rem; height: 1rem; }

.settings-back:hover { background: var(--hover); }

.settings-menu {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.45rem;
  min-width: 0;
}

.settings-menu button {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--secondary);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.settings-menu button:hover { background: var(--hover); color: var(--ink); }

.settings-menu button[aria-current="true"] {
  background: var(--row);
  color: var(--ink);
}

.settings-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 1.75rem 1.5rem 2.5rem;
}

.settings-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 44rem;
  min-width: 0;
}

.settings-body > section, .settings-card, .learning-grid > *, .learning-list > * { min-width: 0; max-width: 100%; }
.settings-card { overflow-wrap: anywhere; }

#settings-general {
  display: flex;
  flex: 1;
  flex-direction: column;
}

#settings-general[hidden] { display: none; }

.app-version {
  margin: auto 0 0;
  padding-top: 2rem;
  color: var(--secondary);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.settings-main h2 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.settings-card {
  padding: 1rem 1.05rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: #1c1c1c;
}

.settings-card + .settings-card,
.usage-card { margin-top: 0.75rem; }

.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.plan-grid .settings-card { margin-top: 0; }

.settings-kicker {
  margin: 0;
  color: var(--secondary);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.settings-value,
.plan-name {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.plan-detail,
.plan-note {
  margin: 0.45rem 0 0;
  color: var(--secondary);
  font-size: 0.88rem;
  line-height: 1.45;
}

.policy-next { margin-top: 1rem; }

/* Work details and steward review follow the existing quiet settings surface. */
.settings-card h3 { margin: 0 0 .5rem; font-size: 1rem; }
.settings-value { overflow-wrap: anywhere; }
.learning-form { display: flex; flex-direction: column; gap: .85rem; }
.learning-form[hidden], .learning-form [hidden] { display: none; }
.learning-form label { display: flex; flex-direction: column; gap: .4rem; font-size: .87rem; line-height: 1.5; }
.learning-form input:not([type="checkbox"]), .learning-form select, .learning-form textarea {
  box-sizing: border-box; width: 100%; min-width: 0; max-height: none;
  border: 1px solid var(--line); border-radius: .5rem; padding: .65rem .7rem;
  background: var(--bg); color: var(--ink); font: inherit; line-height: 1.5;
  font-size: max(1rem, 16px);
}
.learning-form textarea { resize: vertical; min-height: 5rem; }
.learning-form select { min-height: 2.75rem; }
.learning-form input:focus-visible, .learning-form select:focus-visible, .learning-form textarea:focus-visible {
  outline: 2px solid var(--secondary); outline-offset: 2px;
}
.learning-form input:disabled, .learning-form select:disabled { opacity: .5; }
.learning-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.check-row, .learning-form .check-row { display: flex; flex-direction: row; align-items: start; gap: .5rem; }
.check-row input { flex: 0 0 auto; margin-top: .25em; accent-color: #c9c9c9; }
.learning-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.learning-actions button, .learning-form button, .learning-list button {
  border: 1px solid var(--line); border-radius: .5rem; padding: .55rem .75rem;
  background: var(--row); color: var(--ink); font: inherit; font-size: .85rem; cursor: pointer;
}
.learning-actions button:hover, .learning-form button:hover, .learning-list button:hover { background: var(--hover); }
.learning-actions button:disabled, .learning-form button:disabled { opacity: .45; cursor: default; }
.learning-actions .subtle, .learning-form .subtle, .learning-list .subtle { background: transparent; color: var(--secondary); }
.learning-list { margin-top: .8rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: .65rem; }
.learning-list .settings-card { margin: 0; }
.learning-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; font-size: .85rem; line-height: 1.5; }
.learning-list .library-entry { text-align: left; line-height: 1.55; overflow-wrap: anywhere; }
.source-choice, .comparison { border: 1px solid var(--line); border-radius: .5rem; padding: .7rem; font-size: .85rem; }
.source-choice summary, .comparison summary, #review-queue summary { cursor: pointer; line-height: 1.55; overflow-wrap: anywhere; }
.source-choice blockquote { white-space: pre-wrap; margin: .75rem 0; color: var(--secondary); line-height: 1.55; }
.comparison .answer, #feedback-preview .answer, #review-queue .answer { margin-top: 1rem; }
.text-button { background: transparent; border: 0; color: var(--secondary); font: inherit; font-size: .78rem; padding: .25rem 0; cursor: pointer; text-align: left; }
.text-button:hover { color: var(--ink); text-decoration: underline; }
.feedback-button { margin-top: .65rem; }
.member-context { min-width: 0; padding-top: .5rem; border-top: 1px solid var(--line); }
.member-context .check-row { margin: 0; }
.learning-dialog { box-sizing: border-box; width: min(38rem, calc(100vw - 2rem)); max-height: 85dvh; overflow: auto; padding: 1.5rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--bg); color: var(--ink); }
.learning-dialog::backdrop { background: rgb(0 0 0 / .65); }
.learning-dialog h2 { margin: 0; font-size: 1.2rem; }
#feedback-preview { overflow-wrap: anywhere; }
#review-editor { margin-top: 1.5rem; scroll-margin-top: 1rem; }
@media (max-width: 540px) {
  .learning-grid { grid-template-columns: 1fr; }
  .learning-row { align-items: start; }
  .learning-dialog { padding: 1rem; }
}

.plan-note:empty { display: none; }

#plan-upgrade {
  margin-top: 0.9rem;
  padding: 0.4rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--ask);
  color: var(--ask-ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

#plan-upgrade:hover { background: #ffffff; }

#plan-credits {
  margin-top: 0.85rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

#plan-credits:hover { background: var(--hover); }

.billing-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#plan-manage {
  flex: none;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

#plan-manage:hover { background: var(--hover); }
#plan-manage[hidden] { display: none; }

.billing-list {
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
}

.billing-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}

.billing-list p { margin: 0; }

.billing-date {
  margin-top: 0.15rem;
  color: var(--secondary);
  font-size: 0.82rem;
}

.billing-side {
  display: flex;
  flex: none;
  align-items: baseline;
  gap: 0.85rem;
}

.billing-side a {
  color: var(--secondary);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 0.15rem;
}

.usage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.usage-head p {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 650;
}

#usage-percent { color: var(--secondary); font-weight: 600; }

.usage-track {
  height: 0.4rem;
  margin-top: 0.75rem;
  overflow: hidden;
  border-radius: 999px;
  background: #2a2a2a;
}

.usage-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
}

@media (max-width: 720px) {
  .gate {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.35rem;
    padding-top: calc(1.35rem + env(safe-area-inset-top));
    background-position: left center;
  }

  .gate-copy { padding-top: 0.15rem; }
  .lockup-img { width: min(16.5rem, 100%); }

  .settings {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .settings-nav {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-top: calc(0.45rem + env(safe-area-inset-top));
  }

  .settings-menu { flex-direction: row; flex-wrap: wrap; margin-top: 0.15rem; }
  .settings-menu button { width: auto; }
  .plan-grid { grid-template-columns: 1fr; }

  .settings-main {
    padding: 1.15rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  }

  .app {
    display: block;
    height: 100dvh;
    overflow: hidden;
    background: #050505;
  }

  .workspace,
  .workspace.is-empty {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100dvh;
    background: var(--bg);
    transform-origin: left center;
    transition: transform 0.32s ease;
  }

  .sidebar.is-open ~ .workspace {
    transform: translateX(calc(min(20rem, 82vw) + 0.65rem)) scale(0.9);
    border-radius: 1.35rem;
    overflow: hidden;
  }

  .topbar {
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    min-height: 0;
    padding: calc(0.45rem + env(safe-area-inset-top)) 0.7rem 0;
    background: none;
    pointer-events: none;
  }

  .topbar .brand-mark { display: none; }

  #chats,
  #top-new {
    width: 2.45rem;
    height: 2.45rem;
    border: 1px solid var(--glass-line);
    border-radius: 999px;
    background: rgba(22, 22, 22, 0.4);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    pointer-events: auto;
  }

  #chats:hover,
  #chats:active,
  #top-new:hover,
  #top-new:active { background: rgba(255, 255, 255, 0.14); }

  .workspace,
  .workspace.is-empty { grid-template-rows: minmax(0, 1fr); }

  .thread {
    grid-row: 1;
    padding: calc(3.5rem + env(safe-area-inset-top)) 0.9rem calc(6.25rem + env(safe-area-inset-bottom));
  }

  .dock {
    position: absolute;
    z-index: 2;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0;
  }

  .status { top: calc(3.3rem + env(safe-area-inset-top)); }

  .prose { margin-top: 0.7rem; line-height: 1.45; }

  .bubble {
    max-width: 82%;
    padding: 0.62rem 0.9rem;
    border-radius: 1.2rem;
    background: #3a3a3a;
  }

  .sidebar {
    position: fixed;
    z-index: 5;
    top: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.35rem 0.65rem;
    width: min(20rem, 82vw);
    padding: calc(0.9rem + env(safe-area-inset-top)) 0.85rem calc(0.75rem + env(safe-area-inset-bottom));
    background: #050505;
    border: 0;
    transform: translateX(-105%);
    transition: transform 0.32s ease;
  }

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

  .brand {
    grid-column: 1 / -1;
    align-self: start;
    margin: 0.15rem 0.25rem 0.45rem;
  }

  .history { align-self: stretch; }

  .brand .brand-mark { height: 1.45rem; }

  .history { grid-column: 1 / -1; }

  .group {
    margin: 1rem 0.35rem 0.3rem;
    color: var(--ink);
    font-size: 0.98rem;
    font-weight: 650;
  }

  .chat { border-radius: 0.75rem; }

  .term {
    grid-column: 1 / -1;
    margin: 0 0.3rem;
  }

  #new-chat {
    grid-column: 1;
    grid-row: 4;
    width: fit-content;
    margin-top: 0.15rem;
    padding: 0.72rem 1.05rem;
    border-radius: 999px;
    background: #f3f3f3;
    color: #161616;
    font-weight: 650;
  }

  #new-chat[aria-current="true"],
  #new-chat:hover { background: #ffffff; color: #161616; }

  .account {
    grid-column: 2;
    grid-row: 4;
    padding: 0;
  }

  .avatar,
  .account-name { display: none; }

  #settings-open {
    width: 2.7rem;
    height: 2.7rem;
    border: 1px solid var(--glass-line);
    border-radius: 999px;
    background: rgba(22, 22, 22, 0.4);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
    color: var(--ink);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
  }

  .scrim:not([hidden]) {
    position: fixed;
    z-index: 4;
    inset: 0;
    background: transparent;
  }

  .dock {
    width: 100%;
    padding: 0 0.7rem calc(0.45rem + env(safe-area-inset-bottom));
  }

  .workspace.is-empty .dock {
    width: 100%;
    padding-bottom: calc(0.45rem + env(safe-area-inset-bottom));
  }

  .composer {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.28rem 0.28rem 0.28rem 0.7rem;
    border-radius: 1.7rem;
    background: rgba(64, 64, 66, 0.34);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  }

  .composer:focus-within {
    border-color: var(--glass-line);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  }

  .scope { align-self: center; }

  .scope-button {
    max-width: 6.4rem;
    padding: 0.35rem 0.15rem;
    font-size: 0.82rem;
  }

  #book-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  textarea {
    flex: 1;
    width: auto;
    min-height: 1.35rem;
    margin: 0;
    padding: 0.48rem 0.15rem;
    font-size: 1rem;
  }

  .composer-foot { padding: 0; }

  #send {
    position: relative;
    width: 2.35rem;
    height: 2.35rem;
    justify-content: center;
    gap: 0;
    margin: 0;
    padding: 0;
    background: #f3eee4;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  }

  .send-icon { width: 1.35rem; height: 1.35rem; }

  .send-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .cite { grid-template-columns: 2.7rem minmax(0, 1fr); }
  .page { font-size: 1.45rem; }
}

.install {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  align-items: end;
}

.install[hidden] { display: none; }

.install-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.48);
  opacity: 0;
  transition: opacity 0.32s ease;
}

.install-sheet {
  position: relative;
  margin: 0 0.7rem calc(0.7rem + env(safe-area-inset-bottom));
  padding: 1.05rem 1.05rem 1.1rem;
  border: 1px solid #3a3a3a;
  border-radius: 1.15rem;
  background: #1c1c1c;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  transform: translateY(115%);
  transition: transform 0.34s ease;
}

.install.is-open .install-scrim { opacity: 1; }
.install.is-open .install-sheet { transform: translateY(0); }

.install-mark {
  display: block;
  width: auto;
  height: 1.7rem;
  margin-bottom: 0.85rem;
}

.install h2 {
  margin: 0;
  max-width: 16rem;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.install p {
  margin: 0.45rem 0 0;
  color: var(--secondary);
  font-size: 0.95rem;
  line-height: 1.45;
}

.install-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--secondary);
  cursor: pointer;
}

.install-close:hover { background: var(--hover); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .thinking-text, .streaming-prose::after { animation: none; }
  .sidebar,
  .workspace,
  .install-scrim,
  .install-sheet { transition: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .composer,
  .topbar-btn {
    background: #2a2a2a;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
