/* ============================================================
   AI 教师助手 · 设计系统
   Hand-authored CSS (no utility-framework runtime) — design tokens
   as CSS custom properties, themed via prefers-color-scheme and an
   explicit [data-theme] override for the in-app toggle.
   ============================================================ */

/* ---------- 1. Design tokens ---------- */
:root {
  --font-sans: 'Inter', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;

  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-300: #a5b4fc;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-800: #3730a3;
  --brand-900: #312e81;

  --accent-500: #d97706;
  --accent-600: #b45309;

  --ok-500: #10b981;
  --ok-600: #059669;
  --warn-500: #f59e0b;
  --danger-500: #ef4444;
  --danger-600: #dc2626;

  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --bg-subtle: #f8f9fd;
  --surface: #ffffff;
  --surface-2: #f1f2f9;
  --border: #e4e6f2;
  --border-strong: #d3d6e8;
  --text: #1c1e2b;
  --text-muted: #5b5f76;
  --text-faint: #8a8ea3;
  --text-on-brand: #ffffff;

  --shadow-sm: 0 1px 2px rgba(24, 24, 60, 0.05), 0 1px 3px rgba(24, 24, 60, 0.06);
  --shadow-md: 0 4px 14px rgba(30, 32, 70, 0.08), 0 2px 4px rgba(30, 32, 70, 0.05);
  --shadow-lg: 0 16px 40px rgba(30, 32, 70, 0.14), 0 4px 12px rgba(30, 32, 70, 0.06);
  --shadow-brand: 0 10px 24px rgba(79, 70, 229, 0.25);

  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.125rem;
  --radius-xl: 1.5rem;
  --radius-pill: 999px;

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem;

  --ease: cubic-bezier(.22,1,.36,1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1016;
    --bg-elevated: #171923;
    --bg-subtle: #14151e;
    --surface: #191b26;
    --surface-2: #21232f;
    --border: #2b2e3d;
    --border-strong: #383c4f;
    --text: #eef0f7;
    --text-muted: #a4a8bd;
    --text-faint: #71758c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow-md: 0 6px 18px rgba(0,0,0,.45);
    --shadow-lg: 0 20px 48px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1016; --bg-elevated: #171923; --bg-subtle: #14151e;
  --surface: #191b26; --surface-2: #21232f;
  --border: #2b2e3d; --border-strong: #383c4f;
  --text: #eef0f7; --text-muted: #a4a8bd; --text-faint: #71758c;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 6px 18px rgba(0,0,0,.45);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.55);
  color-scheme: dark;
}

/* ---------- 2. Reset & base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-sans); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02","cv03","cv04","cv11";
}
h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-600); }
.hidden { display: none !important; }
.only-mobile { display: none; }
svg { display: block; width: 1.1em; height: 1.1em; flex-shrink: 0; }
.icon-btn svg, .chev { width: 1.15rem; height: 1.15rem; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp .4s var(--ease) both; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.dot-pulse { display: inline-block; width: .4rem; height: .4rem; border-radius: 50%; background: currentColor; animation: pulse 1.8s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .fade-up, .dot-pulse { animation: none !important; } }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 3. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: var(--radius-md); border: 1px solid transparent;
  font-weight: 600; font-size: .875rem; cursor: pointer; transition: all .15s var(--ease);
  white-space: nowrap; background: var(--surface-2); color: var(--text);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); transform: translateY(-1px); }
.btn-accent { background: linear-gradient(135deg, var(--accent-500), var(--accent-600)); color: #fff; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand-300); color: var(--brand-600); }
.btn-danger { background: var(--danger-500); color: #fff; }
.btn-sm { padding: .42rem .75rem; font-size: .8125rem; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.file-btn { position: relative; overflow: hidden; }
.spinner {
  display: inline-block; width: .85rem; height: .85rem; border-radius: 50%; margin-right: .35rem;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .8s linear infinite; vertical-align: -1px;
}
.btn-ghost .spinner, .btn-danger.btn-ghost .spinner { border-color: var(--border-strong); border-top-color: var(--brand-600); }

/* ---------- 4. Form fields ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; }
.field-grow { flex: 1; min-width: 12rem; }
.field-label { font-size: .8125rem; font-weight: 600; color: var(--text-muted); }
.field-hint { font-size: .75rem; color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; padding: .6rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-400); box-shadow: 0 0 0 3px var(--brand-100);
}
.textarea { resize: vertical; min-height: 5rem; font-family: inherit; }
.input-sm, .select-sm { padding: .42rem .6rem; font-size: .8125rem; }
.form-card { display: flex; flex-direction: column; gap: var(--space-4); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: var(--space-4); }
.example-row { display: flex; justify-content: flex-end; margin-bottom: calc(-1 * var(--space-2)); }
.checkbox-row { display: flex; align-items: center; gap: .45rem; font-size: .8125rem; color: var(--text-muted); cursor: pointer; }
.checkbox-row input { width: 1rem; height: 1rem; accent-color: var(--brand-600); }

/* ---------- 5. Cards / badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem;
  border-radius: var(--radius-pill); font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted);
}
.badge-ok { background: rgba(16,185,129,.12); color: var(--ok-600); }
.badge-brand { background: var(--brand-50); color: var(--brand-700); }
.lock-badge { font-size: .7rem; padding: .05rem .4rem; border-radius: var(--radius-pill); background: var(--accent-500); color: #fff; margin-left: .25rem; }
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .8125rem; }
.alert-warn { background: rgba(245,158,11,.12); color: var(--accent-600); border: 1px solid rgba(245,158,11,.3); }
.empty-hint { color: var(--text-faint); font-size: .8125rem; padding: var(--space-4); text-align: center; }

/* ---------- 6. Auth screen ---------- */
.auth-screen { position: relative; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.auth-backdrop {
  position: absolute; inset: 0; background:
    radial-gradient(60% 50% at 15% 10%, rgba(99,102,241,.35), transparent 60%),
    radial-gradient(50% 40% at 90% 90%, rgba(56,189,248,.25), transparent 60%),
    #0b0c14;
}
.auth-card { position: relative; width: 100%; max-width: 26rem; background: var(--bg-elevated); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); padding: var(--space-8); display: flex; flex-direction: column; gap: var(--space-5); }
.auth-brand { display: flex; align-items: center; gap: var(--space-3); }
.auth-brand-mark { font-size: 2.25rem; }
.auth-brand h1 { font-size: 1.25rem; }
.auth-brand p { font-size: .8125rem; color: var(--text-muted); margin-top: .15rem; }
.auth-tabs { display: flex; background: var(--surface-2); border-radius: var(--radius-md); padding: .25rem; }
.auth-tab { flex: 1; padding: .5rem; border: none; background: transparent; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; color: var(--text-muted); }
.auth-tab.is-active { background: var(--bg-elevated); color: var(--brand-700); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-hint { font-size: .75rem; color: var(--text-faint); text-align: center; }

/* ---------- 7. App header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30; height: 4rem; display: flex; align-items: center;
  justify-content: space-between; padding: 0 var(--space-5); background: color-mix(in srgb, var(--bg-elevated) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.app-header-left, .app-header-right { display: flex; align-items: center; gap: var(--space-3); }
.app-brand { display: flex; align-items: center; gap: .6rem; background: none; border: none; cursor: pointer; padding: 0; }
.app-brand-mark { font-size: 1.5rem; }
.app-brand-name { font-weight: 800; font-size: 1.05rem; }
.app-brand-tag { font-size: .7rem; font-weight: 700; color: var(--brand-600); background: var(--brand-50); padding: .15rem .5rem; border-radius: var(--radius-pill); }
.icon-btn { width: 2.25rem; height: 2.25rem; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

.token-pill { display: flex; align-items: center; gap: .5rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: .3rem .7rem .3rem .3rem; cursor: pointer; }
.token-pill-tier { font-size: .7rem; font-weight: 700; background: var(--brand-600); color: #fff; padding: .2rem .55rem; border-radius: var(--radius-pill); }
.token-pill-bar { width: 4.5rem; height: .35rem; border-radius: var(--radius-pill); background: var(--border); overflow: hidden; }
.token-pill-fill { display: block; height: 100%; background: var(--brand-500); border-radius: inherit; transition: width .3s; }
.token-pill-text { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }

.user-menu-wrap { position: relative; }
.avatar-btn { width: 2.25rem; height: 2.25rem; border-radius: 50%; background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; border: none; font-weight: 700; cursor: pointer; }
.user-menu { position: absolute; right: 0; top: 2.7rem; width: 12rem; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: .4rem; z-index: 40; }
.user-menu-head { padding: .5rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; display: flex; flex-direction: column; gap: .25rem; }
.user-menu-item { display: block; width: 100%; text-align: left; padding: .5rem .6rem; border-radius: var(--radius-sm); border: none; background: none; cursor: pointer; }
.user-menu-item:hover { background: var(--surface-2); }

/* ---------- 8. Hall view (1 + N) ---------- */
.view-hall { padding: var(--space-6) var(--space-5) var(--space-10); }
.hall-wrap { max-width: 76rem; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-8); }

.hub-card { position: relative; overflow: hidden; border-radius: var(--radius-xl); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); padding: var(--space-8); }
.hub-glow { position: absolute; inset: 0; pointer-events: none; background:
  radial-gradient(38rem 20rem at 100% -10%, rgba(99,102,241,.16), transparent 60%),
  radial-gradient(30rem 16rem at -10% 120%, rgba(56,189,248,.12), transparent 60%); }
