*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #F0E9DF;
  --surface: #F5EFE6;
  --border: #D9CFC4;
  --border-light: #E8E2D8;
  --accent: #8299AC;
  --accent-light: #D4DDE5;
  --text: #292521;
  --text-mid: #6E6158;
  --text-muted: #B0A9A2;
  --thinking-bg: #E4E0DB;
  --thinking-text: #6E6158;
  --serif: 'Playfair Display', Georgia, serif;
  --garamond: 'EB Garamond', Georgia, serif;
}
html, body { height: 100%; height: 100dvh; overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif; background: var(--bg); color: var(--text); }

/* ── Page system ── */
.page { display: none; flex-direction: column; height: 100dvh; background: var(--bg); }
.page.active { display: flex; }

/* ── Panel (slides from right) ── */
.panel {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s ease;
}
.panel.open { transform: translateX(0); }
.panel-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.back-btn { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; }
.panel-title { font-size: 15px; color: var(--text); flex: 1; }

/* ══════════ HOME ══════════ */
#home-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#home-inner {
  padding: max(48px, env(safe-area-inset-top)) 22px calc(36px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
#home-time-block { text-align: center; padding-bottom: 28px; }
#home-daystr { font-size: 10.5px; color: var(--text-muted); letter-spacing: .2em; text-transform: uppercase; margin-bottom: 14px; }
#home-clock { font-family: var(--serif); font-size: clamp(64px, 19vw, 80px); font-weight: 300; color: var(--text); letter-spacing: -4px; line-height: 1; }
#home-weather { font-size: 12px; color: var(--text-muted); margin-top: 9px; letter-spacing: .03em; }
.home-divider { border: none; border-top: 1px solid var(--border); margin: 0; }
#home-quote { text-align: center; padding: 24px 8px; }
#home-quote-text { font-family: var(--garamond); font-size: 15.5px; color: var(--text-mid); line-height: 2.1; font-style: italic; }
#home-cards { display: flex; flex-direction: column; gap: 10px; padding-top: 28px; }
.home-card-main {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 16px 18px; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; -webkit-user-select: none;
}
.home-card-main:active { opacity: 0.7; }
.home-card-label { font-size: 9.5px; color: var(--accent); letter-spacing: .14em; text-transform: uppercase; margin-bottom: 5px; }
.home-card-title { font-family: var(--serif); font-size: 24px; font-weight: 300; color: var(--text); }
.home-card-arrow {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.home-card-arrow svg { width: 13px; height: 13px; stroke: var(--surface); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.home-cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.home-card-sm {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 14px; cursor: pointer; -webkit-user-select: none;
}
.home-card-sm:active { opacity: 0.7; }
.home-card-sm .home-card-label { font-size: 9px; }
.home-card-sm-title { font-family: var(--serif); font-size: 17px; font-weight: 300; color: var(--text); }

/* ══════════ CHAT ══════════ */
#chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#chat-back { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; flex-shrink: 0; }
#chat-header-center { flex: 1; min-width: 0; }
#chat-header-name { font-size: 15px; color: var(--text); }
#chat-status { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
#chat-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.hdr-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 10px; font-size: 12px; color: var(--text-muted);
  cursor: pointer; font-family: inherit; white-space: nowrap;
  appearance: none; -webkit-appearance: none;
}
.hdr-btn:disabled { opacity: 0.4; pointer-events: none; }
.hdr-btn:active { opacity: 0.7; }
#model-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 12px; color: var(--text-muted);
  cursor: pointer; font-family: inherit; outline: none;
}
#ctx-bar { height: 3px; background: transparent; flex-shrink: 0; }
#ctx-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.6s ease, background 0.4s ease; }
#chat-messages {
  flex: 1; overflow-y: auto; padding: 18px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
#chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; pointer-events: none; }
.message { display: flex; flex-direction: column; max-width: 82%; gap: 6px; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 20px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.message.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.message.assistant .bubble { background: var(--surface); color: var(--text); border-bottom-left-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.thinking-block { max-width: 100%; border-radius: 12px; background: var(--thinking-bg); overflow: hidden; }
.thinking-toggle {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; cursor: pointer;
  font-size: 12px; color: var(--thinking-text); font-weight: 500; user-select: none;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.thinking-toggle .arrow { font-size: 10px; transition: transform 0.2s; }
.thinking-toggle.open .arrow { transform: rotate(90deg); }
.thinking-content { display: none; padding: 0 12px 10px; font-size: 13px; line-height: 1.6; color: var(--thinking-text); white-space: pre-wrap; word-break: break-word; }
.thinking-content.visible { display: block; }
.typing-bubble { display: flex; align-items: center; gap: 4px; padding: 12px 16px; min-width: 56px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: pulse 1.4s ease-in-out infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%,80%,100% { opacity: 0.3; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }
#input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0;
}
#input {
  flex: 1; min-height: 38px; max-height: 130px; padding: 9px 13px;
  border: 1.5px solid var(--border); border-radius: 19px;
  font-family: inherit; font-size: 15px; line-height: 1.4;
  outline: none; resize: none; background: var(--bg); color: var(--text);
  overflow-y: auto; transition: border-color 0.15s;
}
#input::placeholder { color: var(--text-muted); }
#input:focus { border-color: var(--accent); }
#send-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity 0.15s, transform 0.1s;
}
#send-btn:disabled { opacity: 0.35; cursor: default; }
#send-btn:not(:disabled):active { transform: scale(0.92); }
#send-btn svg { width: 18px; height: 18px; fill: white; margin-left: 2px; }
#attach-btn {
  width: 38px; height: 38px; border-radius: 50%; background: none;
  border: 1.5px solid var(--border); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--text-muted); font-size: 22px; line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}
