:root {
  --paper: #eef1f4;
  --paper-raised: #ffffff;
  --ink: #1b2430;
  --ink-soft: #55606e;
  --ink-faint: #8b96a3;
  --rule: #d7dee5;
  --accent: #2a4b7c;
  --accent-soft: #e4eaf3;
  --ticket: #b23a48;
  --ticket-soft: #f7e3e0;
  --success: #2f6f62;
  --success-soft: #e2ede9;
  --warn: #c98a2c;
  --warn-soft: #f6e9d6;
  --radius: 10px;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: 72px; } /* room for bottom nav */

a { color: var(--accent); }

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}

.app { max-width: 720px; margin: 0 auto; padding: 16px; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 16px;
}
.topbar .brand {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
}
.topbar .brand small { color: var(--ink-faint); font-weight: 500; display: block; font-size: 11px; }
.topbar button.linklike {
  background: none; border: none; color: var(--ink-soft); font-size: 13px; cursor: pointer; padding: 8px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2, .card h3 { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Exam ticket (signature element) ---------- */
.ticket {
  position: relative;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.ticket::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; right: 92px;
  width: 0;
  border-left: 2px dashed rgba(255,255,255,0.25);
}
.ticket .stub-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(255,255,255,0.6); margin-bottom: 4px; }
.ticket .stub-detail { font-size: 13px; color: rgba(255,255,255,0.85); }
.ticket .countdown { font-family: var(--font-mono); font-weight: 700; font-size: 40px; line-height: 1; text-align: right; min-width: 84px; }
.ticket .countdown-unit { font-family: var(--font-mono); font-size: 11px; color: rgba(255,255,255,0.6); text-align: right; margin-top: 4px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.not_started { background: var(--rule); color: var(--ink-soft); }
.badge.read { background: var(--accent-soft); color: var(--accent); }
.badge.understood { background: var(--success-soft); color: var(--success); }
.badge.needs_review { background: var(--warn-soft); color: var(--warn); }

/* ---------- Stat blocks ---------- */
.stat { padding: 4px 0; }
.stat .num { font-family: var(--font-mono); font-weight: 700; font-size: 24px; }
.stat .label { font-size: 12px; color: var(--ink-soft); }

/* ---------- Buttons ---------- */
button, .btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
}
button.secondary, .btn.secondary {
  background: transparent;
  color: var(--accent);
}
button.ghost {
  background: transparent;
  border-color: var(--rule);
  color: var(--ink-soft);
}
button.danger { background: var(--ticket); border-color: var(--ticket); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button + button { margin-left: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
label:first-child { margin-top: 0; }
input[type="text"], input[type="date"], input[type="number"], input[type="password"], textarea, select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.checkbox-row label {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px;
  font-weight: 500; font-size: 13px; margin: 0; cursor: pointer;
}
.checkbox-row input { width: auto; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; font-family: var(--font-mono);
}
.chip button { padding: 0; border: none; background: none; color: var(--ink-faint); font-size: 14px; margin: 0; line-height: 1; }

/* ---------- Lists ---------- */
.topic-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--rule);
  cursor: pointer; background: none; border-left: none; border-right: none; border-top: none;
  width: 100%; text-align: left; font-family: var(--font-body);
}
.topic-row:last-child { border-bottom: none; }
.topic-row .title { font-size: 14px; font-weight: 500; }
.module-title { font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; color: var(--ink-faint); letter-spacing: 0.05em; margin: 18px 0 4px; }
.module-title:first-child { margin-top: 0; }

.resource {
  display: block;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink);
}
.resource .kind { color: var(--accent); font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; display: block; margin-bottom: 2px; }

.journal-entry { border-bottom: 1px solid var(--rule); padding: 10px 0; }
.journal-entry:last-child { border-bottom: none; }
.journal-entry .date { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); }
.journal-entry .field-label { font-size: 11px; text-transform: uppercase; color: var(--ink-faint); margin-top: 6px; }

.feedback-item { border-left: 3px solid var(--rule); padding: 8px 10px; margin-bottom: 8px; border-radius: 4px; background: var(--paper); }
.feedback-item.correct { border-left-color: var(--success); }
.feedback-item.incorrect { border-left-color: var(--ticket); }

.quiz-question { margin-bottom: 18px; }
.quiz-question .qtext { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.quiz-question .qtype { font-size: 11px; color: var(--ink-faint); font-family: var(--font-mono); text-transform: uppercase; margin-bottom: 8px; display: block; }
.option-row {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid var(--rule); border-radius: 8px; padding: 10px;
  margin-bottom: 6px; cursor: pointer; font-size: 13px;
}
.option-row input { margin-top: 2px; width: auto; }
.option-row.picked { border-color: var(--accent); background: var(--accent-soft); }
.option-row:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option-row.correct { border-color: var(--success); background: var(--success-soft); }
.option-row.incorrect { border-color: var(--ticket); background: var(--ticket-soft); }

.glossary-entry { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.glossary-entry:last-child { border-bottom: none; }
.glossary-entry .term { font-weight: 700; font-family: var(--font-mono); font-size: 13px; }
.glossary-entry .def { font-size: 13px; margin-top: 2px; }

.warning { background: var(--warn-soft); color: #7a5417; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 8px; }
.error-box { background: var(--ticket-soft); color: #7a2530; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 8px; }
.muted { color: var(--ink-faint); font-size: 13px; }
.spinner-inline { font-family: var(--font-mono); font-size: 13px; color: var(--ink-faint); }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--paper-raised);
  border-top: 1px solid var(--rule);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tabbar button {
  background: none; border: none; color: var(--ink-faint);
  font-size: 10px; font-weight: 600; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: 0; margin: 0; flex: 1; min-width: 0;
}
.tabbar button.active { color: var(--accent); }
.tabbar button .dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--ticket); position: relative; top: -12px; left: 14px; display: none;
}
.tabbar button.has-badge .dot { display: block; }

/* ---------- Login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { max-width: 320px; width: 100%; text-align: center; }
.login-card .lockicon { font-family: var(--font-mono); font-size: 28px; margin-bottom: 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
