:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #dde1e6;
  --accent: #b5651d;
  --accent-ink: #ffffff;
  --accent-2: #2f6f4e;
  --danger: #b3261e;
  --input-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-card: #1d2025;
    --text: #e7e9ec;
    --text-muted: #9aa1ad;
    --border: #2c3038;
    --accent: #e0954f;
    --accent-ink: #1a1207;
    --accent-2: #58b98a;
    --danger: #f2867d;
    --input-bg: #23262c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* iOS Safari auto-zooms the page when a focused input's computed
   font-size is under 16px - every form field gets one explicitly so
   that never happens (was missing entirely before, on every field). */
input, select, textarea { font-size: 1rem; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

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

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

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

/* ---------------------------------------------------------------- header --
   Two rows: brand + utility actions (Export/Log out) on top, primary
   section tabs below. Splitting these apart is what fixes the mobile
   wrapping mess - the tab row scrolls horizontally on narrow screens
   instead of wrapping into a jumble of differently-indented links. */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.brand-mark { flex-shrink: 0; display: block; }
.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.logout-form { margin: 0; }

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs a {
  flex-shrink: 0;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 0.6rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a.active, .tabs a:hover { color: var(--text); border-bottom-color: var(--accent); }

@media (min-width: 601px) {
  .topbar-row { padding-bottom: 0; }
  .tabs { padding: 0 1.25rem 0.5rem; gap: 0.5rem; }
}
@media (max-width: 600px) {
  .brand-text { display: none; }
  .topbar-row { padding: 0.6rem 0.75rem; }
  .tabs { padding: 0 0.5rem; }
  .tabs a { padding: 0.55rem 0.5rem; font-size: 0.85rem; }
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}

h1 { font-size: 1.6rem; margin: 0.25rem 0 1.1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

/* ------------------------------------------------------------------ card --*/

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* --------------------------------------------------------------- stats ---
   Grid, not stacked flex: two tiles side by side even on a phone (a
   180px-ish minimum still fits two per row on any real phone width),
   instead of each one claiming a full-width row and looking empty. The
   overall-progress tile is the one hero number on this view - larger and
   in the accent color; the second tile is supporting detail. */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
}
.stat-card.hero .stat-value { font-size: 2.75rem; }
.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: proportional-nums;
  line-height: 1.1;
}
.stat-label { color: var(--text-muted); font-size: 0.82rem; margin-top: 0.35rem; }

.phase-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.85rem; }
.phase-list li { padding: 0.5rem 0; }
.phase-list li.current { position: relative; padding-left: 0.75rem; border-left: 3px solid var(--accent); }
.phase-row { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.phase-title { font-weight: 500; }
.phase-count { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  margin-left: 0.35rem;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent-2);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.trend-chart { width: 100%; height: auto; max-width: 560px; }
.trend-chart .axis { stroke: var(--border); stroke-width: 1; }
.trend-chart .trend-line { stroke: var(--accent); stroke-width: 2; }
.trend-chart .trend-dot { fill: var(--accent-2); stroke: var(--bg-card); stroke-width: 2; }

.task-list, .resource-list { list-style: none; margin: 0 0 0.75rem; padding: 0; }
.task-item, .resource-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.task-item:last-child, .resource-list li:last-child { border-bottom: none; }

.task-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.task-check { display: flex; align-items: center; gap: 0.6rem; flex: 1 1 260px; cursor: pointer; padding: 0.15rem 0; }
.task-check input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex-shrink: 0; }
.task-item.done .task-text { text-decoration: line-through; color: var(--text-muted); }
.task-buttons { display: flex; gap: 1rem; white-space: nowrap; }

.task-notes { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.35rem; }
.task-notes-input, textarea {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 1rem;
}

.resource-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.resource-list li.visited a { color: var(--text-muted); }
.resource-actions { display: flex; align-items: center; gap: 1rem; }
.resource-actions label { display: flex; align-items: center; gap: 0.4rem; }
.resource-actions input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* --------------------------------------------------------------- inputs --*/

input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* -------------------------------------------------------------- buttons --
   Explicit variant classes only - a button's look is never inferred from
   its type= or its parent element. (That inference is what silently made
   the logout button render as a filled accent button with underlined
   text: it's type="submit", and a now-removed rule styled every
   type="submit" button as primary regardless of what class it actually
   had. Explicit classes can't collide like that.) */

button, input[type="submit"] {
  font: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.5rem 1rem;
  min-height: 2.4rem;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

.btn-primary, input[type="submit"].btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  min-height: 2.2rem;
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border); }

button.small {
  padding: 0.3rem 0.6rem;
  min-height: 1.9rem;
  font-size: 0.8rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0.2rem 0;
  font: inherit;
  text-decoration: underline;
  min-height: 0;
}
.link-btn.danger, .danger { color: var(--danger); }

/* ---------------------------------------------------------------- forms --*/

.stacked-form, .login-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-width: 420px;
}
.stacked-form label, .login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.stacked-form input, .stacked-form textarea, .login-form input {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  font-family: inherit;
}
.stacked-form fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.stacked-form legend { color: var(--text-muted); font-size: 0.85rem; padding: 0 0.3rem; }

.inline-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-form input { background: var(--input-bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; }

.login-wrap { max-width: 360px; margin: 3rem auto; }
.login-title { display: flex; align-items: center; gap: 0.6rem; }
.login-title .brand-mark { width: 34px; height: 34px; }
.error { color: var(--danger); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.domains-table { width: 100%; border-collapse: collapse; min-width: 420px; }
.domains-table th, .domains-table td { text-align: left; padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--border); }
.confidence-cell { display: flex; align-items: center; gap: 0.6rem; }
.confidence-slider { flex: 1; max-width: 160px; height: 1.5rem; }

.exam-entry { margin-bottom: 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.75rem; }
.exam-entry summary { cursor: pointer; font-weight: 500; padding: 0.3rem 0; }
.exam-entry form { margin-top: 0.6rem; }
.exam-entry .stacked-form { margin-bottom: 0.4rem; }

@media (max-width: 600px) {
  main { padding: 0.85rem; }
  .card { padding: 0.9rem 1rem; }
}
