/* MVP-3A family client: neutral OpenDuet-style surfaces, one accent. */

:root {
  color-scheme: light dark;
  --surface: #f6f6f8;
  --card: #ffffff;
  --tile: #f1f1f4;
  --bubble: #ececf0;
  --user-bubble: #e7e3f7;
  --ink: #18181b;
  --muted: #55555e;
  --hair: rgba(24, 24, 27, 0.09);
  --hair-strong: rgba(24, 24, 27, 0.16);
  --accent: #6430ab;
  --accent-fill: #6430ab;
  --accent-soft: #f0ebfa;
  --on-accent: #ffffff;
  --danger: #b91c1c;
  --danger-soft: #fbeaea;
  --success: #147a3a;
  --success-soft: #e6f4ea;
  --warn: #a34a06;
  --warn-soft: #fdf3e1;
  --glass: rgba(246, 246, 248, 0.84);
  --scrim: rgba(18, 18, 24, 0.4);
  --shadow-card: 0 0 0 1px var(--hair), 0 8px 22px -16px rgba(1, 5, 7, 0.28);
  --shadow-float: 0 0 0 1px var(--hair), 0 10px 30px -12px rgba(1, 5, 7, 0.22);
  --radius-card: 20px;
  --radius-field: 28px;
  --target: 44px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --dur-tap: 120ms;
  --dur-enter: 250ms;
  --dur-sheet: 350ms;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #111114;
    --card: #18181b;
    --tile: #202024;
    --bubble: #232327;
    --user-bubble: #2e2642;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --hair: rgba(255, 255, 255, 0.12);
    --hair-strong: rgba(255, 255, 255, 0.2);
    --accent: #a78bfa;
    --accent-fill: #7c3aed;
    --accent-soft: #241e38;
    --on-accent: #ffffff;
    --danger: #f87171;
    --danger-soft: #3a1d1d;
    --success: #4ade80;
    --success-soft: #17301f;
    --warn: #fbbf24;
    --warn-soft: #33280f;
    --glass: rgba(17, 17, 20, 0.86);
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow-card: 0 0 0 1px var(--hair), 0 10px 26px -18px rgba(0, 0, 0, 0.8);
    --shadow-float: 0 0 0 1px var(--hair), 0 14px 36px -14px rgba(0, 0, 0, 0.8);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

html.is-locked,
body.is-locked {
  overflow: hidden;
}

h1,
h2,
h3,
p,
ul,
ol,
blockquote,
pre {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 6vw, 30px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 19px;
  line-height: 1.25;
}

h3 {
  font-size: 16px;
  line-height: 1.3;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

.icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

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

.skip-link {
  position: absolute;
  top: -56px;
  left: 12px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 16px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
}

.skip-link:focus {
  top: 12px;
}

.muted {
  color: var(--muted);
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.fineprint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.fineprint code {
  overflow-wrap: anywhere;
}

.app-shell {
  min-height: 100dvh;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border-bottom: 1px solid var(--hair);
}

.topbar-context {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.topbar-kicker {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.avatar-button {
  width: var(--target);
  height: var(--target);
  border-radius: 50%;
  border: 1px solid var(--hair);
  background: var(--card);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  flex: none;
  transition: transform var(--dur-tap) var(--ease), background var(--dur-tap) var(--ease);
}

.icon-button:active,
.avatar-button:active {
  transform: scale(0.96);
}

.avatar-button {
  font-weight: 700;
  font-size: 15px;
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.demo-chip {
  flex: none;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

/* ---------- rail ---------- */

.rail {
  display: none;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent-fill);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 19px;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.shell-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--target);
  padding: 8px 12px;
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
  font-size: 15px;
}

.nav-item:hover {
  background: var(--tile);
  text-decoration: none;
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.shell-family {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--hair);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shell-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 12px 6px;
}

.child-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}

.child-row:hover {
  background: var(--tile);
  text-decoration: none;
}

.child-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--tile);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}

.child-row:first-of-type .child-dot {
  background: var(--accent-soft);
  color: var(--accent);
}

.child-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.shell-foot {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--hair);
}

.nav-logout {
  color: var(--danger);
}

.logout-form {
  display: flex;
  margin: 0;
}

/* ---------- main / pages ---------- */

.app-main {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px calc(100px + env(safe-area-inset-bottom));
  outline: none;
}

.app-main.has-composer {
  padding-bottom: calc(340px + env(safe-area-inset-bottom));
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.page-head > .button {
  white-space: nowrap;
}

.page-kicker {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.page-lede {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
  max-width: 46ch;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- buttons and chips ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--target);
  padding: 0 18px;
  border-radius: 22px;
  border: 1px solid transparent;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: transform var(--dur-tap) var(--ease), background var(--dur-tap) var(--ease);
}

.button:hover {
  text-decoration: none;
}

.button:active {
  transform: scale(0.98);
}

.button.primary {
  background: var(--ink);
  color: var(--card);
}

.button.secondary {
  background: var(--card);
  border-color: var(--hair-strong);
}

.button.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.button.full {
  width: 100%;
}

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

.text-action {
  min-height: var(--target);
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--target);
  padding: 0 16px;
  border-radius: 22px;
  border: 1px solid var(--hair);
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.pill:hover {
  text-decoration: none;
  border-color: var(--hair-strong);
}

.pill.is-active {
  background: var(--accent-fill);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}

.state-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--tile);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.state-chip.state-ok {
  background: var(--success-soft);
  color: var(--success);
}

.state-chip.state-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.state-chip.state-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.state-note {
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
}

.state-note.state-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.state-note.state-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.status {
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
}

.status[data-kind="error"] {
  color: var(--danger);
}

.status[data-kind="ok"] {
  color: var(--success);
}

/* ---------- notebook ---------- */

.notebook-transcript {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.notebook-empty {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 22px 18px;
  box-shadow: var(--shadow-card);
}

.empty-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.example-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.example-chip {
  min-height: var(--target);
  text-align: left;
  padding: 10px 14px;
  border-radius: 18px;
  border: 1px solid var(--hair);
  background: var(--tile);
  color: var(--ink);
  font-size: 14px;
}

.notebook-message {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notebook-message--adult {
  align-items: flex-end;
}

.notebook-message--assistant {
  align-items: flex-start;
}

.bubble {
  max-width: 94%;
}

.bubble-user {
  max-width: 86%;
  background: var(--user-bubble);
  border-radius: 20px 20px 6px 20px;
  padding: 12px 14px;
}

.bubble-agent {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 20px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}

.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.bubble-actions .text-action {
  margin-left: -4px;
}

.notebook-message,
.message-card,
.chat-card {
  scroll-margin-bottom: 240px;
}

.pending-card {
  position: fixed;
  z-index: 32;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(190px + env(safe-area-inset-bottom));
  width: min(720px, calc(100vw - 24px));
  max-height: 42dvh;
  overflow-y: auto;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: var(--radius-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-float);
}

.pending-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pending-text {
  font-weight: 600;
  font-size: 16px;
}

.pending-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 18px;
}

.pending-list .meta {
  display: block;
}

.jump-latest {
  position: fixed;
  z-index: 32;
  right: max(16px, calc(50vw - 348px));
  bottom: calc(154px + env(safe-area-inset-bottom));
  min-height: var(--target);
  padding: 0 16px;
  border-radius: 22px;
  border: 1px solid var(--hair);
  background: var(--card);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-float);
}

/* ---------- composer ---------- */

.composer {
  position: fixed;
  z-index: 31;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: min(720px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 6px;
  padding: 8px;
  background: var(--glass);
  border: 1px solid var(--hair);
  border-radius: var(--radius-field);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

.composer textarea {
  width: 100%;
  min-height: var(--target);
  max-height: 132px;
  field-sizing: content;
  padding: 11px 12px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  resize: none;
  font-size: 16px;
  line-height: 1.4;
}

.composer textarea:focus {
  outline: none;
}

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

.send-button {
  width: var(--target);
  height: var(--target);
  border: 0;
  border-radius: 50%;
  background: var(--accent-fill);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  transition: transform var(--dur-tap) var(--ease), opacity var(--dur-tap) var(--ease);
}

.send-button:active {
  transform: scale(0.94);
}

.send-button:disabled {
  opacity: 0.5;
}

.composer-status {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 8px 2px;
  min-height: 18px;
}

.composer.is-pending {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--hair));
}

/* ---------- family feed ---------- */

.filter-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-card {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chat-kind {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.message-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-card {
  background: var(--tile);
  border-radius: 18px;
  padding: 12px;
}

.message-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.message-head time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.message-text {
  margin-top: 4px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-deleted {
  margin-top: 4px;
  color: var(--danger);
  font-size: 14px;
}

.message-empty {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.message-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.important-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--target);
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.important-toggle .icon {
  width: 18px;
  height: 18px;
}

.important-toggle.is-on {
  color: var(--accent);
}

.important-toggle.is-on .icon {
  fill: currentColor;
}

.empty-inline {
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--tile);
  color: var(--muted);
  font-size: 14px;
}

.empty-state {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 22px 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

/* ---------- bindings ---------- */

.binding-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.binding-row {
  border: 1px solid var(--hair);
  border-radius: 16px;
  padding: 12px;
  background: var(--card);
}

.binding-children {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--target);
  padding: 0 12px;
  border: 1px solid var(--hair);
  border-radius: 22px;
  background: var(--tile);
  font-size: 14px;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-fill);
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- sources ---------- */

.status-card {
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.source-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-card {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.source-card.source-unavailable {
  opacity: 0.7;
}

.source-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.source-main h3 {
  overflow-wrap: anywhere;
}

.source-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  flex: none;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--target);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}

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

.switch-track {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--hair-strong);
  background: var(--tile);
  transition: background var(--dur-tap) var(--ease);
  flex: none;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--dur-tap) var(--ease), background var(--dur-tap) var(--ease);
}

.switch-row input:checked + .switch-track {
  background: var(--accent-fill);
  border-color: transparent;
}

.switch-row input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
  background: var(--on-accent);
}

