/* =========================================================
   Homework Tutor Design System — soft kid-friendly + pro
   Shared by student SPA and admin backend
   ========================================================= */
:root {
  --bg: #f4f7fb;
  --bg-soft: #eef3fa;
  --bg-deep: #0b1220;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --card: #ffffff;
  --card-hover: #f1f5f9;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-2: #8b5cf6;
  --accent-3: #06b6d4;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --accent-2-soft: rgba(139, 92, 246, 0.12);
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 10px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.10);
  --sidebar-w: 268px;
  --focus: 0 0 0 3px rgba(59, 130, 246, 0.28);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: var(--font);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(59,130,246,.18), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(139,92,246,.14), transparent 50%),
    radial-gradient(600px 300px at 50% 100%, rgba(6,182,212,.08), transparent 45%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; box-shadow: var(--focus);
}

/* ---- Layout ---- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: rgba(255,255,255,.82);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  backdrop-filter: blur(14px);
  position: sticky; top: 0; height: 100vh; overflow: auto;
  z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; padding: 4px 8px 12px; }
.brand-badge {
  width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; color: #fff;
  box-shadow: 0 8px 20px rgba(59,130,246,.35);
  letter-spacing: .02em;
}

.brand-logo {
  width: 44px; height: 44px; border-radius: 14px;
  box-shadow: 0 8px 20px rgba(59,130,246,.35);
  object-fit: cover; display: block; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand-logo.sm { width: 36px; height: 36px; border-radius: 11px; }

.brand h1 { font-size: 16px; margin: 0; letter-spacing: .01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px; color: var(--muted);
  border: 1px solid transparent; transition: .15s ease; font-weight: 560;
}
.nav a:hover { background: var(--card-hover); color: var(--text); }
.nav a.active {
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft));
  color: var(--text); border-color: rgba(59,130,246,.22);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
}
.nav .icon {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--bg-soft); color: var(--accent);
  flex: 0 0 auto;
}
.nav a.active .icon {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.nav .icon svg { width: 16px; height: 16px; display: block; }
.main { padding: 28px 32px 56px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 28px; letter-spacing: -.02em; font-weight: 780; }
.topbar .meta { color: var(--muted); font-size: 14px; margin-top: 4px; }

.mobile-bar {
  display: none; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.icon-btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; color: var(--text); box-shadow: var(--shadow);
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 15;
}

/* ---- Surfaces ---- */
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 999px; background: var(--ok-soft);
  color: #047857; border: 1px solid rgba(16,185,129,.28); font-size: 13px; font-weight: 600;
}
.pill.warn { background: var(--warn-soft); color: #b45309; border-color: rgba(245,158,11,.3); }
.pill.danger { background: var(--danger-soft); color: #b91c1c; border-color: rgba(239,68,68,.3); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  transition: .18s ease;
}
.card:hover { transform: translateY(-2px); border-color: rgba(59,130,246,.28); box-shadow: var(--shadow-lg); }
.card h3 { margin: 0 0 8px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.card .actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.card-icon {
  width: 36px; height: 36px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft));
  color: var(--accent); flex: 0 0 auto;
}
.card-icon svg { width: 18px; height: 18px; }

