/* 《人间》手机优先样式：320px 起，无外部字体/图片依赖 */
:root {
  --paper: #f5f1e8;
  --paper-2: #ece5d6;
  --ink: #1f1b16;
  --ink-soft: #4a423a;
  --ink-mute: #7a7065;
  --zhu: #9e3b2f;
  --dai: #3c4a52;
  --bronze: #6e7f6a;
  --line: #d8cfbd;
  --shadow: 0 8px 24px rgba(31, 27, 22, .16);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font-scale: 1;
  --lh: 1.8;
}
html[data-theme="night"] {
  --paper: #171512;
  --paper-2: #201d18;
  --ink: #e8e0d0;
  --ink-soft: #c9bfae;
  --ink-mute: #8d8478;
  --line: #38322a;
  --zhu: #c96a5c;
  --dai: #8fa3ad;
  --bronze: #8a9b86;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  font-size: 17px;
  line-height: var(--lh);
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; touch-action: manipulation; }

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: var(--safe-t);
  max-width: 100vw;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  padding: 6px 12px 4px;
  background: linear-gradient(var(--paper), color-mix(in srgb, var(--paper) 88%, transparent));
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 0;
}
.topbar-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-row.sub { justify-content: space-between; font-size: 11px; color: var(--ink-mute); }
.brand { font-weight: 700; letter-spacing: .18em; color: var(--ink); }
.clock { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang-btn {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 2px 8px; font-size: 11px; min-height: 26px; color: var(--ink-soft);
}
#placeLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 阅读区 ---------- */
.scroller {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 24px;
  position: relative;
  overscroll-behavior: contain;
}
.scene { max-width: 640px; margin: 0 auto; }
.scene p { margin: 0 0 .85em; text-indent: 2em; }
.scene p.no-indent { text-indent: 0; }
.scene p.inner { color: var(--ink-mute); font-style: italic; text-indent: 2em; }
.scene p.chronicle { text-indent: 0; letter-spacing: .06em; color: var(--ink-soft); }
.scene p.letter { text-indent: 0; background: var(--paper-2); padding: 10px 12px; border-radius: 8px; }
.scene .dialogue { text-indent: 0; }
.scene .speaker { color: var(--dai); font-weight: 600; }
.scene .sys { color: var(--ink-mute); font-size: 13px; text-indent: 0; }
.scene .divider { text-align: center; color: var(--ink-mute); margin: 1.2em 0; text-indent: 0; }
.scene .continue-hint { text-align: center; color: var(--zhu); font-size: 14px; text-indent: 0; margin: 1em 0; }
.new-text-hint {
  position: sticky; bottom: 6px; margin: 0 auto; width: max-content;
  background: var(--zhu); color: #fff; border-radius: 999px; padding: 6px 14px;
  font-size: 13px; box-shadow: var(--shadow);
}

/* ---------- 底栏 ---------- */
.bottombar {
  border-top: 1px solid var(--line);
  background: var(--paper);
  padding: 6px 8px calc(6px + var(--safe-b));
}
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper-2); color: var(--ink-soft); font-size: 15px;
}
.chip:active { transform: scale(.97); }
.composer { display: flex; gap: 8px; }
.input {
  flex: 1 1 auto; min-width: 0; min-height: 44px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--paper); padding: 0 12px; outline: none;
  font-size: 16px; /* iOS 不缩放 */
}
.input:focus { border-color: var(--bronze); }
.send {
  flex: 0 0 48px; min-height: 44px; border: 0; border-radius: 12px;
  background: var(--zhu); color: #fff; font-size: 22px;
}
.send:active { opacity: .8; }
.tabs {
  display: flex; gap: 2px; overflow-x: auto; padding-top: 6px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 44px; padding: 0 8px;
  background: transparent; border: 0; color: var(--ink-mute); font-size: 12px;
  border-radius: 8px;
}
.tab.active { color: var(--zhu); background: var(--paper-2); }
.tab-market { color: var(--bronze); }
.tab-settings { color: var(--ink-mute); }

/* ---------- 抽屉 ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(20, 16, 12, .42);
  z-index: 20;
}
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  height: min(78vh, 680px);
  height: min(78dvh, 680px); /* 移动端浏览器地址栏变化时更稳定 */
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-handle {
  width: 36px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 8px auto 2px;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 8px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 15px; margin: 0; letter-spacing: .1em; }
.close { border: 0; background: transparent; font-size: 18px; min-width: 44px; min-height: 44px; color: var(--ink-mute); }
.drawer-body { overflow-y: auto; padding: 12px 16px 24px; font-size: 14px; }
.drawer-body .row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.drawer-body .row:last-child { border-bottom: 0; }
.drawer-body .k { color: var(--ink-mute); flex: 0 0 auto; }
.drawer-body .v { text-align: right; min-width: 0; word-break: break-word; }
.drawer-body .section-title { color: var(--zhu); margin: 16px 0 6px; font-size: 13px; letter-spacing: .12em; }
.drawer-body .card {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0;
  background: var(--paper-2);
}
.drawer-body .card .name { font-weight: 600; }
.drawer-body .card .muted { color: var(--ink-mute); font-size: 12px; }
.drawer-body .empty { color: var(--ink-mute); text-align: center; padding: 24px 0; }
.drawer-body textarea, .drawer-body input[type="text"] {
  width: 100%; min-height: 44px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--paper); padding: 8px 10px;
}
.drawer-body .actions { display: flex; gap: 8px; margin-top: 8px; }
.drawer-body .btn {
  min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink-soft);
}
.drawer-body .btn.primary { background: var(--zhu); color: #fff; border-color: var(--zhu); }

/* ---------- 浮层 / 初始化 ---------- */
.popover {
  position: fixed; z-index: 30; max-width: 76vw;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px 12px; font-size: 13px;
}
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: #14110e; color: #f1eadc;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.overlay-inner { max-width: 420px; text-align: center; }
.overlay .verse { font-size: 20px; letter-spacing: .14em; margin: 0 0 18px; }
.overlay .hint { color: #cfc4b2; font-size: 14px; min-height: 2.6em; }
.overlay .tiny { color: #8d8478; font-size: 12px; margin-top: 18px; }
.primary {
  min-height: 48px; padding: 0 28px; border-radius: 999px; border: 1px solid #f1eadc;
  background: transparent; color: #f1eadc; font-size: 16px; letter-spacing: .2em;
}
.primary:active { background: rgba(241, 234, 220, .12); }
.muted { color: var(--ink-mute); }
[hidden] { display: none !important; }

/* ---------- 平板 / 桌面增强（不牺牲手机） ---------- */
@media (max-height: 500px) {
  .drawer { height: 92dvh; }
  .scene { padding-top: 0; }
}

@media (min-width: 768px) {
  .scroller { padding: 20px 28px 32px; }
  .scene { max-width: 720px; }
  .app { max-width: 1100px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .drawer { left: auto; right: 0; width: 420px; border-radius: 18px 0 0 0; height: 100vh; animation: slide .22s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
@media (min-width: 1100px) {
  .scene { max-width: 760px; }
  .chips { max-width: 760px; margin: 0 auto; }
  .composer, .tabs { max-width: 760px; margin: 0 auto; }
}

/* 流式草稿：模型增量输出阶段；最终过闸文本到达后移除 */
.provisional {
  opacity: 0.72;
  font-style: italic;
  border-left: 2px solid rgba(140, 45, 38, 0.35);
  padding-left: 10px;
}
