/* ========== 主题变量 ========== */
:root {
  --bg: #1a1410;
  --bg-card: #241c14;
  --bg-elev: #2e2418;
  --bg-hover: #3a2c1e;
  --text: #f0e6d2;
  --text-dim: #a89878;
  --text-mute: #6b5a48;
  --accent: #ff9f43;
  --accent-2: #e67e22;
  --up: #ff4757;
  --down: #2ed573;
  --warn: #ffd32a;
  --border: #3a2c1e;
  --shadow: 0 8px 24px rgba(0,0,0,.5);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
input, button, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
.mono { font-family: "SF Mono", "JetBrains Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }

/* ========== 顶部状态栏 ========== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding-left: 12px; padding-right: 12px;
  z-index: 50;
}
.icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  color: var(--text); border-radius: 8px;
}
.icon-btn:active { background: var(--bg-hover); }
.topbar-title {
  flex: 1; text-align: center; font-size: 17px; font-weight: 600; letter-spacing: .5px;
}
.topbar-status { display: flex; align-items: center; gap: 6px; }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); }
.net-dot.off { background: var(--down); }
.net-dot.load { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* ========== 侧边抽屉 ========== */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--bg-card); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .28s ease;
  z-index: 60; display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}
.drawer.open { transform: translateX(0); }
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none; transition: opacity .28s; z-index: 55;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer-header {
  padding: 24px 20px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.drawer-logo {
  width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e14; font-size: 22px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.drawer-sub { font-size: 13px; color: var(--text-dim); }
.nav-list { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 14px; padding: 13px 14px;
  border-radius: 10px; color: var(--text-dim); font-size: 15px; transition: all .15s;
}
.nav-item.active { background: var(--bg-elev); color: var(--accent); }
.nav-item:active { background: var(--bg-hover); }
.nav-icon { font-size: 18px; width: 22px; text-align: center; }
.drawer-footer { padding: 14px 20px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--border); font-size: 11px; color: var(--text-mute); }

/* ========== 主内容区 ========== */
.content {
  position: fixed; top: calc(56px + var(--safe-top)); left: 0; right: 0; bottom: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(90px + var(--safe-bottom));
}
.content::-webkit-scrollbar { width: 0; }

/* ========== 通用组件 ========== */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 12px;
}
.card-title {
  font-size: 13px; color: var(--text-dim); margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
  text-transform: uppercase; letter-spacing: .5px;
}
.card-title .more { color: var(--accent); font-size: 12px; }
.section-title {
  font-size: 18px; font-weight: 600; margin: 4px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.up { color: var(--up); }
.down { color: var(--down); }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.fdr { flex-direction: row; } .fdc { flex-direction: column; }
.f1 { flex: 1; }
.txt-r { text-align: right; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.big-num { font-size: 26px; font-weight: 600; }
.chip {
  display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px;
  background: var(--bg-elev); color: var(--text-dim); margin-right: 6px;
}
.chip.up { background: rgba(255,71,87,.18); color: var(--up); }
.chip.down { background: rgba(46,213,115,.18); color: var(--down); }
.btn {
  padding: 9px 14px; border-radius: 8px; background: var(--bg-elev); color: var(--text);
  font-size: 13px; border: 1px solid var(--border);
}
.btn:active { background: var(--bg-hover); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.input {
  width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px; outline: none;
}
.input:focus { border-color: var(--accent); }
.label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; display: block; }
.empty {
  text-align: center; padding: 40px 20px; color: var(--text-mute); font-size: 13px;
}
.empty .emoji { font-size: 40px; display: block; margin-bottom: 10px; }
.skeleton {
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-hover) 50%, var(--bg-elev) 75%);
  background-size: 200% 100%; animation: sk 1.4s infinite; border-radius: 6px;
}
@keyframes sk { to { background-position: -200% 0; } }
.markdown { font-size: 14px; line-height: 1.7; }
.markdown h1,.markdown h2,.markdown h3 { margin: 14px 0 8px; line-height: 1.4; }
.markdown h1 { font-size: 18px; } .markdown h2 { font-size: 16px; } .markdown h3 { font-size: 15px; }
.markdown p { margin: 8px 0; }
.markdown ul,.markdown ol { padding-left: 20px; margin: 8px 0; }
.markdown li { margin: 4px 0; }
.markdown code { background: var(--bg-elev); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--accent); }
.markdown pre { background: var(--bg); border: 1px solid var(--border); padding: 10px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: transparent; color: var(--text); padding: 0; }
.markdown blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--text-dim); margin: 8px 0; }
.markdown strong { color: var(--text); }
.markdown a { color: var(--accent); }
.markdown table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.markdown th,.markdown td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; font-size: 12px; }