.switch-row input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch-text {
  font-size: 13px;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.source-filters {
  margin-bottom: 10px;
}

.command {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: var(--tile);
  color: var(--ink);
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- details ---------- */

.detail-card {
  background: var(--tile);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-title {
  font-weight: 600;
}

.source-quote {
  background: var(--card);
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- overlays ---------- */

.overlay-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
}

.overlay-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.drawer-layer {
  justify-content: flex-start;
}

.drawer-panel {
  position: relative;
  z-index: 1;
  width: min(320px, 88vw);
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 0 24px 24px 0;
  padding: calc(16px + env(safe-area-inset-top)) 16px
    calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-float);
  animation: slide-left var(--dur-enter) var(--ease);
}

.sheet-layer {
  align-items: flex-end;
  justify-content: center;
}

.sheet-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 6px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-float);
  animation: slide-up var(--dur-sheet) var(--ease);
}

.sheet-grip {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--hair-strong);
  margin: 6px auto 4px;
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 12px;
}

.sheet-body {
  padding-bottom: 8px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--target);
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--tile);
  color: var(--ink);
}

.list-meta {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(154px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--card);
  font-size: 14px;
  box-shadow: var(--shadow-float);
}

@keyframes slide-left {
  from {
    transform: translateX(-16px);
    opacity: 0;
  }
}

