.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 4px 2px;
  cursor: pointer;
  user-select: none;
  border-radius: 8px;
}
.brand-logo:hover { background: var(--surface-soft); }
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.brand-text strong { display: block; font-size: 0.9688rem; font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; color: var(--ink); }
.brand-text span { display: block; font-size: 0.6875rem; letter-spacing: 0.04em; color: var(--muted); }
.side-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.app-topbar {
  flex: none;
  z-index: 48;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  width: 100%;
  height: 56px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-topbar .btn { white-space: nowrap; flex-shrink: 0; }
.focus-bar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.focus-title { font-size: 0.875rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }

.top-nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.top-nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8438rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.14s ease, color 0.14s ease;
}
.top-nav-btn:hover { background: var(--surface-soft); color: var(--ink); }
.top-nav-btn.active { background: var(--accent-soft); color: var(--accent-fg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent); }

.admin-subbar {
  flex: none;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}
.admin-subbar-inner {
  width: 100%;
  padding: 8px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow-x: auto;
  white-space: nowrap;
}
.admin-sub-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.admin-sub-btn:hover { background: var(--surface); color: var(--ink); }
.admin-sub-btn.active { background: var(--surface); border-color: var(--line); color: var(--accent-fg); box-shadow: var(--shadow-sm); }

.announcement-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 28px; background: var(--accent-soft); color: var(--accent-fg);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 24%, transparent); font-size: 0.8125rem; font-weight: 500;
}
body.focus-mode .announcement-bar, body.immersive-mode .announcement-bar { display: none !important; }

.bank-select-inline {
  padding: 4px 10px;
  font-size: 0.8125rem;
  font-weight: 700;
  border-radius: 8px;
  background: var(--surface-soft);
  max-width: 240px;
}

.user-menu-wrap { position: relative; }
.avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px 4px 5px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.avatar-btn:hover { border-color: var(--accent); }
.avatar-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 28px;
}
.app-main.practice-full { padding: 14px 28px; }