.btn {
  appearance: none; border: none; cursor: pointer;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  color: #fff; font-weight: 700; padding: 10px 16px; border-radius: var(--radius-xs);
  box-shadow: 0 8px 18px rgba(59,130,246,.28);
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(59,130,246,.34); }
.btn.secondary {
  background: var(--surface); color: var(--text-soft); border: 1px solid var(--border-strong);
  font-weight: 650; box-shadow: none;
}
.btn.secondary:hover { background: var(--card-hover); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; border: 1px solid transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

.panel {
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
input, textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-xs); padding: 11px 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:hover, textarea:hover, select:hover { border-color: rgba(59,130,246,.35); }
input:focus, textarea:focus, select:focus { background: #fff; border-color: rgba(59,130,246,.55); }
textarea { min-height: 110px; resize: vertical; }

.video-wrap {
  position: relative; background: linear-gradient(180deg, #0f172a, #1e293b);
  border-radius: 16px; overflow: hidden;
  aspect-ratio: 16/10; border: 1px solid var(--border); display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}
.video-wrap video, .video-wrap canvas, .video-wrap img {
  width: 100%; height: 100%; object-fit: cover;
}
.video-wrap .placeholder {
  color: rgba(248,250,252,.78); text-align: center; padding: 28px; line-height: 1.6;
}
.video-wrap .placeholder .muted { color: rgba(148,163,184,.95); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 650;
  background: var(--accent-soft); color: #1d4ed8; border: 1px solid rgba(59,130,246,.18);
}
.badge.admin { color: #6d28d9; border-color: rgba(139,92,246,.28); background: var(--accent-2-soft); }
.badge.student { color: #0369a1; }
.badge.off { color: #b91c1c; border-color: rgba(239,68,68,.28); background: var(--danger-soft); }
.stat { font-size: 28px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
.muted { color: var(--muted); }
.pre, .code {
  background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 12px 14px; overflow: auto;
  font-family: var(--mono); font-size: 12px; border: 1px solid rgba(148,163,184,.18);
  white-space: pre-wrap; line-height: 1.55;
}
.alert {
  padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(245,158,11,.28);
  background: var(--warn-soft); color: #92400e; font-size: 14px; font-weight: 560;
}
.alert.ok { border-color: rgba(16,185,129,.28); background: var(--ok-soft); color: #047857; }
.alert.danger { border-color: rgba(239,68,68,.28); background: var(--danger-soft); color: #b91c1c; }
.steps { margin: 0; padding-left: 18px; color: var(--text-soft); }
.steps li { margin: 8px 0; }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi .card { padding: 16px; }
.kpi .muted { font-size: 12px; font-weight: 650; text-transform: none; letter-spacing: .02em; }

.empty, .loading {
  display: grid; place-items: center; text-align: center; gap: 8px;
  padding: 36px 20px; color: var(--muted); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); background: rgba(255,255,255,.55);
}
.loading::before {
  content: ""; width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(59,130,246,.2); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin-bottom: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.module-hero {
  display: flex; gap: 14px; align-items: flex-start; margin-bottom: 4px;
}
.answer-box {
  background: linear-gradient(180deg, #f8fafc, #eef2ff);
  border: 1px solid rgba(99,102,241,.18);
  border-radius: 14px; padding: 14px 16px; color: var(--text-soft);
  white-space: pre-wrap; line-height: 1.7; font-size: 15px;
}
.score-ring {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-size: 32px; font-weight: 800; color: var(--accent);
}
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.footer-note { margin-top: 18px; color: var(--muted); font-size: 12px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-bar { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw, 300px);
    transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main { padding: 16px 16px 40px; }
  .topbar h2 { font-size: 24px; }
}
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .row .btn, .row .btn.secondary { width: auto; }
}


/* ---- 拍照批改 close-up guide frame ---- */
.video-wrap.closeup-mode { aspect-ratio: 3/4; max-height: 72vh; }
.guide-frame {
  position: absolute; inset: 10% 8%;
  border: 3px dashed rgba(56, 189, 248, 0.95);
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.42), inset 0 0 0 1px rgba(255,255,255,.15);
  pointer-events: none;
  animation: guide-pulse 1.8s ease-in-out infinite;
}
.guide-tips {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.82); color: #f8fafc;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
  letter-spacing: .02em; pointer-events: none; white-space: nowrap;
  border: 1px solid rgba(56,189,248,.35);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.posture-canvas-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important;
  opacity: 0; pointer-events: none; overflow: hidden;
}
@keyframes guide-pulse {
  0%, 100% { border-color: rgba(56,189,248,.95); }
  50% { border-color: rgba(167,139,250,.95); }
}

/* voice interaction */
.voice-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--border); background: rgba(255,255,255,.72);
}
.voice-bar.listening {
  border-color: rgba(59,130,246,.38);
  background: linear-gradient(180deg, #eff6ff, #f8fafc);
  box-shadow: 0 0 0 3px rgba(59,130,246,.08);
}
.voice-indicator {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 650; color: var(--text-soft); font-size: 14px;
}
.voice-dot {
  width: 12px; height: 12px; border-radius: 50%; background: #94a3b8; flex: 0 0 auto;
}
.voice-dot.pulse {
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239,68,68,.55);
  animation: voice-pulse 1.2s ease-out infinite;
}
@keyframes voice-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70% { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}


/* ---- posture soft kid alerts + session timer ---- */
.session-timer {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(56,189,248,.14), rgba(167,139,250,.14));
  border: 1px solid rgba(56,189,248,.28);
  color: #0f172a; font-weight: 750; font-size: 14px;
}
.posture-toast {
  border-radius: 16px; padding: 16px 18px;
  background: linear-gradient(180deg, #fff7ed, #ffedd5);
  border: 1px solid rgba(251, 146, 60, 0.35);
  color: #9a3412; box-shadow: var(--shadow);
}
.posture-toast.break { background: linear-gradient(180deg, #ecfeff, #e0f2fe); border-color: rgba(14,165,233,.35); color: #075985; }
.posture-toast-title { font-weight: 800; font-size: 16px; margin-bottom: 4px; }
.alert.soft-kid { border-radius: 14px; font-weight: 650; }
.alert.warn-soft { border-color: rgba(56,189,248,.35); background: rgba(224,242,254,.85); color: #075985; }


/* ---- homework workflow (grades 1-6) ---- */
.grade-picker {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 14px;
  background: linear-gradient(180deg, #eff6ff, #f8fafc);
  border: 1px solid rgba(59,130,246,.18);
}
.grade-chip {
  border: 1px solid var(--border); background: #fff; color: var(--text-soft);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; cursor: pointer;
}
.grade-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: 0 8px 18px rgba(59,130,246,.28);
}
.hw-progress {
  font-weight: 800; font-size: 15px; color: var(--accent);
}
.hw-thumb {
  max-width: 220px; max-height: 160px; border-radius: 12px;
  border: 1px solid var(--border); object-fit: cover;
  box-shadow: var(--shadow);
}
.hanzi-card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 14px; box-shadow: var(--shadow);
}
.hanzi-host {
  display: grid; place-items: center; min-height: 260px;
  background:
    linear-gradient(#e2e8f0 1px, transparent 1px) 0 0 / 100% 50%,
    linear-gradient(90deg, #e2e8f0 1px, transparent 1px) 0 0 / 50% 100%,
    #f8fafc;
  border-radius: 12px; border: 1px dashed rgba(148,163,184,.8);
}
.tutoring-grade-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
.btn.ghost {
  background: transparent; color: var(--muted); border: 1px dashed var(--border-strong);
}
.btn.ghost:hover { color: var(--text); background: var(--card-hover); }
.alert.soft-kid.warn-soft { font-weight: 650; }
