/* v94 */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a25;
  --bg-card-hover: #22222f;
  --border-subtle: rgba(255, 191, 105, 0.08);
  --border-gold: rgba(212, 160, 83, 0.2);
  --gold-primary: #d4a053;
  --gold-light: #f0c878;
  --gold-glow: rgba(212, 160, 83, 0.3);
  --gold-dim: rgba(212, 160, 83, 0.12);
  --text-primary: #e8e4dc;
  --text-secondary: #9a9590;
  --text-muted: #5a5550;
  --amber: #c8956c;
  --green-check: #6ecf8e;
  --red-urgent: #e07070;
  --safe-top: 38px;
  --safe-bottom: 20px;
  --border: rgba(255, 191, 105, 0.08);
  --accent: #d4a053;
}

html { height: 100%; background: var(--bg-primary); }
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, 'SF Pro Display', 'PingFang SC', sans-serif;
  background: var(--bg-primary); color: var(--text-primary);
  overflow: hidden; height: 100%;
  user-select: none; -webkit-user-select: none;
}

.app { display: flex; flex-direction: column; position: fixed; top: 0; left: 0; right: 0; height: 100vh; }
.safe-area-top { height: var(--safe-top); background: var(--bg-primary); flex-shrink: 0; }
.safe-area-bottom { height: var(--safe-bottom); background: var(--bg-primary); flex-shrink: 0; }

.page { flex: 1; display: none; overflow: hidden; position: relative; }
.page.active { display: flex; flex-direction: column; }

.scroll-container { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px 20px 20px; }

/* ===== Hero ===== */
.hero { text-align: center; padding: 28px 0 16px; animation: fadeInUp 0.8s ease-out; }
.hero-title { font-size: 12px; letter-spacing: 6px; color: var(--gold-primary); margin-bottom: 20px; font-weight: 500; }
.hero-couple { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 16px; }
.hero-name { font-size: 15px; color: var(--text-secondary); letter-spacing: 1px; font-weight: 300; }
.hero-heart { font-size: 16px; color: #e88a9a; animation: heartbeat 2s ease-in-out infinite; }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
.hero-days { margin: 8px 0; }
.days-number {
  font-size: 80px; font-weight: 200; letter-spacing: -3px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-primary), var(--amber));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1; animation: countUp 1s ease-out 0.3s both;
}
.hero-since { font-size: 11px; letter-spacing: 3px; color: var(--text-muted); font-weight: 300; }

/* ===== 卡片 ===== */
.card {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 20px 22px; position: relative;
  overflow: hidden; margin-bottom: 16px; animation: fadeInUp 0.8s ease-out 0.15s both;
}
.card-glow {
  position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(ellipse at 30% 20%, var(--gold-dim), transparent 60%);
  pointer-events: none; opacity: 0.6;
}
.card-label { font-size: 12px; letter-spacing: 1px; color: var(--gold-primary); margin-bottom: 14px; position: relative; font-weight: 500; }
.card-content { font-size: 15px; line-height: 1.8; color: var(--text-primary); position: relative; font-weight: 300; }
.card-signature { font-size: 12px; color: var(--text-muted); text-align: right; margin-top: 14px; position: relative; font-style: italic; }

/* ===== 待办 ===== */
.todo-card { animation: fadeInUp 0.8s ease-out 0.25s both; }
.todo-list { display: flex; flex-direction: column; gap: 4px; }
.todo-empty { font-size: 13px; color: var(--text-muted); font-weight: 300; padding: 8px 0; text-align: center; }
.todo-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.03); }
.todo-item:last-child { border-bottom: none; }
.todo-check {
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-gold);
  cursor: pointer; transition: all 0.3s ease; flex-shrink: 0; position: relative;
}
.todo-check.done { background: var(--green-check); border-color: var(--green-check); }
.todo-check.done::after {
  content: '✓'; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); font-size: 12px; color: var(--bg-primary); font-weight: 700;
}
.todo-text { flex: 1; font-size: 14px; color: var(--text-secondary); font-weight: 300; }
.todo-item.checked .todo-text { text-decoration: line-through; color: var(--text-muted); }
.todo-badge { font-size: 10px; padding: 2px 8px; border-radius: 10px; font-weight: 500; flex-shrink: 0; letter-spacing: 0.5px; }
.todo-badge.daily { background: rgba(110,207,142,0.12); color: var(--green-check); }
.todo-badge.deadline { background: rgba(212,160,83,0.12); color: var(--gold-primary); }
.todo-badge.urgent { background: rgba(224,112,112,0.12); color: var(--red-urgent); }

/* ===== 首页快捷入口 ===== */
.shortcuts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 16px; animation: fadeInUp 0.8s ease-out 0.35s both;
}
.shortcut-btn {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 14px; cursor: pointer; transition: all 0.2s ease;
}
.shortcut-btn:active { transform: scale(0.97); background: var(--bg-card-hover); border-color: var(--border-gold); }
.shortcut-icon { font-size: 22px; }
.shortcut-title { font-size: 13px; color: var(--text-primary); font-weight: 400; margin-bottom: 2px; }
.shortcut-desc { font-size: 10px; color: var(--text-muted); letter-spacing: 0.5px; }

/* ===== Chat 页 ===== */
.page-chat { background: var(--bg-primary); }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0; }
.chat-menu-btn, .chat-new-btn { font-size: 20px; color: var(--text-secondary); cursor: pointer; padding: 4px 8px; }
.chat-menu-btn:active, .chat-new-btn:active { color: var(--gold-primary); }
.chat-title { font-size: 15px; color: var(--text-primary); font-weight: 400; letter-spacing: 1px; }
.chat-sidebar {
  position: absolute; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--bg-secondary); border-right: 1px solid var(--border-subtle);
  z-index: 100; transform: translateX(-100%); transition: transform 0.3s ease;
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.chat-sidebar.open { transform: translateX(0); }
.chat-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.chat-overlay.show { opacity: 1; pointer-events: auto; }
.sidebar-header { padding: 20px 20px 16px; font-size: 13px; color: var(--gold-primary); letter-spacing: 1px; font-weight: 500; border-bottom: 1px solid var(--border-subtle); }
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-item { display: flex; align-items: center; gap: 12px; padding: 14px 20px; cursor: pointer; }
.sidebar-item:active, .sidebar-item.active { background: var(--gold-dim); }
.sidebar-item-icon { font-size: 18px; }
.sidebar-item-name { font-size: 14px; color: var(--text-primary); font-weight: 300; }
.sidebar-add { padding: 16px 20px; border-top: 1px solid var(--border-subtle); font-size: 13px; color: var(--text-muted); cursor: pointer; }
.sidebar-add:active { color: var(--gold-primary); }
.chat-messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px; }
.chat-placeholder { text-align: center; color: var(--text-muted); font-size: 14px; margin-top: 40%; font-weight: 300; }
.chat-input-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border-subtle); background: var(--bg-secondary); flex-shrink: 0; }
.chat-input { flex: 1; background: #1a1a25; border: 1px solid var(--border-subtle); border-radius: 20px; padding: 10px 16px; font-size: 14px; color: var(--text-primary); outline: none; font-family: inherit; }
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--border-gold); }
.chat-send { width: 36px; height: 36px; border-radius: 50%; background: var(--gold-primary); border: none; color: var(--bg-primary); font-size: 18px; font-weight: 700; cursor: pointer; flex-shrink: 0; }
.chat-send:active { opacity: 0.7; }

/* ===== LIFE 页 - 功能网格 ===== */
.page-life { position: relative; }

.life-header { text-align: center; padding: 20px 0 8px; }
.life-title { font-size: 12px; letter-spacing: 6px; color: var(--gold-primary); font-weight: 500; }

.life-main { display: block; }
.life-main.hidden { display: none !important; }

.life-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  animation: fadeInUp 0.6s ease-out;
}

.life-card {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 28px 16px 22px; text-align: center;
  cursor: pointer; transition: all 0.2s ease;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}

.life-card:active { transform: scale(0.96); background: var(--bg-card-hover); border-color: var(--border-gold); }

.life-card-icon { font-size: 36px; margin-bottom: 4px; }
.life-card-title { font-size: 14px; color: var(--text-primary); font-weight: 400; letter-spacing: 0.5px; }
.life-card-desc { font-size: 11px; color: var(--text-muted); font-weight: 300; }

/* ===== LIFE 子页面 ===== */
.life-subpage {
  position: absolute; inset: 0; z-index: 10;
  background: var(--bg-primary);
  display: none; flex-direction: column;
}

.life-subpage.open {
  display: flex;
  animation: slideInRight 0.25s ease-out;
}