#attach-btn:hover { border-color: var(--accent); color: var(--accent); }
#attachment-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 12px 4px; min-height: 0;
}
#attachment-chips:empty { padding: 0; }
.att-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; font-size: 13px;
  color: var(--text); max-width: 180px;
}
.att-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.att-chip-remove { cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; flex-shrink: 0; }
.bubble .att-tag {
  display: block; margin-top: 5px; font-size: 12px;
  color: var(--text-muted); opacity: 0.8;
}

/* ══════════ CONVERSATIONS SIDEBAR ══════════ */
#convs-sidebar {
  position: fixed; inset: 0; z-index: 150;
  display: flex; pointer-events: none;
}
#convs-sidebar.open { pointer-events: auto; }
#convs-drawer {
  width: min(300px, 85vw); height: 100%; background: var(--surface);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform 0.25s ease;
  box-shadow: 4px 0 20px rgba(0,0,0,0.08);
}
#convs-sidebar.open #convs-drawer { transform: translateX(0); }
#convs-scrim {
  flex: 1; background: rgba(0,0,0,0); transition: background 0.25s ease;
}
#convs-sidebar.open #convs-scrim { background: rgba(0,0,0,0.18); }
#convs-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#convs-drawer-title { font-size: 14px; color: var(--text-muted); letter-spacing: .06em; text-transform: uppercase; }
#convs-new-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: none; cursor: pointer; font-size: 18px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
#convs-new-btn:active { background: var(--bg); }
#convs-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0; }
.conv-item {
  padding: 12px 16px; cursor: pointer; display: flex; align-items: flex-start; gap: 10px;
  border-radius: 0; transition: background 0.1s;
}
.conv-item:active { background: var(--bg); }
.conv-item.active-conv { background: var(--accent-light); }
.conv-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  margin-top: 5px; flex-shrink: 0; opacity: 0;
}
.conv-item.active-conv .conv-dot { opacity: 1; }
.conv-body { flex: 1; min-width: 0; }
.conv-preview { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.conv-preview:empty::before { content: '新对话'; color: var(--text-muted); }
.conv-time { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.conv-edit-btn {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--text-muted); padding: 4px 6px; line-height: 1;
  border-radius: 6px; opacity: 0; transition: opacity 0.15s;
}
.conv-item:hover .conv-edit-btn,
.conv-item.active-conv .conv-edit-btn { opacity: 0.5; }
.conv-edit-btn:active { opacity: 1 !important; }
.conv-title-input {
  font-size: 14px; color: var(--text); line-height: 1.4;
  background: var(--bg); border: 1px solid var(--accent);
  border-radius: 6px; padding: 2px 6px; outline: none;
  width: 100%; font-family: inherit;
}
#convs-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ══════════ ACTION MENU ══════════ */
#action-menu {
  position: fixed; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  min-width: 150px; overflow: hidden;
  display: none; flex-direction: column;
}
#action-menu.open { display: flex; }
.action-menu-item {
  padding: 13px 16px; font-size: 14px; cursor: pointer;
  border: none; background: none; text-align: left; font-family: inherit;
  color: var(--text); width: 100%;
}
.action-menu-item:active { background: var(--bg); }
.action-menu-item.danger { color: #C45555; }
#action-menu-scrim {
  position: fixed; inset: 0; z-index: 199; display: none;
}
#action-menu-scrim.open { display: block; }

