/* 作业管家 H5 — exercise-book paper, navy ink, and a teacher's red pen.
   Red is reserved for marks (对/错) and errors; navy is for actions. */
:root {
  --paper: #fafbfd;
  --grid: #e5ebf4;
  --ink: #1b2440;
  --pencil: #5c6580;
  --line: #d5dcea;
  --navy: #24408e;
  --navy-deep: #182e6b;
  --red: #d2312c;
  --red-soft: #f6d3d1;
  --marker: #ffe57a;
  --marker-soft: #fff6cc;
  --sheet: #ffffff;
  --ok: #1f7a4d;
  --radius-s: 6px;
  --radius-m: 12px;
  --tabbar: 64px;
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  --font-hand: "Kaiti SC", "STKaiti", "KaiTi", "Kaiti", "AR PL UKai CN", serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.6 var(--font);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
:focus-visible { outline: 3px solid var(--marker); outline-offset: 2px; }
.boot { padding: 40vh 24px 0; text-align: center; color: var(--pencil); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.screen { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.screen.has-tabs { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.screen.center { justify-content: center; align-items: center; gap: 16px; padding: 24px; text-align: center; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(250, 251, 253, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; letter-spacing: 0.02em; outline: none; }
.content { flex: 1; padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
.muted { color: var(--pencil); }
.small { font-size: 13px; }
.center { text-align: center; }
.lead { font-size: 18px; font-weight: 600; margin: 0; }
p { margin: 0; }
.section-title { font-size: 16px; font-weight: 650; margin: 10px 0 0; }
.day-head { font-size: 14px; font-weight: 600; color: var(--pencil); margin: 14px 0 2px; }

/* ---------- controls ---------- */
button { cursor: pointer; border: 0; background: none; }
.primary, .ghost {
  min-height: 46px; padding: 10px 18px; border-radius: var(--radius-m);
  font-weight: 600; font-size: 16px; touch-action: manipulation;
}
.primary { background: var(--navy); color: #fff; box-shadow: 0 2px 0 var(--navy-deep); }
.primary:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--navy-deep); }
.primary:disabled { background: #9aa6c4; box-shadow: none; cursor: default; }
.ghost { background: var(--sheet); color: var(--navy); border: 1.5px solid var(--line); }
.ghost.danger { color: var(--red); }
.ghost.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.wide { width: 100%; }
.is-busy { opacity: 0.7; }
.is-busy::after { content: "…"; }
.link { color: var(--navy); padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; align-self: center; }
.link.small { font-size: 14px; padding: 0 0 0 8px; align-self: auto; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon-btn:hover { background: var(--grid); }

input, textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-s);
  background: var(--sheet); font-size: 17px; outline: none;
}
input:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(36, 64, 142, 0.15); }
textarea { resize: vertical; font-family: var(--font-hand), var(--font); }
input.pin { font-size: 26px; letter-spacing: 0.4em; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; font-size: 15px; }
.field-hint { font-size: 13px; color: var(--pencil); }
.form-error { color: var(--red); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--sheet); font-size: 15px;
}
.chip.is-on { border-color: var(--navy); background: var(--navy); color: #fff; }
.student-switch { display: flex; gap: 8px; padding: 10px 16px 0; overflow-x: auto; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--sheet); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 140px; height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--pencil); text-decoration: none; font-size: 12px;
}
.tab.is-on { color: var(--navy); font-weight: 650; }

/* ---------- auth ---------- */
.auth { padding: 0 24px 32px; justify-content: flex-start; }
.brand { padding: 12vh 0 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.brand-name { font-size: 30px; font-weight: 700; letter-spacing: 0.06em; margin-top: 10px; }
.brand-line { color: var(--pencil); max-width: 22em; }
.sheet-card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; }
.sheet-card h2 { margin: 0; font-size: 18px; }

/* ---------- today ---------- */
.snap {
  width: 100%; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px;
  align-items: center; text-align: left;
  padding: 18px 20px; border-radius: var(--radius-m);
  background: var(--navy); color: #fff; box-shadow: 0 3px 0 var(--navy-deep);
}
.snap .icon { grid-row: 1 / 3; width: 34px; height: 34px; }
.snap-main { font-size: 22px; font-weight: 700; letter-spacing: 0.08em; }
.snap-sub { font-size: 14px; opacity: 0.85; }
.task-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.task {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px;
  text-align: left; padding: 12px 14px; background: var(--sheet);
  border: 1px solid var(--line); border-radius: var(--radius-s);
}
.task-subject {
  grid-row: 1 / 3; align-self: center; width: 44px; height: 44px; display: grid; place-items: center;
  border: 1.5px solid var(--line); border-radius: 4px; font-size: 14px; font-weight: 600;
}
.task-title { font-weight: 600; }
.task-state { font-size: 14px; color: var(--pencil); }
.tone-attention .task-state { color: var(--ink); font-weight: 600; background: linear-gradient(transparent 55%, var(--marker) 55%); justify-self: start; }
.tone-done .task-state { color: var(--ok); }

/* ---------- photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.thumb { position: relative; margin: 0; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.thumb img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.thumb figcaption { font-size: 12px; text-align: center; padding: 2px 0; color: var(--pencil); }
.thumb-remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(27, 36, 64, 0.75); color: #fff; font-size: 18px; line-height: 1;
}
.thumb-add {
  aspect-ratio: 3 / 4.6; border: 2px dashed var(--line); border-radius: var(--radius-s);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--navy); background: rgba(255, 255, 255, 0.6); font-size: 14px;
}
.photo-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; }
.photo-frame { flex: 0 0 auto; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--sheet); scroll-snap-align: start; }
.photo-strip .photo { height: 150px; width: auto; }
.photo.small { max-height: 120px; width: auto; }
.photo-missing { padding: 12px; font-size: 13px; color: var(--pencil); }
.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(15, 20, 35, 0.92); }
.lightbox-scroll { width: 100%; height: 100%; overflow: auto; display: grid; place-items: center; padding: 48px 8px 16px; }
.lightbox img { max-width: none; width: 100%; max-width: 1200px; }
.lightbox-close { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; color: #fff; z-index: 1; }

/* ---------- review ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); }
.summary > div { padding: 10px 6px; text-align: center; display: flex; flex-direction: column; }
.summary > div + div { border-left: 1px solid var(--line); }
.summary strong { font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.summary span { font-size: 13px; color: var(--pencil); }
.summary .is-attention strong { background: linear-gradient(transparent 50%, var(--marker) 50%); align-self: center; padding: 0 4px; }

.q-card {
  position: relative; background: var(--sheet);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 14px 14px 14px 26px; display: flex; flex-direction: column; gap: 8px;
}
.q-card::before { /* exercise-book margin line */
  content: ""; position: absolute; top: 0; bottom: 0; left: 12px; width: 2px; background: var(--red-soft);
}
.q-card.is-attention { background: var(--marker-soft); border-color: #efd88a; }
.q-card.is-confirmed { padding-right: 84px; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.q-no { font-weight: 650; }
.q-text { font-size: 17px; }
.q-label { display: inline-block; min-width: 4.5em; color: var(--pencil); font-size: 14px; margin-right: 6px; }
.handwriting { font-family: var(--font-hand), var(--font); font-size: 19px; }
.q-answer { display: flex; align-items: baseline; flex-wrap: wrap; }
.q-facts { display: flex; flex-direction: column; gap: 2px; font-size: 15px; }
.q-facts > p:not(.q-kp) { display: grid; grid-template-columns: 4.5em 1fr; column-gap: 6px; }
.q-facts .q-label { min-width: 0; margin: 0; }
.q-card > .photo-frame { align-self: flex-start; }
.q-kp { font-size: 13px; color: var(--pencil); }
.q-kp::before { content: "知识点："; }
.q-edit { display: flex; gap: 8px; }
.q-reveal { padding: 8px 10px; background: var(--paper); border-radius: var(--radius-s); }
.q-why { display: block; color: var(--pencil); font-size: 14px; }
.stage { font-size: 13px; color: var(--pencil); }
.ai-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--pencil); white-space: nowrap; }
.ai-badge.is-unsure { color: #8a6a00; font-weight: 600; }
.decide { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.decide-btn {
  min-height: 44px; border: 1.5px solid var(--line); border-radius: var(--radius-s);
  background: var(--sheet); font-weight: 600; font-size: 15px;
}
.decide-btn.is-on { color: #fff; border-color: transparent; }
.decide-btn.d-correct.is-on, .decide-btn.d-partial.is-on { background: var(--ok); }
.decide-btn.d-incorrect.is-on { background: var(--red); }
.decide-btn.d-ungradable.is-on { background: var(--pencil); }
.q-verdict { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--red); }

.confirm-bar {
  position: sticky; bottom: 0; z-index: 4; margin: 4px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(250, 251, 253, 0.96); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.done-line { font-weight: 600; }
.waiting { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 28px 12px; }
.pen-writing .mark path { animation: draw 1.6s ease-in-out infinite; }

/* ---------- red-pen marks ---------- */
.mark { flex: none; overflow: visible; }
.mark path { fill: none; stroke: var(--red); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.mark-draw path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 0.45s ease-out forwards; }
.mark-draw path + path { animation-delay: 0.3s; }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.pen-writing .mark path { stroke-dasharray: 1; }

/* ---------- report ---------- */
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--sheet); border: 1.5px solid var(--line); border-radius: var(--radius-m); padding: 3px; margin-bottom: 14px; }
.segmented button { min-height: 38px; border-radius: 9px; font-weight: 600; color: var(--pencil); }
.segmented button.is-on { background: var(--navy); color: #fff; }
.score { display: flex; align-items: center; gap: 18px; padding: 8px 0; }
.score-ring {
  position: relative; width: 112px; height: 104px; flex: none; display: flex; align-items: baseline; justify-content: center; padding-top: 22px;
  color: var(--red); font-family: var(--font-hand), var(--font);
}
.score-ring::before { /* a hand-drawn circle around the score */
  content: ""; position: absolute; inset: 4px 2px 2px 6px; border: 3px solid var(--red);
  border-radius: 52% 48% 46% 54% / 55% 45% 55% 45%; transform: rotate(-8deg);
}
.score-num { font-size: 48px; font-weight: 700; line-height: 1; }
.score-unit { font-size: 20px; }
.facts { margin: 0; padding: 12px 16px 12px 32px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-s); }
.weak { margin: 0; padding: 0; list-style: none; counter-reset: weak; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-s); }
.weak li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 10px 14px; align-items: baseline; }
.weak li + li { border-top: 1px dashed var(--line); }
.weak-name { font-weight: 600; }
.weak-count { color: var(--red); font-variant-numeric: tabular-nums; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 4.5em 1fr 3em auto; gap: 10px; align-items: center; }
.bar-track { height: 12px; background: var(--grid); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--navy); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.daily { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding: 8px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-s); }
.daily-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.daily-bar { width: 100%; max-width: 22px; background: var(--grid); border-radius: 3px 3px 0 0; display: flex; align-items: flex-end; overflow: hidden; }
.daily-ok { display: block; width: 100%; background: var(--navy); }
.daily-day { font-size: 11px; color: var(--pencil); }

