:root {
  color-scheme: dark;

  --bg: #10201f;
  --bg-soft: #18302d;
  --panel: rgba(244, 226, 195, .10);
  --panel-2: rgba(240, 179, 90, .16);
  --border: rgba(244, 226, 195, .20);
  --text: #f4ebd7;
  --muted: #c8bda8;
  --accent: #f0b35a;
  --accent-strong: #ffd99a;
  --button: #f0b35a;
  --button-text: #10201f;
  --danger: #e8a092;
  --page-bg:
    radial-gradient(circle at 82% 8%, rgba(240, 179, 90, .18), transparent 30%),
    radial-gradient(circle at 18% 18%, rgba(139, 184, 160, .14), transparent 34%),
    linear-gradient(160deg, #1c3733 0%, var(--bg) 48%, #0a1718 100%),
    #071818;
  --auth-bg:
    radial-gradient(circle at 50% 14%, rgba(221, 190, 162, .13), transparent 34%),
    linear-gradient(160deg, #263b4d 0%, #172634 56%, #101b27 100%);
  --field-bg: rgba(12, 22, 33, .30);
  --field-border: var(--border);
  --card-shadow: 0 18px 42px rgba(6, 13, 20, .15);
  --glass-highlight: rgba(255, 217, 154, .24);
  --tab-bg: rgba(10, 23, 24, .92);
  --tab-border: rgba(244, 226, 195, .13);
  --tab-active-bg: rgba(240, 179, 90, .15);
  --assistant-bubble: rgba(240, 179, 90, .13);
  --assistant-bubble-border: rgba(255, 217, 154, .16);
  --user-bubble: #9fbe86;
  --user-bubble-text: #10201f;
  --icon-bg: var(--accent);
  --icon-text: var(--bg);
  --ghost-bg: rgba(233, 217, 196, .04);
  --ghost-hover-bg: var(--panel-2);
  --composer-bg: rgba(244, 226, 195, .11);
  --edit-bar-bg: rgba(10, 23, 24, .94);
  --composer-shadow: 0 10px 24px rgba(5, 12, 14, .22);

  --sidebar-width: 276px;
  --sidebar-collapsed: 72px;
  --content-max: 980px;
  --home-max: 680px;
  --mobile-gutter: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  overflow-x: hidden;
  background: var(--page-bg);
}

body {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page-bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei UI", Arial, sans-serif;
}

:root[data-theme="oat"],
body[data-theme="oat"] {
  color-scheme: light;
  --bg: #e8dfcf;
  --bg-soft: #d8cbb8;
  --panel: rgba(35, 50, 47, .08);
  --panel-2: rgba(143, 107, 72, .18);
  --border: rgba(73, 63, 50, .22);
  --text: #24332f;
  --muted: #6f6558;
  --accent: #9b6b3e;
  --accent-strong: #6d4428;
  --button: #9b6b3e;
  --button-text: #f8f4ea;
  --page-bg:
    radial-gradient(circle at 82% 8%, rgba(155, 107, 62, .16), transparent 30%),
    radial-gradient(circle at 18% 18%, rgba(59, 96, 84, .12), transparent 34%),
    linear-gradient(160deg, #f0eadc 0%, #e5dccb 52%, #d6c9b6 100%),
    #d6c9b6;
  --auth-bg:
    radial-gradient(circle at 50% 14%, rgba(155, 107, 62, .12), transparent 34%),
    linear-gradient(160deg, #f5ebdc 0%, #e5dccb 58%, #d2c1aa 100%);
  --field-bg: rgba(255, 252, 244, .42);
  --field-border: rgba(73, 63, 50, .22);
  --card-shadow: 0 12px 28px rgba(90, 70, 46, .08);
  --glass-highlight: rgba(255, 252, 244, .34);
  --tab-bg: rgba(240, 234, 220, .94);
  --tab-border: rgba(73, 63, 50, .16);
  --tab-active-bg: rgba(155, 107, 62, .16);
  --assistant-bubble: rgba(143, 107, 72, .14);
  --assistant-bubble-border: rgba(143, 107, 72, .18);
  --user-bubble: #9b6b3e;
  --user-bubble-text: #f8f4ea;
  --icon-bg: rgba(219, 195, 166, .72);
  --icon-text: #6d4428;
  --ghost-bg: rgba(255, 252, 244, .30);
  --ghost-hover-bg: rgba(143, 107, 72, .18);
  --composer-bg: rgba(255, 252, 244, .54);
  --edit-bar-bg: rgba(248, 242, 230, .95);
  --composer-shadow: 0 8px 18px rgba(90, 70, 46, .08);
}

:root[data-theme="mist"],
body[data-theme="mist"] {
  color-scheme: light;
  --bg: #adcad4;
  --bg-soft: #c1d2c1;
  --panel: rgba(238, 233, 208, .34);
  --panel-2: rgba(223, 213, 219, .42);
  --border: rgba(255, 255, 255, .38);
  --text: #34423f;
  --muted: #66756f;
  --accent: #8f7152;
  --accent-strong: #a88968;
  --button: #a88968;
  --button-text: #f8f4ea;
  --page-bg:
    radial-gradient(circle at 14% 26%, rgba(173, 202, 212, .72), transparent 34%),
    radial-gradient(circle at 74% 16%, rgba(219, 202, 181, .58), transparent 32%),
    radial-gradient(circle at 86% 70%, rgba(223, 213, 219, .58), transparent 34%),
    radial-gradient(circle at 26% 82%, rgba(193, 210, 193, .58), transparent 36%),
    linear-gradient(145deg, #d9e4dc 0%, #c4d9dc 42%, #e6ddd6 100%),
    #adcad4;
  --auth-bg:
    radial-gradient(circle at 16% 20%, rgba(173, 202, 212, .58), transparent 34%),
    radial-gradient(circle at 82% 18%, rgba(219, 202, 181, .46), transparent 34%),
    linear-gradient(145deg, #dce6df 0%, #c7dadc 48%, #e8ded8 100%);
  --field-bg: rgba(248, 244, 234, .50);
  --field-border: rgba(255, 255, 255, .44);
  --card-shadow: 0 6px 16px rgba(95, 105, 101, .045);
  --glass-highlight: rgba(255, 255, 255, .36);
  --tab-bg: rgba(238, 233, 208, .92);
  --tab-border: rgba(255, 255, 255, .42);
  --tab-active-bg: rgba(168, 137, 104, .18);
  --assistant-bubble: rgba(223, 213, 219, .42);
  --assistant-bubble-border: rgba(255, 255, 255, .38);
  --user-bubble: #a88968;
  --user-bubble-text: #f8f4ea;
  --icon-bg: rgba(219, 202, 181, .78);
  --icon-text: #34423f;
  --ghost-bg: rgba(255, 255, 255, .24);
  --ghost-hover-bg: rgba(223, 213, 219, .42);
  --composer-bg: rgba(238, 233, 208, .58);
  --edit-bar-bg: rgba(248, 244, 234, .94);
  --composer-shadow: 0 6px 16px rgba(71, 89, 88, .065);
}

body.auth-locked {
  overflow: hidden;
}

body.auth-locked::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--auth-bg);
  z-index: 0;
}

body.auth-locked .sidebar,
body.auth-locked .sidebar-overlay,
body.auth-locked .topbar,
body.auth-locked .notice,
body.auth-locked .view,
body.auth-locked .status,
body.auth-locked .bottom-tabs,
body.auth-locked .modal-backdrop {
  display: none !important;
}

body.auth-locked .shell {
  display: block;
  height: 100vh;
  height: 100dvh;
}

body.auth-locked .workspace {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: none;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow: hidden;
}

button, textarea, input { font: inherit; }
button {
  border: 0;
  border-radius: 12px;
  color: var(--button-text);
  background: var(--button);
  cursor: pointer;
  padding: 12px 18px;
  font-weight: 600;
}
button:hover { background: var(--accent-strong); }
button:disabled { cursor: wait; opacity: .55; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns .2s ease;
}

.shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--tab-bg);
  backdrop-filter: blur(18px);
  padding: 18px 12px;
  overflow: hidden;
}

.brand, .section-header, .topbar, .settings-actions, .modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand-copy strong { font-size: 20px; white-space: nowrap; }
.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  margin: 0 0 4px;
}

.icon-button, .ghost, .small-button {
  background: var(--ghost-bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.icon-button {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 25px;
}
.ghost { padding: 9px 13px; }
.small-button {
  height: 32px;
  width: 34px;
  padding: 0;
  font-size: 20px;
}
.icon-button:hover, .ghost:hover, .small-button:hover { background: var(--ghost-hover-bg); color: var(--accent-strong); }

.primary-nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.nav-button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  width: 100%;
  color: var(--muted);
  background: transparent;
  text-align: left;
  white-space: nowrap;
}
.nav-button.active, .nav-button:hover {
  color: var(--text);
  background: var(--panel-2);
}
.nav-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 25px;
  color: var(--accent);
  font-weight: 700;
}

.conversation-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1;
}
.section-header {
  color: var(--muted);
  padding: 0 4px;
  font-size: 13px;
}
.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  overflow-y: auto;
}
.conversation-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.conversation-button {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.delete-button {
  opacity: 0;
  flex: none;
  width: 29px;
  height: 36px;
  padding: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}
.conversation-row:hover .delete-button, .conversation-row.active .delete-button { opacity: 1; }
.delete-button:hover { background: rgba(227, 163, 155, .12); color: var(--danger); }
.sidebar-note {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 12px 5px 0;
}

.shell.sidebar-collapsed .brand-copy,
.shell.sidebar-collapsed .nav-label,
.shell.sidebar-collapsed .delete-button {
  display: none;
}
.shell.sidebar-collapsed .sidebar { align-items: center; padding-left: 9px; padding-right: 9px; }
.shell.sidebar-collapsed .primary-nav,
.shell.sidebar-collapsed .conversation-panel { width: 100%; }
.shell.sidebar-collapsed .nav-button { justify-content: center; padding-left: 0; padding-right: 0; }
.shell.sidebar-collapsed .conversation-row .nav-button { display: none; }
.shell.sidebar-collapsed .section-header { justify-content: center; }

.workspace {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 14px;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px max(12px, env(safe-area-inset-bottom));
}
.shell[data-view="home"] .topbar { display: none; }
.shell[data-view="home"] .workspace {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.page-heading { flex: 1; min-width: 0; }
h1 { font-size: clamp(22px, 5vw, 28px); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h2 { margin: 0 0 6px; font-size: 18px; }

.notice, .login-card, .setting-card, .glass-card {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(16px);
  border-radius: 18px;
  padding: 14px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.notice { color: var(--muted); font-size: 14px; }
.notice.error { border-color: rgba(227, 163, 155, .48); color: var(--danger); background: rgba(131, 51, 54, .18); }
.login-card p, .setting-card p { color: var(--muted); line-height: 1.55; margin: 0 0 14px; }
.login-card form { display: grid; gap: 10px; }
.login-card {
  width: min(100%, 420px);
}
body.auth-locked .login-card {
  position: relative;
  z-index: 1;
  display: block;
  margin: 0;
  padding: 26px;
  box-shadow: var(--card-shadow);
}
body.auth-locked .login-card h2 {
  margin-top: 0;
}
.login-error {
  color: var(--danger) !important;
  margin: 12px 0 0 !important;
}
.remember-device {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}
.remember-device input {
  width: auto;
  accent-color: var(--accent);
}

input, select, .setting-card textarea {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 12px;
  background: var(--field-bg);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
select { appearance: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.view { min-height: 0; }
.view[hidden] { display: none; }
.view-enter { animation: view-enter .16s ease-out; }
@keyframes view-enter {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}
.home-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-width: var(--home-max);
  width: 100%;
  margin: 0 auto;
  padding: 2px 0 6px;
}
.home-heading { position: relative; padding: 10px 4px 6px; }
.home-greeting {
  color: var(--accent);
  font-size: 15px;
  letter-spacing: .08em;
  margin: 0 0 9px;
}
.home-heading h2 {
  color: var(--text);
  font-size: clamp(31px, 8vw, 42px);
  font-weight: 400;
  letter-spacing: .04em;
  margin: 0;
}
.home-heading h2 span { color: var(--accent); }
.home-whisper {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  margin: 8px 2px 0;
}
.card-eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  margin: 0 0 6px;
}
.bond-card {
  text-align: center;
  padding: 18px 16px 16px;
}
.bond-card strong {
  display: block;
  color: var(--accent-strong);
  font-size: clamp(66px, 19vw, 94px);
  font-weight: 300;
  letter-spacing: .04em;
  line-height: 1;
}
.bond-caption {
  color: var(--text);
  font-size: 16px;
  letter-spacing: .1em;
  margin: 5px 0 4px;
}
.since {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  margin: 0 0 16px;
}
.continue-button { border-radius: 999px; padding: 10px 20px; }
.home-modules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}
.home-modules > *,
.bond-card,
.activity-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.module-card { min-height: 116px; padding: 14px; }
.home-link-card {
  display: block;
  color: var(--text);
  text-align: left;
  font-weight: 400;
  cursor: pointer;
}
.home-link-card:hover,
.home-link-card:focus-visible {
  color: var(--text);
  background: var(--ghost-hover-bg);
  border-color: var(--glass-highlight);
  outline: none;
}
.module-card h3, .status-card h3, .activity-card h3 {
  font-size: 16px;
  font-weight: 500;
  margin: 7px 0 5px;
}
.module-card p { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 0; }
.module-card small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 8px;
}
.module-icon { color: var(--accent); font-size: 21px; }
.conversation-shortcut p { color: var(--text); font-size: 14px; }
.room-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  color: var(--icon-text);
  background: var(--icon-bg);
  font-size: 21px;
}
.status-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.status-pills { display: flex; gap: 7px; flex-wrap: wrap; }
.status-pills span {
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  padding: 7px 12px;
}
.status-pills .active {
  color: var(--bg);
  background: var(--accent);
  border-color: transparent;
}
.activity-card { padding: 15px; }
.activity-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.activity-head span { color: var(--muted); font-size: 12px; }
.heatmap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.heatmap i {
  display: block;
  aspect-ratio: 1;
  border-radius: 6px;
  background: rgba(219, 191, 163, .06);
}
.heatmap .level-1 { background: rgba(221, 190, 162, .24); }
.heatmap .level-2 { background: rgba(221, 190, 162, .47); }
.heatmap .level-3 { background: rgba(221, 190, 162, .72); }
.heatmap .level-4 { background: var(--accent); }
.conversations-view,
.settings-hub-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}
.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.conversation-header p:not(.card-eyebrow),
.settings-intro p:not(.card-eyebrow) {
  color: var(--muted);
  line-height: 1.5;
  margin: 5px 0 0;
}
.conversation-hub-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.conversation-card {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 5px;
}
.conversation-card.active { border-color: var(--glass-highlight); }
.conversation-card-main {
  display: flex;
  flex: 1;
  min-width: 0;
  text-align: left;
  color: var(--text);
  background: transparent;
  padding: 12px;
}
.conversation-card-main:hover { background: var(--panel-2); }
.conversation-card-copy {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.conversation-card-copy strong,
.conversation-card-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-card-copy small { color: var(--muted); font-weight: 400; }
.conversation-delete { flex: none; padding: 10px 14px; }
.setting-entry-grid {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.setting-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-align: left;
  font-weight: 400;
}
.setting-entry:hover { background: var(--panel-2); color: var(--text); }
.setting-entry span:nth-child(2) {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}
.setting-entry small { color: var(--muted); }
.setting-entry b { color: var(--accent); font-size: 25px; font-weight: 400; }
.avatar-preview,
.message-avatar {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--icon-text);
  background-color: var(--icon-bg);
  background-position: center;
  background-size: cover;
  font-weight: 700;
}
.avatar-preview { width: 50px; height: 50px; font-size: 19px; }
.avatar-preview.user,
.message-avatar.user { background-color: var(--user-bubble); color: var(--user-bubble-text); }
.avatar-card { max-width: 760px; }
.avatar-input-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.avatar-input-grid input { margin-top: 8px; font-size: 13px; }
.diary-view {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}
.diary-placeholder { min-height: 220px; }

