/* Anzdrill. Style: achromatic ledger (taste-skill app sheet, workspace kind).
   The chrome is ink on a blue-grey ground; the one data hue marks what is due; the only other colour is a
   small signal for status. Dark mode is the same system with true neutral darks (html.dark). */

:root {
  --ground: #f2f4f7;          /* the page: a ledger's blue-grey, cards stay white */
  --surface: #ffffff;
  --raised: #f6f7f9;          /* a filled well, hover rows, the answer face */
  --active: #e4e8ee;          /* the active nav pill */
  --border: #e3e6eb;
  --rule: #eceef2;           /* row rules */
  --control: #c9ced7;         /* inputs and outlined buttons */
  --text: #0a0a0a;
  --muted: #5b616b;           /* secondary text, 4.5:1 or more on the ground */
  --faint: #646b75;           /* meta and placeholders */
  --primary: #141414;         /* the one primary action: near-black */
  --primary-ink: #ffffff;
  --data: #1d5fbf;            /* the one chart hue: what is due */
  --data-track: #e1e5ec;
  --positive: #247b50;
  --negative: #c4242a;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-card: 8px;
  --radius-control: 6px;
  --card-pad: 20px;
  --sidebar: 232px;
  color-scheme: light;
}

.dark {
  --ground: #000000;
  --surface: #111111;
  --raised: #1b1b1b;
  --active: #232323;
  --border: #222222;
  --rule: #1a1a1a;
  --control: #3a3a3a;
  --text: #ffffff;
  --muted: #b4b4b4;
  --faint: #949494;
  --primary: #ffffff;
  --primary-ink: #000000;
  --data: #6fa8ff;
  --data-track: #1f1f1f;
  --positive: #3fc07a;
  --negative: #e5566f;
  --pill-positive-bg: #172a1d; --pill-positive-ink: #3fc07a;
  --pill-negative-bg: #2c1a20; --pill-negative-ink: #e5566f;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: 14px/20px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--data); outline-offset: 2px; border-radius: 4px; }
.sub { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; }
.num, table, .kpi-value, .timer { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell: open sidebar on the ground; a folding top bar on the phone ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100svh; }
.nav-toggle, .scrim { position: absolute; opacity: 0; pointer-events: none; }
.sidebar { position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; gap: 2px; padding: 20px 14px; overflow: auto; background: var(--ground); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; font-weight: 600; font-size: 15px; text-decoration: none; }
.brand svg { width: 22px; height: 22px; flex: none; }
.nav a { display: flex; align-items: center; height: 34px; padding: 0 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.nav a:hover { background: var(--raised); color: var(--text); }
.nav a[aria-current="page"] { background: var(--active); color: var(--text); font-weight: 500; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 14px 8px 0; border-top: 1px solid var(--rule); }
.account { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.canvas { min-width: 0; padding: 32px 40px; }
.page { max-width: 1040px; }
.topbar { display: none; }

/* ---------- title block ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
.page-head .sub { margin-top: 4px; }
.finding { margin-bottom: 20px; font-size: 15px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- panels, KPIs, lists ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--card-pad); min-width: 0; }
.panel + .panel { margin-top: 16px; }
.panel-title { font-size: 16px; line-height: 1.3; font-weight: 600; margin-bottom: 12px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.panel-head .panel-title { margin-bottom: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); margin-bottom: 16px; }
.kpi { padding: 16px var(--card-pad); }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { margin-top: 6px; font-size: 30px; line-height: 1.1; font-weight: 500; letter-spacing: -0.01em; }
.kpi-value small { margin-left: 4px; font-size: 14px; font-weight: 400; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 36px; padding: 0 12px; text-align: left; font-weight: 400; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th.n, td.n { text-align: right; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions a + a { margin-left: 14px; }
.due-cell { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.bar { position: relative; height: 8px; width: 140px; border-radius: 999px; background: var(--data-track); }
.bar span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--data); }
.empty { display: grid; place-items: center; min-height: 72px; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-control); color: var(--muted); text-align: center; }

/* ---------- buttons, links, fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 0 14px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); color: var(--text); font-weight: 500; text-decoration: none; cursor: pointer; transition: background-color 150ms ease; }
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { opacity: 0.88; }
.btn.text { height: 28px; padding: 0 2px; border-color: transparent; background: none; color: var(--muted); }
.btn.text:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.btn.danger { color: var(--negative); }
.link { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { text-decoration-thickness: 2px; }
.form { display: grid; gap: 16px; max-width: 420px; }
.field { display: grid; gap: 8px; }
.field > label, .label { font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; }
.note-time { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.note:has(.note-edit[open]) .note-time { display: none; }
.input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); }
.input::placeholder { color: var(--faint); }
.check { display: flex; align-items: center; gap: 8px; }
input[type="checkbox"] { accent-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border: 1px solid var(--control); border-radius: 999px; background: var(--surface); cursor: pointer; }
.chip:has(input:checked) { background: var(--active); }
.flash { margin-bottom: 16px; padding: 12px 14px; border-radius: var(--radius-control); font-weight: 500; }
.flash.notice { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.flash.alert { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }

/* ---------- study: the card face and the four grades ---------- */
.study { max-width: 720px; }
.card-face { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 28px; font-size: 18px; line-height: 1.5; }
.card-face + .card-face { margin-top: 12px; background: var(--raised); }
.card-face .whitespace-pre-wrap { white-space: pre-wrap; }
.card-face code { padding: 1px 5px; border-radius: 4px; background: var(--rule); font-size: 0.9em; }
.card-face pre { margin: 12px 0; padding: 14px; border-radius: var(--radius-control); overflow-x: auto; font-size: 14px; }
.hints { margin-top: 12px; display: grid; gap: 6px; }
.hints summary { cursor: pointer; color: var(--muted); }
.hints div { margin-top: 6px; }
.reveal { margin-top: 16px; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.grade-form { display: grid; }
.grade { display: block; width: 100%; height: auto; padding: 12px 14px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); text-align: left; font-weight: 500; cursor: pointer; }
.grade:hover { background: var(--raised); }
/* the interval each grade schedules is the product's own readout: the largest figure on the answer */
.grade-interval { display: block; margin-top: 4px; font-size: 18px; font-weight: 500; color: var(--data); }
.keys-hint { margin-top: 12px; color: var(--faint); font-size: 12px; }

/* ---------- topic and mock cards ---------- */
.card-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px 16px; }
.card-row + .card-row { margin-top: 8px; }
.card-row summary { cursor: pointer; font-weight: 500; }
.card-row summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.card-row > div { margin-top: 12px; }
.answer { padding: 14px; border-radius: var(--radius-control); background: var(--raised); }
.timer { font-size: 18px; font-weight: 500; }
.stack { display: grid; gap: 12px; }

/* ---------- auth pages ---------- */
.auth { min-height: 100svh; padding: 24px 40px; }
.auth-top { display: flex; align-items: center; justify-content: space-between; max-width: 420px; margin: 0 auto; }
.auth-main { max-width: 420px; margin: 56px auto 0; }
.auth-main h1 { font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }
.auth-main .sub { margin-bottom: 24px; }
.auth-main .links { display: grid; gap: 10px; margin-top: 4px; color: var(--muted); }
.auth-main .panel { padding: 24px; }

/* ---------- spacing and layout helpers used by the views ---------- */
.mt-xs { margin-top: 4px; }
.mt-s { margin-top: 8px; }
.mt-m { margin-top: 12px; }
.mt-l { margin-top: 16px; }
.mt-xl { margin-top: 20px; }
.mt-2xl { margin-top: 24px; }
.mb-s { margin-bottom: 8px; }
.mb-l { margin-bottom: 16px; }
.form-wide { max-width: 560px; }
.grow { flex: 1; min-width: 0; }
.fieldset-reset { min-width: 0; margin: 0; padding: 0; border: 0; }
.textarea { height: auto; padding: 10px 12px; resize: vertical; }
.whitespace-pre-wrap { white-space: pre-wrap; }
.stack > .btn { width: 100%; justify-content: flex-start; }
.row-actions form { display: inline; }
.topic-cell::after { display: none; }
.row-actions .btn.text { height: 22px; }
.correct { font-weight: 600; }
.card-face code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

/* ---------- notes and files under the answer ---------- */
turbo-frame { display: block; }
.notes { margin-top: 16px; }
.notes summary { cursor: pointer; color: var(--muted); }
.notes-count { margin-left: 8px; font-size: 12px; color: var(--faint); }
.notes-body { margin-top: 12px; display: grid; gap: 24px; }
.notes-body section { display: grid; gap: 8px; align-content: start; min-width: 0; }
.notes-body h2 { font-size: 13px; font-weight: 600; color: var(--muted); }
.note { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: var(--radius-control); background: var(--raised); font-size: 15px; }
.note > div { min-width: 0; }
.note .btn.text { flex: none; height: 22px; }
.attachment-img { display: block; max-width: 100%; max-height: 240px; border-radius: var(--radius-control); }
.note-edit { margin-top: 6px; }
.note-edit summary { width: fit-content; cursor: pointer; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.note-edit .note-form { margin-top: 8px; }
.note-edit .when-open, .note-edit[open] .when-closed { display: none; }
.note-edit[open] .when-open { display: inline; }
.note:has(.note-edit[open]) .note-body { display: none; }
.note:has(.note-edit[open]) > div { flex: 1; }
/* a link reads as its page: picture, title, a line of description, the site */
.link-preview { display: flex; gap: 12px; min-width: 0; color: inherit; text-decoration: none; }
.link-preview img { flex: none; width: 96px; height: 64px; object-fit: cover; border-radius: 4px; background: var(--rule); }
.link-text { display: grid; gap: 2px; min-width: 0; }
.link-title { font-weight: 500; overflow-wrap: anywhere; }
.link-preview:hover .link-title { text-decoration: underline; text-underline-offset: 3px; }
.link-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 14px; }
.link-host { color: var(--faint); font-size: 12px; }
.link-form { display: flex; gap: 8px; }
.link-form .input { flex: 1; min-width: 0; }
.note-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.note-form > .btn, .note-form > .hint { justify-self: start; }
.note-form .textarea { width: 100%; }
.file-pick:focus-within { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- Trix editor and rich note text ---------- */
trix-toolbar { min-width: 0; max-width: 100%; }
trix-toolbar .trix-button-group--file-tools, trix-toolbar .trix-button--icon-strike, trix-toolbar .trix-button--icon-decrease-nesting-level, trix-toolbar .trix-button--icon-increase-nesting-level { display: none; }
trix-toolbar .trix-button-row { flex-wrap: wrap; overflow: visible; gap: 0 8px; justify-content: flex-start; }
trix-toolbar .trix-button-group:not(:first-child) { margin-left: 0; }
trix-toolbar .trix-button-group-spacer { display: none; }
trix-toolbar .trix-button-group { margin-bottom: 8px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); overflow: hidden; }
trix-toolbar .trix-button { border-color: var(--rule); background: none; }
trix-toolbar .trix-button.trix-active { background: var(--active); }
trix-toolbar .trix-dialog { border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); box-shadow: none; }
trix-toolbar .trix-input--dialog { border-color: var(--control); background: var(--surface); }
trix-editor { width: 100%; min-height: 96px; padding: 10px 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); font-size: 15px; }
trix-editor:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.dark trix-toolbar .trix-button--icon::before { filter: invert(1); }
.note .trix-content { font-size: 15px; line-height: 1.5; }
.note .trix-content ul, .note .trix-content ol { padding-left: 20px; }
.note .trix-content a { text-decoration: underline; text-underline-offset: 3px; }
.note .trix-content pre { padding: 8px 10px; border-radius: var(--radius-control); background: var(--rule); font-size: 13px; }
.note .trix-content blockquote { border-left: 3px solid var(--control); padding-left: 10px; color: var(--muted); }