.hub-eyebrow { position: relative; display: flex; align-items: center; gap: .5rem; font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--brand-600); }
.hub-body { position: relative; margin-top: var(--space-4); display: grid; grid-template-columns: 1fr 17rem; gap: var(--space-6); align-items: center; }
.hub-label { font-size: .78rem; color: var(--text-faint); }
.hub-name-row { display: flex; align-items: center; gap: .6rem; margin-top: .1rem; }
.hub-name-row h2 { font-size: 1.7rem; }
.hub-scope { margin-top: .3rem; font-size: .85rem; color: var(--text-muted); }
.hub-meta { margin-top: var(--space-3); display: flex; flex-wrap: wrap; gap: .5rem; }
.hub-meta span { background: var(--surface-2); color: var(--text-muted); padding: .3rem .7rem; border-radius: var(--radius-md); font-size: .75rem; }
.hub-actions { display: flex; flex-direction: column; gap: .6rem; }
.hub-switch-wrap { position: relative; }
.hub-switch-menu { position: absolute; z-index: 20; right: 0; top: 2.9rem; width: 20rem; max-width: calc(100vw - 3rem); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: .5rem; max-height: 22rem; overflow-y: auto; }
.hub-switch-item { display: flex; gap: .6rem; width: 100%; text-align: left; padding: .55rem .6rem; border-radius: var(--radius-sm); border: none; background: none; cursor: pointer; }
.hub-switch-item:hover { background: var(--surface-2); }
.hub-switch-item.is-active { background: var(--brand-50); color: var(--brand-700); }