.chat-view { display: grid; grid-template-rows: 1fr auto; gap: 12px; }
.messages {
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 2px;
}
.welcome {
  align-self: center;
  color: var(--muted);
  max-width: 470px;
  text-align: center;
  line-height: 1.65;
  margin: auto 0;
}
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  width: min(88%, 720px);
}
.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message-avatar { width: 38px; height: 38px; font-size: 14px; }
.message-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
}
.message-row.user .message-main { align-items: flex-end; }
.message-meta {
  display: flex;
  gap: 9px;
  align-items: baseline;
  color: var(--muted);
  font-size: 11px;
}
.message-bubble {
  max-width: 100%;
  padding: 12px 15px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.message-bubble.assistant {
  background: var(--assistant-bubble);
  border: 1px solid var(--assistant-bubble-border);
  border-bottom-left-radius: 5px;
}
.message-bubble.user {
  color: var(--user-bubble-text);
  background: var(--user-bubble);
  border-bottom-right-radius: 5px;
}
.message-bubble.pending { color: var(--muted); }
.message-actions { display: flex; gap: 6px; opacity: .7; }
.message-actions button { padding: 4px 9px; border-radius: 8px; font-size: 11px; }
.message-memory-notice {
  align-self: flex-start;
  border: 1px solid rgba(221, 190, 162, .28);
  border-radius: 999px;
  background: rgba(221, 190, 162, .1);
  color: var(--accent);
  font-size: 11px;
  padding: 5px 9px;
}
.reasoning-summary {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--muted);
  font-size: 12px;
  padding: 7px 10px;
}
.reasoning-summary summary { color: var(--accent); cursor: pointer; }
.reasoning-summary p { margin: 8px 0 0; white-space: pre-wrap; }
.composer {
  display: flex;
  position: relative;
  align-items: end;
  gap: 10px;
  border: 1px solid var(--field-border);
  background: var(--composer-bg);
  border-radius: 18px;
  padding: 9px;
  width: min(100%, 700px);
  margin: 0 auto;
}
.edit-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% + 7px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--field-border);
  border-radius: 14px;
  background: var(--edit-bar-bg);
  color: var(--accent-strong);
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: var(--composer-shadow);
}
.edit-bar .ghost,
.stop-button {
  padding: 8px 11px;
  min-height: 38px;
}
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  max-height: 160px;
  background: transparent;
  color: var(--text);
  padding: 9px 8px;
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.send-button {
  align-self: end;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  padding: 0;
  font-size: 22px;
}
.stop-button {
  color: var(--danger);
  border-radius: 999px;
}

