/* ═══════════════════════════════════════════════
   BARE BONES — Dashboard and subject pages
   Loaded last. app.html is the dashboard; /app/<subject>/ pages add a
   .subject-head (scripts/subject-pages.cjs) with one tab per section.
   One centred column: the header, then whichever section is open, which
   scrolls on its own so the header and tabs stay put.
   ═══════════════════════════════════════════════ */

/* minmax(0, …): wide content (the paper guide's panels) scrolls inside its card instead of stretching the page */
.main-content { grid-template-columns: minmax(0, 1fr); }

.subject-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(1180px, 100%);
  margin-inline: auto;
}

.subject-area > .dashboard,
.subject-area > .section-panel,
.subject-area > .guide-inline,
.subject-area > #subjectWorkbench {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── Subject header ─────────────────────────── */
.subject-head {
  flex: none;
  display: grid;
  gap: 0.35rem;
  padding-top: 0; /* sits a little closer under the logo */
}


.subject-head h1 {
  margin: 0;
  font-size: clamp(2rem, 4.2vw, 3rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
}

.subject-head h1 a { color: var(--ink); text-decoration: none; transition: color var(--t) var(--ease); }
.subject-head h1 a:hover { color: var(--accent-strong); }
.subject-head h1 a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* The heading is the back link: a back arrow slides in before it on hover / keyboard focus */
.subject-head h1 a::before {
  content: "←";
  display: inline-block;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  vertical-align: top;
  color: var(--accent);
  transition: max-width var(--t) var(--ease), margin var(--t) var(--ease), opacity var(--t) var(--ease);
}

.subject-head h1 a:focus-visible::before { max-width: 1.2em; margin-right: 0.12em; opacity: 1; }

@media (hover: hover) {
  .subject-head h1 a:hover::before { max-width: 1.2em; margin-right: 0.12em; opacity: 1; }
}

.subject-section-title {
  margin: 0.15rem 0 0;
  color: var(--accent);
  font-size: clamp(1.25rem, 2.2vw, 1.6rem); /* stays below the h1, incl. its 1.4rem phone size on chapter screens */
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subject-section-title:empty { display: none; }

/* Inside a chapter the section's name sits under the chapter's (.study-context-section) */
.subject-area:has(#subjectWorkbench:not(.hidden) .study-context-section) .subject-section-title { display: none; }

.study-context .study-context-section {
  margin-top: 0.3rem;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}

.section-tile:focus-visible,
.chapter-row:focus-visible,
.dash-subject:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Section content ────────────────────────── */
.section-card,
.dash-block {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--s1);
  padding: 1.25rem 1.5rem 1.5rem;
}

.section-panel { display: grid; align-content: start; gap: 1rem; padding-bottom: 1.5rem; }

/* Prebuilt first paint of a subject page (scripts/subject-pages.cjs), drawn over by app.js.
   The wrappers add no boxes, so it lays out exactly like the real panel. */
.page-shell :is(.shell-home, .shell-signed-in, .shell-signed-out, .shell-section) { display: contents; }
html:not(.bb-signed-in) .page-shell .shell-signed-in,
html.bb-signed-in .page-shell .shell-signed-out,
html.bb-section-link .page-shell .shell-home,
html:not(.bb-section-link) .page-shell .shell-section { display: none; }
.page-shell .dash-range { pointer-events: none; } /* its buttons work once app.js has loaded */

/* Tests choose their chapters in the setup, so the chapter breadcrumb has nothing to say */
.subject-area[data-section="tests"] .workbench-bar { display: none; }

/* Exam › By chapter: the panel only holds the view switch; the workbench below scrolls */
.subject-area[data-exam-view="chapter"] > .section-panel { flex: none; overflow: visible; padding-bottom: 0; }

.chapter-rows { list-style: none; margin: 0; padding: 0; }
.chapter-rows li + li { border-top: 1px solid var(--line); }

/* Tiles: the dashboard's subjects and a subject's sections */
.dash-subject-grid,
.section-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dash-subject,
.section-tile {
  display: grid;
  align-content: start;
  gap: 0.6rem;
  height: 100%;
  min-height: 6.5rem;
  padding: 1.1rem 1.2rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: var(--s1);
  color: var(--ink);
  text-decoration: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), transform var(--t) var(--ease);
}

.dash-subject:hover,
.section-tile:hover {
  border-color: var(--accent-light);
  box-shadow: var(--s2);
  transform: translateY(-2px);
}

/* Icon badge on subject and section tiles */
.tile-icon {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: var(--r-sm);
  background: var(--accent-xlight);
  color: var(--accent-strong);
}

.tile-icon svg { width: 1.45rem; height: 1.45rem; }

/* Section tiles are the subject page's only navigation, so they get the room */
.section-tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 1rem; }

