/* Global modules share one navigation; story-specific tools stay inside stories. */
body:has(.module-sidebar) { background: var(--bg); }
.module-sidebar { padding-top: 29px; overflow-y: auto; scrollbar-width: thin; }
.module-sidebar .side-caption { margin-bottom: 25px; }
.module-sidebar .main-nav { gap: 5px; }
.module-sidebar .nav-item { min-height: 46px; padding-top: 11px; padding-bottom: 11px; font-size: 13px; }
.module-sidebar .sidebar-divider { margin: 22px 10px; }
.module-sidebar .side-note p { font-size: 15px; }
.module-sidebar .sidebar-bottom { padding-top: 23px; }
.module-sidebar .nav-mobile-label { display: none; }
.module-directory-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 6px 11px; border: 1px solid #655172; border-radius: 7px; background: #2b2234; color: #d5bde5; font-size: 11px; white-space: nowrap; }
.module-directory-toggle .icon { width: 15px; height: 15px; }
.module-directory-toggle:hover { background: #3b2e45; border-color: #9a78b0; }

#homeView, #conversationsView, #memoryView { padding-bottom: 40px; }
.hub-heading { max-width: 750px; margin: 5px 0 30px; }
.hub-heading .eyebrow, .module-heading .eyebrow { color: #ad91c1; font-size: 9px; letter-spacing: 2.5px; }
.hub-heading h1 { font: 500 clamp(27px, 3vw, 39px)/1.65 var(--serif); letter-spacing: 1.5px; color: #f0e4fa; }
.hub-heading > p { max-width: 630px; margin-top: 12px; color: #a697b5; font-size: 13px; line-height: 1.95; }
.hub-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.hub-card { position: relative; display: flex; flex-direction: column; align-items: flex-start; min-width: 0; min-height: 235px; padding: 25px; text-align: left; border: 1px solid #59406470; border-radius: 13px; background: linear-gradient(145deg, #292030, #201b28); transition: border-color .18s, transform .18s, background .18s; }
.hub-card:hover { transform: translateY(-3px); border-color: #9b74ae; background: linear-gradient(145deg, #33263d, #251e2d); }
.hub-card-icon { width: 43px; height: 43px; display: grid; place-items: center; margin-bottom: 20px; color: #d4b0ec; border: 1px solid #a87ac53b; border-radius: 11px; background: #ab80c414; }
.hub-card-icon .icon { width: 22px; height: 22px; }
.hub-card-number { display: block; max-width: 100%; margin: -6px 0 12px; color: #9782a7; font-size: 9px; line-height: 1.7; letter-spacing: 1px; overflow-wrap: anywhere; }
.hub-card h2 { font-size: 18px; font-weight: 500; letter-spacing: .6px; color: #ecdbf7; }
.hub-card > p { margin-top: 10px; margin-bottom: 23px; color: #aa98b7; font-size: 12px; line-height: 1.9; overflow-wrap: anywhere; }
.hub-card-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; margin-top: auto; padding-top: 14px; border-top: 1px solid #b997cd17; color: #c9a6e0; font-size: 11px; }
.hub-card-footer .icon { width: 16px; height: 16px; }
.hub-note { margin-top: 24px; color: #927f9e; font-size: 11px; line-height: 1.9; }
.hub-note button { margin-left: 7px; padding: 3px 0; background: transparent; color: #b597c9; font-size: inherit; }
.hub-note button:hover { color: #e2c3f4; }

.module-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.module-heading > div { min-width: 0; }
.module-heading h1 { font: 500 29px/1.6 var(--serif); letter-spacing: 1px; color: #eddef5; }
.module-heading p { margin-top: 9px; color: #a592b2; font-size: 12px; line-height: 1.9; }
.module-heading > button { flex-shrink: 0; }
.module-list { display: grid; gap: 13px; }
.module-person-row { display: flex; align-items: center; gap: 20px; padding: 21px; border: 1px solid #9371a32e; border-radius: 11px; background: #211b29; min-width: 0; }
.module-person-avatar { display: grid; place-items: center; flex: 0 0 66px; width: 66px; height: 78px; border-radius: 8px; overflow: hidden; color: #d3b4e2; background: linear-gradient(145deg, #5a3f69, #302338); font: 27px var(--serif); }
.module-person-avatar img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; }
img.module-person-avatar { object-fit: cover; object-position: 50% 22%; }
.module-person-avatar .character-placeholder { gap: 0; }
.module-person-avatar .character-placeholder > strong { font-size: 28px; }
.module-person-avatar .character-placeholder > :is(span, small) { display: none; }
.module-person-copy { min-width: 0; flex: 1; }
.module-person-copy h2 { font: 500 19px/1.6 var(--serif); color: #ebd9f5; }
.module-person-copy p { margin-top: 5px; color: #b5a1c2; font-size: 12px; line-height: 1.9; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.module-person-copy small { display: block; margin-top: 7px; color: #887396; font-size: 10px; line-height: 1.8; }
.module-person-row > .outline-button { flex-shrink: 0; min-height: 40px; white-space: nowrap; }
.module-person-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0; }

.memory-workspace { display: grid; grid-template-columns: 205px minmax(0, 1fr); gap: 22px; align-items: start; }
.memory-character-list { display: grid; gap: 9px; min-width: 0; }
.memory-character { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; padding: 14px 16px; border: 1px solid #82609230; border-radius: 8px; background: #201a28; text-align: left; }
.memory-character strong { max-width: 100%; font-size: 13px; font-weight: 500; color: #d7c0e6; overflow-wrap: anywhere; }
.memory-character small { margin-top: 5px; color: #967da6; font-size: 10px; }
.memory-character:hover { border-color: #9070a2; }
.memory-character.is-active, .memory-character[aria-pressed="true"] { background: #35263f; border-color: #ac80c5; box-shadow: inset 3px 0 #bd92d7; }
.memory-character.is-active strong, .memory-character[aria-pressed="true"] strong { color: #f0dafa; }
.memory-detail { min-width: 0; border: 1px solid #9570a638; background: #211a2a; border-radius: 12px; padding: 25px; }
.memory-summary > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.memory-summary h2 { font: 500 23px/1.6 var(--serif); color: #ecd7f6; }
.memory-summary p { margin-top: 7px; color: #ab94b9; font-size: 12px; line-height: 1.9; }
.memory-summary small { display: block; color: #9b82ad; font-size: 10px; line-height: 1.9; }
.memory-metrics { display: flex; flex-wrap: wrap; gap: 8px 10px; margin-top: 18px; }
.memory-metrics > :is(span, div) { padding: 7px 11px; border: 1px solid #b992cf26; border-radius: 6px; background: #b590c709; color: #b79bc8; font-size: 11px; }
.memory-metrics strong { color: #e6c7f7; font-weight: 500; margin-left: 5px; }
.memory-metrics > label { display: block; flex: 1 1 120px; min-width: 0; padding: 12px 13px; border: 1px solid #b992cf26; border-radius: 7px; background: #b590c709; color: #baa0ca; font-size: 11px; }
.memory-metrics label b { float: right; margin-left: 8px; color: #e6c7f7; font-weight: 500; }
.memory-metrics meter { display: block; width: 100%; height: 9px; margin-top: 10px; border: 0; border-radius: 6px; background: #4b3757; accent-color: #c197dd; }
.memory-metrics meter::-webkit-meter-bar { height: 9px; border: 0; border-radius: 6px; background: #4b3757; }
.memory-metrics meter::-webkit-meter-optimum-value { border-radius: 6px; background: linear-gradient(90deg, #9d75b7, #d2a9e6); }
.memory-metrics meter::-moz-meter-bar { border-radius: 6px; background: linear-gradient(90deg, #9d75b7, #d2a9e6); }
.memory-records { margin-top: 25px; padding-top: 22px; border-top: 1px solid #ad87c125; }
.memory-records h3 { color: #d9c2e6; font-size: 14px; font-weight: 500; }
.memory-records h3 small { margin-left: 8px; color: #957aaa; font-size: 10px; font-weight: 400; }
.memory-records li.memory-empty { border-style: dashed; }
.memory-records > p { margin-top: 10px; color: #9c85ab; font-size: 12px; line-height: 1.9; }
.memory-records ul, ul.memory-records { display: grid; gap: 11px; list-style: none; padding-left: 0; }
.memory-records ul { margin-top: 15px; margin-bottom: 0; }
.memory-records li { position: relative; min-width: 0; padding: 14px 16px; border: 1px solid #8c679e2b; border-radius: 8px; background: #17121e5c; overflow-wrap: anywhere; }
.memory-records li > :is(span, small) { color: #b791cd; font-size: 10px; }
.memory-records li p { margin: 6px 0 9px; color: #d5bfdf; font-size: 12px; line-height: 1.9; white-space: pre-wrap; }
.memory-records li button { padding: 4px 0; background: transparent; color: #a88aba; font-size: 11px; }
.memory-records li button:hover { color: #e8beda; }
.module-memory-form { display: grid; gap: 11px; margin-top: 24px; padding-top: 22px; border-top: 1px solid #a17aba26; }
.module-memory-form label { display: grid; gap: 8px; min-width: 0; color: #c4a9d4; font-size: 12px; }
.module-memory-form :is(input, textarea, select) { width: 100%; min-width: 0; border: 1px solid #7d5d906b; border-radius: 7px; background: #18121f; color: #e2cdea; padding: 11px 12px; font-size: 13px; line-height: 1.8; }
.module-memory-form textarea { resize: vertical; min-height: 91px; }
.module-memory-form :is(input, textarea, select):focus { outline: 1px solid #bb91d3; border-color: #bb91d3; outline-offset: 1px; }
.module-memory-form > :is(button, .primary-button) { justify-self: start; }
.module-memory-form > :is(p, small) { color: #927a9f; font-size: 10px; line-height: 1.9; }

.module-directory-dialog { width: min(650px, calc(100vw - 36px)); max-width: none; padding: 30px; }
.module-directory-dialog > header { display: block; margin-bottom: 23px; padding-right: 30px; }
.module-directory-dialog h2 { font: 500 24px/1.6 var(--serif); color: #eedaf9; }
.module-directory-dialog > p, .module-directory-dialog > header p { margin-top: 6px; color: #a790b6; font-size: 12px; }
.module-directory-dialog .dialog-close { right: 17px; top: 17px; }
.module-directory-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 21px; }
.module-directory-grid > button { display: flex; align-items: center; gap: 11px; padding: 16px; min-width: 0; min-height: 68px; border: 1px solid #7e5d943d; border-radius: 9px; background: #2c2035; color: #ddc2ed; font-size: 13px; text-align: left; }
.module-directory-grid > button:hover { background: #3a2a46; border-color: #a580be; }
.module-directory-grid > button:is(.active, [aria-current="page"]) { background: #43304f; border-color: #ac82c2; }
.module-directory-grid .icon { color: #ba92d4; }
.module-directory-grid strong { font-size: 13px; font-weight: 500; }
.module-directory-grid small { display: block; margin-top: 4px; color: #a38bae; font-size: 10px; }

.story-module-nav { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 8px; padding: 10px; margin: -5px 0 23px; border: 1px solid #89639835; border-radius: 9px; background: #211a2bee; backdrop-filter: blur(12px); }
.story-module-nav > span { margin-right: auto; padding: 0 8px; color: #a58ab6; font-size: 11px; }
.story-module-nav > button { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 8px 15px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: #b199c1; font-size: 12px; white-space: nowrap; }
.story-module-nav > button:hover { background: #3a2846; color: #e0c3ef; }
.story-module-nav > button:is(.active, .is-active, [aria-current="page"]) { border-color: #9e74b455; background: #42304e; color: #ebcef9; }
.story-module-nav .icon { width: 15px; height: 15px; }

@media (min-width: 901px) and (max-height: 800px) {
  .module-sidebar .side-note { display: none; }
  .module-sidebar .sidebar-divider { margin: 18px 10px; }
  .module-sidebar .sidebar-bottom { padding-top: 12px; }
}
@media (max-width: 1150px) {
  .hub-grid { gap: 14px; }
  .hub-card { padding: 21px; }
  .memory-workspace { grid-template-columns: 170px minmax(0, 1fr); gap: 16px; }
  .memory-detail { padding: 21px; }
}
@media (max-width: 1000px) {
  .hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hub-card { min-height: 218px; }
}
@media (min-width: 651px) and (max-width: 900px) {
  .module-sidebar .main-nav { margin-top: 30px; gap: 8px; }
  .module-sidebar .nav-item { padding: 12px; }
}
@media (max-width: 760px) {
  .memory-workspace { grid-template-columns: minmax(0, 1fr); }
  .memory-character-list { display: flex; overflow-x: auto; padding: 1px 1px 8px; gap: 8px; scrollbar-width: thin; }
  .memory-character { flex: 0 0 136px; min-height: 71px; padding: 12px 14px; }
  .memory-character.is-active, .memory-character[aria-pressed="true"] { box-shadow: inset 0 -2px #bd92d7; }
  .module-person-row { gap: 15px; }
  .module-person-actions { flex-direction: column; align-items: stretch; }
}
@media (max-width: 650px) {
  /* The host navigation remains available throughout every story subpage. */
  body:has(.module-sidebar) .module-sidebar { display: flex !important; height: calc(65px + env(safe-area-inset-bottom)); padding: 0 10px env(safe-area-inset-bottom); border-top: 1px solid #70508055; background: #1c1624f5; backdrop-filter: blur(14px); overflow: visible; }
  body:has(.module-sidebar) .module-sidebar .main-nav { display: flex; width: 100%; max-width: none; height: 65px; margin: 0; gap: 0; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-item { display: none !important; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-item[data-mobile-main] { display: flex !important; flex: 1 1 25%; max-width: none; min-width: 0; min-height: 53px; height: auto; gap: 4px; padding: 7px 3px; flex-direction: column; background: transparent !important; color: #a494b2; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-item[data-mobile-main].active { color: #e2befb; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-item > .icon { width: 20px; height: 20px; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-item > span:not(.nav-plus):not(.nav-dot) { font-size: 10px; white-space: nowrap; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-desktop-label { display: none !important; }
  body:has(.module-sidebar) .module-sidebar .main-nav .nav-mobile-label { display: block; }
  body:has(.module-sidebar) .workspace { padding-bottom: calc(65px + env(safe-area-inset-bottom)); }
  body:has(.module-sidebar) .topbar { display: flex !important; padding: 0 17px; gap: 12px; }
  body:has(.module-sidebar) main { padding-top: 24px; }
  body:has(.module-sidebar) .topbar-right { gap: 10px; }
  .topbar .breadcrumb { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .module-directory-toggle { min-height: 32px; padding: 5px 9px; font-size: 10px; }
  .module-directory-toggle .icon { width: 13px; height: 13px; }
  #homeView, #conversationsView, #memoryView { padding-bottom: 27px; }
  .hub-heading { margin: 0 0 23px; }
  .hub-heading .eyebrow, .module-heading .eyebrow { font-size: 8px; letter-spacing: 1.7px; }
  .hub-heading h1 { font-size: 27px; letter-spacing: .8px; line-height: 1.6; }
  .hub-heading > p { margin-top: 10px; font-size: 12px; }
  .hub-grid { gap: 12px; }
  .hub-card { min-height: 223px; padding: 18px 15px; border-radius: 10px; }
  .hub-card-icon { width: 36px; height: 36px; margin-bottom: 17px; border-radius: 9px; }
  .hub-card-icon .icon { width: 19px; height: 19px; }
  .hub-card-number { margin: -5px 0 11px; font-size: 8px; letter-spacing: .4px; }
  .hub-card h2 { font-size: 16px; letter-spacing: 0; }
  .hub-card > p { font-size: 11px; margin-top: 8px; margin-bottom: 17px; line-height: 1.9; }
  .hub-card-footer { font-size: 10px; padding-top: 12px; gap: 5px; }
  .hub-card-footer .icon { width: 13px; height: 13px; }
  .hub-note { font-size: 10px; margin-top: 18px; }
  .hub-note button { display: block; margin-left: 0; margin-top: 4px; }
  .module-heading { display: block; margin-bottom: 22px; }
  .module-heading h1 { font-size: 25px; }
  .module-heading p { font-size: 11px; }
  .module-heading > button { margin-top: 14px; }
  .module-person-row { position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px 14px; padding: 17px; }
  .module-person-avatar { width: 52px; height: 64px; align-self: start; border-radius: 7px; }
  .module-person-copy h2 { font-size: 17px; }
  .module-person-copy p { font-size: 11px; margin-top: 4px; }
  .module-person-copy small { font-size: 9px; margin-top: 5px; }
  .module-person-row > .outline-button, .module-person-actions { grid-column: 2; justify-self: start; }
  .module-person-row > .outline-button { min-height: 36px; padding: 7px 12px; font-size: 11px; }
  .module-person-actions { flex-direction: row; }
  .module-person-actions .outline-button { padding: 7px 11px; font-size: 10px; }
  .memory-workspace { gap: 13px; }
  .memory-detail { padding: 19px 16px; border-radius: 10px; }
  .memory-summary > header { flex-wrap: wrap; gap: 12px; }
  .memory-summary h2 { font-size: 21px; }
  .memory-summary p { font-size: 11px; }
  .memory-metrics { gap: 7px; }
  .memory-metrics > :is(span, div) { font-size: 10px; padding: 7px 9px; }
  .memory-metrics > label { padding: 10px; font-size: 10px; }
  .memory-records { margin-top: 20px; padding-top: 18px; }
  .memory-records li { padding: 12px; }
  .module-memory-form { margin-top: 21px; padding-top: 18px; }
  .module-memory-form :is(input, textarea, select) { font-size: 16px; }
  .module-directory-dialog { width: calc(100vw - 30px); padding: 25px 18px 21px; border-radius: 13px; }
  .module-directory-dialog h2 { font-size: 22px; }
  .module-directory-grid { gap: 10px; margin-top: 20px; }
  .module-directory-grid > button { padding: 14px 11px; min-height: 70px; gap: 8px; font-size: 12px; }
  .module-directory-grid .icon { width: 18px; height: 18px; }
  .module-directory-grid strong { font-size: 12px; }
  .module-directory-grid small { font-size: 9px; }
  .story-module-nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; padding: 6px; margin: -5px 0 21px; border-radius: 8px; }
  .story-module-nav > span { display: none; }
  .story-module-nav > button { min-width: 0; gap: 5px; padding: 8px 4px; font-size: 11px; }
  .story-module-nav .icon { width: 13px; height: 13px; }
  .story-mode .sd-detail-dock { bottom: calc(65px + env(safe-area-inset-bottom)); padding-bottom: 12px; }
}
@media (max-width: 359px) {
  .hub-grid { grid-template-columns: minmax(0, 1fr); }
  .hub-card { min-height: 190px; }
  .module-directory-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .hub-card { transition: none; }
  .hub-card:hover { transform: none; }
}