@keyframes slideInRight {
  from { transform: translateX(30%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.sub-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sub-back {
  font-size: 26px; color: var(--gold-primary); cursor: pointer;
  padding: 0 8px; line-height: 1; font-weight: 300;
}
.sub-back:active { opacity: 0.6; }

.sub-title { font-size: 15px; color: var(--text-primary); font-weight: 400; letter-spacing: 1px; }
.sub-spacer { width: 36px; }

.page-placeholder-inner {
  text-align: center; color: var(--text-muted); font-size: 14px;
  padding-top: 40%; font-weight: 300;
}

/* ===== 月历 ===== */
.calendar-container {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 20px; margin-bottom: 16px;
}
.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.cal-nav-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--gold-primary); cursor: pointer; border-radius: 50%;
}
.cal-nav-btn:active { background: var(--gold-dim); }
.cal-month-label { font-size: 16px; font-weight: 400; color: var(--text-primary); letter-spacing: 2px; }
.calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; margin-bottom: 8px; }
.calendar-weekdays span { font-size: 11px; color: var(--text-muted); font-weight: 400; padding: 4px 0; letter-spacing: 1px; }
.calendar-weekdays .weekend { color: var(--amber); opacity: 0.6; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; cursor: pointer; position: relative; transition: all 0.2s ease;
  font-size: 14px; color: var(--text-secondary); font-weight: 300;
}
.cal-day:active { background: var(--gold-dim); }
.cal-day.other-month { color: var(--text-muted); opacity: 0.3; }
.cal-day.weekend { color: var(--amber); opacity: 0.7; }
.cal-day.today { background: var(--gold-dim); color: var(--gold-light); font-weight: 500; border: 1px solid var(--border-gold); }
.cal-day.selected { background: var(--gold-primary); color: var(--bg-primary); font-weight: 600; }
.cal-day.selected .cal-day-dot { background: var(--bg-primary); }
.cal-day-dot { width: 4px; height: 4px; border-radius: 50%; position: absolute; bottom: 4px; }
.cal-day-dot.milestone { background: #e88a9a; }
.cal-day-dot.event { background: var(--gold-primary); }
.cal-day-dots { position: absolute; bottom: 4px; display: flex; gap: 3px; }
.cal-day.holiday { color: #e88a9a; opacity: 0.85; }

/* ===== 事件列表 ===== */
.event-list { display: flex; flex-direction: column; gap: 6px; }
.event-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 13px; color: var(--text-secondary); font-weight: 300; }
.event-item:last-child { border-bottom: none; }
.event-item-emoji { font-size: 16px; flex-shrink: 0; }
.event-item-date { font-size: 11px; color: var(--text-muted); margin-left: auto; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ===== 占位 ===== */
.page-placeholder { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 15px; font-weight: 300; }

/* ===== 底部导航 ===== */
.tab-bar {
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 16px; cursor: pointer; }
.tab-icon { font-size: 20px; opacity: 0.5; transition: opacity 0.2s; }
.tab-label { font-size: 9px; letter-spacing: 1.5px; color: var(--text-muted); transition: color 0.2s; }
.tab.active .tab-icon { opacity: 1; }
.tab.active .tab-label { color: var(--gold-primary); }

@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes countUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Kyle 日记 ===== */
.diary-list { display: flex; flex-direction: column; gap: 16px; }

.diary-entry {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; overflow: hidden; cursor: pointer;
  transition: all 0.3s ease;
}

.diary-entry:active { transform: scale(0.98); }
.diary-entry.expanded { cursor: default; }
.diary-entry.expanded:active { transform: none; }

.diary-entry-header {
  padding: 20px 22px; display: flex; align-items: center; justify-content: space-between;
}

.diary-header-left { display: flex; flex-direction: column; gap: 4px; }

.diary-date {
  font-size: 12px; color: var(--gold-primary); letter-spacing: 1px; font-weight: 500;
}

.diary-title {
  font-size: 16px; color: var(--text-primary); font-weight: 400;
}

.diary-preview {
  font-size: 13px; color: var(--text-muted); font-weight: 300;
  margin-top: 4px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.diary-entry.expanded .diary-preview { display: none; }

.diary-arrow {
  font-size: 14px; color: var(--text-muted); transition: transform 0.3s ease;
  flex-shrink: 0; margin-left: 12px;
}

.diary-entry.expanded .diary-arrow { transform: rotate(90deg); }

.diary-body {
  max-height: 0; overflow: hidden; transition: max-height 0.4s ease;
}

.diary-entry.expanded .diary-body { max-height: 3000px; }

.diary-content {
  padding: 0 22px 24px; font-size: 14px; line-height: 2;
  color: var(--text-secondary); font-weight: 300;
  white-space: pre-wrap; word-break: break-word;
  border-top: 1px solid var(--border-subtle); margin-top: 0; padding-top: 20px;
}

.diary-signature {
  text-align: right; font-size: 12px; color: var(--text-muted);
  font-style: italic; margin-top: 16px; padding-right: 4px;
}

.diary-empty {
  text-align: center; color: var(--text-muted); font-size: 14px;
  padding: 60px 0; font-weight: 300;
}

/* ===== 记忆书签 ===== */
.bm-add-btn {
  text-align: center; padding: 14px; margin-bottom: 16px;
  border: 1px dashed var(--gold-primary); border-radius: 12px;
  color: var(--gold-primary); font-size: 14px; cursor: pointer;
  transition: all 0.2s;
}
.bm-add-btn:active { background: rgba(212,175,55,0.1); }

.bm-add-form {
  background: #1a1a25; border: 1px solid var(--gold-primary);
  border-radius: 16px; padding: 18px; margin-bottom: 16px;
}
.bm-input, .bm-textarea {
  width: 100%; box-sizing: border-box; background: var(--bg-main);
  border: 1px solid var(--border-subtle); border-radius: 10px;
  color: var(--text-primary); font-size: 14px; padding: 10px 14px;
  font-family: inherit; margin-bottom: 10px; outline: none;
}
.bm-input::-webkit-calendar-picker-indicator { filter: invert(0.8); }
.bm-textarea { resize: none; line-height: 1.6; }
.bm-textarea:focus, .bm-input:focus { border-color: var(--gold-primary); }
.bm-form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.bm-btn {
  padding: 8px 20px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.bm-btn-cancel { color: var(--text-muted); }
.bm-btn-submit {
  background: var(--gold-primary); color: var(--bg-main); font-weight: 500;
}

.bm-list { display: flex; flex-direction: column; gap: 14px; }

.bm-card {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; overflow: hidden; transition: all 0.3s;
}

.bm-card-header { padding: 18px 20px; cursor: pointer; }
.bm-card-header:active { opacity: 0.8; }

.bm-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bm-date { font-size: 12px; color: var(--gold-primary); letter-spacing: 0.5px; }
.bm-author {
  font-size: 11px; color: var(--text-muted); background: rgba(255,255,255,0.05);
  padding: 2px 8px; border-radius: 4px;
}
.bm-text {
  font-size: 14px; color: var(--text-secondary); line-height: 1.8; font-weight: 300;
}

.bm-comments-area {
  max-height: 0; overflow: hidden; transition: max-height 0.4s ease;
}
.bm-card.expanded .bm-comments-area { max-height: 2000px; }

.bm-comments-inner {
  padding: 0 20px 18px; border-top: 1px solid var(--border-subtle);
}

.bm-comment {
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.bm-comment:last-of-type { border-bottom: none; }
.bm-comment-author {
  font-size: 13px; font-weight: 400; margin-bottom: 2px;
}
.bm-comment-author.lina { color: #e8a0bf; }
.bm-comment-author.kebao { color: var(--gold-primary); }
.bm-comment-content {
  font-size: 13px; color: var(--text-secondary); font-weight: 300; line-height: 1.6;
}
.bm-comment-time {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}

.bm-comment-input-row {
  display: flex; gap: 8px; margin-top: 12px; align-items: flex-end;
}
.bm-comment-input {
  flex: 1; background: var(--bg-main); border: 1px solid var(--border-subtle);
  border-radius: 10px; color: var(--text-primary); font-size: 13px;
  padding: 10px 14px; font-family: inherit; outline: none; resize: none;
  min-height: 20px; max-height: 80px; line-height: 1.4;
}
.bm-comment-input:focus { border-color: var(--gold-primary); }
.bm-comment-send {
  background: var(--gold-primary); color: var(--bg-main);
  border: none; border-radius: 10px; padding: 10px 16px;
  font-size: 13px; cursor: pointer; font-weight: 500; white-space: nowrap;
  flex-shrink: 0;
}
.bm-comment-send:active { opacity: 0.8; }

.bm-no-comments {
  font-size: 12px; color: var(--text-muted); padding: 8px 0;
  font-style: italic;
}

.bm-empty {
  text-align: center; color: var(--text-muted); font-size: 14px;
  padding: 60px 0; font-weight: 300;
}

/* ===== 记忆统计 ===== */
.stats-hero {
  text-align: center; padding: 40px 20px 30px;
}
.stats-number {
  font-size: 72px; font-weight: 200; color: var(--gold-primary);
  line-height: 1; letter-spacing: -2px;
  font-family: 'Georgia', serif;
}
.stats-label {
  font-size: 14px; color: var(--text-secondary); margin-top: 8px;
  font-weight: 300; letter-spacing: 2px;
}
.stats-sub {
  font-size: 12px; color: var(--text-muted); margin-top: 6px;
  font-weight: 300;
}

/* 亲密档案入口 */
.intimacy-enter {
  display: flex; align-items: center; gap: 16px;
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 20px; margin: 0 0 20px; cursor: pointer;
  transition: all 0.2s;
}
.intimacy-enter:active { opacity: 0.8; transform: scale(0.98); }
.intimacy-enter-icon { font-size: 28px; }
.intimacy-enter-text { flex: 1; }
.intimacy-enter-title {
  font-size: 16px; color: var(--text-primary); font-weight: 400;
}
.intimacy-enter-desc {
  font-size: 12px; color: var(--text-muted); margin-top: 2px; font-weight: 300;
}
.intimacy-enter-arrow {
  font-size: 20px; color: var(--text-muted);
}

/* 亲密档案面板 */
.intimacy-panel { margin-top: 10px; }

.intimacy-progress-bar {
  height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px;
  overflow: hidden; margin-bottom: 8px;
}
.intimacy-progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--gold-primary), #f0c674);
  border-radius: 2px; transition: width 0.6s ease;
}
.intimacy-progress-text {
  text-align: center; font-size: 12px; color: var(--text-muted);
  margin-bottom: 24px; font-weight: 300;
}

.intimacy-section-label {
  font-size: 13px; color: var(--gold-primary); font-weight: 400;
  margin-bottom: 14px; letter-spacing: 1px;
}
.intimacy-section-label.locked-label {
  margin-top: 28px; color: var(--text-muted);
}

.intimacy-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}

/* 已解锁卡片 */
.int-card {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 14px; padding: 16px 10px; text-align: center;
  transition: all 0.2s; cursor: pointer; position: relative; overflow: hidden;
}
.int-card.unlocked {
  border-color: rgba(212,175,55,0.2);
}
.int-card.unlocked::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-primary), transparent);
}
.int-card:active { transform: scale(0.96); }
.int-card-emoji { font-size: 24px; margin-bottom: 6px; }
.int-card-name {
  font-size: 12px; color: var(--text-primary); font-weight: 400;
  line-height: 1.3;
}
.int-card-date {
  font-size: 10px; color: var(--gold-primary); margin-top: 4px;
  font-weight: 300;
}

