:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eaeef2; --border: #d6dde4; --text: #14212c; --text-2: #4a5866; --muted: #6f7c88;
  --accent: #103049; --accent-ink: #ffffff; --accent-soft: #e1e9f0; --good: #1f7a4a; --good-soft: #def1e5; --warn: #9a6100; --warn-soft: #f8ecd2;
  --bad: #b3261e; --bad-soft: #f8e0dd; --focus: #ff661d; --brand: #ff661d; --shadow: 0 1px 2px rgba(16, 48, 73, .06), 0 4px 16px rgba(16, 48, 73, .05);
  --radius: 10px; --display: "Poppins", "IBM Plex Sans", system-ui, sans-serif; --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; --serif: "Source Serif 4", Georgia, serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1520; --surface: #111f2c; --surface-2: #182a3a; --border: #243848; --text: #e8edf2; --text-2: #b3bfca; --muted: #8494a3;
    --accent: #9cc0de; --accent-ink: #091a28; --accent-soft: #1a3047; --good: #6cc792; --good-soft: #1b3326; --warn: #e2b05c; --warn-soft: #3a2f1b;
    --bad: #f08a80; --bad-soft: #3d2220; --focus: #ff7a3d; --brand: #ff7a3d; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1520; --surface: #111f2c; --surface-2: #182a3a; --border: #243848; --text: #e8edf2; --text-2: #b3bfca; --muted: #8494a3;
    --accent: #9cc0de; --accent-ink: #091a28; --accent-soft: #1a3047; --good: #6cc792; --good-soft: #1b3326; --warn: #e2b05c; --warn-soft: #3a2f1b;
    --bad: #f08a80; --bad-soft: #3d2220; --focus: #ff7a3d; --brand: #ff7a3d; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1, h2 { font-family: var(--display); font-weight: 600; letter-spacing: -.005em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---- layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: inset 0 3px 0 var(--brand); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
.brand span { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; }
.brand small { font: 400 .78rem var(--sans); color: var(--muted); margin-left: .15rem; padding-left: .55rem; border-left: 1px solid var(--border); }
/* The full logo has a light and a dark version; show the one that suits the theme */
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; } :root[data-theme="dark"] .logo-dark { display: inline; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo-light { display: none; } :root:not([data-theme="light"]) .logo-dark { display: inline; } }
.auth-logo { display: block; text-align: center; margin: 1.5rem auto 1.25rem; } .auth-logo img { height: 56px; width: auto; }
.foot { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 2rem; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.foot img { height: 26px; width: auto; opacity: .9; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: var(--text-2); text-decoration: none; padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; font-size: .95rem; }
.nav a.on, .nav a:hover { background: var(--surface-2); color: var(--text); }
.who { display: flex; align-items: center; gap: .5rem; }
main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 3rem; min-height: calc(100vh - 160px); }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
.stack > * + * { margin-top: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); min-width: 0; }
.card h2, .card h3 { margin-bottom: .6rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 0 0 1.25rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--text-2); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--brand); font-weight: 600; }