@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  z-index: 30;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(420px, calc(100vw - 24px));
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-field);
  background: var(--glass);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

.tab {
  flex: 1;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 22px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  line-height: 1.2;
}

.tab:hover {
  text-decoration: none;
  background: var(--tile);
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.tab .icon {
  width: 21px;
  height: 21px;
}

/* ---------- auth ---------- */

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 18px
    calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 24px;
  padding: 26px 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lede {
  color: var(--muted);
  font-size: 15px;
}

.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 14px;
  padding: 12px;
  font-size: 14px;
}

/* ---------- desktop ---------- */

@media (min-width: 1024px) {
  .rail {
    display: flex;
    flex-direction: column;
    position: fixed;
    z-index: 35;
    top: 0;
    left: 0;
    bottom: 0;
    width: 296px;
    padding: 22px 18px;
    background: var(--surface);
    border-right: 1px solid var(--hair);
    overflow-y: auto;
  }

  .topbar {
    margin-left: 296px;
    padding-left: 28px;
    padding-right: 28px;
  }

  .app-main {
    margin-left: 296px;
    max-width: 760px;
    padding: 26px 28px 120px;
  }

  .app-main.has-composer {
    padding-bottom: 170px;
  }

  .tabbar {
    display: none;
  }

  .composer {
    left: calc(296px + (100vw - 296px) / 2);
    bottom: 24px;
    width: min(704px, calc(100vw - 296px - 56px));
  }

  .jump-latest {
    right: max(28px, calc((100vw - 296px - 704px) / 2 + 8px));
    bottom: 96px;
  }

  .pending-card {
    left: calc(296px + (100vw - 296px) / 2);
    bottom: 124px;
    width: min(704px, calc(100vw - 296px - 56px));
  }

  .sheet-layer {
    justify-content: flex-end;
    align-items: stretch;
  }

  .sheet-panel {
    width: 420px;
    max-height: 100dvh;
    border-radius: 24px 0 0 24px;
    padding: 8px 20px 24px;
    animation: slide-left var(--dur-enter) var(--ease);
  }

  .toast {
    left: calc(296px + (100vw - 296px) / 2);
    bottom: 100px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* FC1-B feed and record */
.fc1b-image,
.fc1b-image-detail {
  max-width: 100%;
  margin: 0;
}
.fc1b-image img,
.fc1b-image-detail img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
}
.fc1b-card {
  overflow-wrap: anywhere;
}
.fc1b-ocr {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, currentColor 6%, transparent);
}
.fc1b-ocr-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.75;
  margin-bottom: 4px;
}
.fc1b-ocr-text {
  white-space: pre-wrap;
}
.fc1b-actions {
  flex-wrap: wrap;
  gap: 8px;
}
.source-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, currentColor 7%, transparent);
}