/* 待解锁卡片 */
.int-card.locked {
  opacity: 0.45; border-style: dashed;
}
.int-card.locked .int-card-emoji { filter: grayscale(1); }
.int-card.locked .int-card-name { color: var(--text-muted); }

/* 详情弹窗 */
.int-modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.int-modal-overlay.show { opacity: 1; pointer-events: auto; }

.int-modal {
  background: #1a1a25; border: 1px solid var(--gold-primary);
  border-radius: 20px; padding: 32px 28px; max-width: 280px; width: 85%;
  text-align: center; transform: scale(0.9); transition: transform 0.25s;
}
.int-modal-overlay.show .int-modal { transform: scale(1); }

.int-modal-emoji { font-size: 40px; margin-bottom: 12px; }
.int-modal-name {
  font-size: 18px; color: var(--text-primary); font-weight: 400;
  margin-bottom: 6px;
}
.int-modal-date {
  font-size: 13px; color: var(--gold-primary); margin-bottom: 12px;
  font-weight: 300;
}
.int-modal-note {
  font-size: 14px; color: var(--text-secondary); font-weight: 300;
  line-height: 1.7; font-style: italic;
}
.int-modal-hint {
  font-size: 13px; color: var(--text-muted); font-weight: 300;
  line-height: 1.6; font-style: italic;
}
.int-modal-close {
  margin-top: 20px; font-size: 13px; color: var(--text-muted);
  cursor: pointer;
}

/* ===== 亲密档案分区 ===== */
.int-section {
  margin-bottom: 28px;
}
.int-section-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.int-section-emoji { font-size: 18px; }
.int-section-label {
  font-size: 15px; color: var(--gold-primary); font-weight: 400;
  letter-spacing: 1px; flex: 1;
}
.int-section-count {
  font-size: 12px; color: var(--text-muted); font-weight: 300;
}

/* ===== 设置页 ===== */
.page-settings {
  position: relative; overflow: hidden;
}
.page-settings > .scroll-container {
  padding: 0 20px;
}

.set-header {
  padding: 20px 0 24px;
}
.set-title {
  font-size: 28px; font-weight: 300; color: var(--text-primary);
  letter-spacing: 2px;
}
.set-subtitle {
  font-size: 12px; color: var(--text-muted); font-weight: 300;
  margin-top: 4px; letter-spacing: 1px;
}

.set-group-label {
  font-size: 13px; color: var(--text-muted); font-weight: 300;
  padding: 20px 0 8px; letter-spacing: 1px;
}
.set-group {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 16px; overflow: hidden;
}

.set-row {
  display: flex; align-items: center; padding: 16px 18px;
  cursor: pointer; transition: background 0.15s;
}
.set-row:active { background: rgba(255,255,255,0.03); }
.set-row-label {
  flex: 1; font-size: 15px; color: var(--text-primary); font-weight: 400;
}
.set-row-value {
  font-size: 13px; color: var(--text-muted); font-weight: 300;
  margin-right: 6px;
}
.set-row-arrow {
  font-size: 16px; color: var(--text-muted); opacity: 0.5;
}

.set-divider {
  height: 1px; background: var(--border-subtle); margin: 0 18px;
}

/* 设置子面板 */
.set-panel {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-primary); z-index: 30;
  transform: translateX(100%); transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
.set-panel.active { transform: translateX(0); display: flex; flex-direction: column; }

.set-panel-header {
  display: flex; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.set-panel-back {
  font-size: 24px; color: var(--gold-primary); cursor: pointer;
  padding: 0 8px 0 0; line-height: 1;
}
.set-panel-title {
  flex: 1; font-size: 16px; color: var(--text-primary);
  font-weight: 400; letter-spacing: 1px;
}
.set-panel-spacer { width: 24px; }

.set-panel > .scroll-container {
  padding: 20px; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
}

.set-panel-placeholder {
  text-align: center; color: var(--text-muted); font-size: 14px;
  font-weight: 300; padding: 40px 20px; line-height: 1.8;
}
.set-panel-hint {
  text-align: center; color: var(--text-muted); font-size: 13px;
  font-weight: 300; line-height: 1.8; padding: 16px 0;
}

/* 头像预览 */
.set-avatar-preview {
  text-align: center; padding: 20px 0;
}
.set-avatar-preview img {
  width: 120px; height: 120px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--gold-primary);
}
.avatar-upload-btn {
  display: block; margin: 12px auto; padding: 10px 28px;
  background: transparent; color: var(--gold-primary);
  border: 1px solid var(--gold-primary); border-radius: 20px;
  font-size: 14px; cursor: pointer; transition: all 0.3s;
}
.avatar-upload-btn:active {
  background: var(--gold-primary); color: var(--bg-primary);
}
.avatar-upload-btn.uploading {
  opacity: 0.5; pointer-events: none;
}


/* 工具列表 */
.set-tool-list { }
.set-tool-item {
  display: flex; align-items: center; padding: 14px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.set-tool-item:last-child { border-bottom: none; }
.set-tool-info { flex: 1; }
.set-tool-name {
  font-size: 14px; color: var(--text-primary); font-weight: 400;
}
.set-tool-desc {
  font-size: 12px; color: var(--text-muted); font-weight: 300; margin-top: 2px;
}
.set-tool-time {
  font-size: 12px; color: var(--gold-primary); font-weight: 300; margin-top: 2px;
}

/* 状态标签 */
.set-badge {
  font-size: 11px; padding: 3px 10px; border-radius: 10px;
  font-weight: 300;
}
.set-badge.on {
  background: rgba(212,175,55,0.15); color: var(--gold-primary);
}
.set-badge.off {
  background: rgba(255,255,255,0.06); color: var(--text-muted);
}

/* ===== MCP 服务器卡片 ===== */
.mcp-server-card {
  background: #1a1a25; border: 1px solid var(--border-subtle);
  border-radius: 14px; margin-bottom: 12px; overflow: hidden;
}
.mcp-server-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer; transition: background 0.15s;
}
.mcp-server-header:active { background: rgba(255,255,255,0.03); }
.mcp-server-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.mcp-server-dot.on { background: #4ade80; box-shadow: 0 0 6px rgba(74,222,128,0.4); }
.mcp-server-dot.off { background: #888; }
.mcp-server-info { flex: 1; }
.mcp-server-name {
  font-size: 14px; color: var(--text-primary); font-weight: 400;
}
.mcp-server-meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.mcp-tag {
  font-size: 10px; color: var(--text-muted); background: rgba(255,255,255,0.06);
  padding: 2px 8px; border-radius: 6px; font-weight: 300;
}
.mcp-server-chevron {
  font-size: 16px; color: var(--text-muted); transition: transform 0.2s;
}

.mcp-server-tools {
  max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
  border-top: 0 solid var(--border-subtle);
  padding: 0 16px;
}
.mcp-server-tools.open {
  max-height: 500px; border-top-width: 1px; padding: 8px 16px 12px;
}

/* ===== Toggle 开关 ===== */
.toggle-switch {
  position: relative; display: inline-block; width: 44px; height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.12); border-radius: 12px;
  transition: 0.25s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
  transition: 0.25s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--gold-primary);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ===== IMPRINT Styles ===== */
.imprint-module {
  /* fallback */
  background: #1a1a25; border-radius: 16px; margin-bottom: 16px;
  overflow: hidden; border: 1px solid rgba(255, 191, 105, 0.08);
}
.imprint-module-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; cursor: pointer; transition: background 0.2s;
}
.imprint-module-header:active { background: rgba(255,255,255,0.03); }
.imprint-module-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.imprint-module-icon { font-size: 20px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.05); border-radius: 10px; flex-shrink: 0; }
.imprint-module-text { min-width: 0; }
.imprint-module-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.imprint-module-name span { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 6px; }
.imprint-module-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.imprint-module-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.imprint-token-badge { font-size: 11px; color: var(--text-secondary); background: rgba(255,255,255,0.05); padding: 3px 8px; border-radius: 8px; }
.imprint-module-body { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; }
.imprint-module-body.open { max-height: 2000px; }
.imprint-module-content {
  padding: 0 16px 16px; border-top: 1px solid var(--border);
}
.imprint-content-area {
  width: 100%; min-height: 120px; max-height: 400px; background: rgba(0,0,0,0.3);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text-primary);
  font-size: 13px; line-height: 1.6; padding: 12px; margin-top: 12px;
  resize: vertical; font-family: -apple-system, system-ui, sans-serif;
  box-sizing: border-box; outline: none; transition: border-color 0.2s;
}
.imprint-content-area:focus { border-color: var(--accent); }
.imprint-save-btn {
  display: inline-block; margin-top: 10px; padding: 8px 20px;
  background: var(--accent); color: #000; border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.imprint-save-btn:active { opacity: 0.7; }
.imprint-save-hint {
  display: inline-block; margin-left: 10px; font-size: 12px;
  color: var(--accent); opacity: 0; transition: opacity 0.3s;
}
.imprint-save-hint.show { opacity: 1; }

/* LORE entries */
.imprint-lore-list { margin-top: 12px; }
.imprint-lore-entry {
  background: rgba(0,0,0,0.2); border-radius: 10px; margin-bottom: 10px;
  border: 1px solid var(--border); overflow: hidden;
}
.imprint-lore-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; cursor: pointer;
}
.imprint-lore-header:active { background: rgba(255,255,255,0.02); }
.imprint-lore-name { font-size: 14px; color: var(--text-primary); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.imprint-lore-actions { display: flex; align-items: center; gap: 8px; }
.imprint-lore-delete { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }
.imprint-lore-delete:active { background: rgba(255,0,0,0.15); color: #ff6b6b; }
.imprint-lore-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.imprint-lore-body.open { max-height: 1000px; }
.imprint-lore-body .imprint-content-area { margin: 0 14px 14px; width: calc(100% - 28px); }
.imprint-lore-body .imprint-save-btn { margin-left: 14px; margin-bottom: 14px; }
.imprint-lore-body .imprint-save-hint { margin-bottom: 14px; }
.imprint-add-lore {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px; margin-top: 4px;
  background: rgba(255,255,255,0.03); border: 1px dashed var(--border);
  border-radius: 12px; color: var(--text-secondary); font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.imprint-add-lore:active { background: rgba(255,255,255,0.06); color: var(--accent); border-color: var(--accent); }

/* toggle-sm for lore entries */
.toggle-switch.toggle-sm {
  width: 36px; height: 20px;
}
.toggle-switch.toggle-sm .toggle-slider::before {
  height: 14px; width: 14px;
}
.toggle-switch.toggle-sm input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* ===== 留言板 ===== */
.notes-header-desc {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 16px 20px 8px;
  font-style: italic;
}

.notes-list {
  padding: 0 16px;
}

.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 12px;
  position: relative;
  transition: border-color 0.2s;
}

.note-card:first-child {
  border-color: var(--border-gold);
}

.note-card:first-child::before {
  content: 'NEW';
  position: absolute;
  top: -8px;
  right: 14px;
  background: var(--accent-gold);
  color: var(--bg-primary);
  font-size: 9px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
  letter-spacing: 1px;
}

.note-time {
  font-size: 11px;
  color: var(--accent-gold);
  margin-bottom: 8px;
  font-weight: 300;
  letter-spacing: 0.5px;
}

.note-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.note-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 16px;
  color: var(--text-muted);
  font-size: 11px;
}

.note-divider::before,
.note-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.notes-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 60px 20px;
  line-height: 2;
}

