:root {
  --ink: #313b37;
  --muted: #79827a;
  --cream: #f7f4ee;
  --line: #dddcd3;
  --green: #365d4b;
  --serif: 'Noto Serif SC', 'Source Han Serif SC', 'Source Han Serif CN', 'Songti SC', 'STSong', 'SimSun', serif;
  --sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--cream); color: var(--ink); font-family: var(--sans); }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid #71967d; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
[hidden] { display: none !important; }

/* Page frame */
.shell { max-width: 1440px; margin: auto; padding: 0 7.2%; }
.topbar { height: 92px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font: 600 18px var(--serif); letter-spacing: .12em; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; background: var(--green); color: #f4f4e8; font: 500 22px var(--serif); border-radius: 50%; }
.brand small { display: block; font: 700 8px var(--sans); letter-spacing: .18em; margin-top: 4px; }
.top-actions { display: flex; align-items: center; gap: 20px; }
.pilot-badge, .eyebrow { font-size: 10px; font-weight: 700; letter-spacing: .17em; color: #728779; }
.pilot-badge { background: #e7ece3; border-radius: 99px; padding: 8px 12px; }
.key-button { display: flex; align-items: center; gap: 7px; background: none; border: 0; color: var(--green); font-weight: 700; font-size: 12px; }
.key-dot { width: 7px; height: 7px; border-radius: 50%; background: #c9cfc7; }
.key-dot.ok { background: #5d9a72; }
.key-dot.unknown { background: #d0b46c; }
.footer { border-top: 1px solid var(--line); padding: 25px 0 38px; display: flex; justify-content: space-between; font: 600 12px var(--serif); color: #809084; }
.footer i { font: italic 400 11px var(--serif); margin-left: 8px; }
.footer span:last-child { font-size: 10px; font-weight: 400; }

/* Intro */
.intro { display: grid; grid-template-columns: 1fr 1fr; gap: 5%; padding: 70px 0 84px; align-items: center; }
.intro-text .eyebrow { display: flex; align-items: center; gap: 9px; }
.intro-text .eyebrow span { width: 28px; height: 1px; background: #8aa294; }
.intro h1 { font: 500 clamp(46px, 5.5vw, 78px)/1.35 var(--serif); letter-spacing: .04em; margin: 24px 0; }
.intro h1 em { font-style: normal; color: #76907b; }
.intro-text > p { font: 400 14px/2.2 var(--serif); color: #727b73; margin: 0; }
.intro-note { display: flex; gap: 10px; align-items: center; margin-top: 39px; font-size: 11px; letter-spacing: .08em; color: #869187; }
.intro-note span { font-size: 19px; color: #a9b99d; }
.intro-art { position: relative; min-height: 390px; overflow: hidden; background: #dce6d8; border-radius: 190px 190px 4px 4px; }
.sun { position: absolute; width: 39%; aspect-ratio: 1; border-radius: 50%; background: #efe9cf; top: 13%; left: 30%; }
.orb { position: absolute; border-radius: 50% 50% 0 0; bottom: -23%; width: 53%; height: 87%; transform: rotate(-20deg); background: #819b88; }
.orb-one { left: 6%; }
.orb-two { left: 48%; transform: rotate(18deg); background: #557564; height: 76%; }
.art-lines { position: absolute; top: 22%; left: 11%; font: 600 11px/1.5 var(--sans); letter-spacing: .15em; color: #647b6c; }
.art-lines i { font: italic 20px var(--serif); letter-spacing: 0; }
.art-foot { position: absolute; bottom: 20px; left: 7%; right: 7%; display: flex; justify-content: space-between; color: #f8f9ef; font: 600 8px var(--sans); letter-spacing: .16em; }

/* Story cards */
.stories { border-top: 1px solid var(--line); padding: 39px 0 78px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 26px; }
.section-heading h2 { font: 500 29px var(--serif); margin: 10px 0 0; letter-spacing: .05em; }
.section-heading h2 span { font: 22px var(--sans); color: #9eb19d; }
.section-heading p { font: 12px var(--serif); color: var(--muted); }
.story-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.story-card { height: 247px; position: relative; border: 0; text-align: left; padding: 22px; overflow: hidden; transition: transform .2s; background: #e7ded6; color: #4f5148; }
.story-card:hover { transform: translateY(-4px); }
.card-two { background: #dce4dc; }
.card-three { background: #e9e5d8; }
.card-number { position: relative; z-index: 1; font: 600 10px var(--sans); letter-spacing: .12em; }
.card-resume { position: absolute; top: 48px; left: 22px; z-index: 1; background: #ffffffb8; color: var(--green); font: 700 10px var(--sans); letter-spacing: .06em; padding: 5px 10px; border-radius: 99px; }
.card-illustration { position: absolute; right: 13%; top: 17%; font: 500 55px/1.1 var(--serif); color: #bdaea2; opacity: .8; }
.card-two .card-illustration { color: #9aaf9d; }
.card-star { font: 110px var(--serif); color: #c7bd9c; top: 8%; }
.story-card::after { content: ''; position: absolute; right: -45px; bottom: -70px; border: 1px solid #ffffff75; width: 210px; height: 210px; border-radius: 50%; }
.card-bottom { position: absolute; bottom: 21px; left: 22px; right: 22px; display: flex; justify-content: space-between; align-items: end; z-index: 1; }
.card-bottom strong { display: block; font: 600 20px var(--serif); letter-spacing: .06em; }
.card-bottom small { display: block; margin-top: 8px; font: 11px var(--serif); color: #7e8378; }
.card-bottom b { font-size: 18px; font-weight: 400; }

/* Story view */
.chat-section { border-top: 1px solid var(--line); padding: 30px 0 60px; }
.chat-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.chat-title { flex: 1; min-width: 0; }
.chat-head h2 { font: 500 29px var(--serif); margin: 8px 0 0; letter-spacing: .05em; }
.chat-head p { font: 12px var(--serif); color: var(--muted); margin: 8px 0 0; }
.icon-button { background: none; border: 0; color: var(--green); font-weight: 700; font-size: 12px; padding: 8px 4px; white-space: nowrap; }
.back { order: 2; }
.settings-button, .sheet-head { display: none; }
.chat-layout { display: grid; grid-template-columns: 250px 1fr; gap: 28px; }

.story-settings { background: #edf0e9; padding: 24px; align-self: start; }
.setting-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; }
.story-settings p { font: 12px/1.9 var(--serif); color: #7e897e; }
.mode-toggle { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); background: #e0e8df; padding: 4px; margin-top: 14px; }
.mode-toggle button { padding: 9px 2px; border: 0; background: transparent; font-size: 11px; color: #76897b; }
.mode-toggle button.active { background: #fff; color: var(--green); box-shadow: 0 1px 4px #0001; }
.setting-divider { border-top: 1px solid #d6ded5; margin: 22px 0; }
.cast { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.cast li { background: #f6f8f3; padding: 10px 12px; font: 12px/1.8 var(--serif); color: #6f7d72; }
.cast strong { display: block; color: var(--ink); font: 600 14px var(--serif); }
.cast strong span { font: 400 11px var(--sans); color: #8b978d; }
.switch { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: #55635a; }
.switch input { accent-color: var(--green); width: 16px; height: 16px; margin: 0; }
.story-settings .privacy-note { font-size: 11px; color: #89968a; margin: 8px 0 14px; }
.setting-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ghost-button { border: 1px solid #cfd9cf; background: transparent; color: var(--green); padding: 8px 12px; font-size: 12px; }
.ghost-button.wide { width: 100%; margin-top: 10px; }
.story-settings .ai-note { display: none; }

.chat-panel { background: #fff; border: 1px solid #e8e9e1; display: flex; flex-direction: column; height: clamp(520px, calc(100vh - 220px), 860px); min-width: 0; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px; display: flex; flex-direction: column; gap: 22px; }
.message { max-width: 86%; font: 15px/2 var(--serif); }
.message .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message .speaker { display: block; font: 700 9px var(--sans); letter-spacing: .13em; color: #94a596; margin-bottom: 6px; }
.message.assistant { align-self: flex-start; color: #46524a; }
.message.user { align-self: flex-end; background: #edf2ea; padding: 12px 16px; color: #405a48; }
.message.user .speaker { color: #819987; }
.text.streaming::after { content: '▍'; color: #9aae9d; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.message-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 6px; }
.message-actions button { border: 0; background: none; padding: 6px 0; color: #7f9283; font: 600 12px var(--sans); }
.alt-nav { display: flex; align-items: center; gap: 4px; color: #9aa59b; font: 12px var(--sans); }
.alt-nav button { padding: 6px 8px; font-size: 15px; }
.status { padding: 0 28px; color: #a66658; font-size: 12px; min-height: 16px; }
.composer { margin: 8px 20px 0; border: 1px solid #dfe5dc; background: #fafbf8; }
.composer textarea { display: block; border: 0; resize: none; background: transparent; width: 100%; min-height: 56px; max-height: 160px; padding: 14px 16px; outline: none; color: var(--ink); font: 15px/1.6 var(--serif); }
.composer textarea::placeholder { color: #a6b0a6; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; padding: 4px 10px 10px 16px; color: #a3aca4; font-size: 10px; }
.composer-bottom button, .primary { background: var(--green); color: white; border: 0; padding: 11px 18px; font-size: 12px; }
#sendButton { min-width: 84px; }
#sendButton.stop { background: #8a5a4f; }
.chat-footer { padding: 12px 20px 16px; color: #a0aaa1; font-size: 10px; }

/* Dialogs */
dialog { border: 0; padding: 0; width: min(420px, calc(100% - 32px)); background: var(--cream); color: var(--ink); box-shadow: 0 15px 80px #172a2180; }
dialog::backdrop { background: #26352ec9; }
#ageDialog::backdrop { background: #26352e; }
.dialog-card { padding: 30px; }
.dialog-top { display: flex; justify-content: space-between; align-items: center; }
.close { border: 0; background: none; color: #718377; font-size: 26px; line-height: 1; }
.dialog-card h2 { font: 500 25px var(--serif); }
.dialog-card p { font: 13px/1.9 var(--serif); color: #6f7d72; }
.dialog-card label { display: block; font-size: 12px; font-weight: 700; margin: 23px 0 8px; }
.dialog-card input { width: 100%; border: 1px solid #d9e0d8; background: white; padding: 13px; }
.form-error { min-height: 1em; margin: 8px 0 0; color: #a66658 !important; font-size: 12px !important; }
.dialog-actions { margin-top: 16px; }
.primary { width: 100%; }
.primary:disabled { opacity: .6; }
.dialog-note { font-size: 10px !important; }

@media (max-width: 700px) {
  .shell { padding: 0 5%; }
  .topbar { height: 72px; }
  .brand { font-size: 16px; }
  .brand-mark { width: 36px; height: 36px; font-size: 19px; }
  .pilot-badge { display: none; }
  .intro { grid-template-columns: 1fr; gap: 30px; padding: 48px 0 45px; }
  .intro h1 { font-size: 49px; margin: 18px 0; }
  .intro-note { margin-top: 24px; }
  .intro-art { min-height: 270px; max-height: 300px; border-radius: 120px 120px 4px 4px; }
  .art-lines { top: 13%; left: 10%; }
  .stories { padding: 30px 0 50px; }
  .section-heading p { display: none; }
  .section-heading h2 { font-size: 25px; }
  .story-grid { grid-template-columns: 1fr; gap: 10px; }
  .story-card { height: 170px; }
  .card-illustration { font-size: 43px; top: 12%; }
  .card-star { font-size: 90px; }
  .footer { gap: 15px; }

  /* Full-screen reading mode once a story is open. */
  body.in-story { overflow: hidden; }
  body.in-story .shell { padding: 0; }
  body.in-story .topbar, body.in-story .footer { display: none; }
  .chat-section { position: fixed; left: 0; right: 0; top: var(--app-top, 0); height: var(--app-h, 100dvh); z-index: 5; display: flex; flex-direction: column; padding: 0; border: 0; background: #fff; }
  .chat-head { margin: 0; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) 10px 6px; border-bottom: 1px solid #ecebe4; background: var(--cream); }
  .chat-head .eyebrow, .chat-head p { display: none; }
  .chat-head h2 { margin: 0; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .back { order: 0; }
  .settings-button { display: block; }
  .chat-layout { display: flex; flex: 1; min-height: 0; }
  .chat-panel { flex: 1; height: auto; border: 0; }
  .chat-messages { padding: 22px 20px; gap: 20px; }
  .message { max-width: 94%; font-size: 16px; line-height: 1.95; }
  .status { padding: 0 20px; }
  .composer { display: flex; align-items: flex-end; margin: 0; border-width: 1px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .composer textarea { flex: 1; font-size: 16px; min-height: 48px; padding: 13px 8px 13px 16px; }
  .composer-bottom { padding: 6px 10px 6px 0; }
  .composer-bottom > span { display: none; }
  .chat-footer { display: none; }

  .story-settings { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 84%; overflow-y: auto; padding: 16px 22px calc(22px + env(safe-area-inset-bottom)); background: var(--cream); box-shadow: 0 -10px 40px #172a2133; transform: translateY(105%); visibility: hidden; transition: transform .25s ease, visibility .25s; }
  .story-settings.open { transform: none; visibility: visible; }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font: 600 15px var(--serif); }
  .sheet-backdrop { position: fixed; inset: 0; z-index: 25; background: #26352e66; }
  .story-settings p { font-size: 13px; }
  .mode-toggle button { padding: 11px 2px; font-size: 13px; }
  .story-settings .ai-note { display: block; font-size: 11px; color: #9aa59b; margin: 16px 0 0; }
  .dialog-card input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .story-card, .story-settings { transition: none; }
  .text.streaming::after { animation: none; }
}
