/* 少年宫 Python 课堂 — 主样式 */
:root {
  --color-primary: #2b6cb0;
  --color-primary-dark: #2c5282;
  --color-secondary: #718096;
  --color-success: #38a169;
  --color-danger: #e53e3e;
  --color-warning: #d69e2e;
  --color-bg: #f7fafc;
  --color-bg-card: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #2d3748;
  --color-text-light: #718096;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

/* Nav */
.main-nav {
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand a {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a {
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-links a:hover { color: var(--color-primary); }
.nav-course-sel { padding: 4px 8px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 13px; max-width: 200px; background: #fff; }

.user-name { color: var(--color-text-light); font-size: 0.9rem; }

.btn-link {
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  font: inherit;
}
.btn-link:hover { color: var(--color-primary); }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius);
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.15s;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-secondary); color: white; }
.btn-success { background: var(--color-success); color: white; }
.btn-danger { background: var(--color-danger); color: white; }

/* Hero */
.hero { text-align: center; padding: 3rem 0; }
.hero h1 { font-size: 2.5rem; margin-bottom: 1rem; }
.hero .lead { font-size: 1.1rem; color: var(--color-text-light); margin-bottom: 2rem; }
.cta { display: flex; gap: 1rem; justify-content: center; }

/* Features */
.features { margin-top: 4rem; }
.features h2 { font-size: 1.8rem; margin-bottom: 1.5rem; }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}
.feature-card {
  background: var(--color-bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}
.feature-card h3 { color: var(--color-primary); margin-bottom: 0.5rem; }

/* Error page */
.error-page { text-align: center; padding: 3rem 0; }
.error-page h1 { font-size: 5rem; color: var(--color-danger); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-text-light);
  font-size: 0.85rem;
  border-top: 1px solid var(--color-border);
}

/* Alert */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-success { background: #c6f6d5; color: #22543d; border: 1px solid #9ae6b4; }
.alert-danger { background: #fed7d7; color: #742a2a; border: 1px solid #feb2b2; }
.alert-info { background: #bee3f8; color: #2a4365; border: 1px solid #90cdf4; }

/* Auth page */
.auth-page { max-width: 500px; }
.auth-form { background: var(--color-bg-card); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-form .btn { margin-right: 0.5rem; }

/* Dashboard */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; margin-top: 2rem; }
.dashboard-card { background: var(--color-bg-card); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--color-border); box-shadow: var(--shadow); }
.dashboard-card h2 { color: var(--color-primary); margin-bottom: 0.5rem; font-size: 1.15rem; }
.dashboard-card h2 a { color: inherit; text-decoration: none; }
.dashboard-card h2 a:hover { text-decoration: underline; }
.placeholder { color: var(--color-warning); font-size: 0.85rem; margin-top: 0.5rem; font-style: italic; }

/* Card section */
.card { background: var(--color-bg-card); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--color-border); box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card h2 { margin-bottom: 1rem; font-size: 1.15rem; }

.inline-form { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.data-table th, .data-table td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.data-table th { background: var(--color-bg); font-weight: 600; }
.data-table .empty { text-align: center; color: var(--color-text-light); padding: 2rem; }
code { background: var(--color-bg); padding: 0.1rem 0.4rem; border-radius: 4px; font-family: monospace; font-size: 0.9em; }

/* Role badge */
.role-badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 4px; font-size: 0.8rem; font-weight: 500; }
.role-student { background: #bee3f8; color: #2a4365; }
.role-teacher { background: #c6f6d5; color: #22543d; }
.role-ta { background: #fefcbf; color: #744210; }
.role-admin { background: #fed7d7; color: #742a2a; }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 1rem; align-items: center; margin-top: 1.5rem; }
.pagination a { padding: 0.4rem 0.8rem; background: var(--color-primary); color: white; border-radius: var(--radius); text-decoration: none; }
.pagination a:hover { background: var(--color-primary-dark); }

/* Filter form */
.filter-form { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filter-form select, .filter-form input { width: auto; padding: 0.4rem 0.6rem; }
.text-muted { color: var(--color-text-light); margin-bottom: 0.5rem; font-size: 0.9rem; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1rem; margin-top: 1rem; }
.stat-card { background: var(--color-bg); padding: 1.2rem; border-radius: var(--radius); text-align: center; border: 1px solid var(--color-border); }
.stat-num { font-size: 2rem; font-weight: 700; color: var(--color-primary); }
.stat-label { color: var(--color-text-light); font-size: 0.85rem; margin-top: 0.3rem; }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin: 1.5rem 0 1rem; flex-wrap: wrap; gap: 1rem; }
.page-header h1, .page-header h2 { margin: 0; }
.actions { display: flex; gap: 0.5rem; }

/* Block wrapper (lesson view) */
.block-wrapper { margin-bottom: 1.5rem; padding: 1.5rem; }
.block-wrapper .submission-feedback { margin-top: 1rem; }
.block-code textarea.code-editor { width: 100%; min-height: 200px; font-family: monospace; }
.block-code .code-hint { background: #fff8e1; border-left: 3px solid #ffca28; color: #6b5900; padding: 8px 12px; border-radius: 6px; margin: 8px 0; font-size: 14px; line-height: 1.5; }
#popquizHost .popquiz-banner { background: #ff6b35; color: #fff; padding: 10px 14px; border-radius: 10px 10px 0 0; font-size: 15px; }
#popquizHost .popquiz-block { border: 2px solid #ff6b35; border-top: none; border-radius: 0 0 10px 10px; padding: 14px; margin-bottom: 16px; background: #fff; }
/* 临时测验进行中：隐藏本页原有练习，学生专注答这道题 */
body.has-popquiz #deck .slide-blocks, body.has-popquiz #deck .exo-lock-msg { display: none !important; }
/* 输入行为检测条（不可逆） */
.type-meter { margin: 6px 0 2px; }
.type-meter-track { display: flex; align-items: stretch; height: 12px; background: #f0f0f0; border-radius: 6px; overflow-x: auto; overflow-y: hidden; }
.type-meter-track::-webkit-scrollbar { height: 4px; }
.tm-seg { flex: 0 0 auto; height: 12px; }
.tm-type { background: #2e9e3f; }
.tm-paste { background: #f6c343; }
.tm-delete { background: #e05555; }
.tm-edit { background: #4b8cf7; }
.type-meter-label { font-size: 11px; color: #8a8a8a; margin-top: 2px; }
/* 临时测验 老师面板：左右分区 */
.pq-panel { border: 2px solid #ff6b35; border-radius: 12px; background: #fff8f5; margin-bottom: 12px; }
.pq-panel .pq-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #ffd9c7; }
.pq-panel .pq-body { display: flex; gap: 14px; padding: 12px 14px; flex-wrap: wrap; }
.pq-panel .pq-left { flex: 1 1 300px; min-width: 280px; }
.pq-panel .pq-right { flex: 1 1 340px; min-width: 300px; border-left: 1px dashed #ffd9c7; padding-left: 14px; }
.pq-panel textarea { width: 100%; margin: 3px 0 8px; border: 1px solid #e0d5cf; border-radius: 6px; padding: 6px; }
.pq-panel label { display: block; margin-top: 4px; }
.pq-stream { background: #1e1e1e; color: #c9e7c9; padding: 8px; border-radius: 6px; max-height: 180px; overflow: auto; white-space: pre-wrap; font-size: 12px; margin-top: 6px; }
.pq-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.pq-tab-btn { padding: 5px 12px; border: 1px solid #e0d5cf; background: #fff; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; }
.pq-tab-btn.active { background: #ff6b35; color: #fff; border-color: #ff6b35; }
.pq-trace { max-height: 320px; overflow: auto; }
.pq-trace .row { border-bottom: 1px solid #f0e6e0; padding: 6px 0; font-size: 13px; }
.pq-trace .row .meta { color: #888; font-size: 12px; }
.pq-trace .flag { color: #c0392b; font-weight: 600; }

/* 学生动态弹窗（教师查看本讲提交 + AI 对话） */
.act-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: none; align-items: flex-start; justify-content: center; padding: 4vh 12px; }
.act-modal { background: #fff; border-radius: 12px; width: 100%; max-width: 900px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,0.3); overflow: hidden; }
.act-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 2px solid #0d9488; background: #f0fdfa; flex-wrap: wrap; }
.act-head .muted { font-size: 12px; color: #666; }
.act-head .act-auto { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.act-body { padding: 12px 16px; overflow: auto; }
.act-stu { border: 1px solid #e3e8e7; border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; }
.act-stu > summary { cursor: pointer; font-size: 15px; padding: 4px 0; }
.act-stu .meta { color: #888; font-size: 12px; font-weight: 400; }
.act-grp { margin: 6px 0 4px; }
.act-grp .act-h { display: block; font-size: 12px; color: #0d9488; margin: 6px 0 2px; }
.act-item { border-left: 3px solid #e0e0e0; padding: 3px 0 3px 8px; margin: 4px 0; font-size: 13px; }
.act-item .act-t { color: #555; font-size: 12px; }
.act-item .act-sc { color: #d97706; font-weight: 600; font-size: 12px; }
.act-code { background: #1e1e1e; color: #d4d4d4; padding: 6px 8px; border-radius: 5px; margin-top: 3px; white-space: pre-wrap; font-size: 12px; max-height: 160px; overflow: auto; }
.act-item .act-q { margin: 2px 0; }
.act-item .act-a { color: #0f766e; background: #f0fdfa; border-radius: 5px; padding: 3px 6px; margin: 2px 0; }
/* 学生动态：名单(一级) + 详情(二级) */
.act-list { display: flex; flex-direction: column; gap: 6px; }
.act-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: #fff; border: 1px solid #e3e8e7; border-radius: 8px; padding: 9px 12px; cursor: pointer; font-size: 14px; }
.act-row:hover { background: #f0fdfa; border-color: #99f6e4; }
.act-row .act-row-nm { flex: 1; min-width: 0; }
.act-row .act-row-ct { color: #0d9488; font-size: 13px; white-space: nowrap; }
.act-row .act-row-at { white-space: nowrap; }
.act-row .meta { color: #888; font-size: 12px; font-weight: 400; }
.act-back { margin-bottom: 8px; }
.act-detail-head { font-size: 16px; margin-bottom: 8px; }
.act-detail-head .meta { color: #888; font-size: 12px; font-weight: 400; }
.act-item2 { border: 1px solid #eef0f2; border-radius: 7px; margin: 5px 0; padding: 4px 10px; font-size: 13px; }
.act-item2 > summary { cursor: pointer; color: #374151; padding: 3px 0; list-style: revert; }
.act-item2 .act-sc { color: #d97706; font-weight: 600; }
.act-item2 .act-qprev { color: #6b7280; }
.act-item2 .act-q { margin: 4px 0; }
.act-item2 .act-a { color: #0f766e; background: #f0fdfa; border-radius: 5px; padding: 4px 8px; margin: 2px 0; white-space: pre-wrap; }
.code-output { background: #1e1e1e; color: #d4d4d4; padding: 1rem; border-radius: var(--radius); margin-top: 0.5rem; white-space: pre-wrap; min-height: 60px; }

/* 学习园地文件管理器 */
.gfm { border: 1px solid #e5e7eb; border-radius: 10px; overflow: hidden; }
.gfm-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; background: #f9fafb; border-bottom: 1px solid #eef0f2; }
.gfm-crumb { font-size: 13px; color: #374151; flex: 1; min-width: 0; }
.gfm-crumb a { color: #4f46e5; text-decoration: none; }
.gfm-crumb a:hover { text-decoration: underline; }
.gfm-actions { display: flex; gap: 6px; }
.gfm-msg { padding: 4px 12px; font-size: 12px; min-height: 0; }
.gfm-msg:empty { display: none; }
.gfm-list { max-height: 360px; overflow: auto; }
.gfm-empty { padding: 18px 12px; text-align: center; }
.gfm-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid #f4f4f5; font-size: 14px; }
.gfm-row:last-child { border-bottom: 0; }
.gfm-row:hover { background: #f9fafb; }
.gfm-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gfm-nm[data-open] { color: #b45309; cursor: pointer; }
.gfm-sz { color: #9ca3af; font-size: 12px; white-space: nowrap; }
.gfm-acts { white-space: nowrap; }
.gfm-link { color: #4f46e5; text-decoration: none; font-size: 13px; margin-left: 4px; }
.gfm-link:hover { text-decoration: underline; }
.gfm-link.gfm-del { color: #dc2626; }
.gfm-ys { font-size: 11px; border-radius: 999px; padding: 0 7px; white-space: nowrap; margin-right: 6px; }
.gfm-ys.on { background: #dcfce7; color: #166534; }
.gfm-ys.off { background: #f1f5f9; color: #94a3b8; }
.gfm-vers { background: #f8fafc; border: 1px solid #eef0f2; border-radius: 8px; margin: 0 12px 8px; padding: 6px 10px; }
.gfm-vers-t { font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.gfm-vrow { font-size: 12.5px; padding: 3px 0; border-top: 1px dashed #eef0f2; }

/* 人类可读的学生作答（批改页 + 班级管理台共用） */
.av-block { margin: 10px 0; }
.av-label { font-weight: 700; font-size: 13px; color: #374151; margin-bottom: 5px; }
.av-code { background: #1e1e1e; color: #e6e6e6; padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; overflow: auto; max-height: 340px; }
.av-tests { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.av-tests th, .av-tests td { border: 1px solid #eef0f2; padding: 4px 8px; text-align: left; vertical-align: top; }
.av-tests th { background: #f9fafb; color: #6b7280; font-weight: 600; }
.av-tests td code { background: #f3f4f6; padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.av-tests tr.ok td:nth-child(2) { color: #16a34a; font-weight: 600; }
.av-tests tr.no td:nth-child(2) { color: #dc2626; font-weight: 600; }
.av-tm-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #eee; margin-bottom: 6px; max-width: 420px; }
.av-tm-bar span { display: block; height: 100%; }
.av-tm-nums { font-size: 12.5px; color: #4b5563; }
.av-tm-verdict { font-size: 13px; font-weight: 600; margin-top: 3px; }
.av-quiz { font-size: 15px; font-weight: 600; margin: 4px 0; }
.av-quiz-correct { font-size: 13px; color: #16a34a; }
.av-raw { margin-top: 8px; }
.av-raw summary { cursor: pointer; color: #9ca3af; font-size: 12px; }
.av-raw pre { background: #f9fafb; border: 1px solid #eef0f2; padding: 8px; border-radius: 6px; font-size: 12px; overflow: auto; max-height: 240px; }

/* 课程笔记抽屉 */
.notes-drawer { position: fixed; top: 0; right: 0; width: 380px; max-width: 92vw; height: 100vh; background: #fff; border-left: 3px solid #0ea5e9; box-shadow: -6px 0 24px rgba(0,0,0,0.14); transform: translateX(105%); transition: transform .22s ease; z-index: 300; display: flex; flex-direction: column; }
.notes-drawer.on { transform: translateX(0); }
.notes-drawer .nt-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid #e5f3fb; background: #f0f9ff; }
.notes-drawer .nt-head b { flex: 1; font-size: 14px; min-width: 0; }
.nt-status { font-size: 12px; color: #0369a1; white-space: nowrap; }
.notes-drawer .nt-body { flex: 1; display: flex; flex-direction: column; padding: 12px 14px; gap: 8px; overflow: auto; }
.nt-tip { font-size: 12px; color: #64748b; background: #f8fafc; border-radius: 8px; padding: 6px 8px; }
.nt-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#ntText { flex: 1; min-height: 220px; width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px; font-size: 14px; line-height: 1.6; resize: vertical; font-family: inherit; }
.nt-ask { border-top: 1px dashed #e2e8f0; padding-top: 8px; }
.nt-ask-title { font-size: 13px; font-weight: 700; color: #7c3aed; margin-bottom: 6px; }
.nt-ask-msgs { max-height: 200px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.nt-msg { font-size: 13px; line-height: 1.5; padding: 6px 9px; border-radius: 8px; }
.nt-msg.nt-user { background: #eef2ff; align-self: flex-end; }
.nt-msg.nt-assistant { background: #f0fdfa; }
.nt-add-ans { margin-top: 6px; }
.nt-ask-row { display: flex; gap: 6px; margin-top: 6px; }
.nt-ask-row input { flex: 1; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 13px; }
.note-float { position: absolute; z-index: 400; background: #0ea5e9; color: #fff; border: 0; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; box-shadow: 0 3px 10px rgba(0,0,0,0.22); cursor: pointer; }
.note-float:hover { background: #0284c7; }
@media (max-width: 480px) { .notes-drawer { width: 100vw; } }

/* Block editor (teacher) */
.block-item { background: var(--color-bg); padding: 1rem; border-radius: var(--radius); margin-bottom: 0.75rem; border: 1px solid var(--color-border); }
.block-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.block-item-type { font-weight: 600; color: var(--color-primary); }
.block-item-body textarea, .block-item-body input, .block-item-body select { width: 100%; padding: 0.4rem 0.6rem; margin-top: 0.2rem; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: white; padding: 2rem; border-radius: var(--radius); max-width: 500px; width: 90%; }
.block-type-list { list-style: none; margin: 1rem 0; }
.block-type-list li { margin-bottom: 0.5rem; }
.btn-block { width: 100%; text-align: left; padding: 0.75rem 1rem; background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-block:hover { background: var(--color-primary); color: white; }

/* Lead */
.lead { font-size: 1.1rem; color: var(--color-text-light); margin-bottom: 1.5rem; }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-light); }

/* Course grid */
.course-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }
.course-card h2 { color: var(--color-primary); margin-bottom: 0.5rem; }
.course-card h2 a { color: inherit; text-decoration: none; }

/* Lesson list (student dashboard) */
.lesson-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.lesson-card h3 { color: var(--color-primary); margin-bottom: 0.5rem; }
.lesson-card h3 a { color: inherit; text-decoration: none; }
.lesson-meta { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; font-size: 0.85rem; color: var(--color-text-light); }
.badge { padding: 0.15rem 0.5rem; background: var(--color-bg); border-radius: 4px; font-size: 0.75rem; border: 1px solid var(--color-border); }
.badge-success { background: #c6f6d5; color: #22543d; border-color: #9ae6b4; }