:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --panel: rgba(255, 255, 255, 0.78);
  --ink: #17211d;
  --muted: #6f7772;
  --line: rgba(23, 33, 29, 0.1);
  --brand: #135d4c;
  --brand-soft: #dcebe5;
  --coral: #f08b6e;
  --shadow: 0 20px 60px rgba(32, 50, 43, 0.09);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 88% 5%, #e3efe9 0, transparent 28rem), var(--paper); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.skip-link { position: fixed; top: -4rem; left: 1rem; z-index: 100; padding: .75rem 1rem; background: var(--ink); color: white; border-radius: 10px; }
.skip-link:focus { top: 1rem; }

.test-banner { position: fixed; inset: 0 0 auto; z-index: 20; height: 30px; display: flex; align-items: center; justify-content: center; gap: .45rem; padding: 0 1rem; color: #fff8f4; background: #29332f; font-size: .72rem; font-weight: 750; letter-spacing: .04em; }
.test-banner__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 4px rgba(240,139,110,.16); }
.test-banner[data-available="true"] .test-banner__dot { background: #75d3a3; box-shadow: 0 0 0 4px rgba(117,211,163,.16); }
.app-shell { min-height: 100vh; padding-top: 30px; }
.sidebar { display: none; }
.main-panel { min-width: 0; padding: 0 1rem 6.5rem; }
.topbar { min-height: 104px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.5rem 0 1rem; }
.eyebrow { margin: 0 0 .3rem; color: var(--brand); font-size: .68rem; font-weight: 800; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 8vw, 3.25rem); font-weight: 500; letter-spacing: -.035em; }
h2 { font-size: 1.08rem; }
.avatar { flex: 0 0 auto; width: 46px; height: 46px; display: inline-grid; place-items: center; border: 0; border-radius: 50%; color: white; background: var(--avatar, var(--brand)); font-size: .78rem; font-weight: 800; box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }
.avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.avatar--large { width: 76px; height: 76px; font-size: 1rem; }
.avatar--user { cursor: pointer; background: linear-gradient(145deg, #1f6f5d, #103f35); }
.view { animation: fade-in .24s ease-out; }
@keyframes fade-in { from { opacity: .35; transform: translateY(5px); } }

.card { background: var(--panel); border: 1px solid rgba(255,255,255,.9); border-radius: var(--radius-lg); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin: .4rem 0 1rem; }
.section-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; font-weight: 500; }
.section-heading p { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; }
.text-button { border: 0; padding: .4rem 0; color: var(--brand); background: transparent; font-size: .8rem; font-weight: 750; cursor: pointer; }
.demo-chip { display: inline-flex; align-items: center; width: fit-content; padding: .26rem .48rem; border: 1px solid rgba(19,93,76,.16); border-radius: 999px; color: var(--brand); background: var(--brand-soft); font-size: .6rem; font-weight: 850; letter-spacing: .08em; }
.empty-note { color: var(--muted); font-size: .85rem; }
.empty-state { padding: 1.25rem; }
.empty-state h2 { margin-bottom: .35rem; }
.empty-state p { max-width: 680px; margin-bottom: 1rem; color: var(--muted); font-size: .82rem; line-height: 1.5; }
.empty-state .secondary-button { display: inline-flex; text-decoration: none; }

.story-row { display: flex; gap: 1rem; overflow-x: auto; padding: .2rem .1rem 1.35rem; scrollbar-width: none; }
.story-row::-webkit-scrollbar { display: none; }
.story { min-width: 64px; border: 0; background: transparent; text-align: center; cursor: pointer; }
.story .avatar { width: 55px; height: 55px; margin-bottom: .4rem; outline: 2px solid var(--coral); outline-offset: 3px; }
.story[aria-pressed="true"] .avatar { outline-color: var(--brand); box-shadow: 0 0 0 5px var(--brand-soft); }
.story span:last-child { display: block; max-width: 64px; overflow: hidden; text-overflow: ellipsis; font-size: .72rem; white-space: nowrap; }

.chat-layout { display: grid; gap: 1rem; }
.conversation-list { overflow: hidden; }
.conversation-item { width: 100%; display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: .8rem; align-items: center; padding: .95rem; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.conversation-item:last-child { border-bottom: 0; }
.conversation-item[aria-current="true"] { background: rgba(220,235,229,.62); }
.conversation-item:focus-visible, .story:focus-visible { outline: 3px solid rgba(19,93,76,.35); outline-offset: -3px; }
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy strong { margin-bottom: .23rem; font-size: .9rem; }
.conversation-copy span { color: var(--muted); font-size: .76rem; }
.conversation-meta { align-self: start; color: var(--muted); font-size: .68rem; }
.unread { min-width: 20px; height: 20px; display: grid; place-items: center; margin: .35rem 0 0 auto; border-radius: 50%; color: white; background: var(--coral); font-weight: 800; }

.thread { min-height: 430px; display: flex; flex-direction: column; overflow: hidden; }
.thread__header { display: flex; align-items: center; gap: .8rem; padding: 1rem; border-bottom: 1px solid var(--line); }
.thread__header h2 { margin: 0 0 .15rem; font-size: .95rem; }
.thread__header p { margin: 0; color: var(--muted); font-size: .7rem; }
.chat-error { margin: .8rem .8rem 0; padding: .7rem .85rem; border-radius: 12px; color: #783323; background: #fff1e9; font-size: .76rem; line-height: 1.45; }
.messages { flex: 1; display: flex; flex-direction: column; gap: .65rem; padding: 1rem; background: linear-gradient(180deg, rgba(247,245,239,.38), rgba(220,235,229,.32)); }
.message { max-width: 82%; padding: .72rem .85rem; border-radius: 16px 16px 16px 5px; background: white; box-shadow: 0 8px 24px rgba(23,33,29,.06); font-size: .84rem; line-height: 1.45; }
.message--mine { align-self: end; border-radius: 16px 16px 5px; color: white; background: var(--brand); }
.message small { display: block; margin-top: .3rem; color: inherit; opacity: .62; font-size: .62rem; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: .6rem; padding: .8rem; border-top: 1px solid var(--line); background: rgba(255,255,255,.72); }
.composer input { min-width: 0; padding: .8rem .95rem; border: 1px solid var(--line); border-radius: 999px; outline: none; background: white; }
.composer input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(19,93,76,.11); }
.send-button { width: 44px; height: 44px; border: 0; border-radius: 50%; color: white; background: var(--brand); cursor: pointer; }
.send-button:disabled { opacity: .55; cursor: wait; }
.composer-status { grid-column: 1 / -1; min-height: 0; margin: 0; color: var(--muted); font-size: .72rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.people-grid, .activity-grid, .settings-grid { display: grid; gap: .85rem; }
.person-card { min-height: 340px; display: flex; flex-direction: column; padding: 1rem; border-top: 4px solid var(--person-accent); color: var(--ink); background: rgba(255,255,255,.84); }
.person-card__header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.person-card__avatar { width: 64px; height: 64px; font-size: .95rem; box-shadow: 0 8px 24px rgba(23,33,29,.12); }
.person-card__identity h2 { margin: 0; font: 500 1.42rem Georgia, serif; line-height: 1.15; }
.person-card__identity h2 span { color: var(--muted); font: 700 .7rem/1 ui-sans-serif, sans-serif; white-space: nowrap; }
.person-card__meta { display: grid; gap: .22rem; margin-top: .55rem; color: var(--muted); font-size: .74rem; font-weight: 650; }
.person-card__summary { margin: .85rem 0 0; color: #46504b; font-size: .8rem; line-height: 1.55; }
.interest-block { margin-top: auto; padding-top: .9rem; }
.interest-block > strong { display: block; margin-bottom: .5rem; color: var(--muted); font-size: .63rem; letter-spacing: .08em; text-transform: uppercase; }
.interest-list { display: flex; flex-wrap: wrap; gap: .35rem; margin: .7rem 0; }
.interest-list span { padding: .28rem .52rem; border: 1px solid rgba(19,93,76,.16); border-radius: 999px; color: var(--brand); background: var(--brand-soft); font-size: .64rem; }
.person-card__actions { display: flex; gap: .5rem; margin-top: .35rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.person-card__actions button { border: 1px solid rgba(19,93,76,.2); padding: .5rem .72rem; border-radius: 999px; color: var(--brand); background: transparent; font-size: .7rem; font-weight: 780; cursor: pointer; }
.person-card__actions button:first-child { color: white; background: var(--brand); }
.person-card__actions button:hover { transform: translateY(-1px); }
.character-detail, .character-editor { margin-bottom: 1rem; padding: 1.15rem; }
.character-detail__head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.character-detail__head h2 { margin: .35rem 0 .2rem; font: 500 1.5rem Georgia, serif; }
.character-detail__head p, .character-detail > p { margin-bottom: .75rem; color: var(--muted); font-size: .82rem; line-height: 1.5; }
.character-detail__connection { padding-top: .8rem; border-top: 1px solid var(--line); }
.interest-list--light span { color: var(--brand); border-color: rgba(19,93,76,.18); background: var(--brand-soft); }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; }
.secondary-button { width: fit-content; border: 1px solid rgba(19,93,76,.22); padding: .7rem .9rem; border-radius: 999px; color: var(--brand); background: var(--brand-soft); font-size: .74rem; font-weight: 800; cursor: pointer; }
.character-form { display: grid; gap: .85rem; }
.private-fields { padding: 1rem; border: 1px solid rgba(19,93,76,.14); border-radius: 16px; background: rgba(220,235,229,.38); }
.private-fields h3 { margin: 0 0 .25rem; font-size: .9rem; }
.private-fields > p { margin: 0 0 .8rem; color: var(--muted); font-size: .72rem; }
.private-fields .field + .field { margin-top: .8rem; }
.photo-status { display: flex; align-items: center; gap: .75rem; padding: .7rem; border-radius: 14px; background: rgba(255,255,255,.65); color: var(--muted); font-size: .72rem; }
.photo-status .text-button { margin-left: auto; }
.network-heading { margin-top: 1.6rem; }
.network-list { display: grid; gap: .75rem; }
.network-card { padding: .9rem 1rem; }
.network-card strong { font-size: .82rem; }
.network-card p { margin: .3rem 0 0; color: var(--muted); font-size: .74rem; line-height: 1.45; }
.relationship-label { display: block; margin-bottom: .35rem; color: var(--brand); font-size: .6rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }

.activity-card, .setting-card { padding: 1rem; }
.activity-card { display: grid; grid-template-columns: auto 1fr; gap: .85rem; }
.date-tile { width: 52px; height: 58px; display: grid; place-content: center; border-radius: 14px; color: var(--brand); background: var(--brand-soft); text-align: center; }
.date-tile strong { font: 500 1.45rem/1 Georgia, serif; }
.date-tile span { font-size: .58rem; font-weight: 850; letter-spacing: .08em; }
.activity-card h2, .setting-card h2 { margin-bottom: .3rem; font-size: .9rem; }
.activity-card p, .setting-card p { margin: 0; color: var(--muted); font-size: .76rem; line-height: 1.45; }
.activity-card .demo-chip { grid-column: 2; margin-top: .2rem; }

.profile-hero { padding: 1.25rem; }
.profile-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.2rem; }
.profile-head .avatar { width: 72px; height: 72px; font-size: 1rem; }
.profile-head h2 { margin: 0 0 .25rem; font: 500 1.55rem Georgia, serif; }
.profile-head p { margin: 0; color: var(--muted); font-size: .8rem; }
.profile-form { display: grid; gap: .85rem; }
.field { display: grid; gap: .35rem; }
.field span { font-size: .7rem; font-weight: 750; }
.field input, .field textarea, .field select { width: 100%; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--ink); background: rgba(255,255,255,.85); }
.field input[type="file"] { padding: .6rem; font-size: .74rem; }
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(19,93,76,.1); }
.primary-button { width: fit-content; border: 0; padding: .8rem 1.1rem; border-radius: 999px; color: white; background: var(--brand); font-weight: 750; cursor: pointer; }
.toast { position: fixed; right: 1rem; bottom: 6.5rem; z-index: 30; padding: .75rem 1rem; border-radius: 12px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: .78rem; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.setting-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: var(--brand); background: var(--brand-soft); font-weight: 800; }
.provider-card { border-color: rgba(240,139,110,.36); background: #fff9f5; }
.provider-state { display: flex; align-items: center; gap: .45rem; color: #9b4a34; font-size: .72rem; font-weight: 800; }
.provider-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--coral); }
.provider-state--available { color: #086b45; }
.provider-state--available i { background: #39a874; }
.danger-button { color: #9b3429; }
.regeneration-card { display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 1rem; border-color: rgba(240,139,110,.36); }
.regeneration-preview { margin-bottom: 1rem; padding: 1.15rem; }
.regeneration-preview .section-heading { align-items: start; }
.regeneration-preview .section-heading h2 { margin-top: .45rem; }
.profile-basis { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .6rem; margin-bottom: 1rem; }
.profile-basis span { padding: .7rem; border-radius: 12px; color: var(--muted); background: rgba(220,235,229,.42); font-size: .72rem; overflow-wrap: anywhere; }
.profile-basis strong { display: block; margin-bottom: .2rem; color: var(--ink); font-size: .64rem; text-transform: uppercase; letter-spacing: .06em; }
.impact-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .6rem; }
.impact-grid div { padding: .8rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.7); }
.impact-grid strong, .impact-grid span { display: block; }
.impact-grid strong { color: var(--brand); font: 500 1.35rem Georgia, serif; }
.impact-grid span { margin-top: .15rem; color: var(--muted); font-size: .68rem; line-height: 1.35; }
.preview-subtitle { margin: 1.2rem 0 .65rem; font-size: .8rem; }
.proposed-people { display: grid; gap: .4rem; margin-bottom: 1rem; }
.proposed-people span { padding: .5rem .65rem; border-radius: 10px; background: var(--paper); font-size: .72rem; }
.preserve-option { display: flex; align-items: flex-start; gap: .65rem; padding: .85rem; border: 1px solid rgba(19,93,76,.18); border-radius: 14px; background: var(--brand-soft); cursor: pointer; }
.preserve-option input { margin-top: .2rem; accent-color: var(--brand); }
.preserve-option strong, .preserve-option small { display: block; }
.preserve-option strong { font-size: .78rem; }
.preserve-option small { margin-top: .25rem; color: var(--muted); font-size: .68rem; line-height: 1.4; }
.regeneration-warning { margin: .75rem 0; padding: .75rem; border-radius: 12px; color: #73402f; background: #fff1e9; font-size: .72rem; line-height: 1.45; }
.danger-primary { border: 0; padding: .72rem .95rem; border-radius: 999px; color: white; background: #9b3429; font-size: .74rem; font-weight: 800; cursor: pointer; }

.nav-list { display: grid; gap: .35rem; }
.nav-link { display: flex; align-items: center; gap: .75rem; padding: .72rem .8rem; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 700; }
.nav-link svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-link[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }
.bottom-nav { position: fixed; inset: auto .75rem max(.75rem, env(safe-area-inset-bottom)); z-index: 15; display: grid; grid-template-columns: repeat(5,1fr); padding: .45rem; border: 1px solid rgba(255,255,255,.9); border-radius: 20px; background: rgba(255,255,255,.9); box-shadow: 0 12px 40px rgba(23,33,29,.16); backdrop-filter: blur(18px); }
.bottom-nav .nav-link { flex-direction: column; gap: .18rem; padding: .35rem .1rem; font-size: .58rem; }
.bottom-nav .nav-link svg { width: 18px; height: 18px; }

@media (min-width: 680px) {
  .main-panel { padding-inline: 2rem; }
  .people-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .activity-grid, .settings-grid, .network-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .character-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field--wide, .profile-form .primary-button, .character-form .primary-button { grid-column: 1 / -1; }
  .profile-basis { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .impact-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .proposed-people { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (min-width: 960px) {
  .app-shell { display: grid; grid-template-columns: 232px minmax(0,1fr); }
  .sidebar { position: sticky; top: 30px; height: calc(100vh - 30px); display: flex; flex-direction: column; padding: 1.5rem 1rem; border-right: 1px solid var(--line); background: rgba(247,245,239,.72); backdrop-filter: blur(18px); }
  .brand { display: flex; align-items: center; gap: .7rem; margin: 0 .35rem 2rem; color: var(--ink); text-decoration: none; }
  .brand__mark { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 11px; color: white; background: var(--brand); font-family: Georgia, serif; font-size: 1.2rem; }
  .brand strong, .brand small { display: block; }
  .brand strong { font-family: Georgia, serif; font-size: 1.05rem; }
  .brand small { margin-top: .12rem; color: var(--muted); font-size: .62rem; }
  .sidebar__footer { margin-top: auto; padding: .8rem; }
  .sidebar__footer p { margin: .7rem 0 0; color: var(--muted); font-size: .68rem; line-height: 1.45; }
  .status-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .68rem; font-weight: 750; }
  .status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #35a879; }
  .main-panel { max-width: 1260px; width: 100%; margin: 0 auto; padding: 0 2.5rem 3rem; }
  .bottom-nav { display: none; }
  .chat-layout { grid-template-columns: minmax(250px,.82fr) minmax(400px,1.45fr); }
  .thread { min-height: 560px; }
  .people-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .toast { bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; } }