.settings-view { overflow-y: auto; padding: 4px 0; }
.settings-form { display: flex; flex-direction: column; gap: 14px; max-width: 760px; margin: 0 auto; }
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setting-card label { display: block; color: var(--text); margin: 0 0 8px; font-size: 14px; }
.setting-card textarea { display: block; resize: vertical; min-height: 140px; line-height: 1.55; }
.saved-indicator { color: var(--accent); font-size: 13px; min-height: 20px; }
.api-node-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.api-node-heading h3 {
  margin: 0 0 5px;
  font-size: 16px;
  font-weight: 500;
}
.api-node-heading.compact {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.api-add-button {
  width: 100%;
  margin-top: 10px;
}
.api-node-heading p,
.api-node-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}
.api-node-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.api-node-card {
  border: 1px solid var(--field-border);
  border-radius: 16px;
  background: var(--field-bg);
  padding: 12px;
}
.api-node-list-item {
  display: block;
  width: 100%;
  color: var(--text);
  text-align: left;
}
.api-node-list-item:hover {
  color: var(--text);
  background: var(--panel-2);
}
.api-node-card.readonly {
  opacity: .82;
}
.api-node-card-header,
.api-node-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.api-node-card-header strong {
  font-size: 14px;
  font-weight: 600;
}
.api-node-badge {
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
}
.api-node-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.api-node-fields label {
  margin: 0;
}
.api-node-fields input {
  margin-top: 6px;
}
.api-node-actions {
  justify-content: flex-end;
  margin-top: 10px;
}
.api-node-summary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 8px 0 0;
  overflow-wrap: anywhere;
}
.api-node-fields.single {
  grid-template-columns: 1fr;
}
.push-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.push-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.push-actions button {
  flex: 1 1 180px;
}
.push-devices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.push-devices-heading,
.push-device-card,
.push-device-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.push-devices-heading {
  justify-content: space-between;
}
.push-device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.push-device-card {
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid var(--field-border);
  border-radius: 14px;
  background: var(--ghost-bg);
}
.push-device-card.current {
  border-color: var(--glass-highlight);
}
.push-device-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.push-device-main input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
}
.push-device-main small {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.push-device-actions {
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.saved-indicator.error {
  color: var(--danger);
}
.ghost.danger {
  color: var(--danger);
}

.memory-view {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0;
}
.memory-header, .memory-toolbar, .memory-card-header, .memory-card-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.memory-intro p { margin-bottom: 0; }
.privacy-warning {
  margin-top: 14px !important;
  border-radius: 10px;
  background: rgba(221, 190, 162, .12);
  color: var(--accent) !important;
  padding: 10px 12px;
  font-size: 13px;
}
.memory-form { display: flex; flex-direction: column; gap: 12px; }
.dream-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dream-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.dream-actions button {
  flex: 1 1 160px;
}
.dream-log {
  width: 100%;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--field-border);
  border-radius: 13px;
  background: var(--field-bg);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
}
.memory-fields { display: grid; gap: 8px; }
.memory-fields textarea {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 12px;
  background: var(--field-bg);
  color: var(--text);
  padding: 11px 12px;
  resize: vertical;
}
.memory-toolbar { align-items: center; }
.memory-toolbar input { flex: 1; }
.memory-list { display: flex; flex-direction: column; gap: 10px; }
.memory-empty { color: var(--muted); text-align: center; padding: 28px 10px; }
.memory-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 13px 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.memory-card h3 { margin: 0; font-size: 15px; }
.memory-card p { white-space: pre-wrap; word-break: break-word; line-height: 1.55; margin: 10px 0; }
.memory-meta { color: var(--muted); font-size: 12px; }
.memory-badge {
  background: rgba(221, 190, 162, .18);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}
.memory-card-actions { justify-content: flex-end; }
.memory-card-actions button { padding: 7px 11px; font-size: 13px; }
.memory-card-actions .danger { color: var(--danger); }

.status { text-align: center; font-size: 12px; color: var(--muted); }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 17, .62);
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: min(430px, 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  padding: 22px;
}
.modal-card p { color: var(--muted); line-height: 1.55; }
.modal-card label { display: block; margin: 16px 0 8px; }
.modal-actions { justify-content: flex-end; margin-top: 20px; }
.sr-only { position: absolute; height: 1px; width: 1px; overflow: hidden; clip-path: inset(50%); }
.mobile-only { display: none; }
.mobile-label { display: none; }
.mobile-only[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .view-enter { animation: none; }
}

.send-button {
  background: var(--button);
  color: var(--button-text);
}

.bottom-tabs {
  background: var(--tab-bg);
  border-top: 1px solid var(--tab-border);
}
.tab-button.active {
  background: var(--tab-active-bg);
  color: var(--accent-strong);
}

/* Mobile / iPhone PWA layout */
@media (max-width: 720px) {
  :root {
    --mobile-tab-height: 56px;
    --mobile-tab-safe: env(safe-area-inset-bottom);
    --mobile-tab-total: calc(var(--mobile-tab-height) + var(--mobile-tab-safe));
    --mobile-topbar-height: 48px;
    --app-height: 100dvh;
  }

  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body { min-height: var(--app-height); }

  .shell {
    display: block;
    height: var(--app-height);
    max-height: var(--app-height);
    overflow: hidden;
  }

  .mobile-only { display: inline-grid; place-items: center; }
  .desktop-only,
  .desktop-label,
  .sidebar,
  .sidebar-overlay,
  .status { display: none; }
  .mobile-label { display: inline; }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    height: var(--app-height);
    max-height: var(--app-height);
    min-height: 0;
    overflow: hidden;
    padding:
      max(8px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      calc(var(--mobile-tab-total) + 8px)
      max(12px, env(safe-area-inset-left));
  }

  .topbar {
    flex: 0 0 var(--mobile-topbar-height);
    min-height: var(--mobile-topbar-height);
    padding: 0;
    gap: 8px;
  }

  .topbar .icon-button {
    width: 38px;
    height: 38px;
    min-height: 38px;
    border-radius: 13px;
    font-size: 20px;
  }

  .topbar .ghost {
    min-height: 32px;
    padding: 5px 9px;
    border-radius: 11px;
    font-size: 11px;
  }

  .page-heading { min-width: 0; }
  .page-heading .eyebrow {
    margin-bottom: 1px;
    font-size: 9px;
    letter-spacing: .14em;
  }

  h1 {
    font-size: 19px;
    line-height: 1.1;
  }

  .notice { flex: 0 0 auto; }

  .view:not([hidden]) {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .chat-view {
    gap: 8px;
  }

  .shell[data-view="chat"] .chat-view {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
  }

  .messages {
    padding: 2px 0;
  }

  .shell[data-view="chat"] .messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 4px 0 8px;
  }

  .message-row {
    width: 100%;
    gap: 7px;
  }

  .message-main { max-width: calc(100% - 47px); }
  .message-bubble { padding: 11px 13px; }
  .message-avatar { width: 36px; height: 36px; }

  .shell[data-view="chat"] .composer {
    flex: 0 0 auto;
    position: relative;
    z-index: 15;
    width: 100%;
    max-width: none;
    min-height: 50px;
    margin: 0;
    padding: 6px;
    border-radius: 19px;
    background: var(--composer-bg);
    box-shadow: var(--composer-shadow);
  }

  .shell:not([data-view="chat"]) input,
  .shell:not([data-view="chat"]) textarea,
  .shell:not([data-view="chat"]) select {
    scroll-margin-bottom: 96px;
  }

  .shell[data-view="chat"] .composer textarea {
    min-height: 38px;
    max-height: 104px;
    padding: 7px 6px;
    font-size: 16px;
    line-height: 1.35;
  }

  .shell[data-view="chat"] .send-button {
    width: 38px;
    height: 38px;
    min-height: 38px;
    font-size: 17px;
  }

  input,
  select,
  .setting-card textarea,
  .memory-fields textarea { font-size: 16px; }

  .settings-form,
  .memory-view {
    gap: 10px;
    width: 100%;
    max-width: 100%;
  }

  .api-node-heading { flex-direction: column; }
  .api-node-heading .ghost { width: 100%; justify-content: center; }
  .api-node-fields,
  .avatar-input-grid,
  .home-modules { grid-template-columns: 1fr; }

  .conversations-view,
  .settings-hub-view {
    gap: 10px;
    max-width: 100%;
  }

  .conversation-header { padding: 12px; }
  .conversation-card-main { padding: 10px; }
  .setting-card,
  .memory-card { padding: 12px; }
  .memory-header { align-items: flex-start; }
  .memory-toolbar { gap: 8px; }
  .memory-card-actions button,
  .modal-actions button { min-height: 44px; }
  .memory-card-actions button { flex: 1; }
  .push-device-card {
    align-items: stretch;
    flex-direction: column;
  }
  .push-device-actions button {
    flex: 1 1 90px;
  }
  .modal-card { padding: 18px; }

  .home-view {
    gap: 11px;
    width: 100%;
    max-width: 100%;
    padding: 8px 0 2px;
  }

  .home-heading { padding: 12px 6px 8px; }
  .home-heading h2 { font-size: clamp(31px, 9vw, 38px); }
  .bond-card { padding: 17px 14px 15px; }
  .bond-card strong { font-size: clamp(62px, 20vw, 82px); }
  .module-card { min-height: auto; }
  .activity-card { margin-bottom: 3px; }

  .shell:not([data-view="chat"]) .workspace {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .shell:not([data-view="chat"]) .view:not([hidden]) {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--mobile-tab-total) + 16px);
    scroll-padding-bottom: calc(var(--mobile-tab-total) + 16px);
  }

  .shell:not([data-view="chat"]) .view:not([hidden]) > *:last-child {
    margin-bottom: 0;
  }

  .bottom-tabs {
    position: fixed;
    z-index: 12;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    gap: 3px;
    height: var(--mobile-tab-total);
    min-height: var(--mobile-tab-total);
    padding: 5px 8px var(--mobile-tab-safe);
    border-top: 1px solid var(--tab-border);
    background: var(--tab-bg);
    box-shadow: 0 -8px 20px rgba(0, 0, 0, .04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow: hidden;
  }

  body::after {
    display: none;
  }

  .tab-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 25%;
    height: 48px;
    min-height: 48px;
    border-radius: 16px;
    padding: 4px 4px 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    background: transparent;
    transform: none;
  }

  .tab-icon {
    color: inherit;
    font-size: 20px;
    line-height: 1;
  }

  .tab-button.active,
  .tab-button:hover {
    color: var(--accent-strong);
    background: var(--tab-active-bg);
    box-shadow: none;
    transform: none;
  }
}

@media (max-width: 380px) {
  :root { --mobile-gutter: 14px; }
  .page-heading .eyebrow { letter-spacing: .1em; }
}


/* Mobile keyboard state */
@media (max-width: 720px), (pointer: coarse) {
  html.keyboard-open .bottom-tabs,
  .shell[data-keyboard="open"] .bottom-tabs {
    display: none !important;
    pointer-events: none !important;
  }

  html.keyboard-open .workspace,
  .shell[data-keyboard="open"] .workspace {
    padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
  }

  .shell[data-view="chat"][data-keyboard="open"] .chat-view {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding-bottom: 0 !important;
  }

  .shell[data-view="chat"][data-keyboard="open"] .messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px !important;
  }

  .shell[data-view="chat"][data-keyboard="open"] .composer {
    flex: 0 0 auto !important;
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }
}
