/* Prepnol — Material 3 tokens & base */

/* Fonts — variable woff2, weights 400–900 */
@font-face {
  font-family: Roboto;
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("../fonts/roboto-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}

/* -v2: instanced to wght 400–700 (the weights the CSS uses) and subset to the
   unicode-range below — 120 KB against the 191 KB full face. Regenerate with
   fonttools varLib.instancer + pyftsubset; new glyph needs = new filename
   (see public/_headers) and a matching bump of the app.css?v= references. */
@font-face {
  font-family: "Noto Serif Bengali";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/noto-serif-bengali-v2.woff2") format("woff2");
  unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+200C-200D, U+20B9, U+25CC;
}

:root {
  color-scheme: light;

  /* Color — M3 scheme generated from seed #1e6b54 with
     @material/material-color-utilities; primary kept as the exact brand hex */
  --md-sys-color-primary: #1e6b54;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #82f8cf;
  --md-sys-color-on-primary-container: #002117;
  --md-sys-color-secondary-container: #cee9dc;
  --md-sys-color-on-secondary-container: #082018;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-surface: #fbfdf9;
  --md-sys-color-on-surface: #191c1b;
  --md-sys-color-on-surface-variant: #404944;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f2f7f2;
  --md-sys-color-surface-container: #e6efe9;
  --md-sys-color-surface-container-high: #dbe9e0;
  --md-sys-color-outline: #6f7973;
  --md-sys-color-outline-variant: #bfc9c3;

  /* Shape */
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* Layout */
  --gutter: 8px;
  /* Where page content starts below the top bar — every page container uses
     this, so the gap can never drift apart between one page and the next */
  --page-top: 20px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Round the focus ring on plain text links */
section header a:focus-visible,
footer a:focus-visible {
  border-radius: 4px;
}

[id] {
  scroll-margin-top: 56px; /* keep anchor targets clear of the sticky top bar */
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: Roboto, "Noto Serif Bengali", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

/* Top app bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--gutter);
  background: var(--md-sys-color-surface);
  transition: background-color 200ms cubic-bezier(0.2, 0, 0, 1);
}

.scrolled .topbar {
  background: var(--md-sys-color-surface-container);
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.25px;
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

/* Play Store link, the only thing on the right of the top bar. 40px matches
   .btn and .btn-text; the negative margin pulls the box to the screen edge so
   the icon inside it sits on the same optical gutter as the brand opposite. */
.topbar-app {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: -8px;
  border-radius: var(--md-sys-shape-corner-full);
  /* The brand green, so the bar reads as one unit: wordmark left, mark right */
  color: var(--md-sys-color-primary);
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.topbar-app:hover {
  background: var(--md-sys-color-secondary-container);
}

.topbar-app svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  /* Same 2px as every other icon, scaled for this glyph's 256 grid (2/24×256) */
  stroke-width: 21.33;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons */
/* Low-emphasis button — .btn's metrics with no fill. For actions that must be
   reachable but must not compete with the screen's primary action. */
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.btn-text:hover {
  background: color-mix(in srgb, currentColor 8%, transparent);
}

.btn {
  --bg: var(--md-sys-color-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font: inherit;
  font-weight: 500;
  background: var(--bg);
  color: var(--md-sys-color-on-primary);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

/* M3 state layers: 8% hover, 10% press of the label color over the fill */
.btn:hover {
  background: color-mix(in srgb, currentColor 8%, var(--bg));
}

.btn:active {
  background: color-mix(in srgb, currentColor 10%, var(--bg));
}


/* Hero */
.hero {
  margin: var(--page-top) var(--gutter) 0;
  padding: 28px 20px 24px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.hero small {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--md-sys-color-primary-container);
}

.hero h1 {
  margin: 12px 0 8px;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.3;
}

.hero p {
  margin: 0;
  max-width: 36ch;
  font-size: 14px;
  line-height: 1.55;
  color: color-mix(in srgb, var(--md-sys-color-on-primary) 86%, transparent);
}

.hero .btn {
  --bg: var(--md-sys-color-primary-container);
  margin-top: 20px;
  height: 44px;
  padding: 0 24px;
  color: var(--md-sys-color-on-primary-container);
}

.hero .btn:focus-visible {
  outline-color: var(--md-sys-color-primary-container);
}

/* The hero has no entrance animation, deliberately. It used to fade and rise,
   which pinned Largest Contentful Paint to the end of the animation (740ms on
   the home page against a 60ms first paint) because an element at opacity 0
   does not count as painted. Dropping the fade fixed the metric but left a
   bare 10px slide that read as a jolt, and a blur-in reads no better on
   headline type. Static is the honest answer: the hero is the first thing on
   screen, so there is nothing for it to animate in against. */

/* Sections — shared header rhythm */
section {
  padding: var(--page-top) var(--gutter);
}

/* Class, subject and book pages lead with an h1 (the page's own subject —
   "Class 10 Science Notes"); the hub pages lead with .hero h1 and use h2 for
   the sections below. Both land on the same rhythm here. */
section :is(h1, h2) {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.15px;
}

section header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

hgroup {
  margin: 0;
}

hgroup p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

section header a {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

section header a:hover {
  text-decoration: underline;
}


/* Class picker */

.classes ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

/* Board-exam years (10 and 12) get a wider card, only when the
   auto-fill grid resolves to exactly 3 columns (344–455px viewport) */
@media (min-width: 344px) and (max-width: 455.98px) {
  .classes .board {
    grid-column: span 2;
  }
}

.classes a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 84px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container);
  text-decoration: none;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1),
    transform 150ms cubic-bezier(0.2, 0, 0, 1);
}

.classes a:hover {
  background: var(--md-sys-color-surface-container-high);
}

/* Tonal fill marks the board-exam years */
.classes .board a {
  background: var(--md-sys-color-secondary-container);
}

.classes .board small {
  color: var(--md-sys-color-on-secondary-container);
}

.classes .board a:hover {
  background: var(--md-sys-color-primary-container);
}

.classes b {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--md-sys-color-primary);
}

.classes small {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.classes a:active {
  background: var(--md-sys-color-primary-container);
  transform: scale(0.97);
}

.classes a:active b {
  color: var(--md-sys-color-on-primary-container);
}

/* Featured notes */
.notes ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.notes li {
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}

.notes a {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  text-decoration: none;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.notes a:hover {
  background: var(--md-sys-color-surface-container);
}

.notes a:focus-visible {
  outline-offset: -2px;
}

.notes img {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 2px;
}

.notes h3 {
  margin: 0;
  padding-left: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.notes data {
  padding-right: 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--md-sys-color-primary);
}

/* Search bar */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 16px;
  margin-bottom: 16px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
}

.search:focus-within {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -1px;
}

.search svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--md-sys-color-on-surface-variant);
  stroke-width: 2;
  stroke-linecap: round;
}

.search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--md-sys-color-on-surface);
}

.search input:focus,
.search select:focus {
  outline: none; /* the ring is drawn on the container via :focus-within */
}

.search input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

/* Class picker inside the search bar */
.search select {
  max-width: 40%;
  align-self: stretch;
  border: none;
  border-left: 1px solid var(--md-sys-color-outline-variant);
  padding-left: 12px;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

/* Empty state */
.empty {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}

/* Loading spinner — M3 circular progress, simplified */
.spinner {
  width: 28px;
  height: 28px;
  margin: 20px auto 8px;
  border-radius: 50%;
  border: 3px solid var(--md-sys-color-secondary-container);
  border-top-color: var(--md-sys-color-primary);
  animation: spin 800ms linear infinite;
}

/* Whole-page load state — the client-rendered screens (/account, the quiz)
   show this instead of a blank body while their first fetches are in flight */
.page-status {
  flex: 1;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 48px var(--gutter);
  text-align: center;
}

.page-status p {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 40ch;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

/* Subject list */
.subjects ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}

.subjects li + li a {
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.subjects a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  text-decoration: none;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.subjects a:hover {
  background: var(--md-sys-color-surface-container);
}

.subjects a:active {
  background: var(--md-sys-color-surface-container-high);
}

.subjects a:focus-visible {
  outline-offset: -2px;
}

.subjects svg {
  flex-shrink: 0;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Leading icon in a tonal circle */
.subjects svg:first-of-type {
  width: 40px;
  height: 40px;
  padding: 9px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  stroke: var(--md-sys-color-on-secondary-container);
}

/* Trailing chevron */
.subjects svg:last-of-type {
  width: 20px;
  height: 20px;
  margin-left: auto;
  stroke: var(--md-sys-color-on-surface-variant);
}

.subjects h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.subjects small {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

/* Chapter list */
.chapters ol {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}

.chapters li + li a {
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.chapters a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  text-decoration: none;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.chapters a:hover {
  background: var(--md-sys-color-surface-container);
}

.chapters a:active {
  background: var(--md-sys-color-surface-container-high);
}

.chapters a:focus-visible {
  outline-offset: -2px;
}

.chapters b {
  flex-shrink: 0;
  min-width: 24px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  color: var(--md-sys-color-primary);
}

.chapters div {
  flex: 1;
}

.chapters h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--md-sys-color-on-surface);
}

/* Assamese chapter title */
.chapters div small {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

/* Free badge on the first chapter */
.chapters a > small {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Lock on paid chapters */
.chapters svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--md-sys-color-on-surface-variant);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Before the session is known, a paid chapter shows neither a lock nor a tap
   response — visibility (not display) so the row does not reflow when the
   answer arrives. Free chapters carry no data-play and stay live throughout. */
.chapters[data-entitlement="pending"] a[data-play] {
  pointer-events: none;
}

.chapters[data-entitlement="pending"] a[data-play] > svg {
  visibility: hidden;
}

/* Order form */
.order form {
  display: grid;
  gap: 16px;
}

.order .btn {
  width: 100%;
  height: 48px;
}

/* Low-emphasis sample link under the pay button */
.order form > a {
  justify-self: center;
  margin-top: -8px;
  padding: 2px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.order form > a:hover {
  text-decoration: underline;
}

/* Delivery details — revealed when a printed copy is chosen */
.delivery {
  display: grid;
  gap: 16px;
  max-height: 280px; /* > tallest content; enables the collapse transition */
  overflow: hidden;
  transition: max-height 250ms cubic-bezier(0.2, 0, 0, 1),
    opacity 250ms cubic-bezier(0.2, 0, 0, 1),
    display 250ms allow-discrete;
}

/* display:none removes the row entirely, so the form's grid gap stays even;
   allow-discrete + @starting-style keep the toggle animated */
.delivery[hidden] {
  display: none;
  max-height: 0;
  opacity: 0;
}

@starting-style {
  .delivery {
    max-height: 0;
    opacity: 0;
  }
}

/* Text field — M3 outlined, with floating label */
.field {
  position: relative;
  display: block;
}

.field input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  background: none;
  font: inherit;
  color: var(--md-sys-color-on-surface);
}

.field input:focus {
  outline: none; /* the thickened M3 border below is the focus indicator */
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.field span {
  position: absolute;
  top: 26px; /* center of the 52px input, not of the label (error text adds height) */
  left: 12px;
  translate: 0 -50%;
  padding: 0 4px;
  /* The label notches the outline, so it has to be painted in whatever colour
     sits behind the field — containers with their own background set --field-notch */
  background: var(--field-notch, var(--md-sys-color-surface));
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
  transition: top 150ms cubic-bezier(0.2, 0, 0, 1),
    font-size 150ms cubic-bezier(0.2, 0, 0, 1);
}

.field input:focus + span,
.field input:not(:placeholder-shown) + span {
  top: 0;
  font-size: 12px;
}

.field input:focus + span {
  color: var(--md-sys-color-primary);
}

/* Prefix text (e.g. +91) — appears once the field is focused or filled */
.field b {
  position: absolute;
  top: 26px; /* center of the 52px input, not of the label (error text adds height) */
  left: 16px;
  translate: 0 -50%;
  font-weight: 400;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms cubic-bezier(0.2, 0, 0, 1);
}

.field b + input {
  padding-left: 48px;
}

.field:has(input:focus) b,
.field:has(input:not(:placeholder-shown)) b {
  opacity: 1;
}

/* Disabled — M3: 12% outline, 38% content, and no text cursor. Used for values
   that are shown but not editable here, e.g. the WhatsApp number on /account */
.field input:disabled {
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  /* WebKit paints its own grey over `color` on a disabled control */
  -webkit-text-fill-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  opacity: 1; /* Safari dims disabled controls on top of the colours above */
  cursor: not-allowed;
}

.field input:disabled + span,
.field:has(input:disabled) b {
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}

/* Read-only — for a value the student must be able to read but not change
   here, e.g. their WhatsApp number (identity, admin-only, spec §9). Unlike
   :disabled it keeps full text contrast and stays keyboard-reachable; the
   tinted fill and softened outline are what say "locked". */
.field input[readonly] {
  border-color: var(--md-sys-color-outline-variant);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 4%, transparent);
  cursor: default;
}

/* Error state — after the user has interacted with the field */
.field input:user-invalid {
  border-color: var(--md-sys-color-error);
}

.field input:user-invalid:focus {
  border-color: var(--md-sys-color-error);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-error);
}

.field input:user-invalid + span,
.field input:user-invalid:focus + span {
  color: var(--md-sys-color-error);
}

.field small {
  display: none;
  margin: 4px 16px 0;
  font-size: 12px;
  color: var(--md-sys-color-error);
}

.field:has(input:user-invalid) small {
  display: block;
}

/* Segmented buttons — single-select, two to three options */
.segmented {
  margin: 0;
  padding: 0;
  border: none;
}

.segmented legend {
  padding: 0 4px 0 16px; /* line the label up with the floating labels of .field */
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.segmented div {
  display: flex;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
}

.segmented label {
  flex: 1;
}

.segmented label + label {
  border-left: 1px solid var(--md-sys-color-outline);
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.segmented span:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.segmented svg {
  display: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.segmented input:checked + span {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.segmented input:checked + span svg {
  display: block;
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -2px;
}

/* Bottom sheet — M3 modal bottom sheet on a native <dialog> */
.sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 24px calc(24px + env(safe-area-inset-bottom));
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large)
    var(--md-sys-shape-corner-extra-large) 0 0;
  --field-notch: var(--md-sys-color-surface-container-low);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  translate: 0 100%;
  transition: translate 300ms cubic-bezier(0.05, 0.7, 0.1, 1),
    display 300ms allow-discrete,
    overlay 300ms allow-discrete;
}

.sheet[open] {
  translate: 0 0;
}

/* Drag handle */
.sheet::before {
  content: "";
  display: block;
  width: 32px;
  height: 4px;
  margin: 12px auto 16px;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 40%, transparent);
}

/* Leading icon in a tonal circle */
.sheet > svg {
  display: block;
  width: 48px;
  height: 48px;
  padding: 12px;
  margin: 0 auto 12px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  fill: none;
  stroke: var(--md-sys-color-on-secondary-container);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sheet h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

/* What the unlock includes */
.sheet ul {
  list-style: none;
  display: grid;
  gap: 10px;
  margin: 0 0 20px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container);
}

.sheet li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
}

.sheet li svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--md-sys-color-primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sheet .btn {
  width: 100%;
  height: 48px;
}

/* Dismiss — M3 text button */
.sheet form {
  margin-top: 8px;
}

.sheet form button {
  width: 100%;
  height: 44px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.sheet form button:hover {
  background: color-mix(in srgb, currentColor 8%, transparent);
}

.sheet form button:active {
  background: color-mix(in srgb, currentColor 10%, transparent);
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0);
  transition: background-color 300ms cubic-bezier(0.05, 0.7, 0.1, 1),
    display 300ms allow-discrete,
    overlay 300ms allow-discrete;
}

.sheet[open]::backdrop {
  background: rgb(0 0 0 / 0.32);
}

@starting-style {
  .sheet[open] {
    translate: 0 100%;
  }

  .sheet[open]::backdrop {
    background: rgb(0 0 0 / 0);
  }
}

/* Keep the page from scrolling behind an open sheet */
body:has(.sheet[open]) {
  overflow: hidden;
}

/* About */
.about hgroup p {
  font-size: 15px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
}

.about p {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 60ch;
}

/* Static page — About and legal pages (privacy, terms, refunds, …).
   One <main class="page"> wrapping an <article>; the article header holds
   the page title plus a tagline or a "Last updated" <time> line. */
.page {
  flex: 1;
  padding: var(--page-top) var(--gutter) 40px;
}

.page article {
  max-width: 62ch;
}

.page h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.page article > header {
  margin-bottom: 20px;
}

.page article > header p {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
}

/* Section headings sit close to their own text, apart from the previous
   block; both levels are 16px, told apart by weight */
.page h2,
.page h3 {
  font-size: 16px;
  line-height: 1.4;
  color: var(--md-sys-color-on-surface);
}

.page h2 {
  margin: 28px 0 0;
  font-weight: 600;
}

/* Lighter than .page h2, which is the same 16px — weight is what separates
   the two levels on About and the policy pages, which use both. */
.page h3 {
  margin: 20px 0 0;
  font-weight: 500;
}

.page p {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--md-sys-color-on-surface-variant);
}

.page ul,
.page ol {
  margin: 10px 0 0;
  padding-left: 22px;
}

.page li {
  margin-top: 6px;
  line-height: 1.65;
  color: var(--md-sys-color-on-surface-variant);
}

.page a {
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.page a:hover {
  text-decoration: underline;
}

/* Footer — bottom padding clears the fixed bottom nav, so the two
   surface-container areas read as one continuous surface */
footer {
  margin-top: auto; /* stick to the bottom on short pages */
  padding: 20px var(--gutter) calc(32px + 68px + env(safe-area-inset-bottom));
  background: var(--md-sys-color-surface-container);
}

footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

footer a {
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
}

footer a:hover {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
}

footer small {
  display: block;
  margin-top: 16px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

/* Bottom navigation bar — fixed, so it is out of flow and pages carrying one
   must reserve its height (68px plus the home-indicator inset) or whatever
   ends the page scrolls under it. Pages with a footer already reserve it in
   the footer's own padding, so that the surface runs behind the bar unbroken;
   padding the body too would cut a blank strip between them. Reset in the
   ≥840px rail layout below. */
body:has(.bottomnav):not(:has(footer)) {
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--md-sys-color-surface-container);
}

.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.25px;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
}

.bottomnav svg {
  width: 54px;
  height: 28px;
  padding: 3px 16px;
  border-radius: var(--md-sys-shape-corner-full);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

/* M3 state layers: 8% hover, 10% press over on-surface */
.bottomnav a:hover svg {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.bottomnav a:active svg {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
}

.bottomnav a[aria-current] {
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.bottomnav a[aria-current] svg {
  background: var(--md-sys-color-secondary-container);
  stroke: var(--md-sys-color-on-secondary-container);
}

.bottomnav a[aria-current]:hover svg {
  background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 8%, var(--md-sys-color-secondary-container));
}

.bottomnav a:focus-visible {
  outline-offset: -2px;
  border-radius: var(--md-sys-shape-corner-small);
}

/* Auth flow — narrow centered column, one step (form) visible at a time */
.auth {
  flex: 1;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: var(--page-top) var(--gutter) 48px;
}

.auth form {
  display: grid;
  gap: 16px;
}

/* display:grid above would otherwise beat the hidden attribute */
.auth form[hidden] {
  display: none;
}

.auth h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.auth form > p {
  margin: -6px 0 6px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--md-sys-color-on-surface-variant);
}

.auth .btn {
  height: 48px;
}

/* One-time password — roomy, evenly spaced digits */
.otp input {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 8px;
  font-variant-numeric: tabular-nums;
}

/* Low-emphasis actions (resend, change number) — M3 text buttons.
   Direct children only, so the segmented control's inner div keeps its own layout */
.auth form > div {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.auth form button:not(.btn) {
  padding: 8px 12px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
}

.auth form button:not(.btn):hover {
  background: color-mix(in srgb, currentColor 8%, transparent);
}

.auth form button:not(.btn):disabled {
  background: none;
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  cursor: default;
  font-variant-numeric: tabular-nums;
}

/* Select variant of the outlined text field (e.g. class picker) */
.field select {
  width: 100%;
  height: 52px;
  padding: 0 44px 0 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  appearance: none; /* native arrow hugs the edge; draw our own */
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23404944' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 14px center / 18px;
  font: inherit;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
}

.field select:focus {
  outline: none; /* the thickened M3 border below is the focus indicator */
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

/* A select always shows a value, so its label floats permanently */
.field select + span {
  top: 0;
  font-size: 12px;
}

.field select:focus + span {
  color: var(--md-sys-color-primary);
}

/* ---------- Desktop & tablet — additive only; mobile styles above are untouched ---------- */

/* Medium (≥600px): wider gutters, bottom sheets become centered dialogs */
@media (min-width: 600px) {
  :root {
    --gutter: 24px;
  }

  .notes ul {
    grid-template-columns: repeat(2, 1fr);
  }

  /* M3: modal bottom sheets present as dialogs on larger screens */
  .sheet {
    inset: 0;
    margin: auto;
    width: min(400px, 100% - 48px);
    height: fit-content;
    padding: 28px 24px 24px;
    border-radius: var(--md-sys-shape-corner-extra-large);
    translate: 0 24px;
    opacity: 0;
    transition: translate 300ms cubic-bezier(0.05, 0.7, 0.1, 1),
      opacity 300ms cubic-bezier(0.05, 0.7, 0.1, 1),
      display 300ms allow-discrete,
      overlay 300ms allow-discrete;
  }

  .sheet[open] {
    translate: 0 0;
    opacity: 1;
  }

  .sheet::before {
    display: none; /* no drag handle on a dialog */
  }

  @starting-style {
    .sheet[open] {
      translate: 0 24px;
      opacity: 0;
    }
  }
}

/* Expanded (≥840px): navigation rail, capped content column, roomier layout */
@media (min-width: 840px) {
  :root {
    /* Aligns topbar, sections, hero and footer content on one 1040px column */
    --page-inset: max(var(--gutter), calc(50% - 520px));
    --page-top: 24px; /* one step roomier on the wide layout */
  }

  /* Bottom bar becomes an M3 expanded navigation rail on the left —
     each item is a horizontal icon + label pill */
  body:has(.bottomnav) {
    padding-left: 180px;
  }

  /* Same selector as the mobile reservation, or specificity would keep it */
  body:has(.bottomnav):not(:has(footer)) {
    padding-bottom: 0;
  }

  .bottomnav {
    inset: 0 auto 0 0;
    width: 180px;
    flex-direction: column;
    /* Top, not centred: the rail is full height but holds four items, so
       centring parked the navigation a third of the way down a tall window,
       away from the bar it belongs with. 10px lines the first item's centre
       up with the brand in the 64px bar. */
    justify-content: flex-start;
    gap: 4px;
    padding: 10px 12px;
  }

  .bottomnav a {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    height: 44px;
    padding: 0 16px;
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 13px;
    transition: background-color 150ms cubic-bezier(0.2, 0, 0, 1);
  }

  /* The pill highlight moves from the icon to the whole item; 1px padding
     plus visible overflow keep edge strokes from clipping in the 24px box */
  .bottomnav svg,
  .bottomnav a:hover svg,
  .bottomnav a:active svg,
  .bottomnav a[aria-current] svg,
  .bottomnav a[aria-current]:hover svg {
    width: 24px;
    height: 24px;
    padding: 1px;
    overflow: visible;
    background: none;
  }

  .bottomnav a:hover {
    background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
  }

  .bottomnav a:active {
    background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
  }

  .bottomnav a[aria-current] {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
  }

  .bottomnav a[aria-current]:hover {
    background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 8%, var(--md-sys-color-secondary-container));
  }

  .topbar {
    height: 64px;
    padding: 0 var(--page-inset);
  }

  [id] {
    scroll-margin-top: 64px;
  }

  section {
    padding: var(--page-top) var(--page-inset);
  }

  .hero {
    margin-inline: var(--page-inset);
    padding: 48px 44px 40px;
  }

  .hero h1 {
    font-size: 40px;
  }

  .hero p {
    font-size: 15px;
    max-width: 44ch;
  }

  .page {
    padding: var(--page-top) var(--page-inset) 48px;
  }

  /* No bottom bar to clear any more */
  footer {
    padding: 24px var(--page-inset) 32px;
  }

  .classes ul {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }

  /* Column count follows the space, not the breakpoint. A fixed 3 collapsed
     the cards from 382px to 189px across the 840px line, because the rail
     takes 180px at the same moment the third column is added. Track sizing
     still resolves to 3 columns of 336px once the column reaches its full
     1040, so wide desktop is unchanged. */
  .notes ul {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
  }

  .search {
    max-width: 480px;
  }

  /* Full-width divided lists become two-column card grids */
  .subjects ul,
  .chapters ol {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    background: none;
    border-radius: 0;
    overflow: visible;
  }

  .subjects li,
  .chapters li {
    border-radius: var(--md-sys-shape-corner-large);
    background: var(--md-sys-color-surface-container-low);
    overflow: hidden;
  }

  .subjects li + li a,
  .chapters li + li a {
    border-top: none;
  }

  .subjects a,
  .chapters a {
    height: 100%;
  }

  .order form {
    max-width: 480px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  /* Slowed, not stopped — it is the only signal that a load is still running */
  .spinner {
    animation-duration: 2s;
  }

  .classes a {
    transition: none;
  }

  .classes a:active {
    transform: none;
  }

  .delivery,
  .field span,
  .field b,
  .sheet,
  .sheet::backdrop {
    transition: none;
  }
}

/* ---------- Backend integration additions ---------- */

.form-error {
  margin: 12px 0 0;
  color: var(--md-sys-color-error);
  font-size: 13px;
}

.form-error[hidden] {
  display: none;
}

/* Skeleton line while a list loads from the API */
.loading-hint {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
}

/* Order / plan purchase confirmation */
.done {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 24px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  text-align: center;
}

.done svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--md-sys-color-primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.done h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.done p {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 44ch;
}

/* Download button — the next action after paying, so it gets a full-size
   target rather than the 40px default */
.done .dl-link {
  height: 48px;
  margin-top: 8px;
  padding: 0 24px;
}

/* Buyer fields inside the unlock sheet */
.sheet form.buy {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
}

.sheet form.buy .btn {
  width: 100%;
  margin-top: 8px;
}

/* ---------- Account page ---------- */

.account {
  padding: var(--page-top) var(--gutter) 8px;
  max-width: 720px;
  margin-inline: auto;
  width: 100%;
}

/* The account opens on the same hero every other screen does, carrying the
   student's identity instead of a marketing line — so the page needs no title
   of its own and no off-scale type size to set one. The hero brings its own
   gutter margin, which this container has already paid for. */
.account .hero {
  margin: 0 0 24px;
}

.account h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 24px 0 12px;
}

.account .card {
  --field-notch: var(--md-sys-color-surface-container-low);
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 16px;
}

.account form.card {
  display: grid;
  gap: 16px; /* same field rhythm as .auth form and .order form */
}

/* One row list for both plans and payments — a card split by hairlines, the
   same shape .subjects uses on the class page. It replaces a bespoke plan list
   plus a four-column table that could only be read by scrolling it sideways on
   a phone. Row: title and a right-hand value on the first line, supporting
   detail spanning the full width below it. */
.acct-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  overflow: hidden;
}

.acct-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
  padding: 12px 16px;
}

.acct-list li + li {
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.acct-list b {
  font-weight: 600;
}

/* Full width, so a long payment id gets the whole row instead of a sideways
   scroll */
.acct-list small {
  grid-column: 1 / -1;
  /* Pinned, not left to the browser's 0.83em default, which lands on 11.67px —
     off the scale. 13px is the supporting-text size the rest of the app uses. */
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  overflow-wrap: anywhere;
}

.acct-list .amount {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Plan status. A plan that ran its full year is spent, not broken — it used to
   be painted in the error container, which reads as "something went wrong". */
.acct-list .tag {
  padding: 2px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: 12px;
  font-weight: 500;
}

.acct-list .tag.off {
  background: none;
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
}

/* Empty sections keep the shape of the section they replace */
.account .loading-hint {
  margin: 0;
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
}

.account .logout {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* This section sits after the main @media (min-width: 840px) block, so a rule
   for .account there would lose to the base rules above on source order.
   Hence the second query rather than a specificity fight. */
@media (min-width: 840px) {
  /* .account was the only container centring itself in the window instead of
     sitting on --page-inset, so its content started 160px right of the brand
     in the bar directly above it. Same column edge as every other page now,
     with each block kept to a readable width rather than letting a form or a
     row list stretch across the full 1040. */
  .account {
    max-width: none;
    margin-inline: 0;
    padding-inline: var(--page-inset);
  }

  .account > * {
    max-width: 720px;
  }
}

.done[hidden] {
  display: none;
}

/* The hidden attribute always wins over layout display values */
[hidden] {
  display: none !important;
}