.section-tile {
  align-content: space-between;
  min-height: 10rem;
  padding: 1.4rem 1.5rem;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.section-tile .tile-icon { width: 3.2rem; height: 3.2rem; border-radius: var(--r-md); }
.section-tile .tile-icon svg { width: 1.75rem; height: 1.75rem; }

.chapter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.15rem 1rem;
  width: 100%;
  padding: 1rem 0.75rem;
  border: 0;
  border-radius: var(--r-md);
  background: none;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  transition: background var(--t) var(--ease);
}

.chapter-row:hover { background: var(--accent-xxlight); transform: none; }

.chapter-row { padding-block: 0.8rem; }
.chapter-row-title { font-weight: 600; }
.chapter-row-meta { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.chapter-row-done { color: var(--success); }
.chapter-row-done::before { content: "✓ "; }

/* Notes: a chapter folds open into its subsections */
.chapter-fold > summary { grid-template-columns: minmax(0, 1fr) auto auto; list-style: none; cursor: pointer; }
.chapter-fold > summary::-webkit-details-marker { display: none; }
.chapter-fold > summary::after {
  content: "";
  width: 0.5rem; height: 0.5rem;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--t) var(--ease);
}
.chapter-fold[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.chapter-subs { list-style: none; margin: 0 0 0.6rem; padding: 0 0 0 1.5rem; display: grid; gap: 1px; }
.chapter-subs button {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-left: 2px solid var(--line);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: none;
  box-shadow: none;
  color: var(--ink-2);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
}
.chapter-subs button:hover { border-left-color: var(--accent); background: var(--accent-xxlight); color: var(--accent-strong); }
.chapter-subs button:has(.chapter-sub-count) { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.chapter-sub-count { flex: none; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

/* Flashcards' chapter list. Every row with a bar keeps a chevron-wide last column, so the bars
   of plain rows, folds and subsections all end at the same edge. */
.overview-chapter-row:has(.overview-progress-bar),
.overview-fold .chapter-subs button { grid-template-columns: minmax(0, 1fr) minmax(160px, 34%) 0.5rem; }
.overview-progress-bar { position: relative; }
.overview-progress-pct {
  position: absolute;
  inset: 0 0.9rem 0 auto;
  display: grid;
  place-items: center;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* A chapter with subsections is one white card; opening it grows the card down over its subsections */
.overview-fold {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  overflow: clip;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.overview-fold:hover { border-color: var(--accent-light); box-shadow: inset 0 0 0 1px var(--accent-light); }
.overview-fold > summary.overview-chapter-row { border: 0; border-radius: 0; background: none; }
.overview-fold > summary.overview-chapter-row:is(:hover, :active) { transform: none; box-shadow: none; }
.overview-fold > .chapter-subs { margin: 0; padding: 0.3rem 0 0.5rem; gap: 0; border-top: 1px solid var(--line); }
.overview-fold .chapter-subs button {
  display: grid;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.5rem);
  padding: 0.4rem 1rem; /* same sides as the chapter row, so the bar columns match */
  border: 0;
  border-radius: 0;
}
.overview-fold .chapter-subs button:hover { background: var(--accent-xxlight); color: var(--accent-strong); }
.overview-sub-text { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; min-width: 0; padding-left: 1rem; }
.overview-fold .chapter-subs .overview-progress-bar { height: 28px; }
.overview-fold .chapter-subs .overview-progress-pct { font-size: 0.7rem; }

@media (prefers-reduced-motion: no-preference) {
  @supports (interpolate-size: allow-keywords) {
    .overview-fold { interpolate-size: allow-keywords; }
    .overview-fold::details-content {
      block-size: 0;
      overflow: clip;
      transition: block-size 0.34s cubic-bezier(0.22, 1, 0.36, 1), content-visibility 0.34s allow-discrete;
    }
    .overview-fold[open]::details-content { block-size: auto; }
  }
}

@media (max-width: 620px) {
  .overview-chapter-row:has(.overview-progress-bar) { grid-template-columns: minmax(0, 1fr); }
  .overview-fold { border-radius: var(--r-sm); }
  .overview-fold > summary.overview-chapter-row { grid-template-columns: minmax(0, 1fr) auto; }
  .overview-fold > summary::after { grid-column: 2; grid-row: 1; }
  .overview-fold > summary .overview-progress-bar { grid-column: 1 / -1; }
  .overview-fold .chapter-subs button { grid-template-columns: minmax(0, 1fr); gap: 0.35rem; padding: 0.5rem 0.85rem; }
  .overview-sub-text { padding-left: 0.6rem; }
  .overview-sub-text + .overview-progress-bar { margin-left: 0.6rem; width: calc(100% - 0.6rem); }
}
/* responsive.css thins phone bars to 6px; keep them tall enough to carry the % */
@media (max-width: 640px) {
  .overview-progress-bar,
  .overview-fold .chapter-subs .overview-progress-bar { height: 18px; }
  .overview-progress-pct,
  .overview-fold .chapter-subs .overview-progress-pct { right: 0.55rem; font-size: 0.62rem; }
}

.section-locked { display: grid; gap: 0.6rem; justify-items: start; }
.section-locked h2 { margin: 0; font-size: 1.35rem; }
.section-locked p { margin: 0; color: var(--ink-2); }

.section-locked-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.section-locked-actions button { width: auto; padding-inline: 1.25rem; }

/* Exam: By chapter / By type / Full papers */
.exam-views {
  display: inline-flex;
  justify-self: start;
  gap: 0.25rem;
  padding: 0.28rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-full);
  background: var(--panel-2);
}

.exam-view {
  width: auto;
  white-space: nowrap;
  padding: 0.45rem 1rem;
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
}

.exam-view.active { background: var(--accent); color: #fff; box-shadow: var(--so); }

.exam-type-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.exam-type-chip {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-full);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
}

.exam-type-chip span { color: var(--muted); font-variant-numeric: tabular-nums; }
.exam-type-chip[aria-pressed="true"] { border-color: var(--accent-light); background: var(--accent-xlight); color: var(--accent-strong); }
.exam-type-chip[aria-pressed="true"] span { color: inherit; }
.exam-type-note { margin: 0.9rem 0 0.6rem; }

/* The papers archive used to be its own screen; inside the card it needs no frame of its own */
.section-card .papers-body { padding: 0; }

/* Paper guide: drawn in place instead of as a full-screen modal */
.guide-inline { border-radius: var(--r-xl); }
/* The modal's id rule sets overflow: hidden; inline, the guide scrolls like every other section */
#examBreakdownModal.guide-inline { overflow-y: auto; }
/* …so the inner screen must not be a scroller too: styles.css gives it overscroll-behavior: contain for the
   full-screen modal, which here swallows every wheel scroll before it reaches the guide */
.guide-inline .bd-screen { overflow-y: visible; overscroll-behavior: auto; }
.guide-inline .breakdown-modal-card { height: auto; min-height: 100%; border-radius: var(--r-xl); background: var(--panel); }
/* The page heading already names the subject */
.guide-inline .bd-title { display: none; }
/* …so the guide's own label becomes its title, filling the header beside the stats */
.guide-inline .bd-eyebrow {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 3.4rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.035em;
  text-transform: none;
  color: var(--accent);
}

/* ── Dashboard ──────────────────────────────── */
.dashboard { display: grid; align-content: start; gap: 1.25rem; padding: 0.5rem 0 2rem; }

.dash-head h1 {
  margin: 0;
  font-size: clamp(2rem, 4.2vw, 3rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
}

.dash-head p { margin: 0.5rem 0 0; color: var(--ink-2); }

.dash-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin-bottom: 0.75rem;
}

.dash-block-head h2 { margin: 0; font-size: 1.1rem; font-weight: 750; }

.dash-text-button {
  width: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 650;
}

.dash-text-button:hover { color: var(--accent-dark); transform: none; }

.dash-subject-title { font-size: 1.15rem; font-weight: 750; }
.dash-subject-meta { color: var(--muted); font-size: 0.8rem; font-weight: 600; }

.dash-subject-bar {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--accent-xlight);
  overflow: hidden;
}

.dash-subject-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.dash-empty { margin: 0; color: var(--ink-2); }

.dash-range {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.22rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-full);
  background: var(--panel-2);
}

.dash-range button {
  width: auto;
  white-space: nowrap;
  padding: 0.3rem 0.75rem;
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--ink-2);
  font-size: 0.78rem;
  font-weight: 600;
}