/* ---------- me ---------- */
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; }
.panel .section-title { margin: 0; }
.kid-list { display: flex; flex-direction: column; gap: 6px; }
.kid { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-s); background: var(--sheet); text-align: left; }
.kid.is-on { border-color: var(--navy); }
.kid-name { font-weight: 600; }
details summary { cursor: pointer; color: var(--navy); padding: 4px 0; }
details[open] summary { margin-bottom: 10px; }

/* ---------- sheet & toast & empty ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(15, 20, 35, 0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; background: var(--sheet); border-radius: 18px 18px 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  animation: rise 0.18s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 18px; margin: 12px 0; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); z-index: 40;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: 15px; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--red); }
.empty { padding: 32px 12px; text-align: center; color: var(--pencil); display: flex; flex-direction: column; align-items: center; gap: 14px; }

@media (min-width: 600px) {
  .content { padding: 24px; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .mark-draw path { stroke-dashoffset: 0; }
}

/* registration consent + privacy page */
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.5; }
.consent input { width: 20px; height: 20px; margin-top: 1px; flex: none; }
.doc { max-width: 680px; margin: 0 auto; padding: 20px 18px 48px; line-height: 1.7; }
.doc h1 { font-size: 22px; margin: 8px 0 4px; }
.doc h2 { font-size: 17px; margin: 24px 0 6px; }
.doc li { margin: 4px 0; }

