:root {
  color-scheme: light;
  --paper: #fffefa;
  --paper-deep: #f2f5f2;
  --ink: #17324d;
  --blue: #246b8f;
  --blue-dark: #174a65;
  --red: #a33a2b;
  --green: #2f6b4f;
  --line: #cbd8da;
  --desk: #edf4f3;
  --muted: #546866;
  --shadow: 0 6px 24px rgba(23, 50, 77, .07);
  --radius: 14px;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--desk); }
body { margin: 0; color: var(--ink); background: var(--desk); }
button, input, textarea, select { font: inherit; }
button, .file-button {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: var(--blue-dark);
  padding: .68rem 1rem;
  font-weight: 700;
  cursor: pointer;
}
button:hover, .file-button:hover { color: #fff; background: #0f3b52; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, .file-button:focus-within {
  outline: 3px solid var(--blue-dark);
  outline-offset: 3px;
}
.topbar button:focus-visible, .topbar select:focus-visible, .topbar summary:focus-visible { outline-color: var(--blue-dark); }
button:disabled { cursor: not-allowed; opacity: .45; }
a { color: #155878; text-underline-offset: .18em; }
::selection { color: #fff; background: var(--blue-dark); }

.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 20; padding: .8rem; background: #fff; }
.skip-link:focus { top: 1rem; }
.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem clamp(1rem, 4vw, 3rem);
  color: var(--ink);
  background: #fffefa;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand svg { width: 42px; height: 42px; fill: none; stroke: var(--blue); stroke-width: 2; }
.brand strong, .brand span { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 1.15rem; }
.brand span { color: var(--muted); font-size: .82rem; letter-spacing: .08em; text-transform: uppercase; }
.top-actions, .view-switch, .profile-switch { display: flex; align-items: center; gap: .4rem; }
.view-switch, .timer { padding: .25rem; border: 1px solid var(--line); border-radius: 12px; }
.profile-switch { color: var(--muted); font-size: .75rem; font-weight: 700; }
.profile-switch select {
  min-height: 44px;
  border: 1px solid #6f8581;
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  padding: .35rem 1.8rem .35rem .6rem;
  font-weight: 800;
}
.view-switch .lock-access { color: var(--red); }
.adaptive-link { min-height: 44px; display: inline-flex; align-items: center; padding: .55rem .75rem; border-radius: 9px; color: var(--blue-dark); font-weight: 800; text-decoration: none; }
.adaptive-link:hover { background: #e5efef; }
.timer { color: var(--ink); }
.timer summary { min-height: 44px; display: flex; align-items: center; gap: .55rem; padding: .35rem .6rem; cursor: pointer; font-weight: 800; }
.timer-controls { display: flex; align-items: center; gap: .4rem; padding: .25rem; }
.timer-help { max-width: 190px; padding: 0 .45rem; color: var(--muted); font-size: .78rem; line-height: 1.25; }
.topbar button { min-height: 44px; padding: .55rem .75rem; color: var(--blue-dark); background: transparent; }
.topbar button:hover { background: #e5efef; }
.topbar button.active, .topbar #timer-toggle { color: #fff; background: var(--blue-dark); }
.topbar .quiet { color: var(--blue-dark); }
#timer-display { min-width: 3.4rem; text-align: center; font-variant-numeric: tabular-nums; font-weight: 800; }
.timer-notice { padding: .7rem 1rem; color: #4c3508; background: #f3e5bb; text-align: center; font-weight: 800; }

.workspace {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(0, 940px);
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem clamp(1rem, 4vw, 3rem) 4rem;
  background: var(--desk);
}
.session-rail { color: var(--ink); }
.rail-heading { margin: 0 0 1rem; }
.rail-heading span, .rail-heading strong { display: block; }
.rail-heading span { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; }
.rail-heading strong { margin-top: .2rem; font-family: Georgia, serif; font-size: 1.35rem; }
.week-overview { display: grid; gap: .15rem; margin-bottom: 1rem; }
.week-summary {
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  padding: .45rem .55rem;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}
.week-summary strong, .week-summary span { display: block; }
.week-summary span { color: var(--muted); font-size: .75rem; font-weight: 400; }
.week-summary:hover { color: var(--ink); background: #ddebea; }
.week-summary.active { color: var(--blue-dark); background: #ddebea; outline: 1px solid #a3bdbf; }
.week-summary.active span { color: var(--muted); }
.session-list { display: grid; gap: .35rem; }
.session-tab {
  width: 100%;
  display: grid;
  grid-template-columns: 2.1rem 1fr auto;
  align-items: center;
  gap: .55rem;
  min-height: 48px;
  padding: .55rem .65rem;
  text-align: left;
  color: var(--ink);
  background: transparent;
  border-radius: 9px 0 0 9px;
}
.session-tab:hover { color: var(--ink); background: #ddebea; }
.session-tab span:first-child { font-variant-numeric: tabular-nums; color: var(--muted); }
.session-tab small { color: var(--muted); }
.session-tab.active { color: var(--ink); background: var(--paper); transform: translateX(8px); }
.session-tab.active span:first-child, .session-tab.active small { color: var(--blue-dark); }
.session-tab.checkpoint small { color: #74501c; }
.session-tab.active.checkpoint small { color: var(--blue-dark); }

.notebook, .parent-ledger {
  position: relative;
  min-width: 0;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.notebook { min-height: 700px; padding: clamp(1.2rem, 4vw, 2.5rem) clamp(1.2rem, 5vw, 3.5rem) 3rem; }
.session-header { display: flex; justify-content: space-between; gap: 2rem; align-items: start; }
.student-pdf-link { display: inline-block; margin-bottom: 1.2rem; font-weight: 700; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; text-wrap: balance; }
h1 { max-width: 20ch; margin: .15rem 0 .35rem; font-size: clamp(1.7rem, 3vw, 2.25rem); line-height: 1.08; letter-spacing: -.02em; }
h2 { margin-top: 0; font-size: 1.7rem; }
h3 { margin-bottom: .3rem; }
p { line-height: 1.55; }
.session-meta { margin: 0; color: var(--red); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.session-progress { min-width: 170px; margin-top: .3rem; font-size: .82rem; font-weight: 700; }
.rule-progress { height: 8px; margin-top: .45rem; overflow: hidden; background: var(--line); }
.rule-progress span { display: block; height: 100%; width: 0; background: var(--green); }
.saved-work > summary, .ledger-section > summary, .question-details summary { min-height: 44px; display: flex; align-items: center; color: var(--blue-dark); cursor: pointer; font-weight: 800; }
.questions { max-width: 72ch; }
.question-card { padding: 2.2rem 0 2.5rem; border-top: 1px solid var(--line); }
.question-card:first-child { margin-top: 1.5rem; border-top: 2px solid var(--ink); }
.question-number { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0 0 .55rem; color: var(--blue-dark); }
.question-number strong { font-size: 1rem; }
.question-number span { color: var(--muted); font-size: .85rem; font-weight: 700; text-align: right; }
.child-meta { margin: 0 0 .45rem; color: var(--blue-dark); font-weight: 800; }
.question-card h2 { margin: 0 0 1rem; font-size: 1.25rem; line-height: 1.4; }
.question-details { margin: .5rem 0 1rem; color: var(--muted); font-size: .85rem; }
.question-details p { margin: 0; }
.answer-form { display: grid; gap: .8rem; max-width: 580px; }
.answer-form label { font-weight: 800; }
.answer-form input, .answer-form textarea {
  width: 100%;
  border: 2px solid #78999c;
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255,255,255,.55);
  padding: .8rem;
}
.answer-form textarea { min-height: 150px; resize: vertical; }
.field-error { color: #70251b; font-weight: 800; }
.answer-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.answer-actions .hint-button { color: var(--blue-dark); border: 2px solid var(--blue-dark); background: transparent; }
.answer-actions .not-sure-button { color: #5e4714; border: 2px solid #8c6a1c; background: #fff8df; }
.feedback { margin: 1rem 0 0; padding: .85rem 1rem; border-radius: 9px; font-weight: 700; }
.feedback.correct { color: #17452f; background: #d8eadf; }
.feedback.incorrect { color: #70251b; background: #f3d9d2; }
.feedback.not-sure { color: #5e4714; background: #f3e5bb; }
.feedback.manual { color: #5e4714; background: #f3e5bb; }
.solution { margin-top: .8rem; padding: 1rem; border: 1px solid #91aaad; background: rgba(255,255,255,.4); }
.solution strong { display: block; margin-bottom: .25rem; }
.repair-panel { max-width: 72ch; margin-top: 1rem; padding: 1rem; border: 2px dashed var(--red); background: #fff8ec; }
.repair-panel h3 { margin-top: 0; }
.repair-prompt { font: 700 1.2rem/1.35 Georgia, serif; }
.math-visual { max-width: 420px; margin: .8rem 0 1.2rem; padding: .8rem; border: 1px solid var(--line); background: rgba(255,255,255,.45); }
.math-visual svg { display: block; width: 180px; max-width: 100%; margin: auto; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.math-visual svg .hour-hand { stroke-width: 5; }
.math-visual svg text { fill: var(--ink); stroke: none; font: 700 16px "Trebuchet MS", sans-serif; }
.math-visual.wide-visual { max-width: 520px; }
.math-visual.compact-model { margin: 0 0 .2rem; padding: .25rem; }
.math-visual.wide-visual svg { width: min(100%, 440px); }
.math-visual svg .visual-fill { fill: color-mix(in srgb, var(--blue) 34%, white); }
.math-visual svg .visual-red { fill: #e5a89d; }
.math-visual svg .visual-accent { stroke: var(--red); stroke-width: 7; }
.math-visual svg .visual-grid { stroke: var(--line); stroke-width: 1; }
.bar-visual div { display: grid; grid-template-columns: 4rem 1fr 2rem; align-items: center; gap: .6rem; margin: .45rem 0; }
.bar-visual i { display: block; width: var(--bar); min-width: 8px; height: 22px; background: var(--blue); }
.mobile-session-control { display: none; }

.parent-ledger {
  max-width: 1180px;
  min-height: calc(100vh - 120px);
  margin: 2rem auto 4rem;
  padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1.2rem, 5vw, 4rem);
}
.parent-header { display: flex; justify-content: space-between; gap: 2rem; }
.parent-header h1 { max-width: 22ch; }
.data-actions { display: flex; flex-wrap: wrap; align-content: start; justify-content: end; gap: .5rem; max-width: 420px; }
.data-actions p { flex-basis: 100%; margin: 0 0 .25rem; text-align: right; }
.file-button { display: inline-flex; align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.danger { background: var(--red); }
.danger:hover { background: #78291f; }
.ledger-section { margin-top: 2rem; padding-top: 1rem; border-top: 2px solid var(--ink); }
.ledger-note { max-width: 70ch; color: var(--muted); }
.parent-settings { display: flex; align-items: center; justify-content: space-between; gap: 2rem; }
.parent-settings h2, .parent-settings p { margin-bottom: .35rem; }
.setting-toggle { display: inline-flex; align-items: center; gap: .7rem; min-width: 220px; padding: .8rem 1rem; border: 2px solid var(--blue-dark); border-radius: 10px; color: var(--blue-dark); background: rgba(255,255,255,.45); font-weight: 800; cursor: pointer; }
.setting-toggle input { width: 1.25rem; height: 1.25rem; accent-color: var(--blue-dark); }
.skill-progress { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1.5rem; }
.skill-row { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.skill-row header { display: flex; justify-content: space-between; gap: .5rem; }
.skill-row strong:last-child { font-variant-numeric: tabular-nums; }
.skill-row .rule-progress { margin-top: .5rem; }
.state-counts { display: grid; grid-template-columns: repeat(4, auto); gap: .35rem .8rem; margin-top: .55rem; color: var(--muted); font-size: .78rem; }
.manual-review { display: grid; gap: .8rem; }
.review-item { display: grid; grid-template-columns: minmax(90px, .35fr) 1fr auto; gap: 1rem; align-items: start; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.review-item p { margin: .2rem 0; white-space: pre-wrap; }
.review-item button.reviewed { background: var(--green); }
.empty { padding: 1.2rem; color: var(--muted); border: 1px dashed #78999c; }
.week-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1.5rem; }
.parent-week-summary { min-height: 52px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; border-bottom: 1px solid var(--line); }
.parent-week-summary span { color: var(--muted); }
.guidance-list article, .repair-bank article { padding: .85rem 0; border-bottom: 1px solid var(--line); }
.guidance-list h3, .repair-bank h3 { margin-top: 0; }
.guidance-list p, .repair-bank p { margin: .25rem 0; }
.guidance-list { columns: 2 320px; column-gap: 2rem; }
.guidance-list article { break-inside: avoid; }
.repair-bank { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1.5rem; }
.repair-bank article button { margin-top: .45rem; }
.standards-list { columns: 2 300px; column-gap: 2rem; }
.standard-item { break-inside: avoid; padding: .6rem 0; }
.standard-item strong { display: block; }
.notice { margin-top: 1rem; padding: .8rem 1rem; color: #17452f; background: #d8eadf; border-radius: 9px; }
.notice.error { color: #70251b; background: #f3d9d2; }
dialog { max-width: 480px; border: 0; border-radius: 14px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
dialog form { padding: 1rem; }
dialog label { display: block; margin-bottom: .35rem; font-weight: 800; }
dialog input { width: 100%; min-height: 44px; padding: .65rem .75rem; border: 2px solid #78999c; border-radius: 9px; color: var(--ink); background: #fff; }
dialog::backdrop { background: rgba(23, 50, 77, .35); }
.dialog-actions { display: flex; justify-content: end; gap: .6rem; }
.dialog-error { color: #70251b; font-weight: 700; }
.quiet-dialog { color: var(--blue-dark); border: 2px solid var(--blue-dark); background: transparent; }

@media (max-width: 820px) {
  .topbar, .parent-header { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: space-between; flex-wrap: wrap; }
  .workspace { grid-template-columns: 1fr; padding: 1rem 0 3rem; }
  .session-rail { display: none; }
  .mobile-session-control { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .6rem; margin-bottom: .8rem; font-weight: 800; }
  .mobile-session-control select { min-height: 44px; min-width: 0; border: 2px solid var(--blue-dark); border-radius: 9px; color: var(--ink); background: #fff; padding: .5rem; }
  .notebook, .parent-ledger { border-radius: 0; }
  .notebook { min-height: 700px; padding: 1rem 1.1rem 2.5rem; }
  .parent-settings { align-items: stretch; flex-direction: column; gap: .75rem; }
  .session-header { display: block; }
  .session-progress { margin-top: 1rem; }
  .parent-ledger { margin: 0; padding: 1.25rem 1.1rem 3rem; }
  .data-actions { justify-content: start; }
  .data-actions p { text-align: left; }
  .review-item { grid-template-columns: 1fr; }
  .state-counts { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .topbar { gap: .55rem; padding: .6rem .75rem; }
  .brand svg { width: 34px; height: 34px; }
  .brand span { display: none; }
  .top-actions { display: grid; grid-template-columns: 1fr auto; align-items: start; }
  .profile-switch { grid-column: 1 / -1; justify-content: space-between; }
  .view-switch { grid-column: 1 / -1; justify-content: stretch; flex-wrap: wrap; }
  .view-switch button { flex: 1; }
  .adaptive-link { flex: 1 0 100%; justify-content: center; order: 1; }
  .timer { grid-column: 1 / -1; min-width: 0; }
  .timer-controls { position: absolute; z-index: 8; right: .75rem; left: .75rem; flex-wrap: wrap; padding: .65rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); box-shadow: var(--shadow); }
  .timer-help { flex-basis: 100%; max-width: none; }
  .session-header { display: flex; align-items: start; }
  .session-header h1 { font-size: 1.45rem; }
  .session-note { margin: .15rem 0; }
  .session-progress { min-width: 120px; margin-top: 0; text-align: right; }
  .question-card { padding: 1.7rem 0 2rem; }
  .question-card h2 { font-size: 1.15rem; }
  .question-number { align-items: flex-start; flex-direction: column; gap: .15rem; }
  .question-number span { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
