/*
 * Auto Topical: the phone layout.
 *
 * Loaded by every page with media="(max-width: 760px)", after the other
 * stylesheets, so nothing here reaches a laptop or desktop. Same world as
 * the desktop site (the dotted answer-line page, paper sheets, one yellow
 * highlighter), laid out as an app: a compact bar at the top, content in
 * full-width cards on a 16px gutter, the one action of a screen within
 * reach of the thumb, and the four tabs at the bottom.
 *
 * Rules kept from DESIGN.md: 4px grid, Instrument Sans for the interface and
 * Newsreader for headlines, yellow only on topics and the active number,
 * controls at least 44px, no glows or gradients.
 */

/* ---------------------------------------------------------- Everywhere */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    overflow-x: hidden;
}
a, button, label, summary, .btn, .chip, .paper, .choice { touch-action: manipulation; }

/* Safari zooms into any field whose text is under 16px. */
input, select, textarea, .input { font-size: 16px; }
.input { min-height: 48px; }

.btn { min-height: 44px; }
.btn--sm { min-height: 40px; }
.btn--block { width: 100%; justify-content: center; }

/* Phones have no hover: keep pressed states, drop hover-only lifts. */
@media (hover: none) {
    .paper:hover:not(:disabled), .choice:hover { background: var(--raised); }
}

/* The answer-line page: tighter lines read better on a small screen. */
.ruled { background-size: auto; }

/* ---------------------------------------------------------- Theme switch */

/* One compact 44px control instead of the wide labelled pill. */
.theme-toggle { padding: 2px; border-width: 1.5px; border-radius: 12px; }
.theme-toggle button { min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 9px; }
.theme-toggle .icon { width: 18px; height: 18px; }
.theme-toggle--labels button span { display: none; }

/* ============================================================ Workspace */

.shell { display: block; min-height: 100dvh; }
.main {
    padding: 0 16px calc(152px + env(safe-area-inset-bottom));
    min-height: 100dvh;
}

/* The brand bar along the top of every screen: the logo and the name,
   centred, with the theme switch on the right. The logo's highlighter
   draws itself again every few seconds, the site's signature moment. */
.appbar {
    position: sticky;
    top: 0;
    z-index: 35;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(60px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    border-bottom: 1px solid var(--line);
    background: var(--page);
}
.appbar__brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 8px;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
}
.appbar__mark { width: 36px; height: 36px; padding: 6px; }
@media (prefers-reduced-motion: no-preference) {
    .appbar__mark .stroke { animation: mark-loop 4800ms var(--ease) 400ms infinite both; }
    .appbar__mark .line { animation: line-loop 4800ms var(--ease) 400ms infinite both; }
    .appbar__mark { animation: mark-bob 4800ms var(--ease) 400ms infinite; }
}
/* Draw (640 ms), hold, lift off, and draw again. */
@keyframes mark-loop {
    0% { transform: scaleX(0); opacity: 1; }
    13% { transform: scaleX(1); opacity: 1; }
    84% { transform: scaleX(1); opacity: 1; }
    92% { transform: scaleX(1); opacity: 0; }
    100% { transform: scaleX(0); opacity: 0; }
}
@keyframes line-loop {
    0%, 8% { opacity: 0; }
    16%, 84% { opacity: 0.55; }
    92%, 100% { opacity: 0; }
}
@keyframes mark-bob {
    0%, 100% { transform: none; }
    13% { transform: translateY(-1px) rotate(-3deg); }
    24% { transform: none; }
}

/* Under the bar, the page's name in its own card, full width like the
   cards below it, so it never sits loose on the answer lines. */
.view__head {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 12px;
    padding: 16px 0 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
}
.view__head > div {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 16px 18px 15px;
    border-radius: 16px;
}
.view__head h1 { font-size: 28px; line-height: 34px; }
.view__head p { margin-top: 4px; font-size: 14px; line-height: 20px; }
.view__head p:empty { display: none; }
.view__head .btn { flex: none; }

/* The theme switch sits inside the brand bar, on the right. */
.theme-fab {
    position: fixed;
    top: calc(6px + env(safe-area-inset-top));
    right: 10px;
    z-index: 45;
    display: block;
}
/* In the bar it is one button: the mode you can switch to. */
.theme-fab .theme-toggle { padding: 0; border-width: 1px; border-color: var(--line-strong); border-radius: 12px; }
.theme-fab .theme-toggle button[aria-pressed="true"] { display: none; }
.theme-fab .theme-toggle button { min-width: 46px; min-height: 46px; background: none; color: var(--text); }

/* Cards on the page: full width, 16px inside, one radius. */
.block { padding: 16px; border-radius: 16px; }
.block + .block { margin-top: 12px; }
.block, .maker__cover { scroll-margin-top: 76px; }
.block__title { font-size: 17px; }
.maker { gap: 12px; }
.maker__steps { gap: 12px; }

/* Level switch: full width, three equal parts. */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.seg__btn { min-height: 40px; justify-content: center; }

/* Papers: a compact list. Once one is picked, the list folds to that paper
   and a Change paper button, so the next step is right there. */
