/* ============ 简记 · 极简矢量风格 ============ */
:root {
  --accent: #4F46E5;
  --accent-soft: #EEF2FF;
  --ink: #1F2937;
  --ink-2: #6B7280;
  --ink-3: #9CA3AF;
  --line: #E5E7EB;
  --bg: #FFFFFF;
  --bg-2: #F9FAFB;
  --danger: #DC2626;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(31,41,55,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }
.safe-top { padding-top: max(10px, env(safe-area-inset-top)); }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 500;
  transition: opacity .15s, background .15s;
}
.btn:active { opacity: .75; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.danger { color: var(--danger) !important; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px; color: var(--ink-2);
}
.icon-btn:active { background: var(--bg-2); }

/* ---------- 登录 ---------- */
#view-auth { align-items: center; justify-content: center; background: var(--bg-2); }
.auth-card {
  width: min(360px, calc(100vw - 48px)); background: var(--bg);
  border: 1px solid var(--line); border-radius: 20px; padding: 36px 28px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.auth-logo { width: 56px; height: 56px; margin: 0 auto; }
.auth-card h1 { text-align: center; font-size: 24px; font-weight: 700; letter-spacing: 2px; }
.auth-sub { text-align: center; color: var(--ink-2); font-size: 13px; margin-bottom: 8px; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.field input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; outline: none; background: var(--bg);
}
.field input:focus { border-color: var(--accent); }
.auth-msg { font-size: 12px; color: var(--danger); min-height: 16px; text-align: center; }
.auth-tip { font-size: 11px; color: var(--ink-3); text-align: center; line-height: 1.6; }

/* ---------- 主页 ---------- */
.home-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.home-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.home-actions { display: flex; align-items: center; gap: 8px; }
.home-user { font-size: 13px; color: var(--ink-2); }

.home-body { flex: 1; display: flex; overflow: hidden; }
.folder-panel {
  width: 210px; border-right: 1px solid var(--line); background: var(--bg-2);
  display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 6px; font-size: 12px; color: var(--ink-2); font-weight: 600;
}
.folder-list { list-style: none; padding: 4px 8px; }
.folder-list li {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px;
  border-radius: 9px; font-size: 14px; cursor: pointer; color: var(--ink);
}
.folder-list li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-list li .f-count { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.folder-list li .f-del { display: none; color: var(--ink-3); padding: 2px; }
.folder-list li:hover .f-del { display: inline-flex; }
.folder-list li svg { flex-shrink: 0; }

.notes-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.notes-toolbar { display: flex; gap: 10px; padding: 12px 16px; align-items: center; }
.search-box {
  flex: 1; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--ink-3);
}
.search-box input { flex: 1; border: none; outline: none; font-size: 14px; background: transparent; }
.note-list { list-style: none; flex: 1; overflow-y: auto; padding: 0 16px 24px; }
.note-list li {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer; background: var(--bg);
  transition: border-color .15s;
}
.note-list li:active { border-color: var(--accent); }
.note-item-top { display: flex; align-items: baseline; gap: 8px; }
.note-item-title { font-size: 15px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-time { font-size: 11px; color: var(--ink-3); flex-shrink: 0; }
.note-item-preview {
  margin-top: 6px; font-size: 13px; color: var(--ink-2); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.note-item-tags { margin-top: 8px; display: flex; gap: 6px; }
.tag {
  font-size: 11px; color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 20px;
}
.empty-hint {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--ink-3); font-size: 14px; padding-bottom: 60px;
}
.ios-tip {
  position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 8px 12px 16px;
  font-size: 13px; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); z-index: 60;
}
.ios-tip b { color: #A5B4FC; }
.ios-tip .icon-btn { color: #fff; flex-shrink: 0; }

/* ---------- 编辑器 ---------- */
.ed-top {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.note-title {
  flex: 1; min-width: 60px; border: none; outline: none; font-size: 16px; font-weight: 600;
  padding: 6px 4px; background: transparent;
}
.save-state { font-size: 11px; color: var(--ink-3); flex-shrink: 0; white-space: nowrap; }
.lang-select {
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px;
  font-size: 12px; background: var(--bg); outline: none; color: var(--ink-2);
}
.rec-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 20px; padding: 7px 12px;
  font-size: 13px; color: var(--ink); background: var(--bg); flex-shrink: 0;
}
.rec-btn.on {
  background: #FEF2F2; border-color: #FECACA; color: var(--danger);
}
.rec-btn.on svg { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.fmt-bar {
  display: flex; align-items: center; gap: 2px; padding: 6px 10px;
  border-bottom: 1px solid var(--line); overflow-x: auto; background: var(--bg);
  scrollbar-width: none;
}
.fmt-bar::-webkit-scrollbar { display: none; }
.fmt-bar button {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 10px;
  border-radius: 8px; font-size: 13px; color: var(--ink-2); flex-shrink: 0;
}
.fmt-bar button:active { background: var(--bg-2); }
.fmt-sep { width: 1px; height: 18px; background: var(--line); margin: 0 6px; flex-shrink: 0; }
.hl-dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--c);
  border: 1px solid rgba(0,0,0,.08); flex-shrink: 0; margin: 0 3px;
}

/* 康奈尔布局 */
.cornell { flex: 1; display: flex; overflow: hidden; }
.cue-pane {
  width: 26%; min-width: 130px; max-width: 300px;
  border-right: 1.5px solid var(--accent); background: var(--bg-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.notes-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pane-label {
  padding: 8px 14px 4px; font-size: 11px; font-weight: 700; color: var(--accent);
  letter-spacing: 1px; flex-shrink: 0;
}
.pane-hint { font-weight: 400; color: var(--ink-3); letter-spacing: 0; margin-left: 4px; }
.cue-pane .editable { flex: 1; overflow-y: auto; padding: 8px 14px 40px; font-size: 13.5px; }
.notes-scroll { flex: 1; overflow-y: auto; position: relative; }
#notesEl { min-height: 100%; padding: 8px 16px 120px; font-size: 15px; }
.summary-pane {
  border-top: 1.5px solid var(--accent); background: var(--bg);
  max-height: 26vh; display: flex; flex-direction: column; flex-shrink: 0;
}
.summary-pane .editable { flex: 1; overflow-y: auto; padding: 6px 16px calc(10px + env(safe-area-inset-bottom)); font-size: 14px; }

.editable { outline: none; line-height: 1.75; word-break: break-word; -webkit-user-select: text; user-select: text; }
.editable:empty::before { content: attr(data-ph); color: var(--ink-3); font-size: .92em; }
.editable p { margin: 0 0 4px; }
.editable ul, .editable ol { padding-left: 22px; margin: 4px 0; }
.ts {
  display: inline-block; font-size: 11px; color: var(--accent); background: var(--accent-soft);
  border-radius: 6px; padding: 1px 7px; margin-right: 6px; user-select: none;
}
.anno {
  border-bottom: 2px dotted var(--accent); cursor: pointer;
  background: rgba(79,70,229,.06);
}

#inkCanvas {
  position: absolute; top: 0; left: 0; width: 100%;
  pointer-events: none; z-index: 5;
}
.ink-on #inkCanvas { pointer-events: auto; touch-action: none; }
.ink-on #notesEl { -webkit-user-select: none; user-select: none; }

/* 实时字幕条 */
.live-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(28vh + 12px); max-width: min(560px, calc(100vw - 32px));
  background: rgba(31,41,55,.92); color: #F9FAFB; border-radius: 14px;
  padding: 10px 16px; font-size: 13.5px; line-height: 1.5; z-index: 40;
  display: flex; align-items: center; gap: 10px; backdrop-filter: blur(6px);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #F87171;
  animation: pulse 1.2s infinite; flex-shrink: 0;
}
#liveText { max-height: 60px; overflow: hidden; }

/* 选中浮动条 */
.sel-bar {
  position: fixed; z-index: 50; display: flex; align-items: center; gap: 2px;
  background: var(--ink); border-radius: 12px; padding: 5px 7px; box-shadow: var(--shadow);
}
.sel-bar button {
  color: #E5E7EB; font-size: 13px; padding: 6px 9px; border-radius: 8px; flex-shrink: 0;
}
.sel-bar button:active { background: rgba(255,255,255,.14); }
.sel-bar .hl-dot { width: 18px; height: 18px; padding: 0; }

/* 批注弹层 */
.anno-pop {
  position: fixed; z-index: 55; width: min(300px, calc(100vw - 40px));
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px;
}
.anno-text { font-size: 13.5px; line-height: 1.6; color: var(--ink); white-space: pre-wrap; }
.anno-ops { display: flex; justify-content: flex-end; gap: 4px; margin-top: 10px; }

/* 手写工具条 */
.ink-tools {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom)); z-index: 45;
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px;
  padding: 8px 12px; box-shadow: var(--shadow); max-width: calc(100vw - 20px); overflow-x: auto;
}
.ink-tools button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: var(--ink-2); flex-shrink: 0;
}
.ink-tools button.active { background: var(--accent-soft); color: var(--accent); }
.ink-color { width: 22px !important; height: 22px !important; border-radius: 50% !important; background: var(--c); border: 2px solid transparent; }
.ink-color.active { border-color: var(--accent); box-shadow: 0 0 0 2px #fff inset; }
#inkSize { width: 70px; accent-color: var(--accent); }
.pen-only { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.pen-only input { accent-color: var(--accent); }
#inkDone { width: auto !important; padding: 6px 14px; }

/* 更多菜单 */
.more-menu {
  position: fixed; z-index: 55; right: 10px; top: calc(52px + env(safe-area-inset-top));
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; min-width: 170px;
}
.more-menu button {
  display: block; width: 100%; text-align: left; padding: 12px 18px; font-size: 14px;
}
.more-menu button:active { background: var(--bg-2); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(80px, calc(env(safe-area-inset-bottom) + 70px)); z-index: 99;
  background: rgba(31,41,55,.92); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 20px; max-width: 80vw; text-align: center;
}

/* ---------- 云同步 ---------- */
.sync-chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 11px;
  font-size: 12px; color: var(--ink-2); background: var(--bg); cursor: pointer;
}
.sync-chip .sync-ic { width: 15px; height: 15px; }
.sync-chip.ok { color: #059669; border-color: #A7F3D0; background: #ECFDF5; }
.sync-chip.busy { color: var(--accent); border-color: #C7D2FE; background: var(--accent-soft); }
.sync-chip.err { color: var(--danger); border-color: #FECACA; background: #FEF2F2; }
.sync-chip.busy .sync-ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-mask {
  position: fixed; inset: 0; background: rgba(31,41,55,.4); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: min(420px, 100%); background: var(--bg); border-radius: 18px;
  padding: 24px; box-shadow: var(--shadow); max-height: 86vh; overflow-y: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.modal .modal-sub { font-size: 12px; color: var(--ink-2); line-height: 1.6; margin-bottom: 16px; }
.sync-sec { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.sync-sec h4 { font-size: 13px; margin-bottom: 8px; }
.sync-sec p { font-size: 12px; color: var(--ink-2); line-height: 1.6; margin-bottom: 10px; }
.sync-code-row { display: flex; gap: 8px; }
.sync-code-row input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 10px; font-size: 13px; outline: none; font-family: ui-monospace, monospace;
}
.sync-code-row input:focus { border-color: var(--accent); }
.sync-code-view {
  font-family: ui-monospace, monospace; font-size: 13px; background: var(--bg-2);
  border-radius: 9px; padding: 10px 12px; word-break: break-all; margin-bottom: 10px;
  user-select: all; -webkit-user-select: all;
}
.sync-meta { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.modal-close { position: sticky; float: right; margin: -6px -6px 0 0; }

/* ---------- AI 高亮 / 总结（不改写原文） ---------- */
mark.ai-hl {
  background: #DBEAFE; color: inherit; border-radius: 3px; padding: 0 1px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.ai-sum {
  border-left: 3px solid var(--accent); padding-left: 9px;
  margin: 0 0 6px !important; color: var(--ink);
}
.fmt-bar button.loading { opacity: .55; pointer-events: none; }
.fmt-bar button.loading::after {
  content: ''; width: 12px; height: 12px; display: inline-block;
  border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%;
  margin-left: 6px; vertical-align: -2px; animation: spin .8s linear infinite;
}
.icon-btn .lang-txt { font-size: 11px; font-weight: 700; line-height: 1; }

/* ---------- iPad / 桌面横屏三栏版式 ---------- */
@media (min-width: 1000px) {
  /* 编辑器：线索 | 笔记 | 总结 三栏 */
  #view-editor {
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-columns: minmax(0, 1fr) clamp(240px, 26vw, 340px);
  }
  #view-editor .ed-top { grid-column: 1 / -1; }
  #view-editor .fmt-bar { grid-column: 1 / -1; }
  #view-editor .cornell { grid-column: 1; grid-row: 3; min-height: 0; }
  #view-editor .summary-pane {
    grid-column: 2; grid-row: 3;
    max-height: none; border-top: none; border-left: 1.5px solid var(--accent);
    background: var(--bg-2);
  }
  .cue-pane { width: 24%; min-width: 170px; }
  #notesEl { font-size: 16px; padding: 10px 26px 140px; max-width: 860px; }
  .cue-pane .editable { font-size: 14px; }
  .summary-pane .editable { font-size: 14.5px; }
  .pane-label { padding-top: 12px; font-size: 12px; }
  .live-bar { bottom: 24px; left: calc((100vw - clamp(240px, 26vw, 340px)) / 2); }
  .ink-tools { bottom: 20px; left: calc((100vw - clamp(240px, 26vw, 340px)) / 2); }
  .fmt-bar button { padding: 8px 12px; font-size: 14px; }
  .ed-top { padding: 10px 16px; gap: 10px; }
  .rec-btn { padding: 8px 16px; font-size: 14px; }

  /* 主页：笔记卡片双列 */
  .note-list {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start;
  }
  .note-list li { margin-bottom: 0; }
  .folder-panel { width: 240px; }
  .notes-toolbar { padding: 16px 20px; }
  .note-list { padding: 0 20px 24px; }
}
@media (min-width: 1400px) {
  .note-list { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 720px) {
  .folder-panel { width: 150px; }
  .home-user { display: none; }
}
@media (max-width: 560px) {
  .home-body { flex-direction: column; }
  .folder-panel {
    width: 100%; flex-direction: row; border-right: none; border-bottom: 1px solid var(--line);
    overflow-x: auto; overflow-y: hidden; align-items: center; padding: 0 6px;
  }
  .panel-head { padding: 10px 8px; flex-shrink: 0; }
  .panel-head span { display: none; }
  .folder-list { display: flex; padding: 8px 4px; gap: 4px; }
  .folder-list li { white-space: nowrap; flex-shrink: 0; padding: 7px 12px; }
  .folder-list li .f-count { margin-left: 6px; }
  .folder-list li .f-del { display: none !important; }

  .cornell { flex-direction: column; }
  .cue-pane {
    width: 100%; max-width: none; min-width: 0;
    border-right: none; border-bottom: 1.5px solid var(--accent);
    max-height: 22vh; min-height: 72px;
  }
  .lang-select { font-size: 11px; }
  .save-state { display: none; }
  .live-bar { bottom: calc(24vh + 10px); }
}