.notes-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ===== Dom Kyle 任务板 ===== */
.life-card-dom {
  border-color: rgba(180, 60, 60, 0.3) !important;
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(80, 20, 20, 0.15) 100%) !important;
}
.life-card-dom:active {
  border-color: rgba(200, 70, 70, 0.6) !important;
}

.dom-header-area {
  text-align: center;
  padding: 20px 20px 12px;
}
.dom-header-icon {
  font-size: 40px;
  margin-bottom: 8px;
}
.dom-header-text {
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 400;
  letter-spacing: 1px;
}
.dom-header-rule {
  font-size: 11px;
  color: rgba(200, 120, 120, 0.7);
  margin-top: 6px;
  font-style: italic;
}

.dom-task-list {
  padding: 0 16px;
}

.dom-task-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.dom-task-card.pending {
  border-left: 3px solid rgba(200, 120, 120, 0.6);
}
.dom-task-card.completed {
  border-left: 3px solid rgba(120, 180, 120, 0.5);
  opacity: 0.85;
}

.dom-task-main {
  padding: 14px 16px;
}

.dom-task-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.dom-task-status {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 500;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.dom-task-status.pending {
  background: rgba(200, 120, 120, 0.15);
  color: rgba(220, 140, 140, 0.9);
}
.dom-task-status.completed {
  background: rgba(120, 180, 120, 0.15);
  color: rgba(140, 200, 140, 0.9);
}

.dom-task-time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 300;
}

.dom-task-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.dom-task-detail {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  white-space: pre-wrap;
}

/* 完成区域 */
.dom-task-actions {
  padding: 0 16px 14px;
}

.dom-complete-btn {
  display: inline-block;
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 20px;
  background: rgba(200, 120, 120, 0.12);
  color: rgba(220, 150, 150, 0.9);
  border: 1px solid rgba(200, 120, 120, 0.25);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.dom-complete-btn:active {
  background: rgba(200, 120, 120, 0.25);
  transform: scale(0.96);
}

/* 感想输入 */
.dom-report-area {
  padding: 0 16px 14px;
  display: none;
}
.dom-report-area.show {
  display: block;
}
.dom-report-textarea {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
  padding: 10px 12px;
  resize: none;
  line-height: 1.6;
  font-family: inherit;
  box-sizing: border-box;
}
.dom-report-textarea:focus {
  outline: none;
  border-color: rgba(200, 120, 120, 0.4);
}
.dom-report-textarea::placeholder {
  color: var(--text-muted);
}
.dom-report-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.dom-report-submit {
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 16px;
  background: rgba(200, 120, 120, 0.15);
  color: rgba(220, 150, 150, 0.9);
  border: 1px solid rgba(200, 120, 120, 0.3);
  cursor: pointer;
}

/* 已提交的感想和回复 */
.dom-report-display {
  padding: 0 16px 14px;
}
.dom-report-bubble, .dom-review-bubble {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 8px;
  white-space: pre-wrap;
}
.dom-report-bubble {
  background: rgba(200, 120, 120, 0.08);
  border: 1px solid rgba(200, 120, 120, 0.15);
}
.dom-report-label, .dom-review-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.dom-report-label {
  color: rgba(220, 150, 150, 0.7);
}
.dom-review-bubble {
  background: rgba(180, 160, 100, 0.08);
  border: 1px solid rgba(180, 160, 100, 0.15);
}
.dom-review-label {
  color: var(--accent-gold);
}

.dom-task-completed-time {
  font-size: 11px;
  color: rgba(140, 200, 140, 0.6);
  padding: 0 16px 12px;
}

/* === Chat Settings === */
.chat-settings-btn { font-size: 18px; padding: 8px; cursor: pointer; color: var(--text-secondary); transition: color 0.2s; }
.chat-settings-btn:active { color: var(--gold-primary); }

.chat-settings-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 280px;
  background: var(--bg-secondary); border-left: 1px solid var(--border-subtle);
  z-index: 100; transform: translateX(100%); transition: transform 0.3s ease;
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.chat-settings-panel.open { transform: translateX(0); }

.chat-settings-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border-subtle);
  font-size: 15px; font-weight: 500; color: var(--text-primary); letter-spacing: 1px;
}
.chat-settings-close { cursor: pointer; color: var(--text-muted); font-size: 16px; padding: 4px; }
.chat-settings-close:active { color: var(--gold-primary); }

.chat-settings-body { padding: 20px; overflow-y: auto; flex: 1; }

.chat-setting-item {
  margin-bottom: 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-setting-item:last-child { margin-bottom: 0; }

.chat-setting-label {
  font-size: 12px; color: var(--gold-primary); letter-spacing: 1px;
  text-transform: uppercase; font-weight: 500;
}

.chat-setting-select {
  background: var(--bg-primary); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.chat-setting-select:focus { border-color: var(--gold-primary); }

.chat-setting-range-row { display: flex; align-items: center; gap: 12px; }

.chat-setting-range {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--border-subtle); border-radius: 2px; outline: none;
}
.chat-setting-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--gold-primary); cursor: pointer;
}

.chat-setting-range-val {
  min-width: 40px; text-align: right; font-size: 14px;
  color: var(--text-primary); font-variant-numeric: tabular-nums;
}

/* toggle 在 chat settings 里的间距调整 */
.chat-setting-item .toggle-switch { align-self: flex-start; }

/* === Chat Settings - Extended === */
.chat-setting-section { margin-bottom: 28px; }
.chat-setting-section:last-of-type { margin-bottom: 16px; }
.chat-setting-section-title {
  font-size: 11px; color: var(--text-muted); letter-spacing: 2px;
  text-transform: uppercase; margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.chat-setting-input {
  width: 100%; background: var(--bg-primary); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; outline: none;
  font-family: 'SF Mono', 'Menlo', monospace;
  box-sizing: border-box;
}
.chat-setting-input:focus { border-color: var(--gold-primary); }
.chat-setting-input::placeholder { color: var(--text-muted); font-family: inherit; }

.chat-setting-key-row { display: flex; gap: 8px; align-items: stretch; }
.chat-key-input { flex: 1; }
.chat-key-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 40px; background: var(--bg-primary); border: 1px solid var(--border-subtle);
  border-radius: 8px; cursor: pointer; font-size: 14px; flex-shrink: 0;
  user-select: none; -webkit-user-select: none;
}
.chat-key-toggle:active { background: var(--border-subtle); }

.chat-setting-model-row { display: flex; gap: 8px; align-items: stretch; }
.chat-setting-model-row .chat-setting-select { flex: 1; }
.chat-model-refresh {
  display: flex; align-items: center; justify-content: center;
  width: 40px; background: var(--bg-primary); border: 1px solid var(--border-subtle);
  border-radius: 8px; cursor: pointer; font-size: 18px; color: var(--text-secondary);
  flex-shrink: 0; transition: transform 0.3s;
  user-select: none; -webkit-user-select: none;
}
.chat-model-refresh:active { color: var(--gold-primary); }
.chat-model-refresh.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat-setting-save-hint {
  text-align: center; font-size: 12px; color: var(--gold-primary);
  min-height: 20px; transition: opacity 0.3s; opacity: 0;
}
.chat-setting-save-hint.show { opacity: 1; }