/* FC1-B feed repair: compact photo gallery and authenticated lightbox */
.fc1b-gallery {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.fc1b-cover,
.fc1b-thumb,
.fc1b-grid-item {
  padding: 0;
  border: 0;
  background: var(--tile);
  border-radius: 12px;
  overflow: hidden;
  cursor: zoom-in;
}
.fc1b-cover {
  display: block;
  width: 100%;
  min-height: 44px;
}
.fc1b-cover img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  background: var(--tile);
}
.fc1b-thumbs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.fc1b-thumb {
  display: block;
  min-height: 44px;
}
.fc1b-thumb img {
  display: block;
  width: 100%;
  height: 104px;
  object-fit: cover;
}
.fc1b-more {
  align-self: flex-start;
  min-height: 44px;
}
.fc1b-photo-count {
  margin: 0;
}
.fc1b-manual-note {
  margin-top: 10px;
}
.fc1b-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.fc1b-grid-item {
  display: flex;
  flex-direction: column;
  text-align: left;
  min-height: 44px;
}
.fc1b-grid-item img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}
.fc1b-grid-caption {
  display: block;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
}
.fc1b-children-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.fc1b-child-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.fc1b-image-meta ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fc1b-image-meta li {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hair);
}
.fc1b-lightbox {
  width: min(960px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 12px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-float);
}
.fc1b-lightbox::backdrop {
  background: rgba(0, 0, 0, 0.62);
}
.fc1b-lightbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.fc1b-lightbox-counter {
  margin: 0;
  font-weight: 600;
}
.fc1b-lightbox-close,
.fc1b-lightbox-nav {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}
.fc1b-lightbox-stage {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.fc1b-lightbox-stage img {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-height: calc(100dvh - 220px);
  object-fit: contain;
  background: var(--tile);
  border-radius: 12px;
}
.fc1b-lightbox-caption {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.fc1b-lightbox-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
@media (max-width: 600px) {
  .fc1b-cover img {
    max-height: 280px;
  }
  .fc1b-thumb img {
    height: 84px;
  }
  .fc1b-lightbox {
    width: calc(100vw - 12px);
    padding: 8px;
  }
  .fc1b-lightbox-stage {
    gap: 4px;
  }
  .fc1b-lightbox-stage img {
    max-height: calc(100dvh - 240px);
  }
}