.dash-range button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--s0); }

.study-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.4rem;
}

.study-stats dt { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.study-stats dd { margin: 0.15rem 0 0; font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; }

/* Study time chart: one series, HTML columns so the 2px gaps and rounded tops stay crisp */
.study-chart {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr);
  height: 180px;
  margin-bottom: 1.6rem;
}

.study-y {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 0.5rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: right;
  white-space: nowrap;
  transform: translateY(-0.45em);
}

.study-y span:last-child { transform: translateY(0.9em); }

.study-plot {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  align-items: end;
  border-bottom: 1px solid var(--muted);
  /* Recessive gridlines at the top and middle ticks */
  background:
    linear-gradient(var(--line), var(--line)) 0 0 / 100% 1px no-repeat,
    linear-gradient(var(--line), var(--line)) 0 50% / 100% 1px no-repeat;
}

/* The whole column is the hover target, not just the bar */
.study-col {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 100%;
}

.study-bar {
  display: block;
  width: 70%;
  max-width: 6rem;
  border-radius: 6px 6px 0 0;
  /* orange-600: the brand orange is under 3:1 against the white card */
  background: #EA580C;
}

.study-plot.is-dense .study-bar { border-radius: 2px 2px 0 0; }
.study-col:hover .study-bar { background: var(--accent-strong); }

