:root {
  color-scheme: dark;
  font-family: Inter, Pretendard, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b0f19;
  color: #e7eaf2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(ellipse at 50% -15%, #202b4b 0, #0b0f19 55%); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.app-shell { width: min(1440px, 100% - 48px); min-height: 100vh; margin: 0 auto; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0; border-bottom: 1px solid #ffffff14; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid #a78bfa66; border-radius: 13px; background: #8b5cf622; color: #c4b5fd; font-weight: 800; font-size: 20px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 3px; color: #818ca3; font-size: 11px; }
.status { padding: 7px 11px; border: 1px solid #ffffff20; border-radius: 999px; color: #aab3c5; font-size: 11px; white-space: nowrap; }
.status[data-state="ok"] { border-color: #34d39955; color: #6ee7b7; }
.status[data-state="error"] { border-color: #fb718555; color: #fda4af; }
.workspace { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 22px; flex: 1; min-height: 0; padding: 24px 0; }
.settings-panel, .chat-panel { border: 1px solid #ffffff16; border-radius: 20px; background: #111827c9; box-shadow: 0 20px 70px #0002; }
.settings-panel { align-self: start; padding: 20px; }
.panel-heading, .chat-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading { margin-bottom: 20px; }
.eyebrow { display: block; margin-bottom: 5px; color: #a78bfa; font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.panel-heading h2, .chat-heading h1 { margin: 0; font-size: 17px; letter-spacing: -.03em; }
.local-only { color: #9ca3af; font-size: 10px; white-space: nowrap; }
.settings-panel label { display: grid; gap: 7px; margin-bottom: 15px; color: #aab3c5; font-size: 11px; }
.memory-automation-toggle { display: flex !important; grid-template-columns: 18px 1fr !important; align-items: center; gap: 9px !important; }
.memory-automation-toggle input { width: 16px; height: 16px; margin: 0; accent-color: #a78bfa; }
#memory-summary-interval { max-width: 140px; }
input, select, textarea { width: 100%; min-width: 0; border: 1px solid #ffffff20; border-radius: 10px; outline: none; background: #0b1220; color: #e7eaf2; }
input, select { height: 40px; padding: 0 11px; font-size: 12px; }
textarea { padding: 11px 12px; resize: vertical; font-size: 13px; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: #a78bfa99; box-shadow: 0 0 0 3px #8b5cf622; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details { margin-top: 4px; border-top: 1px solid #ffffff12; padding-top: 14px; }
summary { color: #cbd5e1; font-size: 12px; cursor: pointer; }
details textarea { margin-top: 12px; }
.privacy-note { margin: 18px 0 0; color: #7f8ba2; font-size: 10px; line-height: 1.65; }
.chat-panel { display: flex; flex-direction: column; min-height: 650px; overflow: hidden; }
.chat-heading { padding: 18px 22px; border-bottom: 1px solid #ffffff12; }
.quiet-button { border: 1px solid #ffffff20; border-radius: 9px; padding: 8px 10px; background: transparent; color: #aab3c5; font-size: 11px; }
.quiet-button:hover { background: #ffffff0a; color: #fff; }
.messages { display: flex; flex: 1; flex-direction: column; gap: 16px; min-height: 420px; padding: 24px clamp(14px, 4vw, 42px); overflow-y: auto; }
.empty-state { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #8995ac; }
.empty-orb { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 16px; border: 1px solid #a78bfa55; border-radius: 18px; background: #8b5cf622; color: #c4b5fd; font-size: 24px; }
.empty-state h2 { margin: 0 0 8px; color: #dbe2ef; font-size: 18px; }
.empty-state p { max-width: 360px; margin: 0; font-size: 12px; line-height: 1.7; }
.message { max-width: min(88%, 760px); padding: 13px 16px; border: 1px solid #ffffff12; border-radius: 15px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.8; }
.message.user { align-self: flex-end; border-color: #8b5cf644; border-bottom-right-radius: 5px; background: #49358a44; }
.message.assistant { align-self: flex-start; border-bottom-left-radius: 5px; background: #1a2435; }
.message-speaker { margin: 0 0 6px; color: #a5b4fc; font-size: 11px; font-weight: 700; line-height: 1.4; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message.assistant > :first-child { margin-top: 0; }
.message.assistant > :last-child { margin-bottom: 0; }
.message.assistant p { margin: 0 0 10px; white-space: pre-wrap; }
.message.assistant h1, .message.assistant h2, .message.assistant h3,
.message.assistant h4, .message.assistant h5, .message.assistant h6 { margin: 12px 0 7px; color: #e2e8f0; line-height: 1.45; }
.message.assistant ul, .message.assistant ol { margin: 6px 0 10px; padding-left: 22px; }
.message.assistant li { padding-left: 2px; margin: 3px 0; }
.message.assistant blockquote { margin: 8px 0; padding: 3px 12px; border-left: 2px solid #8b5cf6; color: #aab3c5; }
.message.assistant pre { max-width: 100%; margin: 9px 0; padding: 11px 12px; overflow-x: auto; border: 1px solid #ffffff18; border-radius: 9px; background: #0b0f19; white-space: pre; }
.message.assistant code { padding: 1px 4px; border-radius: 4px; background: #0b0f1988; color: #c4b5fd; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .92em; }
.message.assistant pre code { padding: 0; background: transparent; color: #dbe2ef; }
.message.assistant a { color: #c4b5fd; text-decoration: underline; text-underline-offset: 2px; }

.message.error { align-self: flex-start; border-color: #fb718555; background: #7f1d1d22; color: #fda4af; }
.message.pending:empty::after { content: "리아가 생각하고 있어요…"; color: #8995ac; font-style: italic; }
.composer { padding: 15px; border-top: 1px solid #ffffff12; background: #0b1220aa; }
.composer textarea { min-height: 58px; max-height: 220px; border-radius: 13px; background: #0b0f19; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px 0; }
#turn-status { color: #7f8ba2; font-size: 10px; }
.composer-actions { display: flex; gap: 8px; }
.send-button, .stop-button { min-width: 76px; border: 0; border-radius: 10px; padding: 9px 14px; font-size: 11px; font-weight: 700; }
.send-button { background: #8b5cf6; color: white; }
.send-button:hover { background: #7c3aed; }
.stop-button { border: 1px solid #fb718566; background: #7f1d1d33; color: #fda4af; }
button:disabled { opacity: .4; cursor: not-allowed; }
footer { display: flex; justify-content: space-between; gap: 12px; padding: 14px 2px 20px; color: #737e94; font-size: 10px; }
@media (max-width: 820px) {
  .app-shell { width: min(100% - 24px, 720px); }
  .workspace { grid-template-columns: 1fr; gap: 12px; }
  .settings-panel { order: 0; }
  .chat-panel { order: 1; min-height: 65vh; }
  .messages { min-height: 300px; }
}
@media (max-width: 480px) {
  .app-shell { width: calc(100% - 16px); }
  .topbar { padding: 14px 2px; }
  .workspace { padding: 12px 0; }
  .settings-panel { padding: 15px; }
  .chat-heading { padding: 15px; }
  .message { max-width: 96%; }
  footer { flex-direction: column; }
}

.branch-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.branch-tools label { color: #8995ac; font-size: 10px; }
.branch-tools select { width: auto; min-width: 130px; max-width: 220px; height: 32px; font-size: 10px; }
.message-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; opacity: .75; }
.message-action { border: 1px solid #ffffff20; border-radius: 7px; padding: 4px 8px; background: #0b122055; color: #aab3c5; font-size: 10px; }
.message-action:hover { border-color: #a78bfa88; color: #fff; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .branch-tools { align-items: stretch; }
  .branch-tools select { flex: 1; min-width: 100px; }
  .branch-tools button { flex: 1; }
}

.revision-pager { display: inline-flex; align-items: center; gap: 5px; margin-left: 4px; padding: 2px 4px; border: 1px solid #ffffff1c; border-radius: 8px; }
.revision-arrow { width: 23px; height: 22px; border: 0; border-radius: 5px; background: #ffffff0a; color: #c4b5fd; font-size: 17px; line-height: 1; }
.revision-arrow:not(:disabled):hover { background: #8b5cf633; }
.revision-count { min-width: 28px; color: #aab3c5; font-size: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.info-table-wrap { max-width: 100%; max-height: 250px; overflow: auto; margin-top: 10px; border: 1px solid #ffffff14; border-radius: 9px; }
#info-table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 10px; }
#info-table th, #info-table td { padding: 6px; border-bottom: 1px solid #ffffff12; text-align: left; vertical-align: top; }
#info-table thead th { position: sticky; top: 0; background: #182235; color: #aab3c5; white-space: nowrap; }
#info-table tbody th { color: #c4b5fd; font-variant-numeric: tabular-nums; }
#info-table .info-value { min-width: 65px; height: 30px; padding: 5px 6px; border-radius: 6px; font-size: 10px; }
#info-table td:nth-child(3) .info-value, #info-table td:nth-child(7) .info-value { min-width: 160px; }
#info-table .info-value[readonly] { opacity: .72; background: #111827; }
.info-lock { display: flex !important; align-items: center; grid-template-columns: auto 1fr; gap: 3px !important; margin: 4px 0 0 !important; color: #77839a !important; font-size: 9px !important; }
.info-lock input { width: 12px; height: 12px; }
#info-panel { margin: 0; padding: 12px 22px; border-bottom: 1px solid #ffffff12; background: #0d1422aa; }
#info-panel summary { color: #c4b5fd; font-weight: 700; }

.info-time-field { display: grid; gap: 5px; margin: 10px 0; color: #aab3c5; font-size: 10px; }
.info-time-field input { height: 32px; font-size: 10px; }

#vault-panel { margin: 0; padding: 12px 22px; border-bottom: 1px solid #ffffff12; background: #0d142288; }
#vault-panel summary { color: #c4b5fd; font-weight: 700; }
.vault-add-form { display: grid; gap: 7px; max-width: 680px; margin: 10px 0; }
.vault-add-form input, .vault-add-form select, .vault-add-form textarea { min-width: 0; font-size: 11px; }
.vault-add-form .two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.vault-add-form button { justify-self: start; }
.vault-items { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,260px),1fr)); gap: 8px; }
.vault-item { min-width: 0; padding: 10px; border: 1px solid #ffffff14; border-radius: 9px; background: #ffffff05; }
.vault-item-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.vault-item-heading strong { color: #e2e8f0; font-size: 12px; overflow-wrap: anywhere; }
.vault-item-heading span { color: #aab3c5; font-size: 10px; text-align: right; }
.vault-item p { margin: 7px 0; color: #aab3c5; font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }


.vault-browse-tools { display: grid; grid-template-columns: minmax(0,1fr) 130px; gap: 7px; max-width: 680px; margin: 10px 0; }
.vault-browse-tools input, .vault-browse-tools select { height: 36px; font-size: 11px; }
.vault-item-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
@media (max-width: 480px) { .vault-browse-tools { grid-template-columns: 1fr; } }


#process-plan-panel { padding: 12px 22px; border-bottom: 1px solid #ffffff12; background: #0d142277; }
#process-plan-panel summary { color: #c4b5fd; font-weight: 700; }
#process-plan-editor { display: block; width: 100%; min-height: 170px; margin: 10px 0; font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
.process-plan-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.process-plan-heading strong { color: #e2e8f0; font-size: 12px; overflow-wrap: anywhere; }
.process-plan-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.process-plan-actions button:disabled { opacity: .4; cursor: not-allowed; }
.process-plan-progress { white-space: pre-wrap; overflow-wrap: anywhere; margin: 10px 0; padding: 10px; border: 1px solid #ffffff14; border-radius: 8px; color: #cbd5e1; background: #ffffff05; font: 11px/1.8 ui-monospace, SFMono-Regular, Consolas, monospace; }
@media (max-width: 480px) { #process-plan-panel { padding: 12px 15px; } .process-plan-heading { align-items: flex-start; flex-direction: column; } }


.vault-add-form { max-width: 760px; }
.vault-add-form > input, .vault-add-form > textarea { width: 100%; }
.vault-item-title { display: grid; gap: 3px; min-width: 0; }
.vault-item-title small { color: #818da3; font-size: 10px; overflow-wrap: anywhere; }
.vault-item-details { display: grid; gap: 5px; margin-top: 8px; }
.vault-item-details p { display: grid; grid-template-columns: 92px minmax(0,1fr); gap: 8px; margin: 0; }
.vault-item-details b { color: #8793a8; font-size: 10px; font-weight: 600; }
.vault-item-details span { color: #c1cad8; font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.vault-edit-form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid #ffffff18; }
.vault-edit-field { display: grid; gap: 4px; min-width: 0; color: #9ba8bc; font-size: 10px; }
.vault-edit-field input, .vault-edit-field select, .vault-edit-field textarea { width: 100%; min-width: 0; font-size: 11px; }
.vault-edit-field:nth-last-of-type(-n+2) { grid-column: 1 / -1; }
.vault-edit-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 7px; }
@media (max-width: 480px) {
  .vault-edit-form { grid-template-columns: 1fr; }
  .vault-edit-field:nth-last-of-type(-n+2) { grid-column: auto; }
  .vault-item-details p { grid-template-columns: 78px minmax(0,1fr); }
}

#gallery-panel { padding: 12px 22px; border-bottom: 1px solid #ffffff12; background: #0d142277; }
#gallery-panel summary { color: #c4b5fd; font-weight: 700; }
.gallery-add-form { display:grid; gap:7px; max-width:760px; margin:10px 0; }
.gallery-add-form input,.gallery-add-form select,.gallery-add-form textarea { min-width:0; font-size:11px; }
.gallery-add-form .two-fields { display:grid; grid-template-columns:1fr 1fr; gap:7px; }
.gallery-add-form button { justify-self:start; }
.gallery-browse-tools { display:grid; grid-template-columns:minmax(0,1fr) 130px 140px; gap:7px; margin:10px 0; }
.gallery-items { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,260px),1fr)); gap:9px; }
.gallery-item { min-width:0; padding:10px; border:1px solid #ffffff18; border-radius:10px; background:#ffffff05; }
.gallery-preview { display:flex; align-items:center; justify-content:center; min-height:90px; max-height:300px; overflow:hidden; border-radius:7px; background:#080d16; }
.gallery-media { display:block; max-width:100%; max-height:300px; object-fit:contain; }
.gallery-metadata { display:grid; gap:5px; margin-top:9px; }
.gallery-metadata strong { color:#e2e8f0; font-size:12px; }
.gallery-metadata p { display:grid; grid-template-columns:75px minmax(0,1fr); gap:7px; margin:0; font-size:10px; }
.gallery-metadata b { color:#8793a8; }
.gallery-metadata span { color:#c1cad8; white-space:pre-wrap; overflow-wrap:anywhere; }
.gallery-actions { display:flex; justify-content:flex-end; gap:6px; margin-top:8px; }
.gallery-edit-form { display:grid; gap:7px; margin-top:8px; }
.gallery-edit-form label { display:grid; gap:4px; color:#9ba8bc; font-size:10px; }
.gallery-edit-form input,.gallery-edit-form select { width:100%; font-size:11px; }
@media(max-width:480px){.gallery-browse-tools,.gallery-add-form .two-fields{grid-template-columns:1fr;}#gallery-panel{padding:12px 15px;}}

#process-archives-panel { padding:12px 22px; border-bottom:1px solid #ffffff12; background:#0d142277; }
#process-archives-panel summary { color:#c4b5fd; font-weight:700; }
#process-archive-form { display:grid; gap:7px; max-width:760px; margin:10px 0; }
#process-archive-form input,#process-archive-form textarea { min-width:0; font-size:11px; }

.process-plan-attachment { display:flex; align-items:center; flex-wrap:wrap; gap:8px; margin:8px 0; }
.process-plan-attachment input { max-width:260px; font-size:11px; }
.process-step-row { display:flex; align-items:flex-start; gap:8px; padding:3px 0; }
.process-step-marker { min-width:18px; font-weight:700; }
.process-step-row .is-current { font-weight:700; }
.process-step-row .is-complete { opacity:.65; text-decoration:line-through; }


/* Command autocomplete */
.composer-input-wrap { position: relative; }
.command-suggestions {
  position: absolute; z-index: 20; left: 0; right: 0; bottom: calc(100% + 8px);
  display: grid; gap: 4px; max-height: min(42vh, 280px); overflow: auto;
  padding: 7px; border: 1px solid #ffffff24; border-radius: 12px;
  background: #111a2a; box-shadow: 0 12px 32px #0008;
}
.command-suggestions[hidden] { display: none; }
.command-suggestion { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; width: 100%; padding: 9px 11px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: #e5eaf5; text-align: left; cursor: pointer; }
.command-suggestion strong { font-size: 12px; white-space: nowrap; }
.command-suggestion small { color: #8995ac; font-size: 10px; text-align: right; }
.command-suggestion:hover, .command-suggestion.is-active { border-color: #8b5cf688; background: #8b5cf622; }
@media (max-width: 480px) {
  .command-suggestion { flex-direction: column; gap: 3px; }
  .command-suggestion small { text-align: left; }
}

#turn-status.command-error { color: #fb7185; font-weight: 700; }

/* v2 remote storage and legacy migration */
#storage-panel { margin-top: 12px; padding-top: 10px; border-top: 1px solid #ffffff18; }
#storage-panel > label { display: grid; gap: 6px; margin: 10px 0; }
#storage-panel input[type="password"] { width: 100%; }
#storage-status[data-state="error"], #storage-status[data-state="conflict"] { color: #fb7185; }
#storage-status[data-state="synced"], #storage-status[data-state="connected"] { color: #86efac; }
.migration-options { display: grid; gap: 7px; margin: 10px 0; }
.migration-options label { display: flex; align-items: center; gap: 8px; font-size: 12px; }
#legacy-migrate:disabled { opacity: .55; cursor: wait; }


/* Fixed application chrome: only the conversation timeline scrolls with chat gestures. */
html, body { width: 100%; height: 100%; min-height: 0; overflow: hidden; }
body { height: 100dvh; }
.app-shell {
  width: min(1440px, 100% - 48px);
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.topbar, footer { flex: 0 0 auto; }
.workspace {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}
.settings-panel {
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.chat-panel > * { flex-shrink: 0; }
.messages {
  flex: 1 1 0;
  min-height: 0;
  height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overflow-anchor: none;
}
.composer { flex: 0 0 auto; }

/* Narrow screens keep the settings and chat in fixed regions; chat alone scrolls. */
@media (max-width: 820px) {
  html, body { height: 100%; overflow: hidden; }
  body { height: 100dvh; }
  .app-shell {
    width: calc(100% - 16px);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  .topbar { padding: 10px 2px; }
  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 34%) minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    overflow: hidden;
    padding: 8px 0;
  }
  .settings-panel {
    order: 0;
    min-height: 0;
    max-height: none;
    overflow: hidden;
    padding: 10px 12px;
  }
  .chat-panel {
    order: 1;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  .messages { min-height: 0; height: 0; }
  .composer { padding: 9px; }
  .composer textarea { min-height: 48px; max-height: 120px; }
  footer { padding: 6px 2px; }
}


/* v1-style compact utility controls: panels stay closed until requested. */
.chat-panel { position: relative; }
.chat-panel > details { display: none !important; }
.chat-panel > details.utility-panel-open {
  display: block !important;
  position: absolute;
  z-index: 60;
  left: 12px;
  right: 12px;
  bottom: 112px;
  max-height: min(64dvh, 560px);
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid #ffffff24;
  border-radius: 14px;
  background: #111827f7;
  box-shadow: 0 16px 44px #0009;
}
.utility-panel-buttons {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.utility-panel-buttons::-webkit-scrollbar { display: none; }
.utility-panel-toggle {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid #ffffff20;
  border-radius: 9px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 10px;
  white-space: nowrap;
}
.utility-panel-toggle[aria-expanded="true"] {
  border-color: #a78bfa99;
  background: #6d28d944;
  color: #ede9fe;
}
.composer-input-row { display: flex; align-items: flex-end; gap: 8px; min-width: 0; }
.composer-input-row .composer-input-wrap { flex: 1 1 auto; min-width: 0; }
.composer { position: relative; z-index: 40; }
.messages {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none;
  overflow-y: auto !important;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.chat-panel > .chat-heading { flex: 0 0 auto; }
.chat-panel > .messages { flex: 1 1 0; }
.topbar-actions { display:flex; align-items:center; gap:8px; }
#mobile-settings-toggle { display:none; }
@media (max-width: 820px) {
  #mobile-settings-toggle { display:inline-flex; }
  .topbar-actions .status { max-width:42vw; overflow:hidden; text-overflow:ellipsis; }
  .workspace { position:relative; grid-template-columns: minmax(0,1fr) !important; grid-template-rows: minmax(0,1fr) !important; }
  .settings-panel { display: none !important; }
  .settings-panel.mobile-settings-open {
    display:block !important;
    position:absolute;
    z-index:60;
    top:6px;
    right:4px;
    width:min(92vw,380px);
    max-height:78dvh;
    overflow:auto;
    padding:14px;
    border:1px solid #ffffff2b;
    border-radius:14px;
    background:#111827;
    box-shadow:0 18px 48px #000b;
  }
  .chat-panel { min-height: 0 !important; height: 100%; }
  .chat-panel > details.utility-panel-open { left: 6px; right: 6px; bottom: 106px; max-height: 58dvh; }
  .composer { padding: 8px; }
  .composer-input-row { align-items: stretch; flex-direction: column; gap: 6px; }
  .utility-panel-buttons { width: 100%; }
  .utility-panel-toggle { min-height: 32px; padding: 5px 8px; }
  .composer textarea { min-height: 48px; max-height: 100px; }
  .composer-bottom { padding-top: 6px; }
}


/* v1-style right-side settings drawer */
.workspace { grid-template-columns: minmax(0,1fr) !important; }
.settings-panel {
  position: fixed;
  z-index: 81;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 94vw);
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 18px 0 0 18px;
  padding: 18px;
  background: #0f172a;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform .26s ease, visibility .26s ease;
  -webkit-overflow-scrolling: touch;
}
.settings-panel.drawer-open { transform: translateX(0); visibility: visible; }
.settings-panel.drawer-closed { transform: translateX(105%); visibility: hidden; }
.settings-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  background: rgb(0 0 0 / .62);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.settings-backdrop.is-visible { opacity: 1; pointer-events: auto; }
.settings-backdrop[hidden] { display: none !important; pointer-events: none !important; }
body.drawer-lock { overflow: hidden; }
.topbar-actions { display:flex; align-items:center; gap:8px; }
#settings-toggle { display:inline-flex; align-items:center; min-height:40px; }
.composer { position:relative; }
.composer-input-row { position:relative; display:flex; align-items:center; gap:8px; min-width:0; }
.composer-icon-button {
  flex:0 0 42px; width:42px; height:42px; border:1px solid #ffffff20;
  border-radius:12px; background:#1e293b; color:#cbd5e1; font-size:25px;
}
.composer-plus-menu {
  position:absolute; z-index:70; left:0; bottom:calc(100% + 10px);
  width:min(270px, 82vw); padding:8px; border:1px solid #ffffff25;
  border-radius:14px; background:#252d3c; box-shadow:0 18px 48px #000b;
}
.composer-plus-menu[hidden] { display:none; }
.composer-plus-menu button {
  display:block; width:100%; padding:13px 12px; text-align:left;
  border-radius:9px; color:#e2e8f0; background:transparent; font-size:14px;
}
.composer-plus-menu button:hover { background:#ffffff12; }
@media (max-width:820px) {
  .settings-panel { display:block !important; }
  .workspace { grid-template-columns:minmax(0,1fr) !important; grid-template-rows:minmax(0,1fr) !important; }
  .settings-panel { width:min(480px,94vw); max-height:100dvh; overflow-y:auto; }
  .composer-input-row { align-items:center; }
  .utility-panel-buttons { flex:0 1 auto; }
}


/* Compact, icon-only message action bar */
.message-actions {
  display:flex; align-items:center; justify-content:flex-start; gap:7px;
  margin-top:10px; opacity:.82; flex-wrap:wrap;
}
.message-action-icon {
  display:inline-flex; align-items:center; justify-content:center;
  width:34px; height:34px; flex:0 0 34px;
  padding:7px; border:1px solid transparent; border-radius:9px;
  background:transparent; color:#9aa8bd; cursor:pointer;
  transition:background .15s ease,color .15s ease,border-color .15s ease;
}
.message-action-icon svg {
  display:block; width:20px; height:20px; fill:none;
  stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round;
}
.message-action-icon:hover { color:#f1f5f9; background:#ffffff0d; border-color:#ffffff16; }
.message-action-icon.message-delete-action { color:#94a3b8; }
.message-action-icon.message-delete-action:hover { color:#f87171; border-color:#f8717166; background:#7f1d1d22; }
.message-action-icon.is-selected[data-feedback="positive"] { color:#86efac; background:#14532d40; }
.message-action-icon.is-selected[data-feedback="negative"] { color:#fca5a5; background:#7f1d1d40; }
.message-action-icon:disabled { opacity:.35; cursor:not-allowed; }
.message-action-wrap { position:relative; display:inline-flex; }
.message-action-menu {
  position:absolute; z-index:50; left:0; bottom:calc(100% + 9px);
  display:flex; flex-direction:column; gap:7px;
  width:min(290px,82vw); padding:11px;
  border:1px solid #ffffff25; border-radius:13px;
  background:#202938; box-shadow:0 16px 40px #000a;
}
.message-action-menu[hidden] { display:none; }
.message-action-menu textarea {
  width:100%; min-height:64px; resize:vertical;
  padding:9px; border:1px solid #ffffff20; border-radius:8px;
  background:#0f172a; color:#e2e8f0; font-size:13px;
}
.message-action-menu button {
  width:100%; min-height:36px; padding:8px 10px;
  border-radius:8px; background:#334155; color:#e2e8f0;
  text-align:left; font-size:13px;
}
.message-action-menu button:hover { background:#475569; }
@media (max-width:480px) {
  .message-actions { gap:4px; }
  .message-action-icon { width:32px; height:32px; flex-basis:32px; }
  .message-action-icon svg { width:19px; height:19px; }
}

.character-profile-list { display: grid; gap: 9px; margin: 12px 0; }
.character-profile-card { display: grid; gap: 8px; padding: 12px; border: 1px solid #ffffff18; border-radius: 12px; background: #0b1220; }
.character-profile-card > strong { color: #e2e8f0; font-size: 12px; }
.character-profile-card .privacy-note { margin: 0; white-space: pre-wrap; }
.character-profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.character-profile-form { display: grid; gap: 10px; margin-top: 12px; }
.character-profile-form label { display: grid; gap: 6px; color: #aab3c5; font-size: 11px; }
.character-profile-form textarea { margin-top: 0; }
#profile-character-id[readonly] { opacity: .7; cursor: not-allowed; }

/* Memory review: correction, retraction, and reversible audit records */
.memory-candidate {
  display: grid;
  gap: 9px;
  min-width: 0;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid #ffffff18;
  border-radius: 10px;
  background: #ffffff05;
}
.memory-candidate p { margin: 0; color: #dbe2ef; font-size: 11px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-candidate small { color: #8995ac; font-size: 10px; line-height: 1.6; overflow-wrap: anywhere; }
.memory-candidate .privacy-note { margin: 0; }
.memory-review-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.memory-review-actions select { flex: 1 1 180px; min-width: 0; height: 34px; font-size: 10px; }
.memory-review-actions button { flex: 0 0 auto; }
@media (max-width: 480px) {
  .memory-review-actions { align-items: stretch; }
  .memory-review-actions select, .memory-review-actions button { flex: 1 1 100%; }
}


/* Scene-state Phase 2: branch-local event and relationship ledgers */
#scene-state-panel { padding:12px 22px; border-bottom:1px solid #ffffff12; background:#0d142277; }
#scene-state-panel summary { color:#c4b5fd; font-weight:700; }
.scene-state-content { display:grid; gap:12px; margin-top:10px; }
.scene-state-section { display:grid; gap:8px; }
.scene-state-section h3 { margin:4px 0; color:#cbd5e1; font-size:12px; }
.scene-state-card { display:grid; gap:8px; min-width:0; padding:10px; border:1px solid #ffffff18; border-radius:10px; background:#ffffff05; }
.scene-state-card > strong { color:#e2e8f0; font-size:11px; overflow-wrap:anywhere; }
.scene-state-field { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; color:#9ba8bc; font-size:10px; }
.scene-state-field > span { grid-column:1/-1; }
.scene-state-field input,.scene-state-field textarea,.scene-state-add-form input,.scene-state-add-form select,.scene-state-actions select { min-width:0; width:100%; font-size:11px; }
.scene-state-field textarea { resize:vertical; }
.scene-state-field button,.scene-state-actions button { align-self:start; }
.scene-state-add-form { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; }
.scene-state-add-form input:last-of-type { grid-column:1/-1; }
.scene-state-add-form button { justify-self:start; }
.scene-state-actions { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:7px; }
@media(max-width:480px) {
  #scene-state-panel { padding:12px 15px; }
  .scene-state-add-form { grid-template-columns:1fr; }
  .scene-state-add-form input:last-of-type { grid-column:auto; }
}


/* Per-field evidence audit for integrated multi-character state updates */
.message-state-audit {
  display: grid;
  gap: 8px;
  margin-top: 9px;
  padding: 9px 11px;
  border: 1px solid #ffffff18;
  border-radius: 9px;
  background: #0b122055;
  color: #aab3c5;
  font-size: 11px;
  overflow-wrap: anywhere;
}
.message-state-audit > summary {
  color: #c4b5fd;
  font-weight: 650;
  cursor: pointer;
}
.message-state-audit-field {
  display: grid;
  gap: 5px;
  padding-top: 7px;
  border-top: 1px solid #ffffff12;
}
.message-state-audit-field > strong { color: #e2e8f0; }
.message-state-audit-field > small { color: #93a0b5; line-height: 1.45; }
.message-state-audit-field > p { margin: 2px 0; color: #cbd5e1; }

/* Aetheria v2 workspace refresh */
.app-shell { width:100%; max-width:none; padding:0 22px; }
.topbar { padding:14px 4px; }
.workspace { display:grid; grid-template-columns:248px minmax(0,1fr) !important; gap:16px; padding:14px 0; }
/* Home and chat share the content column; sidebar remains fixed in column one. */
.workspace > #left-sidebar { grid-column:1; grid-row:1; }
.workspace > #home-screen,
.workspace > .chat-panel { grid-column:2; grid-row:1; min-width:0; }
.workspace > #home-screen { align-self:start; width:100%; }
.left-sidebar { display:flex; flex-direction:column; gap:10px; min-height:0; overflow:hidden; padding:14px 10px; border:1px solid #263248; border-radius:18px; background:#101827; }
.sidebar-collapse { align-self:flex-end; width:30px; height:30px; border:0; border-radius:8px; background:#1b2940; color:#aebbd0; font-size:20px; }
.sidebar-new-session { display:flex; align-items:center; gap:10px; min-height:42px; padding:0 13px; border:0; border-radius:11px; background:#6848d8; color:white; text-align:left; }
.sidebar-new-session span { font-size:20px; }
.sidebar-section-label { padding:12px 8px 3px; color:#72819a; font-size:9px; font-weight:800; letter-spacing:.14em; }
.sidebar-nav { display:grid; gap:3px; }
.sidebar-nav-item { display:flex; align-items:center; gap:12px; width:100%; min-height:39px; padding:7px 10px; border:1px solid transparent; border-radius:9px; background:transparent; color:#bdc8d9; text-align:left; font-size:12px; }
.sidebar-nav-item span { display:grid; place-items:center; width:20px; color:#a995f7; font-size:17px; }
.sidebar-nav-item:hover,.sidebar-nav-item[aria-expanded="true"] { border-color:#394662; background:#202c42; color:#fff; }
.session-list { display:grid; gap:4px; min-height:0; overflow:auto; }
.session-item { width:100%; padding:9px 10px; border:1px solid transparent; border-radius:9px; background:transparent; color:#aab7ca; text-align:left; font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.session-item[aria-current="true"] { border-color:#55468c; background:#30264f; color:#f0eaff; }
.left-sidebar.is-collapsed { width:64px; padding:12px 7px; }
.workspace:has(.left-sidebar.is-collapsed) { grid-template-columns:64px minmax(0,1fr) !important; }
.left-sidebar.is-collapsed .sidebar-section-label,.left-sidebar.is-collapsed .sidebar-nav-item b,.left-sidebar.is-collapsed .sidebar-new-session b,.left-sidebar.is-collapsed .session-list { display:none; }
.left-sidebar.is-collapsed .sidebar-nav-item { justify-content:center; padding:7px 0; }
.left-sidebar.is-collapsed .sidebar-new-session { justify-content:center; padding:0; }
.chat-panel { min-width:0; border-color:#263248; background:#101827; }
.chat-heading { background:#111b2c; }
.composer { padding:12px 14px; background:#0d1523; border-top-color:#29364b; }
.composer-input-row { display:flex; align-items:center; gap:9px; }
.composer-input-wrap { flex:1; min-width:0; }
.composer textarea { min-height:56px; max-height:180px; padding:15px 16px; border-color:#2b3950; border-radius:15px; background:#080e19; font-size:14px; }
.composer-icon-button { width:42px; height:42px; flex-basis:42px; }
.composer-bottom { padding-top:9px; }
.composer-actions { align-items:center; }
.composer-tool-icon { display:inline-grid; place-items:center; width:38px; height:38px; border:1px solid #2b3950; border-radius:11px; background:#172337; color:#c7d1e1; font-size:18px; }
.composer-tool-icon:hover { border-color:#7964d5; background:#282344; color:white; }
.send-button { min-width:48px; min-height:40px; font-size:18px; }
.stop-button { min-height:38px; }
#info-panel,#vault-panel,#special-vault-panel,#gallery-panel,#process-archives-panel,#process-plan-panel,#scene-state-panel,#dm-panel,#quality-panel { background:#182438 !important; border:1px solid #35445e !important; box-shadow:0 18px 50px #000b; }
.chat-panel > details.utility-panel-open { background:#182438 !important; opacity:1; backdrop-filter:none; }
.special-vault-switch { display:flex !important; grid-template-columns:auto 1fr !important; align-items:center; justify-content:flex-end; gap:9px !important; margin:8px 0 12px !important; color:#cbd5e1 !important; }
.special-vault-switch input { position:absolute; opacity:0; width:1px; height:1px; }
.switch-track { position:relative; width:38px; height:22px; border-radius:999px; background:#475569; transition:background .18s; }
.switch-track:after { content:""; position:absolute; top:3px; left:3px; width:16px; height:16px; border-radius:50%; background:#fff; transition:transform .18s; }
.special-vault-switch input:checked + .switch-track { background:#8065e8; }
.special-vault-switch input:checked + .switch-track:after { transform:translateX(16px); }
.phone-screen { position:fixed; z-index:100; inset:0; display:grid; place-items:center; background:#030712d9; backdrop-filter:blur(8px); }
.phone-screen[hidden] { display:none; }
.phone-device { position:relative; display:flex; flex-direction:column; width:min(340px,88vw); height:min(690px,86dvh); padding:14px; border:5px solid #39465a; border-radius:42px; background:#101827; box-shadow:0 30px 100px #000c; }
.phone-notch { position:absolute; top:8px; left:50%; width:100px; height:20px; transform:translateX(-50%); border-radius:20px; background:#030712; }
.phone-status { display:flex; justify-content:space-between; padding:12px 12px 18px; color:#fff; font-size:10px; }
.phone-wallpaper { display:flex; flex:1; flex-direction:column; align-items:center; justify-content:center; border-radius:28px; background:radial-gradient(ellipse at 25% 15%,#6b5bb0,#263a62 48%,#111827); }
.phone-date { color:#e0e7ff; font-size:13px; }
.phone-clock { margin:2px 0 45px; color:#fff; font-size:54px; font-weight:250; letter-spacing:-.06em; }
.phone-app-grid { display:flex; gap:22px; }
.phone-app { display:grid; justify-items:center; gap:6px; width:66px; border:0; background:transparent; color:#fff; }
.phone-app span { display:grid; place-items:center; width:52px; height:52px; border-radius:15px; background:#ffffff28; font-size:25px; backdrop-filter:blur(8px); }
.phone-app small { font-size:10px; }
.phone-close { margin-top:12px; min-height:38px; border:1px solid #ffffff25; border-radius:12px; background:#26354c; color:#fff; }
@media(max-width:820px) {
 .app-shell { padding:0 8px; }
 .workspace { grid-template-columns:64px minmax(0,1fr) !important; gap:7px; }
 .left-sidebar { padding:10px 6px; }
 .left-sidebar .sidebar-section-label,.left-sidebar .sidebar-nav-item b,.left-sidebar .sidebar-new-session b,.left-sidebar .session-list { display:none; }
 .left-sidebar .sidebar-nav-item,.left-sidebar .sidebar-new-session { justify-content:center; padding:6px 0; }
 .sidebar-nav-item { min-height:38px; }
 .composer-input-row { flex-direction:row !important; align-items:center !important; }
 .utility-panel-buttons { display:none; }
 .composer-actions { gap:4px; }
 .composer-tool-icon { width:34px; height:34px; }
}
@media(max-width:520px) {
 .topbar { padding:8px 2px; }
 .brand small { display:none; }
 .topbar-actions { gap:4px; }
 .topbar-actions .status { display:none; }
 .workspace { grid-template-columns:52px minmax(0,1fr) !important; }
 .left-sidebar { padding:8px 4px; }
 .sidebar-collapse { width:28px; height:28px; }
 .composer { padding:8px; }
 .composer-icon-button { width:36px; height:36px; flex-basis:36px; }
 .composer textarea { min-height:48px; padding:12px; font-size:13px; }
 .composer-tool-icon { width:30px; height:32px; font-size:15px; }
 .send-button { min-width:38px; padding:6px; }
}

#vault-panel.show-special-vault > p,
#vault-panel.show-special-vault > .vault-browse-tools,
#vault-panel.show-special-vault > #vault-add-form,
#vault-panel.show-special-vault > #vault-items { display:none !important; }
#vault-panel #special-vault-panel { display:block; margin-top:12px; padding:12px; border:1px solid #35445e; border-radius:12px; background:#111c2e; }
#vault-panel #special-vault-panel > summary { display:none; }
#vault-panel #special-vault-panel[open] { display:block; }
#vault-panel #special-vault-panel:not([open]) { display:none; }

/* Consistent custom line symbols for the v2 composer and phone launcher. */
.composer-tool-icon svg { width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.phone-app span svg { width:26px; height:26px; fill:none; stroke:currentColor; stroke-width:1.65; stroke-linecap:round; stroke-linejoin:round; }

/* Single integrated composer: controls remain inside one outlined bar. */
.composer { display:block; width:100%; padding:12px 14px; border-top:1px solid #29364b; background:#0d1523; }
.composer-shell {
  position:relative; display:grid; grid-template-columns:36px minmax(0,1fr) auto;
  align-items:center; gap:8px; width:100%; max-width:1100px; min-height:58px;
  margin:0 auto; padding:7px 10px; border:1px solid #2b3950; border-radius:16px;
  background:#080e19; box-shadow:0 8px 24px #0003;
}
.composer-shell > .composer-icon-button { grid-column:1; grid-row:1; align-self:center; width:34px; height:38px; padding:0; }
.composer-shell > .composer-input-wrap { grid-column:2; grid-row:1; align-self:center; flex:none; width:100%; min-width:0; }
.composer-shell textarea {
  display:block; width:100%; min-width:0; min-height:38px; max-height:220px; height:38px;
  margin:0; padding:9px 4px; resize:none !important; overflow-y:hidden;
  border:0 !important; border-radius:0; outline:0; box-shadow:none !important;
  background:transparent !important; line-height:1.5; color:#e7eaf2;
}
.composer-shell textarea:focus { border:0 !important; box-shadow:none !important; }
.composer-shell > .composer-actions { grid-column:3; grid-row:1; display:flex; align-items:center; justify-content:flex-end; gap:5px; min-width:max-content; }
.composer-shell .composer-tool-icon { display:inline-grid; place-items:center; width:36px; height:38px; padding:0; border:0; background:transparent; color:#aab8cc; }
.composer-shell .composer-tool-icon svg { width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.composer-shell .send-button, .composer-shell .stop-button {
  display:inline-grid; place-items:center; min-width:42px; width:42px; height:42px; min-height:42px;
  padding:0; border:0; border-radius:12px; font-size:20px;
}
.composer-shell .send-button { background:#9333ea; color:#fff; }
.composer-shell .stop-button { background:#8f2638; color:#fff; }
.composer-shell .stop-button[hidden], .composer-shell .send-button[hidden] { display:none !important; }
.composer-shell .composer-plus-menu { position:absolute; left:8px; bottom:calc(100% + 10px); z-index:90; }
.composer-shell #composer-media-file, .composer-shell #composer-camera-input { display:none; }
.composer .phone-screen { position:fixed; inset:0; z-index:120; }
.phone-app-grid { display:grid; grid-template-columns:repeat(2,66px); gap:18px 16px; }
.phone-app span svg { width:26px; height:26px; fill:none; stroke:currentColor; stroke-width:1.65; stroke-linecap:round; stroke-linejoin:round; }
@media (max-width:600px) {
 .composer { padding:8px; }
 .composer-shell { grid-template-columns:30px minmax(0,1fr) auto; gap:4px; min-height:52px; padding:5px 6px; border-radius:14px; }
 .composer-shell > .composer-icon-button { width:30px; height:36px; }
 .composer-shell > .composer-actions { gap:1px; }
 .composer-shell .composer-tool-icon { width:30px; height:34px; }
 .composer-shell .send-button, .composer-shell .stop-button { min-width:36px; width:36px; height:38px; min-height:38px; }
 .composer-shell textarea { min-height:36px; height:36px; padding:8px 2px; font-size:13px; }
}

/* Phone social app: the DM experience lives inside the handset. */
.phone-dm-view { display:flex; flex:1; flex-direction:column; min-height:0; overflow:hidden; margin:8px 0 10px; padding:10px; border-radius:25px; background:#111b2b; color:#e7edf7; }
.phone-dm-view[hidden] { display:none !important; }
.phone-dm-header { display:flex; align-items:center; gap:10px; min-height:38px; padding:0 2px 8px; border-bottom:1px solid #ffffff1c; }
.phone-dm-header button { width:30px; height:30px; border:0; border-radius:9px; background:#26364e; color:#fff; font-size:24px; line-height:1; }
.phone-dm-header strong { font-size:13px; color:#f1f5f9; }
.phone-dm-content { flex:1; min-height:0; overflow:auto; padding:8px 2px; }
.phone-dm-content .scene-state-add-form { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; }
.phone-dm-content select,.phone-dm-content input,.phone-dm-content textarea { max-width:100%; min-width:0; font-size:11px; }
.phone-dm-content button { max-width:100%; font-size:11px; }
.phone-dm-content .messages { max-height:42vh !important; overflow:auto; }
.phone-dm-content .message { padding:8px; margin:6px 0; border-radius:12px; }
.phone-dm-content .message p { font-size:12px; line-height:1.45; }
.phone-dm-content .privacy-note { font-size:10px; line-height:1.4; }
.phone-app-grid { grid-template-columns:repeat(3,66px); justify-content:center; }
.phone-device:has(.phone-dm-view:not([hidden])) .phone-wallpaper { display:none; }
.phone-device:has(.phone-dm-view:not([hidden])) .phone-dm-view { display:flex; }

/* v1-style camera record selector rendered as an app sheet inside the phone. */
.phone-device { overflow:hidden; }
.phone-camera-menu { position:absolute; inset:64px 10px 54px; z-index:8; display:grid; place-items:center; padding:12px; border-radius:28px; background:#070d19df; backdrop-filter:blur(12px); }
.phone-camera-menu[hidden] { display:none !important; }
.phone-camera-card { display:flex; flex-direction:column; gap:12px; width:100%; padding:18px 14px; border:1px solid #ffffff22; border-radius:20px; background:#121e31; color:#edf2fb; text-align:center; box-shadow:0 18px 50px #0009; }
.phone-camera-card strong { font-size:14px; }
.phone-camera-card p { margin:0 0 4px; color:#aab8cc; font-size:11px; line-height:1.55; }
.phone-camera-card button { min-height:42px; padding:9px 12px; border:1px solid #ffffff1c; border-radius:12px; background:#26364e; color:#eef2f8; font-size:12px; font-weight:600; }
.phone-camera-card #phone-toggle-record { border-color:#7042a7; background:#44236d; color:#eadcff; }
.phone-camera-card #phone-camera-cancel { min-height:34px; border:0; background:transparent; color:#91a0b6; font-weight:400; }

/* Phone closes by clicking its dimmed backdrop; no visible close control. */
.phone-close { display:none !important; }

/* Settings workspace: category navigation and contextual help */
.settings-panel { width:min(520px,94vw); max-width:94vw; padding:20px; overflow:hidden auto; }
.settings-intro { margin:2px 0 12px; color:#aebbd0; font-size:12px; line-height:1.55; }
.settings-search { position:sticky; top:0; z-index:3; width:100%; min-height:40px; margin:0 0 10px; padding:10px 12px; border:1px solid #35445e; border-radius:10px; background:#0c1524; color:#edf2fb; }
.settings-category-tabs { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; margin:0 0 14px; padding:0 0 12px; border-bottom:1px solid #344158; }
.settings-category-tab { min-height:36px; padding:7px 5px; border:1px solid #35445e; border-radius:9px; background:#172337; color:#aebbd0; font-size:11px; }
.settings-category-tab[aria-pressed="true"] { border-color:#8065e8; background:#30264f; color:#f4efff; font-weight:700; }
.settings-category-content { min-width:0; }
.settings-category[hidden] { display:none !important; }
.settings-category-description { margin:0 0 12px; color:#9eacc1; font-size:11px; line-height:1.55; }
.settings-category > label,.settings-category > details,.settings-category > .two-fields { margin-bottom:12px; }
.settings-category > details { padding:12px; border:1px solid #35445e; border-radius:11px; background:#111d2f; }
.settings-category > details > summary { color:#e1e9f5; font-size:12px; font-weight:700; cursor:pointer; }
.settings-category > details[open] > summary { margin-bottom:12px; }
.settings-category .privacy-note { color:#9aa9bf; font-size:11px; line-height:1.65; }
.settings-category label { color:#cbd5e1; font-size:11px; }
.settings-category input,.settings-category textarea,.settings-category select { width:100%; min-width:0; }
.settings-category .two-fields { gap:9px; }
@media(max-width:520px) {
 .settings-panel { width:100vw; max-width:100vw; padding:14px; }
 .settings-category-tabs { grid-template-columns:repeat(4,minmax(0,1fr)); }
 .settings-category-tab { font-size:10px; }
}

/* Long-form settings layout inspired by the supplied reference */
.settings-panel{overflow-y:auto;overflow-x:hidden}
.settings-long-page{display:flex;flex-direction:column;gap:20px}
.settings-long-section{display:block;padding:14px 0 18px;border-bottom:1px solid #354158}
.settings-long-section[hidden]{display:none!important}
.settings-section-title{margin:0 0 5px;color:#f1f5fb;font-size:16px;font-weight:750}
.settings-category-description{margin:0 0 14px;color:#aebbd0;font-size:12px;line-height:1.65}
.settings-flat-group{margin:10px 0;padding:12px;border:1px solid #35445e;border-radius:10px;background:#1d293a}
.settings-subsection-title{margin:0 0 12px;color:#e6edf7;font-size:13px}
.settings-long-section label{display:block;margin:10px 0}
.settings-long-section textarea{min-height:72px}
.settings-search{position:sticky;top:0;z-index:5}

/* Settings category list + centered item editor modal */
.settings-menu-list{display:flex;flex-direction:column;gap:18px;padding:8px 0 24px}
.settings-menu-group{display:flex;flex-direction:column;gap:0}
.settings-menu-group h3{margin:8px 0 6px;color:#aebbd0;font-size:12px;font-weight:700}
.settings-menu-entry{display:grid;grid-template-columns:1fr auto;align-items:center;gap:10px;text-align:left;padding:14px 10px;border:0;border-bottom:1px solid #354158;background:transparent;color:#e8edf5;cursor:pointer}
.settings-menu-entry span{grid-column:1;color:#8f9db2;font-size:10px}
.settings-menu-entry b{grid-column:1;font-size:14px;font-weight:650}
.settings-menu-entry i{grid-column:2;grid-row:1/3;font-size:20px;color:#aebbd0;font-style:normal}
.settings-menu-entry:hover{background:#263449}
.settings-editor-backdrop{position:fixed;inset:0;z-index:1200;display:grid;place-items:center;padding:24px;background:rgba(3,7,13,.72);backdrop-filter:blur(5px)}
.settings-editor-backdrop[hidden]{display:none}
.settings-editor-modal{width:min(760px,calc(100vw - 32px));max-height:min(82vh,900px);display:flex;flex-direction:column;overflow:hidden;border:1px solid #3a4960;border-radius:14px;background:#202b3b;box-shadow:0 24px 80px #0009}
.settings-editor-modal>header{display:flex;align-items:center;justify-content:space-between;padding:18px 20px;border-bottom:1px solid #3a4960}
.settings-editor-modal h2{margin:0;font-size:16px}
.settings-editor-close{border:0;background:transparent;color:#dce5f1;font-size:26px;cursor:pointer}
.settings-editor-body{overflow:auto;padding:18px 20px}
.settings-record-list{display:flex;flex-direction:column;gap:12px;margin-top:14px}
.settings-record-card{padding:14px;border:1px solid #3a4960;border-radius:10px;background:#202d40}
.settings-form-field{display:flex;flex-direction:column;gap:6px;margin:10px 0;color:#c4cede;font-size:12px}
.settings-form-field input,.settings-form-field textarea{width:100%;box-sizing:border-box;padding:10px;border:1px solid #46546a;border-radius:7px;background:#111a27;color:#eef3fa;font:inherit}
.settings-form-field textarea{min-height:100px;resize:vertical}
.settings-record-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:10px}
.settings-record-actions button,.settings-primary-action{padding:8px 13px;border:1px solid #46546a;border-radius:7px;background:#29384d;color:#edf3fa;cursor:pointer}
.settings-primary-action{background:#0d9488;border-color:#0d9488;color:white}

/* Settings are a category index; editing happens in centered dialogs */
.settings-source-fields[hidden]{display:none!important}
.settings-menu-list{display:flex;flex-direction:column;gap:18px;padding:8px 0 24px}
.settings-menu-group{display:flex;flex-direction:column}
.settings-menu-group h3{margin:10px 0 4px;color:#aebbd0;font-size:12px;font-weight:700}
.settings-menu-entry{display:flex;align-items:center;justify-content:space-between;width:100%;padding:14px 10px;border:0;border-bottom:1px solid #354158;background:transparent;color:#e8edf5;text-align:left;cursor:pointer}
.settings-menu-entry span{font-size:14px;font-weight:650}
.settings-menu-entry i{font-size:21px;color:#aebbd0;font-style:normal}
.settings-menu-entry:hover{background:#263449}
.settings-editor-backdrop{position:fixed;inset:0;z-index:1200;display:grid;place-items:center;padding:24px;background:rgba(3,7,13,.72);backdrop-filter:blur(5px)}
.settings-editor-backdrop[hidden]{display:none!important}
.settings-editor-modal{width:min(760px,calc(100vw - 32px));max-height:min(82vh,900px);display:flex;flex-direction:column;overflow:hidden;border:1px solid #3a4960;border-radius:14px;background:#202b3b;box-shadow:0 24px 80px #0009}
.settings-editor-modal>header{display:flex;align-items:center;justify-content:space-between;padding:18px 20px;border-bottom:1px solid #3a4960}
.settings-editor-modal h2{margin:0;font-size:16px}
.settings-editor-close{border:0;background:transparent;color:#dce5f1;font-size:26px;cursor:pointer}
.settings-editor-body{overflow:auto;padding:18px 20px}
.settings-record-list{display:flex;flex-direction:column;gap:12px;margin-top:14px}
.settings-record-card{padding:14px;border:1px solid #3a4960;border-radius:10px;background:#202d40}
.settings-form-field{display:flex;flex-direction:column;gap:6px;margin:10px 0;color:#c4cede;font-size:12px}
.settings-form-field input,.settings-form-field textarea{width:100%;box-sizing:border-box;padding:10px;border:1px solid #46546a;border-radius:7px;background:#111a27;color:#eef3fa;font:inherit}
.settings-form-field textarea{min-height:100px;resize:vertical}
.settings-record-action,.settings-primary-action{margin:8px 6px 0 0;padding:8px 13px;border:1px solid #46546a;border-radius:7px;background:#29384d;color:#edf3fa;cursor:pointer}
.settings-primary-action{background:#0d9488;border-color:#0d9488;color:white}


/* App-native dialogs replace browser-origin alert/confirm/prompt popups. */
.app-dialog-backdrop {
  position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center;
  padding: 20px; background: rgba(3, 8, 18, .72); backdrop-filter: blur(7px);
}
.app-dialog {
  width: min(560px, 100%); max-height: min(82vh, 760px); overflow: auto;
  padding: 22px; border: 1px solid #42536f; border-radius: 18px;
  background: #172438; color: #edf3ff; box-shadow: 0 24px 80px #000b;
}
.app-dialog h2 { margin: 0 0 12px; font-size: 17px; }
.app-dialog-message { margin: 0 0 16px; color: #d2dced; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.app-dialog-input, .inline-message-editor-input {
  display: block; width: 100%; min-height: 112px; resize: vertical;
  padding: 12px; border: 1px solid #526580; border-radius: 11px;
  background: #0e1929; color: #f5f7fb; font: inherit; line-height: 1.55;
}
.app-dialog-actions, .inline-message-editor-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.app-dialog-actions button, .inline-message-editor-actions button {
  min-height: 38px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.message:has(.inline-message-editor) {
  width: min(100%, 1080px);
  max-width: calc(100% - 12px);
  box-sizing: border-box;
}
.message:has(.inline-message-editor) .message-content { width: 100%; min-width: 0; }
.inline-message-editor { display: grid; gap: 12px; width: 100%; min-width: 0; }
.inline-message-editor-input {
  width: 100%; min-width: 0; box-sizing: border-box;
  height: min(54vh, 620px); min-height: 360px; max-height: 72vh;
  resize: vertical; padding: 16px; font-size: 14px; line-height: 1.7;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.inline-message-editor-status {
  margin: 0; padding: 10px 12px; border: 1px solid #526580;
  border-radius: 9px; background: #0e1929; color: #dce7f8;
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.inline-message-editor-actions { margin-top: 2px; }
.inline-message-editor-actions button:disabled { opacity: .55; cursor: wait; }
@media (max-width: 700px) {
  .message:has(.inline-message-editor) { width: 100%; max-width: 100%; }
  .inline-message-editor-input { height: 46vh; min-height: 260px; max-height: 65vh; padding: 12px; }
}


/* Account gate and authenticated workspace */
/* The main workspace intentionally locks document scrolling; restore page scrolling on the auth gate. */
html.auth-page, html.auth-page body {
  height:auto !important;
  min-height:100% !important;
  overflow-x:hidden !important;
  overflow-y:auto !important;
}
body.auth-locked { height:auto !important; min-height:100dvh !important; }
body.auth-locked .app-shell { display:none !important; }
.auth-gate {
  box-sizing:border-box;
  min-height:100vh;
  min-height:100dvh;
  display:grid;
  place-items:center;
  padding:24px 16px;
  overflow:visible;
}
.auth-gate[hidden] { display:none !important; }
/* During a returning-session check, show status only; don't flash the login form. */
.auth-checking #auth-form,
.auth-checking #auth-signup,
.auth-checking #auth-google-actions,
.auth-checking #auth-divider { display:none !important; }

.auth-card { width:min(440px,100%); box-sizing:border-box; padding:28px; border:1px solid #ffffff20; border-radius:20px; background:#111c2d; box-shadow:0 24px 80px #0008; }
.auth-card h1 { margin:0 0 10px; font-size:24px; }
.auth-card > p { color:#aebbd0; font-size:13px; line-height:1.6; }
.auth-card label { display:grid; gap:7px; margin:14px 0; color:#cbd5e1; font-size:12px; }
.auth-card input { width:100%; padding:12px; border:1px solid #3a4960; border-radius:10px; background:#0b1220; color:#edf2fb; }
.auth-primary,.auth-secondary { width:100%; min-height:44px; margin-top:10px; border-radius:10px; font-weight:700; }
.auth-primary { border:1px solid #8065e8; background:#6346c8; color:white; }
.auth-secondary { border:1px solid #46546a; background:#202d40; color:#edf2fb; }
.auth-status { min-height:24px; margin:16px 0 0 !important; color:#aebbd0; font-size:12px; white-space:pre-wrap; }
.auth-status[data-state="error"] { color:#fda4af; }
#account-logout[hidden] { display:none !important; }

/* Google and account registration controls */
.auth-google-actions { display:flex; justify-content:center; margin:12px 0 2px; }
.auth-google-actions[hidden] { display:none !important; }
.auth-google-button {
  display:grid; place-items:center; width:44px; height:44px; min-height:44px; padding:0;
  border:1px solid #d4d8df; border-radius:50%; background:#fff; cursor:pointer;
  box-shadow:0 2px 8px #0002; transition:transform .15s ease, box-shadow .15s ease;
}
.auth-google-button:hover { transform:translateY(-1px); box-shadow:0 4px 12px #0003; }
.auth-google-button:focus-visible { outline:3px solid #8b7cf6; outline-offset:3px; }
.auth-google-button svg { display:block; width:23px; height:23px; }
.auth-bootstrap-details {
  margin-top:16px;
  border:1px solid #46546a;
  border-radius:12px;
  background:#0c1524;
  overflow:hidden;
}
.auth-bootstrap-details[hidden] { display:none !important; }
.auth-bootstrap-details > summary {
  padding:13px 14px;
  color:#cbd5e1;
  font-size:12px;
  font-weight:700;
  cursor:pointer;
  list-style-position:inside;
}
.auth-bootstrap-details[open] > summary { border-bottom:1px solid #ffffff18; }
.auth-bootstrap-details > :not(summary) { margin-left:14px; margin-right:14px; }
.auth-bootstrap-details > :last-child { margin-bottom:14px; }
@media (max-width:520px) {
  .auth-gate { place-items:start center; padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom)); }
  .auth-card { padding:22px 18px; margin:auto 0; }
}


/* Home / character discovery */
.home-screen{padding:28px 0 42px;min-height:calc(100vh - 120px)}
.home-welcome{display:flex;align-items:center;justify-content:space-between;gap:18px;margin-bottom:24px}
.home-welcome h1{margin:0;color:#f4f6fb;font-size:clamp(24px,4vw,34px);letter-spacing:-.045em}
.home-welcome p{margin:8px 0 0;color:#8995ac;font-size:13px}
.home-feature{display:grid;grid-template-columns:1fr .85fr;min-height:230px;overflow:hidden;border:1px solid #ffffff18;border-radius:22px;background:linear-gradient(115deg,#142333,#17213b 60%,#25324b);margin-bottom:34px}
.home-feature-copy{padding:clamp(22px,5vw,42px);align-self:center}
.home-feature-copy h2{margin:4px 0 8px;font-size:clamp(30px,5vw,44px)}
.home-feature-copy p{color:#aab3c5;font-size:13px}
.home-primary{display:inline-flex;align-items:center;gap:22px;margin-top:16px;padding:12px 18px;border:0;border-radius:10px;background:#11b7a5;color:#061b1b;font-weight:800}
.home-feature-art{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;background:radial-gradient(ellipse at 50% 45%,#58b9b144,#11182700 70%),linear-gradient(135deg,#1d3448,#111827);color:#d7fff9}
.home-feature-art span{font-size:clamp(42px,8vw,76px);font-weight:900;letter-spacing:-.08em}
.home-feature-art small{font-size:9px;letter-spacing:.22em;color:#91aaa9}
.home-section-heading{display:flex;align-items:end;justify-content:space-between;margin:0 0 14px}
.home-section-heading h2{margin:0;font-size:21px}
.home-count{color:#8995ac;font-size:11px}
.home-character-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,220px));gap:16px}
.home-character-card{text-align:left;overflow:hidden;padding:0;border:1px solid #ffffff1c;border-radius:16px;background:#111827;color:#e7eaf2}
.home-character-card:hover{border-color:#19b9a888;transform:translateY(-2px)}
.home-character-art{display:grid;place-items:center;aspect-ratio:4/5;background:radial-gradient(circle at 50% 35%,#56cfc055,#162b3d 62%,#101827);color:#bafaf1;font-size:58px}
.home-character-meta{display:grid;gap:5px;padding:14px}
.home-character-meta strong{font-size:14px}
.home-character-meta small{color:#8995ac;font-size:11px}
.home-settings-panel{position:fixed;z-index:80;inset:50% auto auto 50%;transform:translate(-50%,-50%);width:min(440px,calc(100vw - 28px));padding:22px;border:1px solid #ffffff24;border-radius:18px;background:#111827;box-shadow:0 25px 90px #000b}
.home-settings-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:22px}
.home-settings-heading h2{margin:0}
.home-account-row{display:flex;justify-content:space-between;gap:10px;padding:14px 0;border-bottom:1px solid #ffffff18;font-size:12px}
.home-account-row span{color:#8995ac}
.home-settings-panel>button{margin:14px 8px 0 0}
@media(max-width:680px){.home-feature{grid-template-columns:1fr}.home-feature-art{min-height:135px}.home-character-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.home-welcome{align-items:flex-start}.home-welcome p{max-width:260px}}

/* Persistent navigation shared by Home and Session views */
.workspace{grid-template-columns:290px minmax(0,1fr);align-items:start}
.workspace>.left-sidebar{position:sticky;top:18px;grid-column:1;grid-row:1;max-height:calc(100vh - 36px);min-height:420px}
.workspace>.home-screen{grid-column:2;grid-row:1;min-width:0;padding-top:8px}
.workspace>.chat-panel{grid-column:2;grid-row:1;min-width:0}
.sidebar-home-item{order:-2;margin-bottom:2px;background:#19263a;color:#5ce5d2}
.sidebar-home-item span{color:#5ce5d2}
body[data-view="home"] .sidebar-home-item{border-color:#1cb6a577;background:#123039;color:#77f2e2}
body[data-view="session"] .sidebar-home-item{background:transparent}
#app-home-brand{cursor:pointer;text-decoration:none}
@media(max-width:900px){.workspace{grid-template-columns:220px minmax(0,1fr);gap:12px}}
@media(max-width:680px){.workspace{grid-template-columns:68px minmax(0,1fr);gap:8px}.workspace>.left-sidebar{padding:8px 5px;min-height:calc(100vh - 110px)}.workspace>.left-sidebar .sidebar-section-label,.workspace>.left-sidebar .sidebar-nav-item b,.workspace>.left-sidebar .sidebar-new-session b,.workspace>.left-sidebar .session-item{display:none}.workspace>.left-sidebar .sidebar-nav-item{justify-content:center;padding:8px 2px}.workspace>.left-sidebar .sidebar-new-session{justify-content:center;padding:0}.workspace>.left-sidebar .sidebar-new-session span{font-size:22px}.workspace>.home-screen{padding-top:4px}.workspace>.home-screen .home-welcome{flex-wrap:wrap}}

.home-settings-page{position:fixed;z-index:80;inset:50% auto auto 50%;transform:translate(-50%,-50%);width:min(680px,calc(100vw - 28px));max-height:min(88vh,900px);overflow:auto;padding:24px}
.home-settings-section{padding:18px 0;border-top:1px solid #ffffff18}
.home-settings-section h3{margin:0 0 12px;font-size:14px}
.home-settings-section label{display:grid;gap:7px;margin:12px 0;color:#aab3c5;font-size:12px}
.home-settings-section input,.home-settings-section select,.home-settings-section textarea{box-sizing:border-box}
.home-settings-actions{display:flex;gap:10px;flex-wrap:wrap;padding-top:12px}
.home-settings-section button{margin-top:8px}
#home-token-result{margin-top:12px;user-select:all;font-family:monospace}
.creator-settings-page{width:min(760px,calc(100vw - 28px))}
.home-character-card[hidden],.home-feature[hidden]{display:none!important}
@media(max-width:680px){.home-settings-page{padding:16px;max-height:90vh}.home-settings-heading{gap:8px}.home-settings-heading h2{font-size:20px}}


/* SQNBI route pages: persistent sidebar + independently scrollable Home/Chat outlets. */
html, body { width:100%; height:100%; min-height:0; overflow:hidden; }
body { height:100dvh; }
.app-shell { display:flex; flex-direction:column; width:min(1440px,100% - 32px); height:100dvh; min-height:0; overflow:hidden; }
.topbar { flex:0 0 auto; }
.workspace { display:grid; grid-template-columns:290px minmax(0,1fr); flex:1 1 auto; min-height:0; height:0; overflow:hidden; padding:14px 0; align-items:stretch; }
.workspace > .left-sidebar { position:relative; top:auto; grid-column:1; grid-row:1; min-height:0; max-height:100%; height:100%; overflow-y:auto; overscroll-behavior:contain; }
.route-content { position:relative; grid-column:2; grid-row:1; min-width:0; min-height:0; height:100%; overflow:hidden; }
.route-content > #home-screen, .route-content > .chat-panel { position:absolute; inset:0; width:100%; height:100%; min-width:0; min-height:0; margin:0; }
.route-content > #home-screen { overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; padding:12px 8px 32px; }
.route-content > .chat-panel { display:flex; flex-direction:column; overflow:hidden; }
.route-content > .chat-panel[hidden], .route-content > #home-screen[hidden] { display:none !important; }
.route-content > .chat-panel .messages { flex:1 1 auto; min-height:0; overflow-y:auto; overscroll-behavior:contain; }
.route-content > .chat-panel .composer { flex:0 0 auto; }
.app-shell > footer { flex:0 0 auto; }
@media(max-width:900px) { .workspace { grid-template-columns:220px minmax(0,1fr); } }
@media(max-width:680px) {
  .app-shell { width:calc(100% - 12px); }
  .workspace { grid-template-columns:58px minmax(0,1fr); gap:8px; }
  .workspace > .left-sidebar { padding:8px 4px; }
  .route-content > #home-screen { padding:6px 4px 24px; }
}


/* SQNBI navigation: Home, Shop, Favorites and populated chat sessions. */
.left-sidebar .sidebar-nav { display:grid; gap:6px; margin:8px 0 18px; }
.left-sidebar .sidebar-section-label { margin:16px 8px 8px; color:#8290a7; font-size:10px; font-weight:750; letter-spacing:.12em; }
.left-sidebar .sidebar-nav-item.is-active { border-color:#1cb6a577; background:#123039; color:#77f2e2; }
.left-sidebar .sidebar-nav-item.is-active span { color:#77f2e2; }
.session-list { display:grid; gap:4px; min-height:0; }
.session-item { width:100%; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:left; padding:9px 10px; border:1px solid transparent; border-radius:9px; background:transparent; color:#cbd5e1; font:inherit; font-size:12px; cursor:pointer; }
.session-item:hover,.session-item[aria-current="true"] { background:#1b2a3f; border-color:#3a506c; color:#f4f7fb; }
.sidebar-new-session,.sidebar-phone-open { display:none !important; }
.route-content > .content-page { position:absolute; inset:0; width:100%; height:100%; min-width:0; min-height:0; overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; padding:20px clamp(14px,3vw,36px) 42px; box-sizing:border-box; }
.route-content > .content-page[hidden] { display:none !important; }
.content-page-top { display:flex; align-items:center; margin-bottom:18px; }
.content-detail-hero { display:grid; grid-template-columns:minmax(180px,260px) minmax(0,1fr); gap:28px; align-items:center; padding:24px; border:1px solid #ffffff1b; border-radius:20px; background:linear-gradient(125deg,#17283b,#1a2035); }
.content-cover { width:100%; aspect-ratio:3/4; border-radius:14px; background:linear-gradient(145deg,#253d55,#101827); background-position:center; background-size:cover; }
.content-detail-copy { min-width:0; }
.content-character-name { margin:0 0 6px; color:#8be8da; font-size:12px; font-weight:750; letter-spacing:.08em; }
.content-title { margin:0 0 10px; color:#f5f7fb; font-size:clamp(25px,4vw,38px); line-height:1.2; overflow-wrap:anywhere; }
.content-author,.content-description { color:#aebbd0; white-space:pre-wrap; line-height:1.65; }
.content-tags { margin:0 0 10px; color:#a9b7cc; font-size:12px; }
.content-counts { display:flex; gap:12px; flex-wrap:wrap; margin-top:14px; color:#8e9db4; font-size:11px; }
.content-tabs { display:flex; gap:6px; overflow-x:auto; margin:24px 0 0; border-bottom:1px solid #ffffff20; }
.content-tabs button { flex:0 0 auto; padding:12px 18px; border:0; border-bottom:2px solid transparent; background:transparent; color:#aebbd0; font:inherit; cursor:pointer; }
.content-tabs button[aria-selected="true"] { border-bottom-color:#4bd7c4; color:#f3fffd; }
.content-tab-panel { min-height:160px; padding:22px 4px; }
.content-tab-panel[hidden] { display:none !important; }
.content-rich-text { margin:0; color:#d5deeb; line-height:1.75; white-space:pre-wrap; overflow-wrap:anywhere; }
.content-disclaimer { margin-top:18px; color:#9ba9bd; font-size:12px; line-height:1.65; white-space:pre-wrap; }
.content-start-settings { margin-top:26px; }
.content-start-settings h2 { margin:0 0 12px; font-size:16px; }
#content-start-settings { display:grid; gap:8px; }
.content-start-option { width:100%; padding:12px 14px; border:1px solid #3a506c; border-radius:10px; background:#17263a; color:#e8eef8; text-align:left; font:inherit; cursor:pointer; }
.content-start-option:hover { border-color:#4bd7c4; background:#1a3441; }
.simple-content-page h1 { margin:8px 0 24px; color:#f4f6fb; font-size:28px; }
@media(max-width:680px) {
 .route-content > .content-page { padding:10px 10px 28px; }
 .content-detail-hero { grid-template-columns:minmax(0,1fr); gap:16px; padding:16px; }
 .content-cover { width:min(190px,65%); margin:0 auto; }
 .content-tabs button { padding:11px 14px; }
 .left-sidebar .sidebar-section-label { display:none; }
 .session-item { padding:8px 4px; font-size:9px; text-align:center; }
 .left-sidebar .sidebar-nav-item b { display:none; }
 .left-sidebar .sidebar-nav-item { justify-content:center; padding:10px 2px; }
}

.content-cover[hidden]{display:none!important;}


/* SQNBI app-admin dashboard (separate from creator/content permissions). */
.admin-dashboard-page{width:min(920px,calc(100vw - 28px))}
.admin-dashboard-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px}
.admin-dashboard-toolbar h3{margin:0}
.admin-metric-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-top:14px}
.admin-metric{min-width:0;padding:14px;border:1px solid #ffffff18;border-radius:12px;background:#0d1726}
.admin-metric span{display:block;color:#8995ac;font-size:10px}
.admin-metric strong{display:block;margin-top:7px;color:#edf3fb;font-size:20px;overflow-wrap:anywhere}
.admin-data-list{display:grid;gap:8px;margin-top:12px}
.admin-data-row{display:grid;grid-template-columns:minmax(0,1.2fr) repeat(3,minmax(0,1fr));gap:10px;align-items:center;padding:11px 12px;border:1px solid #ffffff14;border-radius:10px;background:#0d1726;font-size:11px}
.admin-data-row strong,.admin-data-row span{min-width:0;overflow-wrap:anywhere}
.admin-data-row span{color:#aab3c5}
.admin-data-row small{display:block;margin-top:4px;color:#77849a;font-size:9px}
.admin-role{display:inline-block;margin-left:6px;padding:3px 6px;border-radius:6px;background:#153c3a;color:#7de8d8;font-size:9px}
@media(max-width:620px){
 .admin-metric-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .admin-data-row{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:7px}
}

.home-welcome-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap}
.admin-dashboard-page .admin-data-row{grid-template-columns:minmax(0,1fr)}


/* Admin execution diagnostics */
.admin-diagnostic-bar{height:7px;border-radius:999px;background:var(--border-subtle,rgba(127,127,127,.2));overflow:hidden;margin-top:10px}.admin-diagnostic-bar-fill{display:block;height:100%;border-radius:inherit;background:var(--accent,var(--text-primary));max-width:100%}

/* Account-scoped basic-chat conversation search and pagination. */
.session-search { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; margin:6px 0 8px; }
.session-search input { min-width:0; height:34px; padding:0 9px; border-color:#2b3950; border-radius:8px; background:#0b1422; font-size:11px; }
.session-search .quiet-button { padding:6px 8px; font-size:10px; }
.session-load-more { width:100%; margin-top:7px; padding:8px 6px; font-size:10px; }
.left-sidebar.is-collapsed .session-search,
.left-sidebar.is-collapsed #session-load-more { display:none !important; }
@media(max-width:680px) {
  .left-sidebar .session-search,
  .left-sidebar #session-load-more { display:none !important; }
}


/* Stage 3: data-driven roleplay definition controls. */
.roleplay-runtime-controls{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:8px}
.roleplay-runtime-controls>label{font-size:11px;color:var(--text-muted,#9aa9bc)}
.roleplay-runtime-controls>select{min-width:150px;max-width:min(280px,100%);height:34px;padding:0 9px;border:1px solid var(--border-subtle,rgba(127,127,127,.3));border-radius:8px;background:var(--surface-2,#111c2b);color:var(--text-primary,inherit);font-size:12px}
.roleplay-definition-editor{flex:1 1 100%;max-width:620px;margin-top:3px}
.roleplay-definition-editor>summary{width:max-content;cursor:pointer;color:var(--text-muted,#9aa9bc);font-size:11px}
.roleplay-definition-editor textarea{display:block;width:100%;min-height:180px;margin:8px 0;padding:10px;border:1px solid var(--border-subtle,rgba(127,127,127,.3));border-radius:8px;background:var(--surface-2,#111c2b);color:var(--text-primary,inherit);font:11px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;resize:vertical}
.roleplay-definition-editor .quiet-button{font-size:11px}
@media(max-width:680px){.roleplay-runtime-controls{align-items:flex-start}.roleplay-runtime-controls>select{flex:1;min-width:0}.roleplay-definition-editor{flex-basis:100%}}


/* Stage 4: roleplay-defined INFO, status and inventory panels. */
.roleplay-state-panels{display:grid;gap:8px;max-height:min(42vh,360px);overflow:auto;overscroll-behavior:contain;margin:0 0 8px}
.roleplay-state-panel{min-width:0;border:1px solid var(--border-subtle,rgba(127,127,127,.25));border-radius:10px;background:var(--surface-1,#111c2b);overflow:hidden}
.roleplay-state-panel>summary{padding:10px 12px;color:var(--text-primary,inherit);font-size:12px;font-weight:700;cursor:pointer;list-style-position:inside}
.roleplay-state-panel[open]>summary{border-bottom:1px solid var(--border-subtle,rgba(127,127,127,.18))}
.roleplay-state-fields{display:grid;grid-template-columns:minmax(90px,.8fr) minmax(0,1.4fr);gap:0;margin:0;padding:4px 12px 10px;font-size:11px}
.roleplay-state-fields dt,.roleplay-state-fields dd{margin:0;padding:7px 4px;border-bottom:1px solid var(--border-subtle,rgba(127,127,127,.12));overflow-wrap:anywhere}
.roleplay-state-fields dt{color:var(--text-muted,#9aa9bc)}
.roleplay-state-fields dd{color:var(--text-primary,inherit);white-space:pre-wrap}
.roleplay-state-table-wrap{width:100%;overflow:auto}
.roleplay-state-table-wrap table{width:100%;border-collapse:collapse;font-size:11px}
.roleplay-state-table-wrap th,.roleplay-state-table-wrap td{padding:8px 9px;border-bottom:1px solid var(--border-subtle,rgba(127,127,127,.14));text-align:left;white-space:normal;overflow-wrap:anywhere}
.roleplay-state-table-wrap th{color:var(--text-muted,#9aa9bc);font-weight:650;background:var(--surface-2,#0c1524)}
.roleplay-state-table-wrap td{color:var(--text-primary,inherit)}
.roleplay-state-summary-row td{font-weight:750;border-top:1px solid var(--border-subtle,rgba(127,127,127,.4));background:var(--surface-2,#0c1524)}
@media(max-width:680px){.roleplay-state-panels{max-height:34vh}.roleplay-state-fields{grid-template-columns:minmax(76px,.8fr) minmax(0,1.4fr)}}

.roleplay-state-inventory-list{display:grid;gap:8px;padding:10px}
.roleplay-state-inventory-item{min-width:0;padding:10px;border:1px solid var(--border-subtle,rgba(127,127,127,.18));border-radius:8px;background:var(--surface-2,#0c1524)}
.roleplay-state-inventory-item>strong{display:block;margin-bottom:6px;color:var(--text-primary,inherit);font-size:12px}
.roleplay-state-inventory-item dl{display:grid;grid-template-columns:minmax(76px,.7fr) minmax(0,1.3fr);gap:4px 10px;margin:0;font-size:11px}
.roleplay-state-inventory-item dt{color:var(--text-muted,#9aa9bc)}
.roleplay-state-inventory-item dd{margin:0;color:var(--text-primary,inherit);overflow-wrap:anywhere}


/* Stage 3: visual roleplay creator and reusable definition library. */
.roleplay-library-toolbar{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:8px;align-items:end;margin:10px 0}
.roleplay-library-toolbar label,.roleplay-builder-grid label,.roleplay-builder-form label{display:grid;gap:5px;min-width:0;color:var(--text-muted,#9aa9bc);font-size:11px}
.roleplay-library-toolbar select,.roleplay-builder-grid input,.roleplay-builder-grid textarea,.roleplay-builder-form input,.roleplay-builder-form textarea,.roleplay-builder-form select{box-sizing:border-box;width:100%;min-width:0;padding:9px 10px;border:1px solid var(--border-subtle,rgba(127,127,127,.3));border-radius:8px;background:var(--surface-2,#0c1524);color:var(--text-primary,inherit);font:12px/1.45 inherit}
.roleplay-builder-grid,.roleplay-builder-form{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px;margin:10px 0}
.roleplay-builder-wide{grid-column:1/-1}
.roleplay-builder-section{margin-top:14px;padding-top:12px;border-top:1px solid var(--border-subtle,rgba(127,127,127,.2))}
.roleplay-builder-section-heading{display:flex;align-items:center;justify-content:space-between;gap:8px}
.roleplay-builder-section-heading h3{margin:0;font-size:13px;color:var(--text-primary,inherit)}
.roleplay-builder-list{display:grid;gap:7px;margin:8px 0}
.roleplay-builder-item{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:4px 8px;padding:9px;border:1px solid var(--border-subtle,rgba(127,127,127,.2));border-radius:8px;background:var(--surface-1,#111c2b)}
.roleplay-builder-item strong,.roleplay-builder-item p{grid-column:1;min-width:0;margin:0;overflow-wrap:anywhere;font-size:11px}
.roleplay-builder-item p{color:var(--text-muted,#9aa9bc);white-space:pre-wrap}
.roleplay-builder-item button{grid-column:2;grid-row:1/3;align-self:center}
.roleplay-builder-form{padding:10px;border:1px solid var(--border-subtle,rgba(127,127,127,.2));border-radius:9px;background:var(--surface-1,#111c2b)}
.roleplay-builder-actions{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0}
.roleplay-json-advanced{margin-top:10px}
.roleplay-json-advanced>textarea{display:block;width:100%;box-sizing:border-box;margin:8px 0;padding:9px;border:1px solid var(--border-subtle,rgba(127,127,127,.25));border-radius:8px;background:var(--surface-2,#0c1524);color:var(--text-primary,inherit);font:11px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace}
@media(max-width:680px){.roleplay-library-toolbar{grid-template-columns:1fr 1fr}.roleplay-library-toolbar label{grid-column:1/-1}.roleplay-builder-grid,.roleplay-builder-form{grid-template-columns:1fr}.roleplay-builder-wide{grid-column:auto}}

/* Visual creator controls override the legacy JSON textarea sizing. */
.roleplay-definition-editor .roleplay-builder-grid textarea,
.roleplay-definition-editor .roleplay-builder-form textarea{min-height:58px;font:inherit;font-size:12px;line-height:1.45;resize:vertical}
.roleplay-definition-editor .roleplay-builder-grid input,
.roleplay-definition-editor .roleplay-builder-form input,
.roleplay-definition-editor .roleplay-builder-form select{font:inherit;font-size:12px;line-height:1.45}
.roleplay-definition-editor .roleplay-builder-grid textarea,
.roleplay-definition-editor .roleplay-builder-form textarea{height:auto}

.roleplay-definition-editor .roleplay-builder-memory input[type="checkbox"]{width:auto;min-width:0;accent-color:var(--accent,#79a8ff);vertical-align:middle}
.roleplay-builder-memory .roleplay-builder-grid label>span{display:flex;align-items:center;gap:7px;color:var(--text-primary,inherit);font-size:11px}
.roleplay-builder-memory .roleplay-builder-grid textarea{min-height:64px}


/* Roleplay definition revision history controls */
.roleplay-version-toolbar{align-items:end}
.roleplay-version-toolbar .privacy-note{grid-column:1/-1;margin:0}
.roleplay-version-toolbar select{min-width:0;width:100%}
.roleplay-version-toolbar button:disabled{opacity:.45;cursor:not-allowed}


/* Roleplay-defined generic INFO and inventory panels */
.roleplay-data-panels{display:grid;gap:8px;margin:10px 0}
.roleplay-data-panel{border:1px solid var(--border,#333);border-radius:10px;background:var(--panel-bg,transparent);padding:10px}
.roleplay-data-panel>summary{cursor:pointer;font-weight:650}
.roleplay-data-panel-body{padding-top:10px;display:grid;gap:10px}
.roleplay-data-fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}
.roleplay-data-field{display:grid;gap:4px;min-width:0}
.roleplay-data-field>span{font-size:11px;color:var(--text-secondary,inherit)}
.roleplay-data-field input,.roleplay-data-field select,.roleplay-data-field textarea{box-sizing:border-box;width:100%;min-width:0}
.roleplay-data-field output{display:block;min-height:34px;padding:8px;border:1px solid var(--border,#333);border-radius:7px}
.roleplay-data-table-wrap{overflow-x:auto}
.roleplay-data-table{width:100%;border-collapse:collapse;font-size:12px}
.roleplay-data-table th,.roleplay-data-table td{padding:6px;border-bottom:1px solid var(--border,#333);text-align:left;vertical-align:middle}
.roleplay-data-table input,.roleplay-data-table select{max-width:180px;min-width:70px;width:100%;box-sizing:border-box}
@media(max-width:680px){.roleplay-data-fields{grid-template-columns:1fr}.roleplay-data-table{min-width:420px}}

.roleplay-data-list{display:grid;gap:8px}
.roleplay-data-list-item{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;padding:9px;border:1px solid var(--border,#333);border-radius:8px}
.roleplay-data-summary{display:flex;flex-wrap:wrap;gap:8px 14px;align-items:center;padding:8px 0;font-size:12px}
.roleplay-data-summary strong{margin-right:4px}
@media(max-width:680px){.roleplay-data-list-item{grid-template-columns:1fr}}

.roleplay-data-panels[hidden]{display:none}


.normalized-memory-review {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border, #333);
}
.normalized-memory-candidate {
  background: color-mix(in srgb, var(--surface, #fff) 5%, transparent);
}
.normalized-memory-candidate .memory-review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.roleplay-data-new-item-draft{display:grid;gap:8px;padding:10px;border:1px dashed var(--border,#333);border-radius:8px}
.roleplay-data-new-item-actions{display:flex;flex-wrap:wrap;gap:8px}
.roleplay-data-new-item-actions button:disabled{opacity:.45;cursor:not-allowed}