/* ---------- filter row ---------- */
.filters .actions { align-items: stretch; }
.filters .input { width: auto; min-width: 160px; }

/* ---------- cards list: fixed columns, so Edit and Delete never leave the screen ---------- */
.panel.flush { padding: 0; overflow: clip; }
.cards-table { table-layout: fixed; }
.cards-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.cards-table .c-key { width: 27%; }
.cards-table .c-topic { width: 14%; }
.cards-table .c-status { width: 96px; }
.cards-table .c-actions { width: 132px; }
.cards-table code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }
.cards-table .c-question { color: var(--muted); }
.cards-table td.c-question, .cards-table td.c-topic { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--raised); color: var(--muted); font-size: 12px; }
.pill.ok { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }

/* ---------- settings screens: panels holding a form, a ledger of facts or topic tiles ---------- */
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panels > .panel { display: flex; flex-direction: column; margin-top: 0; }
.panel .form { max-width: none; }
/* paired panels share a height, so their buttons line up at the bottom */
.panels > .panel > .form { flex: 1; display: flex; flex-direction: column; }
.panels .form > .panel-foot, .panels > .panel > .panel-foot { margin-top: auto; }
.panel > .sub { max-width: 60ch; }
.panels > .panel > .sub { margin-bottom: 20px; }
.input[type="file"] { height: auto; padding: 8px 12px; }
.panel-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); }
.facts { display: grid; margin: 0; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.facts > div:last-child { border-bottom: 0; padding-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.fields-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.topic-option { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); cursor: pointer; transition: background-color 150ms ease; }
.topic-option:hover { background: var(--raised); }
.topic-option:has(input:checked) { border-color: var(--text); background: var(--raised); }
.topic-option .faint { margin-left: auto; white-space: nowrap; }

/* ---------- phone: the navigation folds into a top bar and a sheet ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 16px; background: var(--ground); border-bottom: 1px solid var(--border); }
  .topbar .brand { padding: 0; }
  .menu-button { display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); font-weight: 500; cursor: pointer; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(84vw, 300px); height: 100svh; background: var(--surface); transform: translateX(-100%); transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1); }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .scrim { display: none; }
  .nav-toggle:checked ~ .scrim { position: fixed; inset: 0; z-index: 15; display: block; opacity: 1; pointer-events: auto; background: rgba(0, 0, 0, 0.3); }
  .canvas { padding: 20px 16px 32px; }
  .page-head h1 { font-size: 22px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(even) { border-left: 1px solid var(--border); }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .grades { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-face { padding: 20px; font-size: 17px; }
  .auth { padding: 16px; }
  .auth-main { margin-top: 32px; }
  /* a table becomes two-line rows: the figures that do not fit move to a grey line under the name */
  .hide-phone { display: none; }
  .topic-cell::after { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); content: attr(data-phone); }
  .bar { width: 48px; }
  td, th { padding-left: 6px; padding-right: 6px; }
  .row-actions a + a { margin-left: 10px; }
  .panel { padding: 16px; }
  .panels { grid-template-columns: minmax(0, 1fr); }
  .fields-row { grid-template-columns: minmax(0, 1fr); }
  .panel.flush { padding: 0; }
  .cards-table .c-key { width: auto; }
  .filters .input { min-width: 0; flex: 1; }
  .cards-table .c-actions { width: 104px; }
  .cards-table th { top: 52px; }
}

/* Stats: activity heatmap, one cell per day, weeks as columns (Monday first). */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 15px); grid-auto-columns: 15px; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.heat { border-radius: 2px; background: var(--data-track); }
.heat[data-level="1"] { background: color-mix(in srgb, var(--data) 30%, var(--data-track)); }
.heat[data-level="2"] { background: color-mix(in srgb, var(--data) 55%, var(--data-track)); }
.heat[data-level="3"] { background: color-mix(in srgb, var(--data) 80%, var(--data-track)); }
.heat[data-level="4"] { background: var(--data); }

/* Optional typed answer on the study screen. */
.typed-answer { margin-top: 16px; }
.typed-answer summary { cursor: pointer; color: var(--muted); }
.typed-answer summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.card-face.mine { margin-bottom: 12px; }

/* Card tags and the Focus filters. */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
a.pill { text-decoration: none; }
a.pill:hover { color: var(--text); }