.study-x {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
}

.study-plot.is-dense .study-x { left: 0; transform: none; }

.study-tip {
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 50%;
  z-index: 2;
  display: none;
  padding: 0.3rem 0.55rem;
  border-radius: var(--r-xs);
  background: var(--ink);
  color: var(--panel);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.study-col:hover .study-tip { display: block; }
.study-col:first-child .study-tip { left: 0; transform: none; }
.study-col:last-child .study-tip { left: auto; right: 0; transform: none; }

/* Close on the sign-in panel, only where the page behind is worth staying on */
.auth-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--r-full);
  background: var(--panel-2);
  color: var(--ink-2);
}

body:not([data-subject]) .auth-close { display: none; }

/* ── Narrow screens ─────────────────────────── */
@media (max-width: 640px) {
  /* [data-screen] matches responsive.css, which zeroes the gap for the old one-screen layout */
  .subject-area,
  .subject-area[data-screen] { gap: 0.75rem; }
  .subject-head { gap: 0.25rem; padding-top: 0.25rem; }
  .subject-head h1 { font-size: 2rem; }
  .section-card,
  .dash-block { padding: 1rem; border-radius: var(--r-lg); }
  .chapter-row { padding-inline: 0.4rem; }
  .dash-subject-grid,
  .section-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .dash-subject { min-height: 5.5rem; padding: 0.9rem; }
  .section-tile { min-height: 7.5rem; padding: 1rem; font-size: 1.15rem; }
  .study-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .study-chart { height: 150px; }

  /* Studying a chapter: the card gets the room, the header keeps only the name and tabs */
  .subject-area:is([data-screen="chapter"], [data-screen="study"]) .subject-head h1 { font-size: 1.4rem; }
}

/* Paper / AAC guide: the sections stack one above another under the marks bar. The open one
   shows its tips; the rest are a row each (tap one, or its slice of the bar, to open it). */
.guide-inline .bd-panels { flex: none; flex-direction: column; gap: 0.6rem; min-height: 0; overflow: visible; }
.guide-inline .bd-panel,
.guide-inline .bd-panel.is-open { flex: none; }
.guide-inline .bd-panel-head { grid-template-columns: 1fr auto; column-gap: 1rem; }
.guide-inline .bd-kicker,
.guide-inline .bd-panel-title,
.guide-inline .bd-facts { grid-column: 1; }
.guide-inline .bd-marks { grid-column: 2; grid-row: 1 / span 3; margin: 0; align-self: center; text-align: right; }
.guide-inline .bd-marks strong { display: block; }
.guide-inline .bd-panel-cue { position: static; padding: 0 1.5rem 1.1rem; }
.guide-inline .bd-panel.is-open .bd-panel-cue,
.guide-inline .bd-panel:not(.is-open) .bd-panel-body { display: none; }
.guide-inline .bd-panel-body { min-width: 0; }

.guide-inline .bd-panel { scroll-margin-top: 0.75rem; }

/* Subject page "about" text (scripts/subject-pages.cjs): signed-out visitors and search engines only */
.bb-signed-in .subject-about { display: none; }
.subject-about { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); color: var(--ink-2); }
.subject-about h2 { margin: 0 0 0.5rem; font-size: 1.05rem; color: var(--ink); }
.subject-about h3 { margin: 1.25rem 0 0.5rem; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.subject-about p { margin: 0; max-width: 65ch; font-size: 0.9rem; line-height: 1.6; }
.subject-about-chapters { margin: 0; padding-left: 1.4rem; columns: 2 16rem; column-gap: 2rem; font-size: 0.88rem; line-height: 1.5; }
.subject-about-chapters li { break-inside: avoid; padding: 0.15rem 0; }
.subject-about-chapters a { color: var(--ink-2); text-decoration-color: var(--line); text-underline-offset: 3px; }
.subject-about-chapters a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }
