:root {
  --paper: #f5efe2;
  --paper-deep: #e8dcc3;
  --ink: #262019;
  --muted: #776b5c;
  --red: #8f3328;
  --red-dark: #67231d;
  --jade: #315f55;
  --line: rgba(60, 46, 30, .16);
  --shadow: 0 16px 50px rgba(47, 35, 22, .12);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: #d8cfbc; font-family: "Noto Serif SC", "Songti SC", "STSong", serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 300px minmax(0, 1fr); background: radial-gradient(circle at 70% 0%, rgba(255,255,255,.56), transparent 35%), var(--paper); }
.sidebar { border-right: 1px solid var(--line); padding: 24px 20px; background: linear-gradient(180deg, #e9dfcc, #ddd0b8); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .12em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.seal { width: 48px; height: 48px; border: 2px solid var(--red); color: var(--red); display: grid; place-items: center; font-size: 25px; font-weight: 700; border-radius: 8px 5px 9px 4px; transform: rotate(-2deg); background: rgba(255,255,255,.28); }
.seal.small { width: 38px; height: 38px; font-size: 19px; }
.muted-card { background: rgba(255,255,255,.38); border: 1px solid rgba(96,74,47,.12); border-radius: 16px; padding: 14px; box-shadow: inset 0 1px rgba(255,255,255,.4); }
.profile h3 { margin: 0 0 6px; font-size: 19px; }
.profile .identity { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.stat { background: rgba(255,255,255,.5); padding: 9px; border-radius: 10px; }
.stat b { display: block; font-size: 16px; }
.stat span { color: var(--muted); font-size: 11px; }
.meter { margin-top: 7px; height: 5px; background: rgba(0,0,0,.08); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--jade); border-radius: inherit; }
.family-summary { margin-top: 12px; font-size: 12px; line-height: 1.8; color: #5e5447; }
.sidebar-actions { display: grid; gap: 8px; margin-top: auto; }
.ghost-button, .primary-button { border-radius: 10px; padding: 10px 14px; border: 1px solid var(--line); background: rgba(255,255,255,.38); color: var(--ink); }
.ghost-button:hover { background: rgba(255,255,255,.7); }
.primary-button { background: var(--red); color: white; border-color: var(--red); }
.primary-button:hover { background: var(--red-dark); }
.ghost-button:disabled { opacity: .45; cursor: default; }
.footnote { color: var(--muted); font-size: 11px; line-height: 1.7; }
.main { height: 100vh; min-width: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.topbar { height: 72px; padding: 0 26px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: rgba(245,239,226,.87); backdrop-filter: blur(14px); z-index: 3; }
.icon-button { display: none; border: 0; background: transparent; font-size: 22px; }
.date-label { font-weight: 700; letter-spacing: .08em; }
.place-label { color: var(--muted); font-size: 12px; margin-top: 3px; }
.save-dot { margin-left: auto; color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 6px; }
.save-dot span { width: 7px; height: 7px; border-radius: 50%; background: #5f826b; }
.chat { overflow-y: auto; padding: 30px max(24px, calc((100% - 850px)/2)) 70px; scroll-behavior: smooth; }
.message { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 22px; animation: rise .24s ease-out; }
.message.user { flex-direction: row-reverse; }
.avatar { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px; display: grid; place-items: center; background: var(--red); color: white; font-size: 14px; box-shadow: 0 5px 15px rgba(100,35,29,.18); }
.message.user .avatar { background: var(--jade); }
.bubble { max-width: min(720px, calc(100% - 50px)); padding: 15px 17px; border-radius: 6px 18px 18px 18px; background: rgba(255,255,255,.70); border: 1px solid rgba(80,58,37,.11); box-shadow: 0 8px 24px rgba(63,44,23,.06); line-height: 1.75; }
.message.user .bubble { background: #dce8df; border-radius: 18px 6px 18px 18px; }
.bubble h2 { margin: 2px 0 8px; font-size: 20px; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.event-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pill { display: inline-flex; padding: 3px 7px; border-radius: 99px; font-size: 10px; background: #eee4d0; color: #6c5b45; }
.pill.historical { background: #ead2ca; color: var(--red-dark); }
.choice-list { display: grid; gap: 9px; margin-top: 16px; }
.choice-button { text-align: left; border: 1px solid rgba(74,54,34,.16); background: rgba(252,248,239,.86); border-radius: 12px; padding: 12px 14px; color: var(--ink); transition: transform .14s, border-color .14s, box-shadow .14s; }
.choice-button:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(143,51,40,.45); box-shadow: 0 8px 16px rgba(78,48,27,.08); }
.choice-button:disabled { opacity: .52; cursor: default; }
.choice-button b { display: block; margin-bottom: 3px; }
.choice-button small { color: var(--muted); line-height: 1.45; }
.risk { color: #92473d !important; }
.commitment { margin-top: 12px; padding-top: 9px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 10px; word-break: break-all; }
.result-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
.result-cell { background: #eee6d7; border-radius: 10px; padding: 8px; text-align: center; }
.result-cell b { display: block; font-size: 18px; }
.result-cell span { color: var(--muted); font-size: 10px; }
.change-list { margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; list-style: none; }
.change-list li { background: #e2ebdf; color: #315b45; border-radius: 99px; font-size: 11px; padding: 4px 8px; }
.continue-button { margin-top: 14px; width: 100%; }
.composer-wrap { padding: 12px max(24px, calc((100% - 850px)/2)) 18px; border-top: 1px solid var(--line); background: rgba(245,239,226,.92); backdrop-filter: blur(14px); }
.composer { display: flex; gap: 9px; align-items: flex-end; background: rgba(255,255,255,.72); border: 1px solid rgba(71,52,34,.15); border-radius: 16px; padding: 8px; box-shadow: var(--shadow); }
.composer textarea { resize: none; flex: 1; min-height: 42px; max-height: 130px; border: 0; outline: 0; background: transparent; padding: 10px; color: var(--ink); line-height: 1.45; }
.composer button { border: 0; border-radius: 11px; padding: 10px 18px; min-height: 42px; color: white; background: var(--red); }
.composer button:disabled, .composer textarea:disabled { opacity: .45; cursor: default; }
.composer-hint { text-align: center; color: var(--muted); font-size: 10px; margin-top: 7px; }
.interpretation { margin-bottom: 8px; padding: 10px 12px; background: #f2dfcc; border: 1px solid #d8b99e; border-radius: 12px; font-size: 12px; }
.interpretation button { margin-left: 6px; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--line); background: white; }
dialog { width: min(520px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 18px; padding: 0; color: var(--ink); background: var(--paper); box-shadow: 0 28px 100px rgba(29,22,15,.3); }
dialog::backdrop { background: rgba(35,29,22,.46); backdrop-filter: blur(4px); }
.new-game-form { padding: 24px; display: grid; gap: 14px; }
.dialog-heading { display: flex; gap: 12px; align-items: center; margin-bottom: 5px; }
.dialog-heading h2 { margin: 0; }
.dialog-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.new-game-form label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.new-game-form input, .new-game-form select { width: 100%; padding: 10px 11px; background: rgba(255,255,255,.65); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-note { background: #ebe1cd; color: #665946; padding: 10px 12px; border-radius: 10px; font-size: 11px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 3px; }
.typing .bubble { display: flex; gap: 5px; padding: 14px 17px; }
.typing .bubble span { width: 6px; height: 6px; border-radius: 50%; background: #978a78; animation: blink 1s infinite alternate; }
.typing .bubble span:nth-child(2) { animation-delay: .2s; }
.typing .bubble span:nth-child(3) { animation-delay: .4s; }
.empty-welcome { max-width: 680px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty-welcome h2 { color: var(--ink); font-size: 30px; margin-bottom: 8px; }
.empty-welcome button { margin-top: 16px; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
@keyframes blink { from { opacity: .25; transform: translateY(0); } to { opacity: 1; transform: translateY(-2px); } }
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; width: min(310px, 86vw); transform: translateX(-105%); transition: transform .22s; box-shadow: 15px 0 60px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .icon-button { display: block; }
  .topbar { padding: 0 14px; }
  .chat { padding: 22px 13px 55px; }
  .composer-wrap { padding: 10px 10px 12px; }
  .result-grid { grid-template-columns: 1fr 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
}


.story-text { white-space: pre-line; line-height: 1.9; }
.pill.ai-source { background: #dce9e3; color: #285d4f; }
.pill.fallback-source { background: #efe0c7; color: #7b5b2c; }
.script-warning { margin: 11px 0 4px; padding: 9px 11px; border-radius: 10px; background: #f4e2cf; color: #7b4937; font-size: 11px; line-height: 1.55; }
.next-story-note { margin-top: 12px; color: var(--muted); font-size: 11px; font-style: italic; }
.retry-story-button { margin-top: 10px; }
.ai-status { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.ai-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.ai-status.online { color: #315f55; }
.ai-status.online::before { background: #4d8877; box-shadow: 0 0 0 3px rgba(77,136,119,.14); }
.ai-status.offline { color: #8b5d31; }
.ai-status.offline::before { background: #b57a3f; }