/* ══════════ CALENDAR ══════════ */
#cal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#cal-back { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; }
#cal-month-title { font-family: var(--serif); font-size: 17px; font-weight: 300; color: var(--text); }
#cal-nav { display: flex; gap: 0; }
.cal-nav-btn { background: none; border: none; cursor: pointer; font-size: 22px; color: var(--text-muted); padding: 2px 10px; line-height: 1; }
#cal-body { flex: 1; display: flex; flex-direction: column; padding: 16px 16px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#cal-day-headers { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; flex-shrink: 0; }
#cal-day-headers span { text-align: center; font-size: 11px; color: var(--text-muted); padding: 4px 0; letter-spacing: .03em; }
#cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; }
.cal-cell { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; border-radius: 10px; padding: 2px 0; }
.cal-cell:active { background: var(--border); }
.cal-cell.empty { cursor: default; pointer-events: none; }
.cal-num {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 16px; font-weight: 300; color: var(--text);
}
.cal-cell.today .cal-num { background: var(--accent); color: white; }
.cal-dots { display: flex; gap: 3px; min-height: 6px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; }
#cal-legend { display: flex; gap: 18px; padding-top: 14px; border-top: 1px solid var(--border); flex-shrink: 0; margin-top: 12px; }
.cal-legend-item { display: flex; align-items: center; gap: 5px; }
.cal-legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.cal-legend-label { font-size: 11px; color: var(--text-muted); }

/* ══════════ DAY PANEL ══════════ */
#panel-day {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg); display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(.32,.72,0,1);
}
#panel-day.open { transform: translateY(0); }
#day-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#day-title { font-family: var(--serif); font-size: 18px; font-weight: 300; color: var(--text); }
#day-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-muted); padding: 2px 4px; line-height: 1; }
#day-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 22px 18px; display: flex; flex-direction: column; gap: 22px; }
.day-section { display: flex; flex-direction: column; gap: 10px; }
.day-label { font-size: 9.5px; color: var(--text-muted); letter-spacing: .14em; text-transform: uppercase; }
#mood-chips, #cycle-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.mood-chip, .cycle-chip {
  padding: 7px 16px; border-radius: 20px; font-size: 13px; color: var(--text-mid);
  background: var(--surface); border: 1px solid var(--border); cursor: pointer;
  font-family: inherit; transition: all 0.15s;
}
.mood-chip.sel { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.cycle-chip.sel { background: #EDE0EF; border-color: #C4A8C8; color: #7A5A7E; }
.cycle-chip[data-cycle=""].sel { background: var(--bg); border-color: var(--border); color: var(--text-mid); }
#day-note {
  width: 100%; min-height: 80px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  font-family: inherit; font-size: 14px; line-height: 1.65; color: var(--text);
  background: var(--surface); resize: none; outline: none;
}
#day-note:focus { border-color: var(--accent); }
#day-note::placeholder { color: var(--text-muted); }
#plans-list { display: flex; flex-direction: column; gap: 10px; }
.plan-row { display: flex; align-items: center; gap: 10px; }
.plan-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.plan-input {
  flex: 1; background: none; border: none; border-bottom: 1px solid var(--border-light);
  padding: 4px 0; font-family: inherit; font-size: 14px; color: var(--text); outline: none;
}
.plan-input::placeholder { color: var(--text-muted); }
.plan-input:focus { border-bottom-color: var(--accent); }
#add-plan-btn { background: none; border: none; cursor: pointer; font-size: 13px; color: var(--accent); font-family: inherit; padding: 4px 0; text-align: left; }
#day-reply {
  font-size: 14px; line-height: 1.7; color: var(--text-mid);
  background: var(--bg); border-radius: 12px; padding: 12px 14px;
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--garamond); font-style: italic; font-size: 15px;
  min-height: 52px; display: flex; align-items: center;
}
#day-reply.empty { color: var(--text-muted); font-style: normal; font-family: inherit; font-size: 13px; }
#day-footer { padding: 14px 18px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); flex-shrink: 0; }
#day-save {
  width: 100%; padding: 14px; border-radius: 14px;
  background: var(--accent); color: white; border: none;
  font-size: 15px; font-family: inherit; cursor: pointer;
}
#day-save:active { opacity: 0.8; }