/* filing numbers at the bottom of public pages */
.filing { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; padding: 20px 12px 12px; font-size: 12px; }
.filing a { color: var(--pencil); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.filing a:hover { text-decoration: underline; }

/* printable mistake sheet (views/print.js) */
.print-sheet { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px; }
.print-head h2 { margin: 0 0 4px; font-size: 18px; }
.print-head p { margin: 0 0 14px; font-size: 13px; color: var(--pencil); }
.print-q { padding: 10px 0; border-top: 1px dashed var(--line); }
.print-q-title { margin: 0; font-size: 16px; line-height: 1.6; }
.print-tag { margin-left: 10px; font-size: 12px; color: var(--pencil); }
.print-photo { display: block; max-width: 100%; max-height: 320px; margin-top: 8px; }
.print-space { height: 96px; }
.print-answers { margin-top: 18px; padding-top: 12px; border-top: 2px solid var(--line); }
.print-answers h2 { font-size: 16px; margin: 0 0 8px; }
.print-answers li { margin: 4px 0; line-height: 1.6; }
.print-why { color: var(--pencil); font-size: 13px; }

@media print {
  html, body { background: #fff !important; }
  .topbar, .tabbar, .student-switch, .no-print, #toast, .filing { display: none !important; }
  .screen, .content { padding: 0 !important; margin: 0 !important; min-height: 0 !important; }
  .print-sheet { border: 0; padding: 0; border-radius: 0; }
  .print-head p, .print-tag, .print-why { color: #333; }
  .print-q { break-inside: avoid; page-break-inside: avoid; border-top: 1px dashed #999; }
  .print-space { height: 3.2cm; }
  .print-answers { break-before: page; page-break-before: always; border-top: 0; margin-top: 0; }
  @page { margin: 1.5cm; }
}
.segmented.three { grid-template-columns: 1fr 1fr 1fr; }
.segmented.three button { font-size: 13px; }