.papers { grid-template-columns: 1fr; gap: 6px; margin-top: 12px; }
.paper {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "subject check" "part check" "meta check";
    align-items: center;
    min-height: 64px;
    padding: 12px 14px;
    border-radius: 12px;
}
.paper__subject { grid-area: subject; font-size: 15px; }
.paper__part { grid-area: part; }
.paper__meta { grid-area: meta; margin-top: 4px; }
.paper__check { grid-area: check; position: static; margin-left: 12px; }
.papers.is-picked:not(.is-open) > .paper:not(.is-on) { display: none; }
.papers.is-picked:not(.is-open) > .hint { display: none; }
.papers__change { display: inline-flex; margin-top: 2px; }
.papers:not(.is-picked) > .papers__change { display: none; }

/* Topics: the search field and Add on one line, chips that wrap. */
.adder { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.adder .btn { min-height: 48px; padding: 0 18px; }
.chips { gap: 8px; }
.chip { min-height: 36px; }
.browse__list { max-height: none; overflow: visible; }
.browse__list li { min-height: 0; }
.browse__list .topic { min-height: 44px; padding-block: 8px; }
.suggest { max-height: 50dvh; }
.suggest li { min-height: 44px; }

/* Mark scheme choices: one column of rows, the diagram small on the left. */
.choices { grid-template-columns: 1fr; gap: 8px; }
.choice {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 8px 14px 8px 8px;
}
.choice .diagram { height: 48px; min-height: 0; margin: 0; }
.choice__text b { font-size: 15px; }
.choice__text span { font-size: 13px; }
.opt__head { flex-direction: column; align-items: flex-start; gap: 2px; }
.opt--row { flex-direction: column; align-items: stretch; gap: 12px; }
.check { min-height: 44px; }

/* Years: the range and the session switches stacked, full width. */
.years, .range { width: 100%; }

/* The live cover of the topical: centred, not wider than a sheet. */
.maker__cover { position: static; display: grid; gap: 12px; scroll-margin-top: 76px; }
.result { width: 100%; max-width: 420px; justify-self: center; }
.result__list { max-height: 220px; }
.mstate { border-radius: 16px; }
.done__buttons { grid-template-columns: 1fr 1fr; }

/* The action bar: count on the left, the button on the right, sitting on
   top of the tabs, in the thumb zone. */
.mbar:not([hidden]) {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(68px + env(safe-area-inset-bottom));
    z-index: 41;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 8px 8px 16px;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--pop-shadow);
}
.mbar__text { display: grid; min-width: 0; line-height: 18px; }
.mbar__text strong { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mbar__text span { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mbar .btn { flex: none; min-height: 44px; padding: 0 18px; }
@media (prefers-reduced-motion: no-preference) {
    .mbar:not([hidden]) { animation: rise var(--mid) var(--ease); }
}

/* The four tabs: 56px plus the home indicator, labels always shown. */
.tabbar {
    height: calc(60px + env(safe-area-inset-bottom));
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    background: var(--surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}
.tabbar a {
    position: relative;
    align-content: center;
    min-height: 52px;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    -webkit-user-select: none;
    user-select: none;
}
.tabbar a .icon { width: 22px; height: 22px; }
.tabbar a.is-on { color: var(--text); }
.tabbar a.is-on .icon { padding: 2px 14px; box-sizing: content-box; border-radius: 999px; background: var(--raised-2); }

/* My topicals: the Make tab does what New topical does, so the title gets
   the whole bar. Search full width, the two filters side by side. */
[data-view="topicals"] .view__head .btn { display: none; }
select { min-height: 44px; }
.tcard__more { width: 44px; height: 44px; }
.skip:not(:focus) { height: 1px; }
.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toolbar__search { grid-column: 1 / -1; }
.select--sm select { min-height: 44px; }
.tgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tcard__meta { padding: 10px 12px; }

/* One topical: the cover on top, then the facts, then the actions. */
.detail { gap: 16px; }
.detail__thumb { justify-self: center; width: min(220px, 70%); }
.detail__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail__actions .btn { width: 100%; justify-content: center; }
.detail__actions .btn--primary { grid-column: 1 / -1; }
.facts { grid-template-columns: 1fr; gap: 2px; }
.facts dt { margin-top: 10px; }
.facts dt:first-child { margin-top: 0; }

/* Progress and Account: figures two by two, rows stacked. */
.figures { grid-template-columns: 1fr 1fr; gap: 8px; }
.panels { gap: 12px; }
.row { flex-direction: column; align-items: stretch; gap: 12px; }
.row .btn { width: 100%; justify-content: center; }

/* The viewer: full screen, actions in a bar at the bottom. */
.viewer { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
.viewer__head { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.viewer__foot { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.viewer__actions { display: grid; grid-auto-flow: column; gap: 8px; width: 100%; }
.viewer__actions .btn { justify-content: center; }

/* Toasts sit above the tabs. */
.toast { bottom: calc(140px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }

/* ============================================================== Login */

.auth { display: block; min-height: 100dvh; }
.auth__stage { display: none; }
.auth__form {
    display: grid;
    align-content: start;
    min-height: 100dvh;
    padding: calc(72px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.auth__form .form { width: 100%; max-width: 440px; margin-inline: auto; padding: 24px 20px; border-radius: 20px; }
.auth__theme { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 5; }
.auth .back { min-height: 44px; display: inline-flex; align-items: center; }
.auth .btn { min-height: 52px; font-size: 16px; }
.form__alt a, .form__guest a, .form__guest button, .link { display: inline-flex; min-height: 44px; align-items: center; }

/* ============================================================ Landing */

.wrap, .nav__inner { width: calc(100% - 32px); }

/* Top bar: brand, theme, menu. Log in and the CTA move into the menu and
   the hero. */
.nav { padding-top: env(safe-area-inset-top); }
.nav__inner { height: 56px; gap: 8px; }
.brand { min-height: 44px; padding: 4px 14px 4px 6px; font-size: 16px; }
.brand__mark { width: 30px; height: 30px; }
.nav__login, .nav__cta { display: none; }
.nav__toggle { display: inline-flex; width: 44px; height: 44px; justify-content: center; }
.nav__links {
    inset: calc(56px + env(safe-area-inset-top)) 0 auto 0;
    padding: 8px 16px 16px;
    box-shadow: var(--pop-shadow);
}
.nav__links a { min-height: 48px; display: flex; align-items: center; padding: 0 12px; font-size: 16px; border-radius: 10px; }

/* Hero: the promise, two full-width buttons, then the moving PDF. */
.hero { padding: 16px 0 8px; min-height: 0; }
.hero__grid { gap: 24px; }
.hero__panel, .section__head:not(.section__head--split), .section__head--split > div,
.split__head, .account__copy, .download__text, .about__text { padding: 20px; border-radius: 20px; }
h1 { font-size: 40px; line-height: 44px; letter-spacing: -0.01em; }
h2 { font-size: 30px; line-height: 36px; }
.hero__sub, .lead { font-size: 16px; line-height: 25px; margin-top: 14px; }
.hero__actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 20px; }
.hero__actions .btn { width: 100%; justify-content: center; min-height: 52px; font-size: 16px; }
.hero__visual { max-width: none; }

/* Figures in a two by two grid. */
.glance { grid-template-columns: 1fr 1fr; gap: 8px; }
.glance > :last-child:nth-child(odd) { grid-column: 1 / -1; }
.pulse { grid-template-columns: 1fr 1fr; gap: 8px; }
.pulse__state { grid-column: 1 / -1; min-height: 44px; white-space: normal; }

/* Sections: less air, the same rhythm. */
.section { padding: 48px 0; }
.section--tight { padding: 40px 0; }
.section__head { margin-bottom: 20px; }

/* How it works and Why it matters: cards you swipe through sideways, so
   each one is a full screen idea instead of one very long column. */
.steps, .reasons {
    display: grid;
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-auto-columns: 84%;
    gap: 12px;
    margin-inline: -16px;
    padding: 4px 16px 16px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.steps::-webkit-scrollbar, .reasons::-webkit-scrollbar { display: none; }
.step, .reason { scroll-snap-align: start; }
.reason { padding: 20px; }

/* Activity, download, about: one column. */
.split, .activity, .download, .section__head--split, .account { grid-template-columns: 1fr; gap: 20px; }
.feed__list { max-height: 420px; }
.feed__item { grid-template-columns: 32px minmax(0, 1fr); }
.feed__meta { grid-column: 2; justify-items: start; grid-auto-flow: column; gap: 12px; }
.download__actions { display: grid; gap: 10px; }
.download__actions .btn { width: 100%; justify-content: center; }
.about { grid-template-columns: 1fr; gap: 20px; justify-items: start; }
.about__links { grid-template-columns: 1fr; width: 100%; }
.about__links a { min-height: 48px; }
.account__card { justify-self: stretch; }
.footer { padding: 24px 0 calc(32px + env(safe-area-inset-bottom)); }
.footer__inner a { display: inline-flex; min-height: 44px; align-items: center; }

/* The Windows download makes no sense as the first thing on a phone. */
.hero__actions a[href="#download"] { display: none; }

/* One topical: a smaller title, the back link and icon buttons at 44px. */
.detail__head h1, .detail h1 { font-size: 28px; line-height: 34px; }
.back { min-height: 44px; display: inline-flex; align-items: center; }
.iconbtn { min-width: 44px; min-height: 44px; }
.view[data-view="topical"] { padding-top: 12px; }

/* What Auto Topical records: each row becomes a small card, no table to
   scroll sideways. The column names come back as a line under the what. */
.records, .records tbody, .records tr, .records td { display: block; width: 100%; }
.records thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.records tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
.records td { padding: 0; border: 0; white-space: normal; }
.records td:first-child { font-weight: 500; color: var(--text); white-space: normal; }
.records td + td { display: inline; width: auto; font-size: 13px; color: var(--text-3); }
.records td:nth-child(2)::before { content: "Kept: "; }
.records td:nth-child(3)::before { content: " · Shown to others: "; }
.card { min-width: 0; }
.card * { overflow-wrap: anywhere; }
.toggle input, .switch input { min-height: 0; }