.scene-block + .scene-block { margin-top: var(--space-8); }
.scene-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem .75rem; margin-bottom: var(--space-4); }
.scene-head h3 { font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
.scene-head p { font-size: .78rem; color: var(--text-faint); }
.scene-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: var(--space-4); }
.tool-card { text-align: left; cursor: pointer; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); padding: var(--space-5); transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s; }
.tool-card:hover, .tool-card:focus-visible { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand-300); outline: none; }
.tool-card-head { display: flex; align-items: flex-start; justify-content: space-between; }
.tool-card-icon { width: 2.6rem; height: 2.6rem; border-radius: var(--radius-md); background: var(--brand-50); border: 1px solid var(--brand-100); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.tool-card h4 { margin-top: var(--space-3); font-size: .95rem; }
.tool-card .tool-tag { display: inline-block; margin-top: .35rem; font-size: .68rem; font-weight: 600; padding: .15rem .5rem; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text-muted); }
.tool-card p.tool-desc { margin-top: .5rem; font-size: .78rem; line-height: 1.5; color: var(--text-muted); }

.hall-chat-fab { position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: 25; }
.fab { display: inline-flex; align-items: center; gap: .45rem; padding: .8rem 1.2rem; border-radius: var(--radius-pill); border: none;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; font-weight: 700; box-shadow: var(--shadow-lg); cursor: pointer; }
.hall-footnote { text-align: center; font-size: .72rem; color: var(--text-faint); }

