:root {
  --bg: #f4f7f5;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #6b7c74;
  --primary: #1f9d6b;
  --primary-d: #157a52;
  --accent: #2b8acb;
  --warn: #e08e0b;
  --line: #e3eae6;
  --shadow: 0 2px 10px rgba(31, 42, 36, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

a { color: var(--accent); }

.topbar {
  background: linear-gradient(120deg, var(--primary), var(--accent));
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.topbar .logo { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.topbar .sub { font-size: 12px; opacity: .9; }
.topbar .spacer { flex: 1; }
.topbar a.back, .topbar button {
  color: #fff; background: rgba(255,255,255,.18); border: none;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; text-decoration: none;
}

.wrap { max-width: 920px; margin: 0 auto; padding: 16px; }

.hero {
  text-align: center; padding: 34px 18px 18px;
}
.hero h1 { font-size: 26px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 560px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 22px; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }

.role-card {
  background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink); display: block; transition: transform .15s, box-shadow .15s;
  border: 1px solid var(--line);
}
.role-card:hover { transform: translateY(-3px); box-shadow: 0 6px 18px rgba(31,42,36,.14); }
.role-card .ic { font-size: 34px; }
.role-card h3 { margin: 10px 0 6px; font-size: 19px; }
.role-card p { color: var(--muted); font-size: 13.5px; margin: 0; }

.section-title { font-size: 17px; font-weight: 700; margin: 22px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title small { font-weight: 400; color: var(--muted); font-size: 12.5px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.tag {
  display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  background: #eafaf2; color: var(--primary-d); margin: 2px 4px 2px 0; border: 1px solid #cdeede;
}
.tag.theme { background: #eaf2fb; color: #1f6aa8; border-color: #cfe2f5; }
.tag.long { background: #fff4e0; color: #b9760a; border-color: #f3e0b3; }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14.5px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,157,107,.15); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; padding: 11px 18px; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--primary-d); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--primary-d); border: 1px solid var(--primary); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.accent { background: var(--accent); }
.btn.accent:hover { background: #1f6fa8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

.exp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .exp-grid { grid-template-columns: 1fr; } }
.exp-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: #fff;
  transition: border-color .15s, background .15s;
}
.exp-item:hover { border-color: var(--primary); }
.exp-item.sel { border-color: var(--primary); background: #f0fbf6; }
.exp-item h4 { margin: 0 0 4px; font-size: 15px; }
.exp-item .src { font-size: 12px; color: var(--muted); }

/* 学生端时间线 */
.timeline { position: relative; padding-left: 22px; margin-top: 8px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before {
  content: ''; position: absolute; left: -19px; top: 6px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary);
}
.tl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tl-date { font-weight: 700; font-size: 14px; }
.tl-phase { font-size: 12px; background: #eafaf2; color: var(--primary-d); padding: 1px 8px; border-radius: 999px; }
.tl-weather { font-size: 12px; color: var(--muted); }
.tl-content { margin: 6px 0 0; font-size: 14px; white-space: pre-wrap; }
.tl-metrics { font-size: 13px; color: var(--accent); margin-top: 4px; }
.tl-photo { margin-top: 8px; max-width: 220px; border-radius: 10px; border: 1px solid var(--line); display: block; }

.phase-progress { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.phase-dot { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: #f0f2f1; color: var(--muted); }
.phase-dot.done { background: var(--primary); color: #fff; }

.photo-preview { margin-top: 10px; }
.photo-preview img { max-width: 160px; border-radius: 10px; border: 1px solid var(--line); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.stat .num { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat .lab { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1f2a24; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50;
  max-width: 88vw; text-align: center; line-height: 1.45;
}
.toast.show { opacity: 1; }
.toast-success { background: #1f9d6b; }
.toast-error { background: #c0392b; }
.toast-info { background: #1f2a24; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

/* 实验日志打印 */
.log-sheet { background: #fff; padding: 22px; border-radius: var(--radius); box-shadow: var(--shadow); }
.log-sheet h2 { margin: 0 0 2px; }
.log-sheet .meta { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th, .log-table td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.log-table th { background: #f0fbf6; }
.log-photo { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; display: block; }
@media print {
  body * { visibility: hidden; }
  #logView, #logView * { visibility: visible; }
  #logView {
    position: absolute; left: 0; top: 0; width: 100%;
    background: #fff; padding: 0; margin: 0; overflow: visible;
  }
  .log-sheet { box-shadow: none; border-radius: 0; }
  .no-print { display: none !important; }
}

.modal-mask {
  position: fixed; inset: 0; background: rgba(20,30,25,.45); display: none;
  align-items: center; justify-content: center; z-index: 40; padding: 16px;
}
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 12px; }

.banner {
  background: #eafaf2; border: 1px solid #cdeede; color: var(--primary-d);
  border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px;
}
.locked-cls {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  background: #f0fbf6; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

/* 辅导老师工作台：班级头卡片 */
.tutor-head {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, #eaf2ff, #f0fbf6);
  border: 1px solid #d4e6ff;
}
.tutor-head .th-name { font-size: 16px; font-weight: 700; color: var(--ink); }
.tutor-head .muted { font-size: 13px; }


/* 班级学生名单（名册） */
.roster-box { margin: 4px 0; }
.roster-list { display: flex; flex-wrap: wrap; gap: 8px; }
.roster-item {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px 5px 12px;
  background: #f7faf8; font-size: 13.5px;
}
.roster-name { font-weight: 600; }
.roster-item .btn { padding: 2px 8px; font-size: 12px; }

/* 状态标签 */
.status-pill {
  display: inline-block; font-size: 11.5px; padding: 1px 9px; border-radius: 999px; margin-left: 6px;
  vertical-align: middle; font-weight: 600;
}
.status-pill.ok { background: #e9f7ef; color: #1e7e46; }
.status-pill.warn { background: #fff3e0; color: #b26a00; }

/* ==================== 注册 / 登录页（auth） ==================== */
.auth-page {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #e9f7ef 0%, #f2fbf7 40%, #e3f0fb 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 16px 40px;
}
/* 背景装饰：漂浮的原子 / 分子圆环 */
.auth-page::before, .auth-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.auth-page::before {
  width: 340px; height: 340px; top: -120px; right: -100px;
  background: radial-gradient(circle at 35% 35%, rgba(47, 158, 107, .16), rgba(47, 158, 107, 0) 65%);
  border: 2px dashed rgba(47, 158, 107, .25);
}
.auth-page::after {
  width: 300px; height: 300px; bottom: -110px; left: -90px;
  background: radial-gradient(circle at 60% 40%, rgba(43, 138, 203, .14), rgba(43, 138, 203, 0) 65%);
  border: 2px dashed rgba(43, 138, 203, .22);
}
.auth-page .atom {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(31, 157, 107, .28);
  pointer-events: none;
}
.auth-page .atom.a1 { width: 90px; height: 90px; top: 16%; left: 6%; }
.auth-page .atom.a2 { width: 54px; height: 54px; bottom: 22%; right: 8%; border-color: rgba(43, 138, 203, .3); }
.auth-page .atom.a3 { width: 34px; height: 34px; top: 10%; right: 26%; background: rgba(255,255,255,.5); }
.auth-page .atom::after {
  content: '';
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); top: -4px; left: 50%; transform: translateX(-50%);
}
.auth-page .atom.a2::after { background: var(--accent); }
.auth-page .atom.a3::after { width: 6px; height: 6px; top: -3px; background: var(--warn); }

.auth-brand { position: relative; text-align: center; margin-bottom: 22px; }
.auth-brand .auth-ico {
  width: 64px; height: 64px; margin: 0 auto 10px;
  border-radius: 18px; background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #fff; box-shadow: 0 8px 22px rgba(31, 157, 107, .35);
}
.auth-brand h1 {
  margin: 0; font-size: 30px; letter-spacing: 3px; font-weight: 800;
  background: linear-gradient(90deg, #157a52, #2b8acb);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-brand .auth-sub { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; letter-spacing: 1px; }

.auth-card {
  position: relative;
  width: 100%; max-width: 560px;
  background: rgba(255, 255, 255, .94);
  border-radius: 20px;
  box-shadow: 0 16px 44px rgba(31, 42, 36, .12);
  border: 1px solid rgba(255,255,255,.7);
  padding: 28px 30px 26px;
  backdrop-filter: blur(6px);
}
.auth-card h3 { margin: 0 0 4px; font-size: 19px; color: var(--ink); }
.auth-card .auth-desc { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
/* 左标签 右输入框 两栏 */
.auth-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.auth-row label { text-align: right; font-size: 14px; font-weight: 600; color: #33443c; white-space: nowrap; }
.auth-row input {
  width: 100%; min-height: 42px;
  border: 1.5px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 15px; background: #fbfdfc; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.auth-row input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 157, 107, .12); background: #fff; }
.auth-tip { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin: -4px 0 2px; text-align: right; }
.auth-err { grid-column: 1 / -1; color: #c0392b; font-size: 13px; min-height: 18px; text-align: right; }
.auth-foot { grid-column: 1 / -1; text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.auth-foot a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-actions { grid-column: 1 / -1; margin-top: 6px; }
@media (max-width: 480px) {
  .auth-page { padding: 22px 12px 30px; }
  .auth-brand h1 { font-size: 24px; letter-spacing: 2px; }
  .auth-card { padding: 22px 18px; }
  .auth-row { grid-template-columns: 1fr; gap: 5px; }
  .auth-row label { text-align: left; }
  .auth-row input { min-height: 44px; }
}

/* ==================== 移动端响应式（<600px） ==================== */
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .topbar .logo { font-size: 16px; }
  .topbar .sub { font-size: 11px; }
  .wrap { padding: 10px; }

  /* 卡片单列 */
  .exp-grid { grid-template-columns: 1fr; }
  .mat-grid { grid-template-columns: 1fr; }

  /* 按钮全宽 */
  .btn { width: 100%; }
  .btn.sm { width: auto; }

  /* 按钮最小 44px 点击区域 */
  button, .btn, .btn.sm, .btn.ghost {
    min-height: 44px;
  }
  .topbar button, .topbar a.back {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
  }

  /* 输入框字体不小于 16px 防 iOS 缩放 */
  input, select, textarea {
    font-size: 16px;
    padding: 12px 14px;
  }

  /* 表格改为卡片式布局 */
  .log-table {
    display: block;
    border: none;
  }
  .log-table thead { display: none; }
  .log-table tbody { display: block; }
  .log-table tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff;
  }
  .log-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 0;
    border: none;
    border-bottom: 1px solid #f0f2f1;
    text-align: right;
    font-size: 13px;
  }
  .log-table td:last-child { border-bottom: none; }
  .log-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    flex: 0 0 90px;
    text-align: left;
    font-size: 12px;
  }
  .log-table th { display: none; }

  /* 日志照片：移动端也保持统一缩略图，不撑满单元格 */
  .log-photo { width: 110px; height: 82px; object-fit: cover; }

  /* 学生清单卡片化 */
  .section-title { font-size: 15px; }
  .row > * { flex: 1 1 100%; }
  .roster-list { gap: 6px; }

  /* === topbar 允许换行，避免标题/按钮在窄屏挤压 === */
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .topbar .spacer { display: none; }
  .topbar .logo { font-size: 15px !important; line-height: 1.3; word-break: break-all; }
  .topbar .sub { font-size: 11px; word-break: break-all; line-height: 1.35; max-width: 100%; }
  .topbar > div:not(.spacer) { min-width: 0; flex: 1 1 60%; }
  .topbar .btn.sm, .topbar button { width: auto; min-width: 64px; }

  /* === 教师后台班级列表行（roster-item）改成卡片 === */
  .roster-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
    border-radius: 14px;
    gap: 8px;
  }
  .roster-item > * {
    flex: none !important;
    width: 100% !important;
    max-width: none !important;
  }
  /* 行内的两个 .btn.sm（保存 / 入口链接）保持并排 */
  .roster-item > .btn.sm {
    flex: 1 1 calc(50% - 4px) !important;
    width: auto !important;
    min-width: 0;
  }

  /* === 辅导老师头卡片（.tutor-head）允许换行 + 文字收缩 === */
  .tutor-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  .tutor-head > div {
    flex: 1 1 calc(100% - 60px);
    min-width: 0;
  }
  .tutor-head .th-name { font-size: 15px; word-break: break-all; }
  .tutor-head .muted { font-size: 12px; word-break: break-all; line-height: 1.4; }
}

/* ==================== 加载状态 ==================== */
.loading-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  font-size: 14px;
}
.loading-placeholder::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-placeholder {
  text-align: center;
  padding: 28px 14px;
  color: #c0392b;
  font-size: 14px;
}
.error-placeholder .retry-btn {
  margin-top: 10px;
  display: inline-block;
}

/* 探究资料网格 */
.mat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mat-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
@media (max-width: 640px) { .mat-grid { grid-template-columns: repeat(2, 1fr); } }
.mat-item {
  position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: #f7faf8; text-align: center;
}
.mat-item img { width: 100%; height: 110px; object-fit: cover; display: block; background: #eef3f0; }
.mat-file {
  height: 110px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; gap: 4px;
}
.mat-name {
  font-size: 11.5px; color: var(--ink); padding: 5px 6px; word-break: break-all; line-height: 1.35;
  border-top: 1px solid var(--line); background: #fff;
}
.mat-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; cursor: pointer; line-height: 1;
}
.mat-del:hover { background: #c0392b; }

/* ===== Login Tabs ===== */
.login-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 20px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
}
.login-tab {
  flex: 1;
  padding: 10px 12px;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}
.login-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.login-pane { display: none; }
.login-pane.active { display: block; }
