:root {
  --bg: #0b0e14;
  --bg-elev: #131826;
  --bg-elev-2: #1b2233;
  --border: #232b3d;
  --text: #e6e9f0;
  --text-dim: #9aa3b8;
  --accent: #c9b8ff;
  --accent-2: #8ea2ff;
  --good: #6ee7a8;
  --warn: #ffd479;
  --danger: #ff8a8a;
  --nav-h: 64px;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  /* respect notches */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(11, 14, 20, 0.95), rgba(11, 14, 20, 0.8));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { border-radius: 8px; }
.brand-name { font-weight: 600; letter-spacing: 0.3px; }

.app-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- Bottom navigation ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  padding: 6px 2px;
  transition: color 0.15s;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.active svg { stroke: var(--accent); }

/* ---------- Cards & sections ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.section-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 4px; }
.section-sub { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 14px; line-height: 1.4; }
.practice-block { margin-bottom: 18px; }
.practice-block h3 { font-size: 0.98rem; margin: 0 0 2px; color: var(--accent); }
.practice-block .sub { color: var(--text-dim); font-size: 0.8rem; margin: 0 0 10px; }

/* ---------- Assessment items ---------- */
.item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.item:first-of-type { border-top: none; }
.item .text { flex: 1; font-size: 0.9rem; line-height: 1.45; }

/* checkbox */
.check {
  appearance: none;
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s;
}
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after {
  content: "";
  width: 7px; height: 12px;
  border: solid #0b0e14;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* stars */
.stars { display: flex; gap: 4px; }
.star {
  width: 30px; height: 30px;
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--border);
}
.star svg { width: 100%; height: 100%; }
.star.on { color: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); color: #0b0e14; border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: rgba(255,138,138,0.4); }
.btn.small { width: auto; padding: 8px 12px; font-size: 0.85rem; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }

/* ---------- Inputs ---------- */
input[type="date"], select {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: 12px;
  font-size: 0.95rem;
}
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }

/* ---------- Stats ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar select { flex: 1; min-width: 140px; }
.seg { display: flex; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1; background: none; border: none; color: var(--text-dim);
  padding: 10px 8px; font-size: 0.82rem; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #0b0e14; font-weight: 600; }

.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; min-width: 320px; display: block; }
.chart .bar { fill: var(--accent); transition: fill 0.15s; }
.chart .bar:hover { fill: var(--accent-2); }
.chart .axis { stroke: var(--border); }
.chart .grid { stroke: var(--border); stroke-dasharray: 2 4; opacity: 0.5; }
.chart text { fill: var(--text-dim); font-size: 10px; }
.chart .val { fill: var(--text); font-size: 9px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 0.8rem; color: var(--text-dim); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

.breakdown { margin-top: 8px; }
.breakdown .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--border); font-size: 0.9rem;
}
.breakdown .row .label { color: var(--text); }
.breakdown .row .value { color: var(--accent); font-weight: 600; }

/* ---------- Records table ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 520px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; position: sticky; top: 0; background: var(--bg-elev); }
td.num { text-align: center; }
.actions-cell { display: flex; gap: 6px; }
.icon-btn {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.danger { color: var(--danger); }

.empty { text-align: center; color: var(--text-dim); padding: 40px 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--accent-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: 0.9rem;
  max-width: 90vw;
}
.toast[hidden] { display: none; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 40;
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.modal h2 { margin: 0 0 16px; font-size: 1.1rem; }

/* ---------- Cheatsheet ---------- */
.cheat-group { margin-bottom: 18px; }
.cheat-group h3 { color: var(--accent); font-size: 1rem; margin: 0 0 8px; }
.cheat-group ul { margin: 0; padding-left: 18px; }
.cheat-group li { margin-bottom: 8px; line-height: 1.45; font-size: 0.9rem; }
.cheat-group strong { color: var(--text); }

h1.page-title { font-size: 1.3rem; margin: 4px 0 16px; }
.muted { color: var(--text-dim); font-size: 0.85rem; }
.push-card { display: flex; flex-direction: column; gap: 10px; }
