:root {
  color-scheme: light;
  --bg: #e7eef0;
  --ink: #102027;
  --muted: #3d4c57;
  --line: #d3dee3;
  --card: #ffffff;
  --accent: #0c5c56;
  --accent-ink: #ffffff;
  --warn: #7a3018;
  --warn-bg: #fde8df;
  --ok: #0d5c32;
  --ok-bg: #e5f6ee;
  --tutor: #f3faf8;
  --student: #f8f4ea;
  --shadow: 0 10px 30px rgba(16, 32, 39, 0.06);
  --radius: 16px;
  --tap: 44px;
  --measure: 68ch;
  --page: min(100% - 1.25rem, 100%);
}

html { font-size: 18px; }
html[data-text="sm"] { font-size: 16px; }
html[data-text="md"] { font-size: 18px; }
html[data-text="lg"] { font-size: 22px; }

* { box-sizing: border-box; }

html, body { max-width: 100%; }

body {
  margin: 0;
  overflow-x: clip;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(12, 92, 86, 0.08), transparent 28rem),
    var(--bg);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  overflow-wrap: break-word;
}

img, svg, video, canvas { max-width: 100%; height: auto; }

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.25;
  font-weight: 600;
  overflow-wrap: anywhere;
}

h1 { font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.5rem); margin: 0 0 0.55rem; }
h2 { font-size: clamp(1.3rem, 1.05rem + 0.7vw, 1.7rem); margin: 0 0 0.55rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 0.35rem; }

p { margin: 0 0 0.8rem; }
a { color: var(--accent); }
.prose { max-width: var(--measure); }

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--ink);
  color: white;
  padding: 0.55rem 0.8rem;
  z-index: 5;
}
.skip:focus { top: 0.5rem; }

.wrap {
  width: min(1120px, calc(100% - clamp(1rem, 4vw, 2rem)));
  margin: 0 auto;
}

.site-header, .site-footer {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}
.site-footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
  padding: 1rem 0 calc(1.2rem + env(safe-area-inset-bottom));
  color: var(--muted);
}
.site-header { padding: 0.7rem 0; }

.header-row, .header-tools, .site-nav, .text-size, .voice-samples, .action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.header-row { justify-content: space-between; }
.header-tools { justify-content: flex-end; }
.site-nav form { margin: 0; }

.brand {
  display: flex;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
  min-height: var(--tap);
  justify-content: center;
  max-width: 100%;
}
.mark { font-family: Georgia, serif; font-size: clamp(1.15rem, 1rem + 0.6vw, 1.45rem); }
.mark-note { color: var(--muted); font-size: 0.92rem; }

main { padding: 1rem 0 2rem; }