/* ========== 浮动 AI 按钮 ========== */
.fab-ai {
  position: fixed; right: 18px; bottom: calc(22px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e14; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(255,159,67,.45); z-index: 40;
}
.fab-ai:active { transform: scale(.92); }

/* ========== AI 面板 ========== */
.ai-panel {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg-card); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0; transform: translateY(100%);
  transition: transform .3s ease; z-index: 70;
  max-height: 75vh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.ai-panel.open { transform: translateY(0); }
.ai-panel-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 65;
}
.ai-panel-mask.show { opacity: 1; pointer-events: auto; }
.ai-panel-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.ai-panel-title { font-size: 15px; font-weight: 600; }
.ai-quick {
  padding: 10px 12px 4px; display: flex; gap: 8px; overflow-x: auto; flex-wrap: nowrap;
}
.ai-quick::-webkit-scrollbar { display: none; }
.ai-quick .chip { white-space: nowrap; flex-shrink: 0; padding: 6px 12px; font-size: 12px; }
.ai-history {
  flex: 1; overflow-y: auto; padding: 10px 14px; min-height: 120px;
}
.ai-msg { margin-bottom: 12px; font-size: 13px; line-height: 1.6; }
.ai-msg.user { text-align: right; }
.ai-msg.user .bubble { background: var(--accent-2); color: #fff; display: inline-block; padding: 8px 12px; border-radius: 12px 12px 2px 12px; max-width: 85%; text-align: left; }
.ai-msg.bot .bubble { background: var(--bg-elev); padding: 10px 12px; border-radius: 12px 12px 12px 2px; max-width: 92%; }
.ai-msg.bot .bubble .markdown { font-size: 13px; }
.ai-msg.bot.loading .bubble::after { content: '思考中...'; color: var(--text-dim); animation: pulse 1s infinite; }
.ai-input-row {
  display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--border);
}
#aiInput {
  flex: 1; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 22px; color: var(--text); font-size: 14px; outline: none;
}
#aiInput:focus { border-color: var(--accent); }
.ai-send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent-2); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ai-send-btn:active { transform: scale(.92); }
.ai-send-btn:disabled { opacity: .5; }

/* ========== Toast ========== */
.toast {
  position: fixed; top: calc(70px + var(--safe-top)); left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 22px; font-size: 13px; z-index: 90;
  opacity: 0; pointer-events: none; transition: all .25s; max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========== 股票模块 ========== */
.index-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.index-cell { padding: 12px; border-radius: 10px; background: var(--bg-elev); }
.index-cell .nm { font-size: 12px; color: var(--text-dim); }
.index-cell .val { font-size: 18px; font-weight: 600; margin: 4px 0; }
.index-cell .pct { font-size: 12px; }
.stock-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.stock-item:last-child { border-bottom: none; }
.stock-item .nm { flex: 1; }
.stock-item .nm .name { font-size: 14px; }
.stock-item .nm .code { font-size: 11px; color: var(--text-mute); }
.stock-item .price { text-align: right; min-width: 80px; }
.stock-item .price .p { font-size: 15px; font-weight: 600; }
.stock-item .price .c { font-size: 11px; }

/* ========== 英语模块 ========== */
.word-card {
  background: linear-gradient(135deg, #3a2c1e, #241c14);
  border: 1px solid var(--border); border-radius: 16px; padding: 24px 18px; text-align: center;
}
.word-card .w { font-size: 30px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.word-card .ph { font-size: 14px; color: var(--text-dim); margin-bottom: 14px; font-style: italic; }
.word-card .mean { font-size: 16px; margin-bottom: 8px; }
.word-card .ex { font-size: 13px; color: var(--text-dim); padding: 10px; background: rgba(0,0,0,.2); border-radius: 8px; margin-top: 10px; }
.lesson-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 12px;
  background: var(--bg-elev); border-radius: 10px; margin-bottom: 8px;
}
.lesson-item.done { opacity: .5; }
.lesson-item .num { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--accent); }
.lesson-item.done .num { background: var(--up); color: #fff; }
.lesson-item .tt { flex: 1; font-size: 14px; }
.lesson-item .tt .sub { font-size: 11px; color: var(--text-mute); }

/* ========== 博客模块 ========== */
.blog-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.blog-item:last-child { border: none; }
.blog-item .tt { font-size: 15px; font-weight: 500; margin-bottom: 6px; line-height: 1.4; }
.blog-item .meta { font-size: 11px; color: var(--text-mute); display: flex; gap: 10px; }
.blog-item .sum { font-size: 13px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; }
.blog-tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: rgba(255,159,67,.18); color: var(--accent); }

/* ========== 设置 ========== */
.set-group { margin-bottom: 18px; }
.set-group .gt { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border: none; }
.set-row .k { font-size: 14px; }
.set-row .v { font-size: 13px; color: var(--text-dim); }
.switch { width: 42px; height: 24px; border-radius: 12px; background: var(--bg-elev); position: relative; transition: background .2s; }
.switch.on { background: var(--up); }
.switch::after { content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: left .2s; }
.switch.on::after { left: 20px; }

/* ========== 自选股管理 ========== */
.watch-add { display: flex; gap: 8px; margin-bottom: 12px; }
.watch-add .input { flex: 1; }

/* 详情弹层 */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; top: 0; z-index: 80;
  background: rgba(0,0,0,.6); display: none; align-items: flex-end;
}
.sheet.show { display: flex; }
.sheet-box {
  background: var(--bg-card); width: 100%; max-height: 90vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + var(--safe-bottom));
}
.sheet-bar { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 14px; }
.sheet-title { font-size: 17px; font-weight: 600; margin-bottom: 14px; padding-right: 30px; }
.sheet-close { position: absolute; top: 14px; right: 16px; color: var(--text-dim); }

/* 大屏适配 */
@media (min-width: 820px) {
  .content { padding: 18px 18px calc(90px + var(--safe-bottom)); }
  .index-grid { grid-template-columns: repeat(4, 1fr); }
}