.app-footer {
  flex: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 28px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

/* 刷题工作台 */
.practice-shell { width: 100%; }
.practice-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.toolbar-bank-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
  padding: 4px 8px 4px 2px;
}
.toolbar-sub-select { padding: 4px 9px; font-size: 0.7813rem; border-radius: 8px; }
.mode-pills {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 100%;
  overflow-x: auto;
}
.mode-pill {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.7813rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.14s ease, color 0.14s ease;
}
.mode-pill:hover { color: var(--ink); }
.mode-pill.active { background: var(--surface-hover); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.practice-layout {
  display: grid;
  grid-template-columns: var(--notes-w, 280px) 12px minmax(0, 1fr) 12px var(--aside-w, 332px);
  gap: 0;
  align-items: start;
}

.question-box {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 32px;
  box-shadow: var(--shadow-sm);
}
.q-progress-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: transparent;
}
.q-progress-track > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.q-title { font-size: 1.1563rem; font-weight: 600; margin: 16px 0 20px; white-space: pre-wrap; line-height: 1.72; }
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.option-item:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.option-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.option-item.correct { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.option-item.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.opt-key {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}
.answer-box {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.practice-aside {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  border-radius: 14px;
}
.aside-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-soft);
  border-radius: 9px;
  margin-bottom: 12px;
}
.aside-tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.7813rem;
  font-weight: 600;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
}
.aside-tab-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  margin: 10px 0;
  font-variant-numeric: tabular-nums;
}
.sheet-cell {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  height: 34px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.sheet-cell:hover:not(.current):not(.ok):not(.bad) { border-color: var(--line-strong); background: var(--surface-soft); }
.sheet-cell.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.sheet-cell.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.sheet-cell.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.sheet-settings { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.sheet-settings summary { cursor: pointer; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.note-textarea { width: 100%; min-height: 140px; resize: vertical; line-height: 1.6; }
.note-history-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.note-history-item {
  text-align: left; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface-soft); cursor: pointer; font: inherit; font-size: 0.75rem; color: var(--ink);
}

/* 统计页专属栅格 & 导题分栏 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-icon { width: 28px; height: 28px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-soft); color: var(--muted); }
.kpi-val { font-size: 1.5rem; font-weight: 800; margin-top: 4px; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.kpi-card.is-clickable { cursor: pointer; transition: border-color .15s ease; }
.kpi-card.is-clickable:hover { border-color: var(--accent); }
.chart-stage {
  display: flex; align-items: flex-end; gap: 4px; height: 152px; padding: 14px 8px 6px; margin-top: 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft);
  background-image: linear-gradient(to bottom, var(--line) 1px, transparent 1px); background-size: 100% 50%;
}
.chart-col { flex: 1; min-width: 5px; height: 100%; display: flex; align-items: flex-end; cursor: pointer; padding: 0 1px; }
.chart-bar { width: 100%; border-radius: 4px 4px 1px 1px; background: var(--line); transition: opacity .12s ease, transform .12s ease; }
.chart-bar.has-val { background: var(--accent); opacity: .78; }
.chart-col:hover .chart-bar.has-val, .chart-col.active .chart-bar.has-val { opacity: 1; transform: scaleY(1.03); transform-origin: bottom; }
.chart-col.active .chart-bar:not(.has-val) { background: var(--line-strong); }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 0.7188rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rank-head-meta { display: inline-flex; align-items: center; gap: 4px; }
.rank-reveal-btn { padding: 2px 5px; color: var(--muted); }
.rank-reveal-btn.is-on { color: var(--accent-fg); }
.rank-list { display: flex; flex-direction: column; gap: 6px; max-height: 224px; overflow-y: auto; padding-right: 2px; }
.rank-row { padding: 7px 9px; border-radius: 8px; border: 1px solid transparent; display: flex; flex-direction: column; gap: 5px; }
.rank-row.is-me { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.rank-track { height: 3px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.rank-track > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.hot-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); }
.hot-row:first-child { border-top: 0; }
.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 14px;
}
.stats-grid > *,
.practice-layout > *,
.split-workbench > * {
  min-width: 0;
}
.split-workbench { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.split-col { display: flex; flex-direction: column; min-height: 0; }
.workbench-textarea {
  width: 100%; flex: 1; min-height: 0; resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8125rem; line-height: 1.5;
}
.preview-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

/* 专注态与沉浸模式 */
body.focus-mode .top-nav,
body.focus-mode #go-home,
body.focus-mode #admin-subbar,
body.focus-mode .app-footer,
body.focus-mode .mobile-tabbar { display: none !important; }
body.focus-mode .app-main { padding-top: 14px; }

body.immersive-mode .app-topbar,
body.immersive-mode #admin-subbar,
body.immersive-mode .app-footer,
body.immersive-mode .practice-toolbar,
body.immersive-mode .practice-notes,
body.immersive-mode .practice-aside,
body.immersive-mode .pane-resizer,
body.immersive-mode .mobile-tabbar { display: none !important; }
.immersive-bar { display: none; }
body.immersive-mode .immersive-bar { display: flex; }

.mobile-tabbar { display: none; }
.mobile-sheet-trigger, .mobile-only-btn { display: none; }

@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid, .practice-layout, .split-workbench { grid-template-columns: 1fr; }
  .practice-notes, .practice-aside, .pane-resizer, .desktop-only-btn { display: none; }
  .mobile-sheet-trigger, .mobile-only-btn { display: inline-flex; }
}

@media (max-width: 860px) {
  .topbar-inner { height: 52px; padding: 0 12px; gap: 8px; }
  .top-nav { display: none; }
  .brand-text span { display: none; }
  .admin-subbar-inner { padding: 8px 12px; }
  .topbar-right { flex-shrink: 0; }
  .topbar-right .row-gap { flex-wrap: nowrap; gap: 6px; }
  .topbar-right .btn { white-space: nowrap; }
  .app-main { overflow-y: auto; padding: 14px 12px 86px; }
  body.focus-mode .app-main { padding-bottom: 76px; }
  .app-footer { display: none; }
  .workbench-textarea { min-height: 260px; }
  .preview-scroll { max-height: 360px; }
  .mobile-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 4px 4px env(safe-area-inset-bottom);
  }
  .m-tab-btn {
    border: 0; background: transparent; color: var(--muted); font: inherit;
    font-size: 0.6875rem; font-weight: 600; padding: 8px 2px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  .m-tab-btn.active { color: var(--accent-fg); }
  .question-box { padding: 16px 14px; }
  .option-item { min-height: 44px; padding: 11px 12px; }
  .practice-nav-footer {
    position: fixed; left: 0; right: 0; bottom: calc(45px + env(safe-area-inset-bottom)); z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 8px 12px !important; margin-top: 0 !important;
  }
  body.focus-mode .practice-nav-footer,
  body.immersive-mode .practice-nav-footer {
    bottom: 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
  }
  .kbd-hint { display: none; }
}