.card, .hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  min-width: 0;
}
.hero {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.lede { margin: 0; max-width: var(--measure); }

.stack, .parent-grid, .grade-grid, .admin-grid, .login-layout, .home-shell, .lesson-shell {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.banner, .status {
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
}
.banner { background: #efe7d2; }
.banner.warn, .status.warn { background: var(--warn-bg); color: var(--warn); }
.status.ok { background: var(--ok-bg); color: var(--ok); }

label, .choice { display: block; margin: 0.75rem 0 0.35rem; }
.choice {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  min-height: var(--tap);
  margin: 0.35rem 0;
}
.choice input { width: 1.25rem; height: 1.25rem; min-height: 1.25rem; }

input, select, textarea, button, .button, .action, .topic-link {
  font: inherit;
  font-size: 1rem;
}
input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0.6rem 0.75rem;
  border: 1px solid #b7c6cc;
  border-radius: 12px;
  background: white;
  color: var(--ink);
}
textarea { min-height: 8rem; resize: vertical; }

button, .button, .action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  margin-top: 0.75rem;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.site-nav button, .text-size button, .voice-samples button { width: auto; margin-top: 0; }
.browser-voice { display: grid; gap: 0.35rem; margin: 0.4rem 0 0.8rem; }
.browser-voice[hidden] { display: none !important; }
.voice-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.voice-choice { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.voice-choice .voice-name { flex: 1 1 12rem; min-width: 0; }
.voice-choice button { width: auto; margin-top: 0; min-height: 44px; }
.speech-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 0.2rem; width: 100%; }
.speech-actions .action { flex: 1 1 12rem; width: auto; min-width: 0; min-height: 44px; height: auto; margin-top: 0; }
.dialog-head { display: grid; gap: 0.45rem; }
.voice-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.voice-picker label { font-weight: 700; }
.voice-picker select { width: min(100%, 18rem); margin-top: 0; }
.voice-picker button { width: auto; min-width: 0; margin-top: 0; min-height: 44px; }
.rate-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.rate-picker span { font-weight: 700; }
.rate-picker button { width: auto; min-width: 44px; min-height: 44px; margin-top: 0; }
.rate-picker button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.quick-asks { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.4rem 0; }
.quick-asks form { margin: 0; }
.quick-asks button { width: auto; min-width: 0; margin-top: 0; min-height: 44px; }
.composer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.composer-bar .icon-button, .composer-bar button { width: auto; flex: 0 0 auto; margin-top: 0; }
.composer-bar #send-question { flex: 1 1 8rem; }
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  min-width: 44px;
  margin-top: 0;
  padding: 0.45rem 0.75rem;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}
.mic-button.is-listening, .icon-button.is-listening {
  background: #9d1c1c;
  border-color: #9d1c1c;
  color: #fff;
}
.icon-button.is-listening .mic-face { animation: mic-pulse 1s ease-in-out infinite; }
@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.photo-draft { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 0.5rem; }
.photo-draft[hidden] { display: none !important; }
.photo-draft img { width: 7rem; height: 7rem; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.photo-form { margin-top: 0.4rem; }
.says p { margin: 0.45rem 0; }
.says ul, .says ol { margin: 0.35rem 0 0.35rem 1.2rem; padding: 0; }
.says li { margin: 0.25rem 0; }
.dmath, .imath { font-family: Georgia, "Times New Roman", serif; }
.dmath { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin: 0.6rem 0; font-size: 1.35rem; }
.imath { display: inline-flex; align-items: center; }
button.secondary, .action.is-unavailable {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.action.is-unavailable { color: var(--muted); border-color: #9aab8f; cursor: not-allowed; }
.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.35rem;
  text-decoration: none;
  font-weight: 650;
}

.text-size button {
  min-width: var(--tap);
  padding-inline: 0.7rem;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.text-size button[data-text-size="sm"] { font-size: 0.9rem; }
.text-size button[data-text-size="lg"] { font-size: 1.25rem; }
.text-size button[aria-pressed="true"] { background: var(--accent); color: white; }

.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-link {
  display: flex;
  align-items: center;
  width: auto;
  min-height: var(--tap);
  margin: 0;
  justify-content: flex-start;
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  text-decoration: none;
}
.topic-link:hover, .topic-link.is-current { background: var(--tutor); color: var(--accent); }
.topic-link.is-static { cursor: default; }

.book-button { width: auto; min-height: 44px; margin: 0; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.tutor-hero { align-items: start; }
.tutor-home { margin-top: 0.8rem; }
.toc-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.toc-head h2 { margin: 0; }
.toc-head button { width: auto; min-width: 0; margin: 0; }
dialog#textbook {
  width: min(36rem, calc(100vw - 1.5rem));
  max-height: min(80vh, 42rem);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
}
dialog#textbook::backdrop { background: rgba(16, 32, 39, 0.45); }
.toc-section { margin: 0.35rem 0; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.toc-section summary { min-height: 44px; padding: 0.65rem 0.8rem; font-weight: 700; cursor: pointer; }
.toc-section .topic-list { padding: 0 0.4rem 0.4rem; }

.topic-drawer > summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-weight: 700;
  cursor: pointer;
}
.topic-drawer[open] > summary { border-radius: 12px 12px 0 0; }
.topic-drawer .topic-list {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: white;
  padding: 0.4rem;
}

.formula-box {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.8rem;
  border-radius: 12px;
  background: #f4fbf9;
  border: 1px solid #d5ebe6;
}
.math {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  max-width: 100%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.25rem, 1rem + 0.8vw, 1.75rem);
  line-height: 1.35;
}
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  margin-inline: 0.1rem;
}
.frac .num, .frac .den { text-align: center; }
.frac .den { border-top: 0.08em solid currentColor; padding-top: 0.08em; min-width: 0.8em; }
.op { margin-inline: 0.25rem; }
sub, sup { line-height: 0; }

.transcript { display: grid; gap: 0.7rem; min-width: 0; }
.message {
  max-width: min(100%, 65ch);
  border-radius: 14px;
  padding: 0.75rem 0.85rem;
}
.message .who { margin: 0 0 0.25rem; color: var(--muted); font-size: 0.92rem; }
.message p:last-child { margin: 0; }
.message.tutor { background: var(--tutor); }
.message.student { background: var(--student); margin-left: auto; }

.action-grid { margin: 0.4rem 0 0.8rem; }
.action-grid form { margin: 0; min-width: 0; flex: 1 1 14rem; display: flex; }
.action-grid form .action { width: 100%; }
.action-grid .action { margin-top: 0; flex: 1 1 14rem; }
.dialog, .lesson-card, .composer { min-width: 0; }
.composer-actions { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.message .says { margin: 0; }
.composer {
  margin-top: 0.8rem;
  padding: 0.15rem 0 0.2rem;
}
.dialog .composer:last-of-type {
  padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
}
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.file-action { margin-top: 0.4rem; }
.file-name:empty { display: none; }
.hint, .unavailable-note { color: var(--muted); max-width: var(--measure); }
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.file-list li, .file-list a {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  min-height: var(--tap);
}
.rules { max-width: var(--measure); padding-left: 1.2rem; }
.facts { margin: 0; display: grid; gap: 0.7rem; }
.facts div { min-width: 0; }
.facts dt { font-weight: 700; }
.facts dd { margin: 0.15rem 0 0; }
.demo-list { padding-left: 1.1rem; max-width: var(--measure); }
code { overflow-wrap: anywhere; }

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.65rem 0.45rem;
  border-bottom: 1px solid var(--line);
}
td form { margin: 0; }
td button { margin-top: 0; width: auto; }

.inline-form { display: grid; gap: 0.35rem 0.8rem; }
.inline-form button { justify-self: stretch; }

:focus-visible {
  outline: 3px solid #0b4f8a;
  outline-offset: 3px;
}

.lab-card { min-width: 0; max-width: 52rem; }
.lab-card h1 { font-size: clamp(1.25rem, 1rem + 2vw, 2.1rem); }
.lab-details {
  margin: 0.7rem 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.lab-details > summary {
  cursor: pointer;
  padding: 0.8rem 0.9rem;
  font-weight: 700;
  min-height: var(--tap);
  list-style-position: inside;
}
.lab-details-body { padding: 0 0.9rem 0.9rem; min-width: 0; }
.lab-steps, .lab-ready-list { padding-left: 1.2rem; }
.lab-steps li, .lab-details li { margin: 0.35rem 0; }
.lab-formula {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.lab-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.lab-table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
}
.lab-table th, .lab-table td {
  border: 1px solid var(--line);
  padding: 0.45rem;
  text-align: left;
  vertical-align: middle;
}
.lab-table input {
  width: 100%;
  min-width: 5.5rem;
  min-height: var(--tap);
}
.lab-conclusion { width: 100%; max-width: 100%; }
.lab-fill {
  color: var(--warn);
  background: var(--warn-bg);
  padding: 0 0.2rem;
  border-radius: 6px;
}
.emergency-help > summary { color: var(--warn); }

@media (max-width: 599px) {
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; width: 100%; }
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  tr {
    margin-bottom: 0.8rem;
    padding: 0.35rem 0.7rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  td { border: 0; padding: 0.45rem 0; }
  td::before {
    content: attr(data-label);
    display: block;
    font-weight: 700;
    color: var(--muted);
  }
  td button { width: 100%; }
  .lab-table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
  }
  .lab-table,
  .lab-table thead,
  .lab-table tbody,
  .lab-table tr,
  .lab-table th,
  .lab-table td {
    display: revert;
    width: auto;
  }
  .lab-table { display: table; width: 100%; min-width: 32rem; }
  .lab-table thead {
    display: table-header-group;
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }
  .lab-table tbody { display: table-row-group; }
  .lab-table tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
  }
  .lab-table th, .lab-table td {
    display: table-cell;
    border: 1px solid var(--line);
    padding: 0.45rem;
  }
  .lab-table td::before { content: none; }
  .speech-actions { flex-direction: column; align-items: stretch; }
  .speech-actions .action { width: 100%; flex: 0 0 auto; }
  .voice-choice { flex-direction: column; align-items: stretch; }
  .voice-choice button { width: 100%; }
}

@media (min-width: 600px) {
  .wrap { width: min(1120px, calc(100% - 2rem)); }
  .action-grid { display: grid; grid-template-columns: 1fr 1fr; }
  .composer-actions button { width: 100%; min-width: 0; }
  .action-grid .action { width: auto; min-width: 0; max-width: 100%; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form button { grid-column: 1 / -1; justify-self: start; width: auto; min-width: 12rem; }
  .login-layout { grid-template-columns: 1fr 1fr; align-items: start; }
  .parent-grid { grid-template-columns: 1fr 1fr; }
  button, .button { width: auto; min-width: 12rem; }
  .action, .file-action, .action-grid .action { width: 100%; }
}

@media (min-width: 768px) {
  .lesson-shell { align-items: start; }
  .hero { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
}

@media (max-width: 767px) {
  .topic-drawer:not([open]) .topic-list { display: none; }
}

@media (min-width: 1024px) {
  .wrap { width: min(1240px, calc(100% - 2.5rem)); }
  .lesson-shell { grid-template-columns: minmax(16rem, 1.15fr) minmax(16rem, 1fr); }
  .toc-launch { grid-column: 1 / -1; }
  .lesson-card { grid-column: 1; }
  .dialog { grid-column: 2; }
  .lab-shell { grid-template-columns: 1fr; }
  .lab-shell .lesson-card { grid-column: 1; }
  .grade-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .admin-grid { grid-template-columns: 0.8fr 1.2fr; align-items: start; }
  .site-nav button { min-width: 0; }
}

@media (min-width: 1440px) {
  .wrap { width: min(1440px, calc(100% - 3rem)); }
  .lesson-shell { grid-template-columns: minmax(18rem, 1.2fr) minmax(22rem, 1fr); }
  .message { max-width: min(100%, 62ch); }
}

@media (max-height: 500px) and (orientation: landscape) {
  .site-header { padding-block: 0.25rem; }
  .card, .hero { padding: 0.7rem; }
  h1 { font-size: 1.45rem; }
  .topic-drawer .topic-list { max-height: calc(100vh - 4.5rem); }
}

@media (min-width: 1024px) {
  .dialog {
    position: sticky;
    top: 0.75rem;
    max-height: calc(100vh - 5.5rem);
    overflow: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  .icon-button.is-listening .mic-face { animation: none; }
}

@media (prefers-contrast: more) {
  :root { --line: #102027; --muted: #102027; }
  button, .action, input, select, textarea { border: 2px solid #102027; }
}
