/*
 * Auto Topical: shared design system
 *
 * The world is a desk late at night: dark graphite, white A4 sheets catching
 * the lamp light, black exam type, and one yellow highlighter. The paper is
 * the only bright thing. The highlighter is the only accent, and it is only
 * ever used on a topic, or on the one number that matters on a screen.
 *
 * 4px grid. One easing curve, three durations. Instrument Sans for the
 * interface, Newsreader for headlines, Arial inside the paper sheets.
 * Loaded by every page; landing.css and app.css add their own parts.
 */

:root {
    color-scheme: dark;

    /* Warm charcoal, like a desk under a lamp, not pure black. */
    --page: #191816;
    --surface: #222120;
    --raised: #2d2b29;
    --raised-2: #393634;
    --sheet: #ece8df;

    --text: #dcd8cf;
    --text-2: #aca79d;
    --text-3: #9a958b;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.17);

    /* The answer lines of the background, and the shadow of a card. */
    --dot: rgba(220, 216, 207, 0.20);
    --card-shadow: none;

    --mark: #e9cf63;
    --mark-ink: #1a1608;
    --ok: #5fb58a;
    --bad: #e0705f;

    --btn: #dcd8cf;
    --btn-text: #1a1917;
    --btn-hover: #e8e4db;

    --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
    --paper: Arial, Helvetica, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --fast: 160ms;
    --mid: 240ms;
    --slow: 480ms;

    --sheet-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.28), 0 18px 40px rgba(0, 0, 0, 0.35);
    --pop-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --nav-h: 64px;
}

/* The light theme, chosen in Account settings. Same roles, paper colours. */
[data-theme="paper"] {
    color-scheme: light;
    --sheet: #ffffff;
    --page: #e8e0d1;
    --surface: #fffdf8;
    --raised: #f4eee2;
    --raised-2: #e5dcc8;
    --text: #1f1b16;
    --text-2: #4b4238;
    --text-3: #685f53;
    --line: rgba(31, 27, 22, 0.17);
    --line-strong: rgba(31, 27, 22, 0.32);
    --dot: rgba(31, 27, 22, 0.34);
    --card-shadow: 0 1px 2px rgba(31, 27, 22, 0.08), 0 8px 20px rgba(31, 27, 22, 0.07);
    --ok: #2f7d4f;
    --bad: #b3372f;
    --btn: #1f1b16;
    --btn-text: #fffdf8;
    --btn-hover: #000000;
    --sheet-shadow: 0 1px 1px rgba(31, 27, 22, 0.05), 0 3px 6px rgba(31, 27, 22, 0.05), 0 12px 28px rgba(31, 27, 22, 0.08);
    --pop-shadow: 0 8px 24px rgba(31, 27, 22, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--nav-h) + 16px);
    -webkit-text-size-adjust: 100%;
    background: var(--page);
}

body {
    margin: 0;
    background: var(--page);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 22px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote, fieldset { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
img { display: block; max-width: 100%; height: auto; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
::selection { background: var(--mark); color: var(--mark-ink); }

:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
    border-radius: 4px;
}

.sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon--sm { width: 16px; height: 16px; }

.skip {
    position: absolute;
    left: 16px;
    top: -60px;
    z-index: 100;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--btn);
    color: var(--btn-text);
    text-decoration: none;
}
.skip:focus { top: 12px; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }

/* Answer lines: the rows of dots an exam paper leaves for the answer, drawn
   behind a whole area and fading out at its sides and its foot. Put .ruled
   on a container; its content sits above the lines, and anything with a
   solid background (cards, sheets) hides them, so they fill the gaps. */
.ruled { position: relative; isolation: isolate; }
.ruled::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background-image: radial-gradient(circle, var(--dot) 1.2px, transparent 1.9px);
    background-size: 7px 30px;
    background-position: 0 15px;
    -webkit-mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent), linear-gradient(to bottom, #000 calc(100% - 140px), transparent);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent), linear-gradient(to bottom, #000 calc(100% - 140px), transparent);
    mask-composite: intersect;
    pointer-events: none;
}

/* Cards and pills stand off the page: a clear edge in both themes, and in
   the light theme a soft shadow as well. */
.pulse, .jump, .author, .step, .reason, .feed, .discord, .glance > div, .block, .figure, .panel, .card,
.paper, .choice, .brand, .tag, .chip, .seg, .theme-toggle, .toggle, .side__user, .stat, .tick {
    box-shadow: var(--card-shadow);
}

/* ------------------------------------------------------------- The brand */

/* The logo is a pill: the paper icon in its own circle, then the name.
   The highlighter stroke on the icon draws itself once when the page
   loads, and again when the pill is hovered. */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 5px 18px 5px 5px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--surface);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.005em;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.brand:hover { border-color: var(--line-strong); background: var(--raised); }