/* ---------- 9. Workspace ---------- */
.view-workspace { display: flex; height: calc(100vh - 4rem); height: calc(100dvh - 4rem); overflow: hidden; }
/* The workspace has its own scroll areas; a second page-level scrollbar makes the wheel jump between them. */
body:has(#view-workspace:not(.hidden)) { overflow: hidden; }
.ws-sidebar, .ws-main, .history-list, .chat-conv-list, .chat-messages, .roster-list, .hub-switch-menu, .modal-panel { overscroll-behavior: contain; }
.ws-sidebar { width: 18rem; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg-subtle); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; }
.ws-nav { display: flex; flex-direction: column; gap: var(--space-3); }
.ws-nav-group { display: flex; flex-direction: column; gap: .2rem; }
.ws-nav-group + .ws-nav-group { padding-top: var(--space-3); border-top: 1px solid var(--border); }
.ws-nav-group-title { font-size: .7rem; font-weight: 700; color: var(--text-faint); letter-spacing: .04em; padding: 0 .7rem .15rem; }
.ws-nav-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: var(--radius-sm); border: none; background: none; cursor: pointer; text-align: left; font-size: .85rem; color: var(--text-muted); }
.ws-nav-item:hover { background: var(--surface-2); }
.ws-nav-item.is-active { background: var(--brand-600); color: #fff; font-weight: 600; }
.ws-side-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); }
/* Never shrink below 16rem: on short screens the sidebar scrolls instead of squeezing history to nothing. */
.ws-side-card-grow { flex: 1 0 16rem; min-height: 16rem; display: flex; flex-direction: column; overflow: hidden; }
.ws-side-card-grow .history-list { flex: 1; min-height: 0; overflow-y: auto; }
.ws-side-title { font-size: .8125rem; font-weight: 700; }
.ws-side-desc { font-size: .72rem; color: var(--text-faint); margin-top: .2rem; }
.tag-container { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.tag-chip { display: inline-flex; align-items: center; gap: .3rem; background: var(--brand-50); color: var(--brand-700); padding: .2rem .55rem; border-radius: var(--radius-pill); font-size: .72rem; }
.tag-chip button { border: none; background: none; cursor: pointer; color: inherit; font-size: .85rem; line-height: 1; }
.tag-input-row { display: flex; gap: .35rem; margin-top: .5rem; }
.history-list { display: flex; flex-direction: column; gap: .3rem; margin-top: .5rem; }
.history-item { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: .5rem .6rem; border-radius: var(--radius-sm); cursor: pointer; }
.history-item:hover { background: var(--surface-2); }
.history-item-title { font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-date { font-size: .68rem; color: var(--text-faint); flex-shrink: 0; }
.history-item-del { border: none; background: none; color: var(--text-faint); cursor: pointer; flex-shrink: 0; }
.history-item-del:hover { color: var(--danger-500); }
.history-toolbar { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.history-filter-row { display: flex; gap: .4rem; }
.history-filter-row .select { flex: 1; min-width: 0; }
#history-fav { flex-shrink: 0; }
#history-fav[aria-pressed="true"] { border-color: var(--brand-400); color: var(--brand-600); }
.history-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.variation-card { padding: 1.1rem; margin-bottom: .8rem; display: flex; flex-direction: column; gap: .5rem; }
.variation-head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.variation-head { font-weight: 700; color: var(--brand-600); }
.variation-line { white-space: pre-wrap; }
.export-version { width: auto; }
.paper-preview { display: flex; flex-direction: column; gap: var(--space-4); }
.paper-head { text-align: center; display: flex; flex-direction: column; gap: .35rem; }
.paper-head h2 { font-size: 1.25rem; }
.paper-meta { font-size: .8rem; color: var(--text-muted); }
.paper-section { display: flex; flex-direction: column; gap: .6rem; }
.paper-section h3 { font-size: 1rem; border-bottom: 1px solid var(--border); padding-bottom: .35rem; }
.paper-question { padding: .7rem .9rem; border-radius: var(--radius-md); background: var(--surface-2); display: flex; flex-direction: column; gap: .35rem; }
.paper-stem { white-space: pre-wrap; line-height: 1.7; }
.paper-score { color: var(--text-muted); font-size: .85em; }
.paper-options { list-style: none; margin: 0; padding: 0 0 0 1.4rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .2rem .8rem; }
.paper-answer summary { cursor: pointer; font-size: .8rem; color: var(--brand-600); }
.paper-answer p { margin-top: .3rem; white-space: pre-wrap; font-size: .88rem; }
.history-item-fav { border: none; background: none; cursor: pointer; flex-shrink: 0; padding: 0; color: var(--text-faint); font-size: .9rem; line-height: 1; }
.history-item-fav:hover, .history-item-fav.is-on { color: #f59e0b; }

.ws-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }

.ws-main { flex: 1; overflow-y: auto; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.ws-topbar { display: flex; align-items: center; gap: var(--space-3); }
.ws-topbar-icon { font-size: 1.6rem; }
.ws-topbar-text { flex: 1; min-width: 0; }
.ws-topbar-text h2 { font-size: 1.1rem; }
.ws-topbar-text p { font-size: .78rem; color: var(--text-faint); margin-top: .1rem; }
#ws-chat-btn { flex-shrink: 0; white-space: nowrap; }
.ws-body { display: flex; flex-direction: column; gap: var(--space-5); }

.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-md); padding: var(--space-6); text-align: center; color: var(--text-muted); font-size: .8125rem; cursor: pointer; position: relative; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag-over { border-color: var(--brand-400); background: var(--brand-50); }
.lock-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--surface) 92%, transparent); border-radius: inherit; font-weight: 700; color: var(--accent-600); }
.upload-result { display: flex; align-items: center; gap: .6rem; font-size: .78rem; color: var(--text-muted); }
.file-chip-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.file-chip { display: inline-flex; align-items: center; gap: .35rem; background: var(--surface-2); padding: .3rem .55rem; border-radius: var(--radius-pill); font-size: .75rem; }
.file-chip button { border: none; background: none; cursor: pointer; color: var(--text-faint); }