/* Chat setting hint */
.chat-setting-hint {
  font-size: 11px; color: var(--text-muted); line-height: 1.5;
  margin-top: 2px;
}


/* ===== Activity Feed ===== */
.activity-feed {
  margin: 8px 20px 0;
  opacity: 0.7;
}
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.activity-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  line-height: 1.4;
}
.activity-item .activity-icon {
  font-size: 10px;
  flex-shrink: 0;
}
.activity-item .activity-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-item .activity-time {
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  flex-shrink: 0;
}

/* ===== Bookmark New Badge ===== */
.bm-new-badge {
  display: inline-block;
  font-size: 10px;
  color: #d4a853;
  margin-left: 6px;
  animation: badgePulse 2s ease-in-out infinite;
}
@keyframes badgePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.shortcut-badge, .life-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: #d4a853;
  border-radius: 50%;
  animation: badgePulse 2s ease-in-out infinite;
}
.shortcut-btn, .life-card {
  position: relative;
}

/* ===== Dailylog in Imprint ===== */
.dailylog-content { padding: 14px !important; }
.dailylog-add-row {
  display: flex; gap: 8px; align-items: flex-end;
  margin-bottom: 16px; padding-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.dailylog-date-input {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: var(--text-primary); padding: 8px 10px;
  font-size: 13px; min-width: 120px; flex-shrink: 0;
  color-scheme: dark;
}
.dailylog-new-input {
  flex: 1; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: var(--text-primary); padding: 8px 10px;
  font-size: 13px; resize: none; min-height: 36px; font-family: inherit;
}
.dailylog-new-input:focus, .dailylog-date-input:focus { border-color: var(--accent); outline: none; }
.dailylog-add-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #000; border-radius: 8px; font-size: 18px; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
}
.dailylog-add-btn:active { opacity: 0.7; }
.dailylog-day { margin-bottom: 12px; }
.dailylog-day-header {
  display: flex; align-items: center; gap: 8px; padding: 6px 0; margin-bottom: 4px;
}
.dailylog-day-date { font-size: 13px; font-weight: 600; color: var(--accent); }
.dailylog-day-count { font-size: 11px; color: var(--text-secondary); }
.dailylog-day-delete {
  margin-left: auto; font-size: 11px; color: var(--text-secondary); opacity: 0.4;
  padding: 4px 6px; cursor: pointer;
}
.dailylog-day-delete:active { opacity: 1; color: #e74c3c; }
.dailylog-entries { padding-left: 4px; }
.dailylog-entry {
  display: flex; align-items: flex-start; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.dailylog-entry-text {
  flex: 1; font-size: 13px; color: var(--text-secondary); line-height: 1.5;
}
.dailylog-entry-text::before {
  content: '·'; color: var(--accent); margin-right: 6px; font-weight: 700;
}
.dailylog-entry-delete {
  font-size: 11px; color: var(--text-secondary); opacity: 0.3;
  padding: 2px 4px; cursor: pointer; flex-shrink: 0;
}
.dailylog-entry-delete:active { opacity: 1; color: #e74c3c; }
.dailylog-empty {
  text-align: center; color: var(--text-secondary); font-size: 13px;
  padding: 20px 0; opacity: 0.5;
}

/* ===== Imprint Fullscreen Editor ===== */
.imprint-fs-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-primary); z-index: 9999;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s ease;
}
.imprint-fs-overlay.open { transform: translateY(0); }
.imprint-fs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255,255,255,0.06); flex-shrink: 0;
}
.imprint-fs-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.imprint-fs-close {
  font-size: 14px; font-weight: 600; color: var(--accent);
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
  background: rgba(212,175,55,0.1);
}
.imprint-fs-close:active { opacity: 0.6; }
.imprint-fs-textarea {
  flex: 1; margin: 12px 16px; margin-bottom: max(12px, env(safe-area-inset-bottom));
  padding: 14px; background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08); border-radius: 12px;
  color: var(--text-primary); font-size: 14px; line-height: 1.7;
  resize: none; font-family: inherit; outline: none;
}
.imprint-fs-textarea:focus { border-color: var(--accent); }
.imprint-btn-row {
  display: flex; align-items: center; gap: 10px;
}
.imprint-expand-btn {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: var(--text-secondary); font-size: 16px;
  cursor: pointer; flex-shrink: 0;
}
.imprint-expand-btn:active { background: rgba(212,175,55,0.15); color: var(--accent); }

/* ===== Chat Messages ===== */
.chat-msg { margin-bottom: 16px; max-width: 100%; }
.chat-msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.chat-msg-assistant { display: flex; flex-direction: column; align-items: flex-start; }

.chat-bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.65; word-break: break-word;
}
.chat-bubble-user {
  background: var(--gold-primary); color: #0a0a12;
  border-bottom-right-radius: 4px;
}
.chat-bubble-assistant {
  background: rgba(255,255,255,0.06); color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.06);
  border-bottom-left-radius: 4px;
}
.chat-bubble-assistant pre {
  background: rgba(0,0,0,0.3); padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0; font-size: 13px;
}
.chat-bubble-assistant code.inline-code {
  background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 13px;
}
.chat-bubble-assistant strong { color: var(--gold-primary); }

.chat-msg-time {
  font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 4px;
}
.chat-msg-meta {
  font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 4px;
}

/* Thinking block */
.chat-thinking {
  max-width: 85%; margin-bottom: 8px; border-radius: 12px;
  border: 1px solid rgba(212,175,55,0.15); background: rgba(212,175,55,0.04);
  overflow: hidden;
}
.chat-thinking-header {
  padding: 8px 12px; font-size: 13px; color: var(--gold-primary);
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  user-select: none; -webkit-user-select: none;
}
.chat-thinking-icon { font-size: 14px; }
.chat-thinking-icon.spinning { animation: spin 1.5s linear infinite; }
.chat-thinking-body {
  max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
  padding: 0 12px; font-size: 13px; line-height: 1.6;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-word;
}
.chat-thinking.open .chat-thinking-body {
  max-height: 400px; overflow-y: auto; padding: 0 12px 10px;
}
.chat-thinking.streaming .chat-thinking-header {
  color: var(--gold-secondary); opacity: 0.9;
}