.side .brand, .auth__stage .brand { background: var(--raised); }
.side .brand:hover, .auth__stage .brand:hover { background: var(--raised-2); }
.brand__mark {
    width: 32px;
    height: 32px;
    padding: 5px;
    flex: none;
    border-radius: 50%;
    background: var(--page);
    box-shadow: inset 0 0 0 1px var(--line-strong);
}
.brand__mark .sheet-shape { fill: var(--text); }
.brand__mark .fold { fill: var(--text-3); }
.brand__mark .stroke { fill: var(--mark); transform-box: fill-box; transform-origin: left center; }
@media (prefers-reduced-motion: no-preference) {
    .brand__mark .stroke { animation: stroke-draw 640ms var(--ease) 360ms both; }
    .brand:hover .brand__mark .stroke { animation: stroke-draw 480ms var(--ease) both; }
}
@keyframes stroke-draw { from { transform: scaleX(0); } }
.brand__mark .line { fill: var(--page); opacity: 0.55; }

/* ------------------------------------------------------- The highlighter */

.hl {
    padding: 0 0.15em;
    margin: 0 -0.15em;
    border-radius: 0.2em 0.35em 0.25em 0.3em;
    background-image: linear-gradient(100deg, rgba(255, 225, 77, 0.6), var(--mark) 8%, var(--mark) 92%, rgba(255, 225, 77, 0.65));
    background-repeat: no-repeat;
    background-size: 0% 100%;
    color: inherit;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    transition: background-size 560ms var(--ease), color 200ms var(--ease);
}
.hl.is-on { background-size: 100% 100%; color: var(--mark-ink); }

/* ---------------------------------------------------------------- Sheets */

.sheet {
    background: var(--sheet);
    color: #111;
    border-radius: 3px;
    box-shadow: var(--sheet-shadow);
    font-family: var(--paper);
}

/* --------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { background: var(--raised); border-color: var(--line); color: var(--text-3); cursor: not-allowed; }
.btn--primary { background: var(--btn); color: var(--btn-text); }
.btn--primary:hover:not(:disabled) { background: var(--btn-hover); }
.btn--quiet { background: var(--raised); border-color: var(--line); color: var(--text); }
.btn--quiet:hover:not(:disabled) { background: var(--raised-2); border-color: var(--line-strong); }
.btn--ghost { background: none; color: var(--text-2); padding: 0 12px; }
.btn--ghost:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.btn--danger { background: #c4382e; border-color: #c4382e; color: #fff; }
.btn--danger:hover:not(:disabled) { background: #8f241c; border-color: #8f241c; }
.btn--danger:active:not(:disabled) { background: #741a14; border-color: #741a14; }
.btn--sm { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 8px; }
.btn--block { width: 100%; }

.iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text-2);
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.iconbtn:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.iconbtn:disabled { opacity: 0.35; cursor: not-allowed; }

.link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    text-underline-offset: 3px;
    transition: text-decoration-color var(--fast) var(--ease);
}
.link:hover { text-decoration-color: currentColor; }

/* ---------------------------------------------------------------- Inputs */

.input, .select select {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--raised);
    font-size: 15px;
    transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select select:focus { outline: none; border-color: var(--text-2); background: var(--raised-2); }
.select { position: relative; }
.select select { appearance: none; padding-right: 40px; cursor: pointer; }
.select::after {
    content: "";
    position: absolute;
    right: 16px;
    top: 17px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--text-2);
    border-bottom: 1.5px solid var(--text-2);
    transform: rotate(45deg);
    pointer-events: none;
}
.label { display: block; margin-bottom: 8px; font-size: 14px; color: var(--text-2); }
.hint { min-height: 20px; margin-top: 8px; font-size: 13px; line-height: 20px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.hint.is-bad, .is-bad { color: var(--bad); }

/* Segmented control */
.seg {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 2px;
    padding: 3px;
    background: var(--raised);
    border: 1px solid var(--line);
    border-radius: 11px;
}
.seg__btn {
    height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: 8px;
    background: none;
    font-size: 14px;
    color: var(--text-2);
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-on { background: var(--raised-2); color: var(--text); font-weight: 500; box-shadow: inset 0 0 0 1px var(--line-strong); }

/* Checkbox and switch */
.check {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}
.check input { position: absolute; opacity: 0; width: 20px; height: 20px; margin: 0; cursor: pointer; }
.check__box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--raised);
    color: transparent;
    transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.check__box .icon { width: 14px; height: 14px; }
.check input:checked + .check__box { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.check input:focus-visible + .check__box { outline: 2px solid var(--text); outline-offset: 2px; }
.check__hint { color: var(--text-3); }

.switch {
    position: relative;
    display: inline-flex;
    flex: none;
    width: 40px;
    height: 24px;
}
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch__track {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: var(--raised-2);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    transition: background-color var(--fast) var(--ease);
}
.switch__track::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--text-2);
    transition: transform var(--mid) var(--ease), background-color var(--fast) var(--ease);
}
.switch input:checked + .switch__track { background: var(--btn); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: var(--btn-text); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--text); outline-offset: 2px; }