/* ---- controls */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .5rem .9rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; line-height: 1.3; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.small, .btn.small { padding: .3rem .6rem; font-size: .875rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 .3rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: .9rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.inline { display: inline-flex; align-items: center; gap: .4rem; }
.inline input[type=number] { width: 5.5rem; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
.form-narrow { max-width: 420px; margin: 3rem auto; }
.error { background: var(--bad-soft); color: var(--bad); padding: .6rem .8rem; border-radius: 8px; margin-bottom: .9rem; }
.note { background: var(--accent-soft); padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.note.warn-note { background: var(--warn-soft); border-left: 3px solid var(--warn); }
.conflict { border: 1px solid var(--border); border-radius: 10px; padding: .8rem .9rem; margin-bottom: .8rem; }
.conflict .note { margin: .5rem 0 .3rem; }
.conflict-opts { margin: .3rem 0; padding-left: 1.4rem; }
.conflict-opts li { margin: .15rem 0; }
.conflict-opts .is-key { font-weight: 600; }
button.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
button.linkish:hover { color: var(--brand); }
.passage { white-space: pre-wrap; font: .92rem/1.6 var(--serif, Georgia, serif); max-width: 68ch; }
.passage mark { background: var(--warn-soft); color: inherit; outline: 2px solid var(--warn-soft); border-radius: 2px; }
.passage-nav { gap: .5rem; margin-bottom: .8rem; align-items: center; }
select.kind-sel { width: auto; padding: .2rem .4rem; font-size: .8rem; }

/* ---- meters */
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); position: relative; overflow: visible; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--accent); }
.bar > span.good { background: var(--good); } .bar > span.warn { background: var(--warn); } .bar > span.bad { background: var(--bad); }
.bar > i { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .7; }
.meter-row { display: grid; grid-template-columns: minmax(90px, 210px) 1fr 3.2rem; gap: .75rem; align-items: center; margin: .45rem 0; font-size: .92rem; }
.meter-row .val { text-align: right; font-variant-numeric: tabular-nums; }
.ring { width: 84px; height: 84px; flex: none; }
.ring text { font: 700 20px var(--sans); fill: var(--text); }
.kpis { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.kpi .n { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---- project cards */
.pcard { display: flex; flex-direction: column; gap: .8rem; }
.pcard .top { display: flex; gap: 1rem; align-items: center; }
.pcard h2 { margin: 0; font-size: 1.12rem; }
.pcard h2 a { color: var(--text); text-decoration: none; }
.pcard .foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: auto; }
.newcard { border-style: dashed; display: grid; place-items: center; min-height: 220px; color: var(--text-2); cursor: pointer; background: transparent; box-shadow: none; }

/* ---- tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- exam runner */
.runner { display: grid; grid-template-columns: 1fr 260px; gap: 1.25rem; align-items: start; }
.qcard { padding: 1.5rem; }
.qmeta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .9rem; color: var(--muted); font-size: .88rem; }
.stem { font: 1.18rem/1.55 var(--serif); margin-bottom: 1.1rem; }
.opts { display: flex; flex-direction: column; gap: .55rem; }
.opt { display: flex; gap: .75rem; align-items: flex-start; text-align: left; padding: .75rem .9rem; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); width: 100%; }
.opt .k { flex: none; width: 1.7rem; height: 1.7rem; border-radius: 6px; display: grid; place-items: center; font: 600 .85rem var(--mono); background: var(--surface-2); }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .k { background: var(--accent); color: var(--accent-ink); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .k { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.feedback { margin-top: 1rem; padding: .9rem 1rem; border-radius: 9px; background: var(--surface-2); }
.feedback.good { background: var(--good-soft); } .feedback.bad { background: var(--bad-soft); }
.feedback strong { display: block; margin-bottom: .25rem; }
.qnav { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 5px; }
.qnav button { padding: 0; height: 34px; justify-content: center; font-size: .8rem; font-variant-numeric: tabular-nums; }
.qnav button.ans { background: var(--accent-soft); border-color: var(--accent); }
.qnav button.mark { box-shadow: inset 0 -3px 0 var(--warn); }
.qnav button.cur { outline: 2px solid var(--text); }
.qnav button.right { background: var(--good-soft); border-color: var(--good); }
.qnav button.wrong { background: var(--bad-soft); border-color: var(--bad); }
.timer { font: 700 1.5rem var(--mono); font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: space-between; margin-top: 1.25rem; }

/* ---- flashcards */
.flash { min-height: 260px; display: grid; place-items: center; text-align: center; padding: 2rem; cursor: pointer; font: 1.35rem/1.5 var(--serif); }
.flash .def { font-size: 1.1rem; }

/* ---- dialogs & toasts */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(10, 12, 14, .45); }
dialog .dhead { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
dialog .dhead h2 { margin: 0; }
dialog .dbody { padding: 1.1rem 1.2rem; overflow-y: auto; max-height: calc(100vh - 190px); }
dialog .dfoot { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1.2rem; border-top: 1px solid var(--border); }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
#toast div { background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.copybox { display: flex; gap: .5rem; } .copybox input { font-family: var(--mono); font-size: .85rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .gl { stroke: var(--border); } .chart .ax { fill: var(--muted); font: 11px var(--sans); }
.chart .ln { stroke: var(--accent); fill: none; stroke-width: 2.5; } .chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .pass { stroke: var(--bad); stroke-dasharray: 5 4; stroke-width: 1.5; } .chart .passl { fill: var(--bad); font: 600 11px var(--sans); }
.steps { margin: 0; padding-left: 1.2rem; } .steps li { margin: .35rem 0; }
.qtext { font-family: var(--serif); }
.optlist { margin: .4rem 0 0; padding-left: 1.3rem; } .optlist li.right { color: var(--good); font-weight: 600; }
.edit-opt { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; margin-bottom: .45rem; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; background: var(--c); }

@media (max-width: 820px) {
  .brand small { display: none; }
  .runner { grid-template-columns: 1fr; }
  .who .uname { display: none; }
  .topbar-in { flex-wrap: wrap; gap: .5rem; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 1rem 16px 4rem; }
  .meter-row { grid-template-columns: minmax(70px, 120px) 1fr 3rem; }
  .qcard { padding: 1.1rem; }
}

@media print {
  .topbar, .tabs, .no-print, button, .btn, .foot { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  main { max-width: none; padding: 0; }
}

#themeBtn { font-size: .85rem; color: var(--text-2); }
.dom-ch { grid-column: 1 / -1; margin-top: -.25rem; }