.stream-status { font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: .4rem; }
.think-box { background: var(--surface-2); border-radius: var(--radius-md); padding: .6rem .8rem; font-size: .78rem; }
.think-box summary { cursor: pointer; font-weight: 600; color: var(--text-muted); }
.think-box pre { white-space: pre-wrap; margin: .5rem 0 0; color: var(--text-faint); font-family: inherit; }
.tw-caret::after { content: '▋'; animation: pulse 1s step-end infinite; }

.ws-preview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: var(--space-4); }
.ws-preview-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.ws-preview-head h3 { font-size: 1rem; }

/* ---------- 10. Markdown / rendered content ---------- */
.md-body { font-size: .9rem; line-height: 1.75; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 1.1em 0 .5em; line-height: 1.35; }
.md-body h1 { font-size: 1.3rem; color: var(--brand-700); }
.md-body h2 { font-size: 1.15rem; color: var(--brand-700); }
.md-body h3 { font-size: 1.02rem; }
.md-body p { margin: .6em 0; }
.md-body ul, .md-body ol { padding-left: 1.4em; margin: .5em 0; }
.md-body li { margin: .25em 0; }
.md-body strong { color: var(--text); font-weight: 700; }
.md-body code { background: var(--surface-2); padding: .1em .4em; border-radius: .3em; font-size: .88em; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md-body table { border-collapse: collapse; width: 100%; margin: .75em 0; font-size: .85em; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: .4em .6em; text-align: left; }
.md-body th { background: var(--surface-2); }
.chat-md { font-size: .875rem; line-height: 1.6; }
.chat-md p { margin: .3em 0; }

/* ---------- 11. Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 16rem 1fr; gap: var(--space-4); height: calc(100vh - 12rem); min-height: 26rem; }
.chat-list-col { display: flex; flex-direction: column; gap: .6rem; min-height: 0; }
.chat-conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .3rem; }
.chat-conv-item { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: .55rem .65rem; border-radius: var(--radius-sm); cursor: pointer; font-size: .8125rem; }
.chat-conv-item:hover { background: var(--surface-2); }
.chat-conv-item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.chat-conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-conv-actions { display: flex; gap: .25rem; flex-shrink: 0; opacity: 0; }
.chat-conv-item:hover .chat-conv-actions { opacity: 1; }
.chat-conv-actions button { border: none; background: none; cursor: pointer; color: var(--text-faint); font-size: .78rem; }
.chat-main-col { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.chat-empty { margin: auto; }
.chat-bubble-row { display: flex; }
.chat-bubble-row.user { justify-content: flex-end; }
.chat-bubble { max-width: 80%; padding: .65rem .9rem; border-radius: var(--radius-md); font-size: .875rem; }
.chat-bubble-row.user .chat-bubble { background: var(--brand-600); color: #fff; border-bottom-right-radius: .3rem; }
.chat-bubble-row.assistant .chat-bubble { background: var(--surface-2); border-bottom-left-radius: .3rem; }
.chat-composer { border-top: 1px solid var(--border); padding: var(--space-4); display: flex; flex-direction: column; gap: .5rem; }
.chat-input-row { display: flex; gap: .5rem; align-items: flex-end; }
.chat-input-row textarea { flex: 1; }
.chat-bubble { min-width: 0; overflow-wrap: anywhere; }
.chat-bubble table { display: block; overflow-x: auto; }
.chat-mobile-bar { display: none; }
.chat-seed { background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: var(--radius-md); padding: .5rem .75rem; font-size: .8rem; color: var(--brand-700); }
.chat-seed summary { cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.chat-seed-body { margin-top: .5rem; max-height: 14rem; overflow-y: auto; white-space: pre-wrap; color: var(--text-muted); font-size: .78rem; }
/* Touch screens have no hover, so rename / delete must always be visible. */
@media (hover: none) { .chat-conv-actions { opacity: 1; } }

/* ---------- 12. Analytics / tables ---------- */
.an-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.an-search-row { display: flex; gap: .4rem; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--space-3); }
.stat-card { background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-4); }
.stat-card .stat-value { font-size: 1.4rem; font-weight: 800; }
.stat-card .stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }
.an-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.data-table th, .data-table td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { color: var(--text-muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.pager { display: flex; align-items: center; gap: .6rem; font-size: .78rem; color: var(--text-muted); margin-top: .5rem; }

/* ---------- 13. Students ---------- */
.students-layout { display: grid; grid-template-columns: 19rem 1fr; gap: var(--space-4); align-items: start; }
.students-list-col { display: flex; flex-direction: column; gap: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); }
.stu-toolbar { display: flex; gap: .4rem; }
.roster-list { display: flex; flex-direction: column; gap: .25rem; max-height: 32rem; overflow-y: auto; }
.roster-item { padding: .55rem .65rem; border-radius: var(--radius-sm); cursor: pointer; font-size: .82rem; display: flex; justify-content: space-between; }
.roster-item:hover { background: var(--surface-2); }
.roster-item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.students-detail-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-6); min-height: 20rem; }
.timeline { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
.timeline-item { border-left: 2px solid var(--brand-200); padding-left: var(--space-3); }
.timeline-item .timeline-date { font-size: .72rem; color: var(--text-faint); }
.timeline-item .timeline-type { font-size: .72rem; font-weight: 700; color: var(--brand-600); }

/* ---------- 14. Image ---------- */
.image-result { display: flex; flex-direction: column; gap: .6rem; }
.image-result img { max-width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border); }
.image-note { font-size: .78rem; color: var(--text-muted); background: var(--surface-2); padding: .5rem .7rem; border-radius: var(--radius-sm); }