/* ══════════ HISTORY / SESSION ══════════ */
#sessions-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.session-item { padding: 14px 18px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; align-items: center; gap: 10px; }
.session-item:active { background: var(--surface); }
.session-item-body { flex: 1; min-width: 0; }
.session-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.session-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.session-title { font-size: 14px; color: var(--text); }
.session-title-input { font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px; width: 100%; font-family: inherit; outline: none; }
.session-edit-btn { background: none; border: none; cursor: pointer; font-size: 14px; color: var(--text-muted); padding: 4px 6px; flex-shrink: 0; line-height: 1; }
.session-del-btn {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  font-size: 18px; color: var(--text-muted); padding: 4px 6px; line-height: 1;
  border-radius: 6px; opacity: 0.5;
}
.session-del-btn:active { background: var(--border); opacity: 1; }
#panel-session { z-index: 200; }
#viewer-messages {
  flex: 1; overflow-y: auto; padding: 18px 14px;
  display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch;
}
.panel-empty { padding: 60px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ══════════ MEMORY PANEL ══════════ */
#memory-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 16px; background: var(--bg); flex-shrink: 0; }
.mem-tab { background: none; border: none; cursor: pointer; font-family: inherit; font-size: 13px; color: var(--text-muted); padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.15s, border-color 0.15s; }
.mem-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#memory-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.mem-section { padding: 20px 18px; }
.mem-text { font-size: 13px; line-height: 1.75; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.store-entry { border-bottom: 1px solid var(--border); padding: 14px 0; }
.store-entry:last-child { border-bottom: none; }
.store-meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.store-tags { font-size: 11px; color: var(--accent); letter-spacing: .04em; }
.store-date { font-size: 11px; color: var(--text-muted); }
.store-text { font-size: 13px; line-height: 1.7; color: var(--text); white-space: pre-wrap; word-break: break-word; }

/* ══════════ ARTIFACT PREVIEW ══════════ */
.artifact-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 12px; cursor: pointer;
  font-size: 13px; color: var(--text-mid); font-family: inherit;
  margin-top: 6px; transition: border-color 0.15s, color 0.15s;
}
.artifact-btn:active { border-color: var(--accent); color: var(--accent); }
#artifact-panel {
  position: fixed; inset: 0; z-index: 250;
  background: #111; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(.32,.72,0,1);
}
#artifact-panel.open { transform: translateY(0); }
#artifact-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: #1e1e1e; border-bottom: 1px solid #333; flex-shrink: 0;
}
#artifact-title { font-size: 13px; color: #aaa; letter-spacing: .04em; }
#artifact-close { background: none; border: none; cursor: pointer; font-size: 20px; color: #888; padding: 2px 8px; line-height: 1; }
#artifact-iframe { flex: 1; border: none; background: white; width: 100%; }