/* Streaming cursor */
.chat-cursor {
  animation: blink 0.8s step-end infinite; color: var(--gold-primary); font-size: 13px;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Stop button */
.chat-send.chat-stop { background: #ff4444; }

/* Error */
.chat-error { color: #ff6b6b; font-size: 13px; }

/* Chat placeholder update */
.chat-placeholder { color: var(--text-muted); font-size: 14px; text-align: center; margin-top: 30vh; }

/* Chat textarea input */
textarea.chat-input {
  resize: none; overflow-y: auto; min-height: 20px; max-height: 120px;
  line-height: 20px; font-family: inherit;
}

/* Sidebar item actions */
.sidebar-item { position: relative; }
.sidebar-item-actions {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 8px; opacity: 0; transition: opacity 0.2s;
}
.sidebar-item:hover .sidebar-item-actions,
.sidebar-item.active .sidebar-item-actions { opacity: 1; }
/* Always show on touch devices */
@media (hover: none) {
  .sidebar-item-actions { opacity: 0.6; }
}
.sidebar-action {
  font-size: 14px; padding: 4px 6px; color: var(--text-muted);
  border-radius: 4px; cursor: pointer; line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-action:active { color: var(--gold-primary); background: rgba(212,175,55,0.1); }
.sidebar-delete:active { color: #ff6b6b; background: rgba(255,107,107,0.1); }

/* ===== Chat v2: head / foot / actions / versions ===== */
.chat-msg { margin-bottom: 22px; }

/* Head: avatar + name + time */
.chat-msg-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  width: 100%; box-sizing: border-box;
}
.chat-msg-user .chat-msg-head { flex-direction: row-reverse; }
.chat-ava {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border-gold); flex-shrink: 0; background: var(--bg-card);
}
.chat-msg-info { display: flex; flex-direction: column; line-height: 1.3; }
.chat-msg-user .chat-msg-info { align-items: flex-end; }
.chat-name { font-size: 13px; color: var(--gold-primary); font-weight: 600; }
.chat-time { font-size: 11px; color: var(--text-muted); }

/* Foot: actions + token + version */
.chat-foot {
  display: flex; align-items: center; gap: 10px; margin-top: 6px;
  padding: 0 2px; width: 100%; box-sizing: border-box;
}
.chat-msg-user .chat-foot { flex-direction: row-reverse; }
.chat-acts { display: flex; align-items: center; gap: 2px; }
.chat-act {
  background: none; border: none; padding: 5px; border-radius: 6px;
  color: var(--text-muted); cursor: pointer; display: inline-flex;
  align-items: center; transition: color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.chat-act:hover, .chat-act:active { color: var(--gold-primary); background: rgba(212,175,55,0.08); }
.chat-act.copied { color: var(--green-check); }
.chat-act[data-act="delete"]:hover, .chat-act[data-act="delete"]:active { color: var(--red-urgent); background: rgba(220,60,60,0.08); }

.chat-foot-meta {
  margin-left: auto; font-size: 11px; color: var(--text-muted);
  white-space: nowrap;
}
.chat-msg-user .chat-foot-meta { margin-left: 0; margin-right: auto; }
.chat-tok { color: var(--text-muted); white-space: nowrap; }
.chat-ver { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.ver-prev, .ver-next {
  cursor: pointer; padding: 2px 5px; border-radius: 4px;
  color: var(--text-secondary); font-size: 14px; line-height: 1;
}
.ver-prev:active, .ver-next:active { color: var(--gold-primary); background: rgba(212,175,55,0.1); }
.ver-num { font-variant-numeric: tabular-nums; min-width: 30px; text-align: center; }

/* Edit box */
.chat-edit-box { width: 100%; max-width: 100%; margin-top: 4px; }
.chat-msg-user .chat-edit-box { margin-left: auto; }
.chat-edit-area {
  width: 100%; min-height: 100px; max-height: 400px; padding: 10px 12px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border-gold);
  border-radius: 8px; color: var(--text-primary); font-size: 14px; line-height: 1.6;
  resize: none; overflow-y: auto; font-family: inherit;
  box-sizing: border-box;
}
.chat-edit-area:focus { outline: none; border-color: var(--gold-primary); }
.chat-edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.chat-edit-btn {
  border: none; border-radius: 8px; padding: 6px 16px; font-size: 13px; cursor: pointer;
}
.chat-edit-btn.save { background: var(--gold-primary); color: #0a0a12; }
.chat-edit-btn.cancel { background: rgba(255,255,255,0.08); color: var(--text-secondary); }

/* Delete popup */
.chat-del-pop {
  position: fixed; z-index: 9999;
  background: var(--bg-card); border: 1px solid var(--border-gold);
  border-radius: 10px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 130px;
}
.chat-del-pop button {
  display: block; width: 100%; background: none; border: none;
  color: var(--text-secondary); padding: 9px 14px; font-size: 13px;
  text-align: left; cursor: pointer; border-radius: 6px; white-space: nowrap;
}
.chat-del-pop button:hover, .chat-del-pop button:active {
  background: rgba(220,60,60,0.1); color: var(--red-urgent);
}

/* ===== Chat Image Support ===== */
.chat-img-btn {
  width: 36px; height: 36px; border-radius: 50%; background: transparent;
  border: 1px solid var(--border-subtle); color: var(--text-muted);
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.chat-img-btn:active { opacity: 0.7; }
.chat-img-btn:hover { border-color: var(--border-gold); color: var(--gold-primary); }

/* Preview area above input bar */
.chat-img-preview {
  display: flex; gap: 8px; padding: 8px 16px; flex-wrap: wrap;
  border-top: 1px solid var(--border-subtle); background: var(--bg-secondary);
}
.chat-preview-thumb {
  position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.chat-preview-thumb img { width: 100%; height: 100%; object-fit: cover; }
.chat-preview-remove {
  position: absolute; top: -2px; right: -2px; width: 20px; height: 20px;
  background: rgba(0,0,0,0.7); color: #fff; border-radius: 50%;
  font-size: 13px; line-height: 20px; text-align: center; cursor: pointer;
}

/* Images in message bubble */
.chat-msg-images {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px;
  max-width: 100%;
}
.chat-msg-img {
  max-width: 240px; max-height: 240px; border-radius: 10px; cursor: pointer;
  object-fit: cover; border: 1px solid var(--border-subtle);
  transition: opacity 0.2s;
}
.chat-msg-img:active { opacity: 0.8; }

/* Single image: bigger */
.chat-msg-images:only-child .chat-msg-img:only-child,
.chat-msg-images .chat-msg-img:only-child {
  max-width: 280px; max-height: 320px;
}

/* Lightbox overlay */
.chat-lightbox {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.92); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 20px;
}
.chat-lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px;
}

/* ===== File preview tag ===== */
.chat-preview-file {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border-subtle);
  font-size: 12px; color: var(--text-secondary); max-width: 200px;
}
.chat-preview-file .file-icon { font-size: 16px; flex-shrink: 0; }
.chat-preview-file .file-info { display: flex; flex-direction: column; min-width: 0; }
.chat-preview-file .file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--text-primary); }
.chat-preview-file .file-size { font-size: 10px; color: var(--text-muted); }
.chat-preview-file .chat-preview-remove {
  margin-left: auto; width: 18px; height: 18px;
  background: rgba(0,0,0,0.5); color: #fff; border-radius: 50%;
  font-size: 12px; line-height: 18px; text-align: center; cursor: pointer; flex-shrink: 0;
}

/* ===== Chat File Card (collapsible) ===== */
.chat-file-card {
  margin-bottom: 6px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border-subtle); background: rgba(255,255,255,0.04);
  max-width: 300px;
}
.chat-msg-user .chat-file-card { margin-left: auto; }
.chat-file-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  cursor: pointer; user-select: none; transition: background 0.15s;
}
.chat-file-header:active { background: rgba(255,255,255,0.06); }
.chat-file-icon { font-size: 18px; flex-shrink: 0; }
.chat-file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-file-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-file-size { font-size: 11px; color: var(--text-muted); }
.chat-file-toggle { font-size: 10px; color: var(--text-muted); flex-shrink: 0; transition: transform 0.2s; }
.chat-file-body {
  border-top: 1px solid var(--border-subtle); max-height: 300px; overflow: auto;
}
.chat-file-body pre {
  margin: 0; padding: 10px 12px; font-size: 12px; line-height: 1.5;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-all;
}
.chat-file-body code { font-family: 'SF Mono', 'Menlo', 'Monaco', monospace; }

/* ===== Markdown Rendering ===== */

/* Headings */
.md-h { color: var(--gold-primary); margin: 12px 0 6px; line-height: 1.35; }
h1.md-h { font-size: 1.35em; }
h2.md-h { font-size: 1.2em; }
h3.md-h { font-size: 1.1em; }
h4.md-h, h5.md-h, h6.md-h { font-size: 1em; }