/* ---------- 15. Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,10,20,.5); backdrop-filter: blur(2px); }
.modal-panel { position: relative; width: 100%; max-width: 26rem; max-height: 88vh; overflow-y: auto; background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-panel-lg { max-width: 40rem; }
.modal-panel-xl { max-width: 60rem; }
.modal-panel-sm { max-width: 22rem; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-elevated); z-index: 1; }
.modal-close { border: none; background: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--text-faint); }
.modal-body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }

/* 新手引导 / 使用教程 */
.ob-panel { max-width: 32rem; }
.ob-kicker { font-size: .75rem; font-weight: 700; color: var(--brand-600); letter-spacing: .02em; }
.ob-body { gap: var(--space-4); min-height: 18rem; }
.ob-hero { display: flex; align-items: flex-start; gap: var(--space-4); }
.ob-icon { flex-shrink: 0; width: 3.5rem; height: 3.5rem; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; font-size: 1.75rem; background: var(--surface-2); border: 1px solid var(--border); }
.ob-icon.is-core { background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); border-color: transparent; box-shadow: var(--shadow-brand); }
.ob-core-badge { display: inline-block; margin-bottom: .25rem; padding: .1rem .5rem; border-radius: 999px; font-size: .68rem; font-weight: 700; background: var(--brand-100); color: var(--brand-700); }
.ob-title { font-size: 1.1rem; line-height: 1.35; margin-bottom: .3rem; }
.ob-desc { font-size: .84rem; line-height: 1.75; color: var(--text-muted); }
.ob-desc.is-core { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); }
.ob-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.ob-points li { display: flex; gap: .5rem; font-size: .8rem; color: var(--text-muted); }
.ob-check { color: var(--brand-600); flex-shrink: 0; }
.ob-pager { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: 0 var(--space-6) var(--space-3); }
.ob-dots { display: flex; gap: .35rem; }
.ob-dot { width: .4rem; height: .4rem; border-radius: 999px; background: var(--border-strong); transition: all .2s var(--ease); }
.ob-dot.is-active { width: 1.25rem; background: var(--brand-600); }
.ob-progress { font-size: .7rem; color: var(--text-faint); }
.ob-foot { border-top: 1px solid var(--border); background: var(--surface-2); padding: var(--space-4) var(--space-6); display: flex; flex-direction: column; gap: var(--space-3); }
.ob-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }

.recharge-current { background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-4); font-size: .82rem; }
.recharge-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: var(--space-3); }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: .5rem; }
.plan-card .plan-price { font-size: 1.3rem; font-weight: 800; color: var(--brand-700); }
.plan-card ul { margin: 0; padding-left: 1.1em; font-size: .78rem; color: var(--text-muted); }
.redeem-row { display: flex; gap: .5rem; }

.admin-section { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.admin-section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: var(--space-3); }

/* 我的 Token 用量 */
.usage-section { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.usage-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: var(--space-3); }
.usage-section-head h4 { margin: 0; font-size: .9rem; }
.usage-plot { position: relative; }
.usage-bars { display: flex; align-items: flex-end; gap: 2px; height: 9rem; border-bottom: 1px solid var(--border); }
.usage-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; }
.usage-bar { display: block; width: 100%; max-width: 1.25rem; background: var(--brand-500); border-radius: 4px 4px 0 0; transition: opacity .15s; }
.usage-bars:hover .usage-bar { opacity: .45; }
.usage-bars .usage-col:hover .usage-bar, .usage-col:focus-visible .usage-bar { opacity: 1; }
.usage-tip { position: absolute; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap; font-size: .75rem; padding: .3rem .55rem; background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); z-index: 2; }
.usage-axis { display: flex; justify-content: space-between; margin-top: .3rem; font-size: .7rem; color: var(--text-faint); }
.usage-share { display: inline-block; width: 4rem; height: .35rem; margin-right: .4rem; vertical-align: middle; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.usage-share > span { display: block; height: 100%; background: var(--brand-500); border-radius: inherit; }
.usage-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.tabs { display: flex; gap: .3rem; margin: var(--space-3) 0; }
.tab { padding: .35rem .8rem; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .78rem; }
.tab.is-active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.code-output { font-family: ui-monospace, monospace; font-size: .78rem; }

/* ---------- 16. Toasts ---------- */
#toast-wrap { position: fixed; top: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .5rem; pointer-events: none; width: max-content; max-width: calc(100vw - 2rem); }
/* Toasts are text-only: let clicks pass through so a toast never swallows a click on the button beneath it. */
.toast { pointer-events: none; padding: .6rem 1rem; border-radius: var(--radius-sm); color: #fff; font-size: .8125rem; font-weight: 600; box-shadow: var(--shadow-lg); animation: fadeUp .25s var(--ease); }
.toast-info { background: #1f2233; }
.toast-ok { background: var(--ok-600); }
.toast-err { background: var(--danger-600); }

/* ---------- 17. KaTeX tweaks ---------- */
.katex-display { overflow-x: auto; overflow-y: hidden; }

/* ---------- 18. Responsive ---------- */
@media (max-width: 1024px) {
  .hub-body { grid-template-columns: 1fr; }
  .students-layout { grid-template-columns: 1fr; }
  .roster-list { max-height: 18rem; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list-col { max-height: 12rem; }
  .chat-main-col { min-height: 22rem; }
}
@media (min-width: 769px) {
  .show-mobile { display: none !important; }
}
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .only-mobile { display: inline-flex; }
  /* iOS Safari zooms the page when focusing a field whose text is under 16px. */
  .input, .select, .textarea { font-size: 16px; }

  /* Header */
  .app-header { padding: 0 var(--space-3); gap: .5rem; }
  .app-header-left, .app-header-right { gap: .4rem; min-width: 0; }
  .app-brand-tag, .app-header-right .btn-text, .token-pill-text { display: none; }
  .token-pill { padding-right: .5rem; }
  .token-pill-bar { width: 2.5rem; }
  .auth-card { padding: var(--space-6) var(--space-5); }

  /* Hall — leave room under the last card for the floating chat button */
  .view-hall { padding: var(--space-4) var(--space-3) calc(6rem + env(safe-area-inset-bottom)); }
  .hall-wrap { gap: var(--space-6); }
  .hub-card { padding: var(--space-5); }
  .hub-name-row { flex-wrap: wrap; }
  .hub-name-row h2 { font-size: 1.35rem; }
  .hub-switch-menu { left: 0; right: 0; width: auto; max-width: none; }
  .scene-grid { grid-template-columns: 1fr; gap: var(--space-3); }
  .tool-card { padding: var(--space-4); }
  .hall-chat-fab { right: var(--space-4); bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }

  /* Workspace */
  .ws-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; width: min(18rem, 85vw); transform: translateX(-100%);
    transition: transform .25s var(--ease); box-shadow: var(--shadow-lg);
  }
  .ws-sidebar.is-open { transform: translateX(0); }
  .ws-main { padding: var(--space-3); gap: var(--space-3); }
  .ws-topbar-icon { font-size: 1.3rem; }
  .ws-topbar-text p { display: none; }
  .ws-topbar .btn-text { display: none; }
  .ws-body { gap: var(--space-3); }
  .form-card, .ws-preview { padding: var(--space-4); }
  .form-grid { grid-template-columns: 1fr; }
  .form-card > .btn-primary { width: 100%; }
  .dropzone { padding: var(--space-5) var(--space-3); }
  .md-body table { display: block; overflow-x: auto; }
  .data-table th, .data-table td { padding: .45rem .55rem; }

  /* Chat — fills the viewport; the conversation list sits behind a toggle */
  .chat-layout { display: flex; flex-direction: column; gap: .5rem; height: calc(100vh - 8.75rem); height: calc(100dvh - 8.75rem); min-height: 20rem; }
  .chat-list-col { display: none; max-height: 45%; }
  .chat-layout.list-open .chat-list-col { display: flex; }
  .chat-main-col { flex: 1; min-height: 0; }
  .chat-mobile-bar { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
  .chat-mobile-title { flex: 1; min-width: 0; font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-messages { padding: var(--space-3); }
  .chat-bubble { max-width: 92%; }
  .chat-composer { flex-direction: row; flex-wrap: wrap; gap: .4rem .9rem; padding: var(--space-3) var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .chat-input-row { flex-basis: 100%; }
  .chat-input-row .textarea { min-height: 2.75rem; }

  /* Students / analytics */
  .students-list-col, .students-detail-col { padding: var(--space-4); }
  .stu-toolbar { flex-wrap: wrap; }
  .stu-toolbar > * { flex: 1 1 8rem; }
  .an-toolbar > * { flex: 1 1 100%; }
  .an-search-row .input { flex: 1; }

  /* Modals become bottom sheets */
  .modal { padding: 0; align-items: flex-end; }
  .modal-panel { max-width: none !important; max-height: 92dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-head { padding: var(--space-4); }
  .modal-body { padding: var(--space-4) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom)); }
  .redeem-row, .admin-section-head, .pager, .tabs { flex-wrap: wrap; }
  .redeem-row .input { flex: 1 1 12rem; }
}
@media (max-width: 420px) {
  .app-brand-name, .token-pill-bar, .ws-topbar .badge { display: none; }
  .token-pill { padding: .3rem; }
}

/* ── 按档位分配模型：顶栏模型标签 / 免费版升级提示 / 充值弹窗模型对比 ── */
.model-chip { font-size: .72rem; font-weight: 700; white-space: nowrap; padding: .3rem .65rem; border-radius: var(--radius-pill); border: 1px solid var(--brand-200); background: var(--brand-50); color: var(--brand-700); cursor: pointer; }
.model-chip.is-free { border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.12); color: var(--accent-600); }
.model-notice { margin-top: .5rem; padding: .5rem .75rem; border-radius: var(--radius-sm); font-size: .78rem; background: rgba(245,158,11,.12); color: var(--accent-600); border: 1px solid rgba(245,158,11,.3); }
.link-btn { background: none; border: none; padding: 0 0 0 .35rem; font: inherit; font-weight: 700; color: var(--brand-600); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.recharge-models h4 { margin: 0 0 .5rem; font-size: .9rem; }
.model-compare th.is-current { color: var(--brand-700); }
.model-compare td.is-free { color: var(--text-muted); }
.model-compare td.is-pro { font-weight: 600; }

/* ── 🔄 文件格式转换弹窗 ── */
.convert-lock { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem .75rem; padding: .65rem 1rem; border-radius: var(--radius-sm); background: var(--brand-50); color: var(--brand-700); font-size: .8125rem; font-weight: 600; }
.convert-matrix summary { cursor: pointer; font-size: .8125rem; font-weight: 600; color: var(--text-muted); }
.convert-matrix-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .6rem; font-size: .78rem; color: var(--text-muted); }
.convert-matrix-row strong { color: var(--text); margin-right: .35rem; }