/* ══════════ READING ══════════ */
#page-reading { background: var(--bg); }
#reading-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#reading-back { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; }
#reading-header-title { font-family: var(--serif); font-size: 18px; font-weight: 300; color: var(--text); flex: 1; }
#reading-header-actions { display: flex; gap: 8px; }
.icon-btn { background: none; border: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.icon-btn:active { background: var(--border); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#reading-body { flex: 1; overflow-y: auto; padding: 20px 16px 40px; -webkit-overflow-scrolling: touch; }
#reading-stats { display: flex; gap: 24px; padding: 12px 0 20px; justify-content: center; }
.reading-stat { text-align: center; }
.reading-stat-num { font-family: var(--serif); font-size: 22px; font-weight: 300; color: var(--text); }
.reading-stat-label { font-size: 10px; color: var(--text-muted); letter-spacing: .08em; text-transform: uppercase; margin-top: 2px; }
#reading-upload-row { display: flex; justify-content: flex-end; margin-bottom: 14px; }
#reading-upload-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent); color: white; border: none; border-radius: 20px;
  padding: 8px 16px; font-size: 13px; cursor: pointer; font-family: inherit;
}
#reading-upload-btn:active { opacity: 0.8; }
#book-grid { display: flex; flex-direction: column; gap: 10px; }
.book-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 16px 16px 20px; cursor: pointer; -webkit-user-select: none;
  border-left: 4px solid var(--accent); transition: transform 0.15s, box-shadow 0.15s;
}
.book-card:active { transform: scale(0.98); box-shadow: 0 1px 6px rgba(0,0,0,0.06); }
.book-card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.book-title { font-family: var(--serif); font-size: 18px; font-weight: 300; color: var(--text); }
.book-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.book-progress-bar { height: 3px; background: var(--border); border-radius: 2px; margin-top: 12px; }
.book-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }
.book-card-del { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; padding: 2px 6px; opacity: 0.5; flex-shrink: 0; }
.book-card-del:active { opacity: 1; color: #C45555; }

/* Reader panel */
#panel-reader { z-index: 150; display: flex; flex-direction: column; }
#reader-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#reader-back { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; }
#reader-title { font-family: var(--serif); font-size: 16px; font-weight: 300; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#reader-progress-label { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
#reader-notebook-btn { flex-shrink: 0; }
#reader-layout { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
#reader-text-area {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px 22px 80px;
  -webkit-overflow-scrolling: touch; scroll-behavior: smooth;
}
#reader-content {
  font-size: 17px; line-height: 2; color: var(--text); font-family: var(--garamond);
}
#reader-seek-bar {
  position: absolute; bottom: 22px; left: 22px; right: 22px;
  height: 24px; display: flex; align-items: center; z-index: 5;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
#reader-seek-bar.visible {
  opacity: 1; pointer-events: auto;
}
#reader-seek-track {
  width: 100%; height: 3px; background: var(--border); border-radius: 2px; position: relative;
}
#reader-seek-fill {
  height: 100%; background: var(--accent); border-radius: 2px; width: 0%; transition: width 0.1s;
}
#reader-seek-thumb {
  position: absolute; top: 50%; width: 16px; height: 16px;
  background: var(--accent); border: 2px solid white; border-radius: 50%;
  transform: translate(-50%, -50%); left: 0%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
#reader-page-indicator {
  position: absolute; bottom: 6px; left: 0; right: 0;
  text-align: center; font-size: 11px; color: var(--text-muted);
  letter-spacing: .06em; cursor: pointer; z-index: 5;
}
.reader-para {
  padding: 4px 8px; margin: 0 -8px 6px; border-radius: 8px;
  cursor: pointer; transition: background 0.2s, border-color 0.2s;
  border: 1px solid transparent; text-indent: 2em;
  break-inside: avoid;
}
.reader-para.highlighted { background: var(--accent-light); border-color: var(--accent); }
.reader-para.has-discussion {
  border-left: 3px solid var(--accent); padding-left: 10px;
}
#reader-action-bar {
  position: absolute; bottom: 56px; left: 16px; right: 16px;
  display: flex; gap: 8px; padding: 10px 14px;
  background: rgba(245,239,230,0.95); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 10;
}
#reader-action-bar.visible {
  transform: translateY(0); opacity: 1; pointer-events: auto;
}
.para-action-btn {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer; font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.para-action-btn:active { background: var(--accent); color: white; border-color: var(--accent); }

/* Discuss panel */
#discuss-panel {
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: height 0.28s cubic-bezier(.32,.72,0,1);
  height: 0; overflow: hidden; flex-shrink: 0;
}
#discuss-panel.open { height: 55vh; }
#discuss-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#discuss-quote {
  font-size: 12px; color: var(--accent); font-style: italic;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#discuss-bookmark-btn { background: none; border: none; cursor: pointer; font-size: 16px; padding: 2px 4px; }