/* Inline code */
.md-inline-code {
  background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 4px;
  font-family: 'SF Mono','Menlo','Monaco','Consolas',monospace; font-size: 0.88em;
  color: var(--gold-secondary, #e8c577); word-break: break-all;
}

/* Code block wrapper */
.md-code-block {
  position: relative; margin: 8px 0; border-radius: 8px; overflow: hidden;
  background: #0d0d14; border: 1px solid var(--border-subtle);
}
.md-code-block pre {
  margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 12.5px; line-height: 1.6;
}
.md-code-block code {
  font-family: 'SF Mono','Menlo','Monaco','Consolas',monospace;
  color: #c8ccd4; white-space: pre;
}
.md-code-lang {
  position: absolute; top: 6px; left: 12px;
  font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
  pointer-events: none;
}
.md-code-copy {
  position: absolute; top: 6px; right: 8px;
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: rgba(255,255,255,0.08); border: 1px solid var(--border-subtle);
  color: var(--text-muted); cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.md-code-copy:active { color: var(--gold-primary); border-color: var(--border-gold); }

/* Lists */
.md-list { margin: 6px 0; padding-left: 20px; }
.md-list li { margin: 3px 0; line-height: 1.6; }
ul.md-list { list-style: disc; }
ol.md-list { list-style: decimal; }

/* Blockquote */
.md-blockquote {
  border-left: 3px solid var(--gold-primary); margin: 8px 0; padding: 6px 12px;
  background: rgba(255,255,255,0.03); color: var(--text-secondary);
  border-radius: 0 6px 6px 0; font-style: italic;
}

/* Horizontal rule */
.md-hr {
  border: none; height: 1px; margin: 12px 0;
  background: linear-gradient(90deg, transparent, var(--border-gold), transparent);
}

/* Links */
.md-link { color: var(--gold-primary); text-decoration: underline; text-underline-offset: 2px; }

/* Strikethrough */
del { opacity: 0.6; }


/* Conversation switch polish */
.chat-messages { transition: opacity .18s ease, transform .18s ease, filter .18s ease; }
.chat-messages.chat-switching { opacity: .45; transform: translateY(8px); filter: blur(.3px); pointer-events: none; }
.sidebar-item { transition: background .18s ease, transform .18s ease; }
.sidebar-item:active { transform: scale(.985); }
.chat-title { transition: opacity .18s ease; }

/* Chat stability: iOS PWA scroll anchoring + content-visibility caused visible jump after images/layout settled.
   Keep DOM light via JS pagination instead; do not let browser estimate message heights. */
.chat-msg { overflow-anchor: none; }
.chat-messages { overflow-anchor: none; overscroll-behavior: contain; }
.chat-messages.is-rendering { pointer-events: none; }

/* Reserve image space before actual decode, otherwise iOS recalculates scroll position after pictures load. */
.chat-msg-img { width: min(280px, 72vw); height: 320px; }
.chat-msg-images:not(:has(.chat-msg-img:only-child)) .chat-msg-img { width: 120px; height: 120px; }
@supports not selector(:has(.x)) {
  .chat-msg-img { width: min(280px, 72vw); height: 320px; }
}

/* Code block has lang label: add top padding */
.md-code-block:has(.md-code-lang) pre { padding-top: 28px; }
/* Fallback for browsers without :has */
@supports not selector(:has(.x)) {
  .md-code-block pre { padding-top: 28px; }
}

/* Stream code block (lightweight) */
pre.stream-code {
  background: #0d0d14; border: 1px solid var(--border-subtle);
  border-radius: 8px; padding: 12px 16px; margin: 6px 0;
  overflow-x: auto; font-size: 12.5px; line-height: 1.6;
}
pre.stream-code code {
  font-family: 'SF Mono','Menlo','Monaco','Consolas',monospace;
  color: #c8ccd4; white-space: pre;
}

/* API Preset row */
.chat-preset-row {
  display: flex; gap: 8px; align-items: center;
}
.chat-preset-row .chat-preset-select {
  flex: 1; min-width: 0;
}
.chat-preset-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.chat-preset-btn:active { background: rgba(255,255,255,0.12); border-color: var(--gold-primary); }
.chat-preset-del { font-size: 14px; color: #999; }
.chat-preset-del:active { color: #ff6b6b; }

/* send button locked/sending state (prevents double-tap confusion) */
.chat-send.chat-sending { opacity: .55; pointer-events: none; cursor: not-allowed; }
.chat-send:disabled { opacity: .55; cursor: not-allowed; }

/* "load earlier messages" button for paginated history */
.chat-load-more { text-align:center; padding:10px; margin:6px auto 14px; font-size:13px; color:var(--gold,#c9a04e); background:rgba(201,160,78,.08); border:1px solid rgba(201,160,78,.25); border-radius:20px; width:fit-content; cursor:pointer; transition:.2s; }
.chat-load-more:hover { background:rgba(201,160,78,.16); }

/* v69: chat settings mobile overflow fix */
.chat-settings-panel {
  width: min(360px, 88vw);
  max-width: 100vw;
  overflow-x: hidden;
}
.chat-settings-body {
  overflow-x: hidden;
}
.chat-setting-section,
.chat-setting-item,
.chat-preset-row,
.chat-setting-key-row,
.chat-setting-model-row,
.chat-setting-range-row {
  min-width: 0;
  max-width: 100%;
}
.chat-setting-select,
.chat-setting-input,
.chat-key-input,
.chat-setting-range {
  min-width: 0;
  max-width: 100%;
}
.chat-setting-model-row .chat-setting-select,
.chat-preset-row .chat-preset-select {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-setting-hint {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ===== Reading together ===== */
.reading-wrap { padding: 16px 20px 24px; }
.reading-toolbar, .reading-nav { display:flex; gap:10px; align-items:center; margin-bottom:12px; }
.reading-toolbar { position: sticky; top: 0; z-index: 2; background: linear-gradient(var(--bg-primary) 75%, transparent); padding-top: 4px; }
.reading-btn { border:1px solid var(--border-subtle); background: var(--bg-card); color: var(--text-primary); border-radius: 12px; padding: 9px 12px; font-size: 13px; font-family: inherit; }
.reading-btn.primary { background: var(--gold-primary); color: #09090d; border-color: var(--gold-primary); font-weight: 700; }
.reading-btn:active, .reading-send:active { transform: scale(.96); opacity:.85; }
.reading-library { display:none; margin-bottom: 12px; border:1px solid var(--border-subtle); background: var(--bg-card); border-radius:16px; overflow:hidden; }
.reading-library.open { display:block; animation: fadeInUp .2s ease-out; }
.reading-book-item { padding:13px 15px; border-bottom:1px solid var(--border-subtle); display:flex; justify-content:space-between; gap:10px; align-items:center; }
.reading-book-item:last-child { border-bottom:0; }
.reading-book-title { color: var(--text-primary); font-size:14px; line-height:1.4; }
.reading-book-meta { color: var(--text-muted); font-size:11px; margin-top:4px; }
.reading-card { border:1px solid var(--border-subtle); background: #14141d; border-radius:18px; padding:18px; min-height: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.22); }
.reading-empty { color: var(--text-muted); text-align:center; padding:90px 20px; line-height:1.8; }
.reading-title { color: var(--gold-primary); font-size:13px; margin-bottom:10px; letter-spacing:.5px; }
.reading-text { color: var(--text-primary); font-size:16px; line-height:1.9; white-space:pre-wrap; word-break:break-word; }
.reading-page-indicator { flex:1; text-align:center; color: var(--text-muted); font-size:12px; }
.reading-nav { margin-top:12px; }
.reading-nav .reading-btn { flex: 0 0 86px; }
.reading-chat { margin-top: 14px; border:1px solid var(--border-subtle); background: var(--bg-card); border-radius:18px; overflow:hidden; }
.reading-chat-log { max-height: 260px; overflow:auto; padding:12px; display:flex; flex-direction:column; gap:10px; }
.reading-chat-empty { color: var(--text-muted); font-size:13px; text-align:center; padding:10px; }
.reading-chat-msg { display:flex; }
.reading-chat-msg.user { justify-content:flex-end; }
.reading-chat-msg.assistant { justify-content:flex-start; }
.reading-chat-bubble { max-width:86%; border-radius:16px; padding:10px 12px; font-size:14px; line-height:1.7; white-space:pre-wrap; word-break:break-word; border:1px solid var(--border-subtle); background:#20202b; color:var(--text-primary); }
.reading-chat-msg.user .reading-chat-bubble { background: var(--gold-primary); color:#08080c; border-color: var(--gold-primary); }
.reading-chat-inputrow { border-top:1px solid var(--border-subtle); display:flex; gap:10px; padding:10px; align-items:flex-end; }
.reading-input { flex:1; background:#111119; border:1px solid var(--border-subtle); border-radius:14px; color:var(--text-primary); padding:10px 12px; resize:none; font-family:inherit; font-size:14px; outline:none; }
.reading-send { width:38px; height:38px; border-radius:50%; border:0; background:var(--gold-primary); color:#08080c; font-size:18px; font-weight:800; }
@media (max-width: 520px) { .reading-wrap{padding:12px 14px 24px;} .reading-card{padding:15px; min-height:330px;} .reading-text{font-size:15px; line-height:1.85;} }


/* Reading v2 polish */
.reading-toolbar { position: relative; top: auto; z-index: 3; background: transparent; padding-top: 0; pointer-events: auto; }
.reading-toolbar .reading-btn { min-width: 76px; }
.reading-btn[disabled] { opacity: .55; pointer-events: none; }
.reading-btn.danger { color: #ff9a9a; border-color: rgba(255,120,120,.28); background: rgba(80,20,20,.16); }
.reading-book-main { flex: 1; min-width: 0; }
.reading-book-actions { display:flex; gap:8px; flex-shrink:0; }
.reading-book-actions .reading-btn { padding: 7px 9px; font-size: 12px; }
.reading-card { min-height: 0; }
.reading-chat { display: none; margin-top: 12px; }
.reading-chat.open { display:block; position: sticky; bottom: 8px; z-index: 5; box-shadow: 0 -8px 28px rgba(0,0,0,.35); }
.reading-chat-log { max-height: 150px; padding: 10px; }
.reading-chat-inputrow { padding: 8px; gap: 8px; }
.reading-input { min-height: 40px; max-height: 74px; padding: 9px 10px; font-size: 13px; }
.reading-send { width: 36px; height: 36px; }
.reading-chat-bubble { font-size: 13px; line-height: 1.6; }
@media (max-width: 520px) { .reading-toolbar { gap:8px; } .reading-toolbar .reading-btn{padding:8px 10px; min-width:70px;} .reading-chat-log{max-height:130px;} }


/* Reading chat toggle v3 */
.reading-chat-head { display:flex; align-items:center; justify-content:space-between; padding:9px 10px; border-bottom:1px solid var(--border-subtle); }
.reading-chat-title { color: var(--gold-primary); font-size:13px; font-weight:600; }
.reading-chat-close { border:1px solid var(--border-subtle); background:#151520; color:var(--text-muted); border-radius:10px; padding:5px 9px; font-size:12px; }
.reading-quick-row { padding:8px 10px 0; }
.reading-quick { width:100%; border:1px solid rgba(221,166,81,.35); background:rgba(221,166,81,.12); color:var(--gold-primary); border-radius:12px; padding:8px 10px; font-size:13px; font-family:inherit; }
.reading-quick:disabled { opacity:.55; }


/* Reading full-screen chat v4 */
.reading-chat.open {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: calc(86px + env(safe-area-inset-bottom)) !important;
  z-index: 80 !important;
  margin: 0 !important;
  border-radius: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  background: var(--bg-primary) !important;
  box-shadow: none !important;
}
.reading-chat.open .reading-chat-head {
  padding: calc(18px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(10,10,15,.98);
}
.reading-chat.open .reading-chat-title { font-size: 16px; }
.reading-chat.open .reading-quick-row { padding: 12px 16px 0; }
.reading-chat.open .reading-chat-log { flex: 1; max-height: none !important; padding: 14px 16px; }
.reading-chat.open .reading-chat-inputrow { padding: 10px 14px 14px; background: rgba(10,10,15,.98); }
.reading-chat.open .reading-input { min-height: 44px; max-height: 96px; }
.reading-chat-full-open { overflow: hidden; }


/* Reading chat as real page v5 */
#sub-reading.chat-mode {
  position: fixed !important;
  inset: 0 !important;
  z-index: 3000 !important;
  background: var(--bg-primary) !important;
}
#sub-reading.chat-mode > .sub-header { display: none !important; }
#sub-reading.chat-mode .reading-wrap {
  padding: 0 !important;
  height: 100% !important;
  overflow: hidden !important;
}
#sub-reading.chat-mode .reading-toolbar,
#sub-reading.chat-mode .reading-library,
#sub-reading.chat-mode .reading-card,
#sub-reading.chat-mode .reading-nav { display: none !important; }
#sub-reading.chat-mode .reading-chat.open {
  position: relative !important;
  inset: auto !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  bottom: auto !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  background: var(--bg-primary) !important;
}
#sub-reading.chat-mode .reading-chat-head {
  padding: calc(54px + env(safe-area-inset-top)) 18px 14px !important;
  border-bottom: 1px solid var(--border-subtle);
  background: #0a0a0f !important;
}
#sub-reading.chat-mode .reading-chat-title { font-size: 18px !important; }
#sub-reading.chat-mode .reading-chat-log {
  flex: 1 !important;
  max-height: none !important;
  overflow: auto !important;
  padding: 16px !important;
}
#sub-reading.chat-mode .reading-chat-inputrow {
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom)) !important;
  background: #0a0a0f !important;
}
body.reading-chat-full-open .tab-bar,
body.reading-chat-full-open .safe-area-bottom { display: none !important; }


/* Reading no quick button v6 */
#sub-reading.chat-mode .reading-quick-row { display:none !important; }
.reading-chat-empty { color: var(--text-muted); }


/* Reading fixed shell + inner text scroll v7 */
#sub-reading .reading-wrap {
  flex: 1 !important;
  min-height: 0 !important;
  height: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  padding: 12px 14px 14px !important;
}
#sub-reading .reading-toolbar {
  flex-shrink: 0 !important;
  position: relative !important;
  top: auto !important;
  margin-bottom: 10px !important;
  padding-top: 0 !important;
  background: transparent !important;
}
#sub-reading .reading-library.open {
  flex-shrink: 0 !important;
  max-height: 34vh !important;
  overflow: auto !important;
}
#sub-reading .reading-card {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 14px !important;
}
#sub-reading .reading-title {
  flex-shrink: 0 !important;
  margin-bottom: 10px !important;
}
#sub-reading .reading-text {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  padding-right: 4px !important;
  overscroll-behavior: contain !important;
}
#sub-reading .reading-nav {
  flex-shrink: 0 !important;
  margin-top: 10px !important;
  margin-bottom: 0 !important;
}
#sub-reading .reading-empty {
  flex: 1 !important;
  display:flex !important;
  align-items:center !important;
  justify-content:center !important;
  padding: 20px !important;
}


/* ===== Foundation viewport fix v84 =====
   不再用独立 safe-area-bottom 占位块制造底部空白；
   底部安全区并入 tab-bar / composer 自身 padding。 */
html, body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}
.app {
  position: fixed;
  inset: 0;
  height: var(--app-height, 100dvh) !important;
  min-height: 0;
}
.safe-area-bottom { display: none !important; height: 0 !important; }
.tab-bar {
  padding: 8px 0 max(8px, env(safe-area-inset-bottom)) !important;
  background: rgba(10,10,15,0.96);
}
.page-chat .chat-input-bar {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.chat-sidebar {
  padding-top: max(38px, env(safe-area-inset-top));
}
.chat-settings-panel {
  padding-top: max(38px, env(safe-area-inset-top));
}


/* ===== Clamp broken iOS PWA bottom env v85 =====
   某些 iOS standalone 下 env(safe-area-inset-bottom) 会异常变大，
   不能直接拿它当 padding；底部统一限制在 12px 内。 */
:root { --k-bottom-safe: clamp(0px, env(safe-area-inset-bottom), 12px); }
.safe-area-bottom { display: none !important; height: 0 !important; padding: 0 !important; }
.tab-bar {
  padding-top: 8px !important;
  padding-bottom: var(--k-bottom-safe) !important;
  min-height: 74px;
  align-items: center;
}
.page-chat .chat-input-bar {
  padding-bottom: 10px !important;
}
.chat-settings-panel { bottom: 0 !important; }


/* ===== Fullscreen foundation v88: fixed bottom nav + calmer top safe ===== */
:root {
  --k-top-safe: max(54px, env(safe-area-inset-top));
  --k-tab-h: 86px;
}
.safe-area-top {
  height: var(--k-top-safe) !important;
  flex-shrink: 0;
}
.app {
  overflow: hidden;
}
.page.active {
  /* tabbar is fixed now, so page needs its own bottom breathing room */
  padding-bottom: var(--k-tab-h);
}
.page-chat.active {
  padding-bottom: calc(var(--k-tab-h) + 58px);
}
.scroll-container {
  padding-bottom: 24px;
}
.tab-bar {
  position: fixed !important;
  left: 0; right: 0; bottom: 0;
  height: var(--k-tab-h) !important;
  min-height: var(--k-tab-h) !important;
  padding: 6px 0 8px !important;
  z-index: 80;
  background: rgba(10,10,15,0.98);
  border-top: 1px solid var(--border-subtle);
}
/* Chat composer sits above fixed tabbar for now; later we rebuild it like the reference. */
.page-chat .chat-input-bar {
  position: fixed !important;
  left: 0; right: 0;
  bottom: var(--k-tab-h);
  z-index: 70;
  padding: 10px 16px !important;
  border-top: 1px solid var(--border-subtle);
}
.page-chat .chat-messages {
  padding-bottom: 96px !important;
}
.chat-sidebar,
.chat-settings-panel {
  padding-top: var(--k-top-safe) !important;
}


/* ===== Fullscreen foundation v88: fixed bottom nav + calmer top safe ===== */
:root {
  --k-top-safe: max(54px, env(safe-area-inset-top));
  --k-tab-h: 86px;
}
.safe-area-top {
  height: var(--k-top-safe) !important;
  flex-shrink: 0;
}
.app {
  overflow: hidden;
}
.page.active {
  /* tabbar is fixed now, so page needs its own bottom breathing room */
  padding-bottom: var(--k-tab-h);
}
.page-chat.active {
  padding-bottom: calc(var(--k-tab-h) + 58px);
}
.scroll-container {
  padding-bottom: 24px;
}
.tab-bar {
  position: fixed !important;
  left: 0; right: 0; bottom: 0;
  height: var(--k-tab-h) !important;
  min-height: var(--k-tab-h) !important;
  padding: 6px 0 8px !important;
  z-index: 80;
  background: rgba(10,10,15,0.98);
  border-top: 1px solid var(--border-subtle);
}
/* Chat composer sits above fixed tabbar for now; later we rebuild it like the reference. */
.page-chat .chat-input-bar {
  position: fixed !important;
  left: 0; right: 0;
  bottom: var(--k-tab-h);
  z-index: 70;
  padding: 10px 16px !important;
  border-top: 1px solid var(--border-subtle);
}
.page-chat .chat-messages {
  padding-bottom: 96px !important;
}
.chat-sidebar,
.chat-settings-panel {
  padding-top: var(--k-top-safe) !important;
}


/* ===== Status-bar black test v89 =====
   iOS chin-gap often appears with black-translucent + viewport-fit.
   Switch status bar to black, then let app begin below system bar and keep bottom fixed. */
:root { --k-top-safe: 32px; }
.safe-area-top { height: var(--k-top-safe) !important; }
.tab-bar { bottom: 0 !important; }


/* ===== White gap diagnostic v90 =====
   临时把 html/body 底色调白，用来判断底部黑空是不是 WebView 外部系统区域。
   .app 本身仍保持深色。 */
html, body { background: #ffffff !important; }
.app { background: var(--bg-primary) !important; }
:root { --k-top-safe: max(54px, env(safe-area-inset-top)); }
.safe-area-top { height: var(--k-top-safe) !important; }
.chat-sidebar, .chat-settings-panel { padding-top: var(--k-top-safe) !important; }


/* ===== Viewport max fix v91 ===== */
html, body { background: var(--bg-primary) !important; }
.app { background: var(--bg-primary) !important; }
:root { --k-top-safe: max(54px, env(safe-area-inset-top)); }
.safe-area-top { height: var(--k-top-safe) !important; }


/* ===== Visual bottom blend v92 =====
   iOS 26 PWA chin gap cannot be reached by CSS viewport in Lina's device.
   Blend html/body/background with app and extend a fixed bottom backdrop behind the system gap. */
html, body {
  background: var(--bg-primary) !important;
}
body::after {
  content: "";
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 96px;
  background: var(--bg-primary);
  z-index: 1;
  pointer-events: none;
}
.app { background: var(--bg-primary) !important; z-index: 2; }
.tab-bar { z-index: 90 !important; }
.page-chat .chat-input-bar { z-index: 85 !important; }
.chat-sidebar, .chat-overlay, .chat-settings-panel { z-index: 100; }


/* ===== Chat bottom blank reduction v93 =====
   page-chat already reserves space for fixed composer + tabbar;
   large chat-messages padding-bottom created an obvious blank area before input. */
.page-chat .chat-messages {
  padding-bottom: 14px !important;
}
.chat-msg:last-child {
  margin-bottom: 8px !important;
}


/* ===== Browser-only top safe fix v94 =====
   In Safari/normal browsers the system/browser chrome already reserves top space.
   Keep the bigger safe top only for installed standalone PWA. */
@media not all and (display-mode: standalone) {
  :root { --k-top-safe: 12px; }
  .safe-area-top { height: var(--k-top-safe) !important; }
  .chat-sidebar, .chat-settings-panel { padding-top: var(--k-top-safe) !important; }
}
@media (display-mode: standalone) {
  :root { --k-top-safe: max(54px, env(safe-area-inset-top)); }
  .safe-area-top { height: var(--k-top-safe) !important; }
  .chat-sidebar, .chat-settings-panel { padding-top: var(--k-top-safe) !important; }
}

/* Reading mobile nav visibility fix v95
   让阅读器底部翻页条固定在 iPhone PWA tab-bar 上方，不被可滚动文本区挤到屏幕外。 */
#sub-reading .reading-wrap {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
}
#sub-reading .reading-card {
  flex: 1 1 0 !important;
  max-height: none !important;
}
#sub-reading .reading-nav {
  position: fixed !important;
  left: 14px !important;
  right: 14px !important;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  z-index: 60 !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  margin: 0 !important;
  padding: 10px 12px !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: 18px !important;
  background: rgba(15, 15, 23, 0.96) !important;
  box-shadow: 0 -10px 34px rgba(0,0,0,.42) !important;
  backdrop-filter: blur(18px) !important;
  -webkit-backdrop-filter: blur(18px) !important;
}
#sub-reading .reading-nav .reading-btn {
  flex: 0 0 86px !important;
  min-height: 40px !important;
}
#sub-reading .reading-page-indicator {
  flex: 1 !important;
  text-align: center !important;
  min-width: 70px !important;
}
#sub-reading.chat-mode .reading-nav { display: none !important; }