/* Light / dark switch: sun and moon, the chosen one on a raised step */
.theme-toggle {
    display: inline-flex;
    flex: none;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--raised);
}
.theme-toggle button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 32px;
    height: 28px;
    padding: 0 7px;
    border: 0;
    border-radius: 7px;
    background: none;
    font-size: 13px;
    color: var(--text-3);
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle { border: 2px solid var(--text); background: var(--surface); }
.theme-toggle button { color: var(--text-2); font-weight: 600; }
/* The chosen side is solid: yellow highlighter for light, off-white for dark */
.theme-toggle button[aria-pressed="true"] { box-shadow: none; }
.theme-toggle button[data-theme="paper"][aria-pressed="true"] { background: var(--mark); color: var(--mark-ink); }
.theme-toggle button[data-theme="dark"][aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.theme-toggle .icon { width: 16px; height: 16px; }
.theme-toggle--labels { width: 100%; }
.theme-toggle--labels button { flex: 1; padding: 0 10px; }
@media (prefers-reduced-motion: no-preference) {
    .theme-toggle button[aria-pressed="true"] .icon { animation: turn var(--mid) var(--ease); }
}
@keyframes turn { from { transform: rotate(-60deg) scale(0.7); opacity: 0.4; } }

/* Colours ease over when the theme changes, instead of snapping. */
html.is-switching, html.is-switching * { transition: background-color var(--mid) var(--ease), border-color var(--mid) var(--ease), color var(--mid) var(--ease) !important; }

/* ----------------------------------------------------------------- Chips */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 4px 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--raised);
    font-size: 14px;
}
.chip__n { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chip__tag { font-size: 13px; color: var(--text-3); }
.chip__x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text-3);
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.chip__x:hover { background: var(--raised-2); color: var(--text); }
.chip__x .icon { width: 14px; height: 14px; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 8px;
    border-radius: 6px;
    background: var(--raised);
    font-size: 13px;
    color: var(--text-2);
    white-space: nowrap;
}
.dot { width: 8px; height: 8px; flex: none; border-radius: 4px; background: var(--text-3); }
.dot--live { background: var(--ok); }
.dot--off { background: var(--text-3); }

/* ---------------------------------------------------------------- Viewer */

.viewer {
    width: min(1040px, calc(100vw - 32px));
    height: calc(100vh - 32px);
    max-width: none;
    max-height: none;
    margin: auto;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    overflow: hidden;
    box-shadow: var(--pop-shadow);
}
.viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.viewer::backdrop { background: rgba(0, 0, 0, 0.6); }
.viewer__head, .viewer__foot {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px 12px 20px;
    background: var(--surface);
}
.viewer__head { border-bottom: 1px solid var(--line); }
.viewer__foot { justify-content: space-between; border-top: 1px solid var(--line); }
.viewer__titles { min-width: 0; margin-right: auto; }
.viewer__titles h2 { font-family: var(--sans); font-size: 16px; font-weight: 600; line-height: 22px; letter-spacing: 0; }
.viewer__titles p { font-size: 13px; line-height: 18px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.viewer__tools { display: flex; align-items: center; gap: 4px; }
.viewer__zoom { width: 48px; font-size: 13px; text-align: center; color: var(--text-2); font-variant-numeric: tabular-nums; }
.viewer__scroll { position: relative; overflow: auto; padding: 24px 16px; background: var(--page); outline-offset: -2px; }
.viewer__pages { display: grid; justify-items: center; gap: 16px; width: max-content; min-width: 100%; }
.vpage { position: relative; background: var(--sheet); border-radius: 2px; box-shadow: var(--sheet-shadow); }
.vpage canvas { display: block; width: 100%; height: 100%; border-radius: 2px; }
.viewer__page { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.viewer__actions { display: flex; gap: 8px; }

/* ----------------------------------------------------------------- Toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 32px);
    padding: 12px 16px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--raised);
    box-shadow: var(--pop-shadow);
    font-size: 14px;
    transform: translateX(-50%);
}
.toast .icon { color: var(--ok); }

/* ----------------------------------------------------------------- Motion */

@media (prefers-reduced-motion: no-preference) {
    .enter {
        opacity: 0;
        transform: translateY(10px);
        animation: enter var(--slow) var(--ease) forwards;
        animation-delay: calc(var(--i, 0) * 60ms + 60ms);
    }
    .reveal {
        opacity: 0;
        transform: translateY(12px);
        transition: opacity var(--slow) var(--ease), transform var(--slow) var(--ease);
    }
    .reveal.is-in { opacity: 1; transform: none; }
    .chip { animation: rise var(--mid) var(--ease); }
    .viewer[open] { animation: rise var(--mid) var(--ease); }
    .viewer[open]::backdrop { animation: fade var(--mid) var(--ease); }
    .toast { animation: toast var(--mid) var(--ease); }
}
@keyframes enter { to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 720px) {
    .viewer { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
    .viewer__scroll { padding: 12px 8px; }
    .viewer__foot { flex-wrap: wrap; }
}