#discuss-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 20px; padding: 0 4px; line-height: 1; }
#discuss-messages {
  flex: 1; overflow-y: auto; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
#discuss-messages:empty::after {
  content: '聊聊这段话……';
  color: var(--text-muted); font-size: 13px; font-style: italic;
  align-self: center; margin-top: 40px; opacity: 0.5;
}
.discuss-bubble-user {
  align-self: flex-end; background: var(--accent); color: white;
  border-radius: 16px 16px 4px 16px; padding: 8px 12px;
  font-size: 14px; line-height: 1.55; max-width: 85%;
}
.discuss-bubble-ai {
  align-self: flex-start; background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px; padding: 8px 12px;
  font-size: 14px; line-height: 1.6; max-width: 90%; white-space: pre-wrap; word-break: break-word;
}
.discuss-thinking {
  align-self: flex-start; font-size: 12px; color: var(--text-muted);
  font-style: italic; padding: 2px 4px; max-width: 90%;
}
#discuss-input-row {
  display: flex; gap: 8px; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); flex-shrink: 0;
}
#discuss-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 8px 14px; font-size: 14px; color: var(--text); font-family: inherit;
  resize: none; outline: none; height: 36px; max-height: 90px;
}
#discuss-send {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#discuss-send:disabled { opacity: 0.4; }
#discuss-send svg { width: 14px; height: 14px; stroke: white; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Notebook panel */
#panel-notebook { z-index: 160; }
#notebook-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#notebook-back { background: none; border: none; cursor: pointer; font-size: 24px; color: var(--text-muted); padding: 0 4px; line-height: 1; }
#notebook-body { flex: 1; overflow-y: auto; padding: 14px 16px 40px; -webkit-overflow-scrolling: touch; }
.nb-entry {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.nb-entry-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.nb-type-tag {
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  background: var(--accent-light); color: var(--accent); border-radius: 6px; padding: 2px 7px;
}
.nb-book-name { font-size: 11px; color: var(--text-muted); }
.nb-date { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.nb-text {
  font-size: 15px; line-height: 1.8; color: var(--text); font-family: var(--garamond); font-style: italic;
  position: relative; padding-left: 16px;
}
.nb-text::before {
  content: '\201C'; position: absolute; left: -2px; top: -4px;
  font-size: 32px; color: var(--accent); opacity: 0.3; font-family: var(--serif); line-height: 1;
}
.nb-note { font-size: 12.5px; color: var(--text-mid); margin-top: 6px; font-style: normal; font-family: inherit; }
.nb-discussion-trail { margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--accent-light); }
.nb-discuss-reply { font-size: 12.5px; color: var(--text-mid); line-height: 1.6; margin-bottom: 6px; font-style: italic; }
.nb-del { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 14px; float: right; padding: 2px 4px; opacity: 0.5; }
.nb-del:active { opacity: 1; color: #C45555; }

/* ══════════ CONFIRM MODALS ══════════ */
.confirm-modal {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.28); align-items: flex-end; justify-content: center;
}
.confirm-modal.open { display: flex; }
.modal-sheet {
  background: var(--surface); border-radius: 22px 22px 0 0;
  width: 100%; max-width: 480px;
  padding: 26px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.modal-title { font-size: 15px; color: var(--text); text-align: center; margin-bottom: 2px; font-weight: 500; }
.modal-desc { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 4px; }
.modal-btn { width: 100%; padding: 13px; border-radius: 12px; font-size: 15px; cursor: pointer; font-family: inherit; border: none; }
.modal-btn.primary { background: var(--accent); color: white; font-weight: 500; }
.modal-btn.danger { background: #C45555; color: white; font-weight: 500; }
.modal-btn.ghost { background: none; color: var(--text-muted); font-size: 14px; }
