:root {
  --bg: #0b0d11;
  --bg-elev: #141821;
  --bg-elev-2: #1c2230;
  --fg: #f4f6fa;
  --fg-dim: #9aa3b2;
  --fg-faint: #6b7281;
  --accent: #ff9d3a;
  --accent-2: #4cc9ff;
  --accent-3: #b388ff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #ef4444;
  --border: #232a3a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0,0,0,0.4);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  min-height: 100vh;
  min-height: 100dvh;
}
img { max-width: 100%; display: block; }
a { color: var(--accent-2); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

#app {
  padding: calc(var(--safe-top) + 12px) 16px calc(80px + var(--safe-bot)) 16px;
  max-width: 720px; margin: 0 auto;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 14px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.topbar .logo {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  display: grid; place-items: center; font-weight: 800; color: #1c1410;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: 0.2px; }
.topbar .icon-btn {
  appearance: none; background: transparent; border: 1px solid var(--border);
  height: 36px; min-width: 36px; padding: 0 10px; border-radius: 10px;
  color: var(--fg); display: inline-grid; place-items: center;
}

/* ---- Bottom nav ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 6px 6px calc(6px + var(--safe-bot)) 6px;
  background: rgba(11,13,17,0.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  z-index: 50;
}
.tabbar button {
  appearance: none; background: transparent; border: 0; color: var(--fg-dim);
  padding: 8px 6px; min-height: var(--tap); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px;
}
.tabbar button[aria-current="page"] { color: var(--fg); background: var(--bg-elev); }
.tabbar .ico { font-size: 20px; line-height: 1; }

/* ---- Cards ---- */
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 8px 0; font-size: 18px; }
.card h3 { margin: 0 0 6px 0; font-size: 15px; color: var(--fg-dim); font-weight: 600; }
.card.compact { padding: 12px; }
.card .meta { font-size: 12px; color: var(--fg-dim); }

.section-title {
  margin: 16px 4px 8px;
  font-size: 12px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--fg-faint);
}

/* ---- Lesson list ---- */
.lesson-tile {
  display: flex; gap: 14px; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  text-decoration: none; color: var(--fg);
}
.lesson-tile:active { background: var(--bg-elev-2); }
.lesson-tile .emo {
  width: 48px; height: 48px; flex: 0 0 48px;
  border-radius: 12px; background: var(--bg-elev-2);
  display: grid; place-items: center; font-size: 22px;
}
.lesson-tile .body { flex: 1; min-width: 0; }
.lesson-tile .title-row { display: flex; align-items: baseline; gap: 8px; }
.lesson-tile .title { font-weight: 600; font-size: 16px; }
.lesson-tile .dur { font-size: 11px; color: var(--fg-faint); }
.lesson-tile .summary { color: var(--fg-dim); font-size: 13px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lesson-tile .progress-pill {
  font-size: 10px; padding: 2px 7px; border-radius: 99px;
  background: var(--bg-elev-2); color: var(--fg-dim); letter-spacing: 0.4px;
}
.lesson-tile .progress-pill.done { background: rgba(74,222,128,0.15); color: var(--ok); }

/* ---- Buttons ---- */
.btn {
  appearance: none; background: var(--accent); color: #1c1410; border: 0;
  padding: 12px 16px; border-radius: 10px; font-weight: 700;
  min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
}
.btn.secondary { background: var(--bg-elev-2); color: var(--fg); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--accent-2); border: 1px solid var(--border); }
.btn.danger { background: #2a1517; color: var(--err); border: 1px solid #4a1f23; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 13px; width: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }

/* ---- Lesson view ---- */
.lesson-hero {
  display: flex; gap: 14px; align-items: center; margin-bottom: 8px;
}
.lesson-hero .emo {
  width: 56px; height: 56px; border-radius: 14px; background: var(--bg-elev);
  display: grid; place-items: center; font-size: 28px;
}
.lesson-hero h2 { margin: 0; font-size: 22px; }
.lesson-hero .meta { color: var(--fg-dim); font-size: 12px; }

.markdown { color: var(--fg); line-height: 1.6; }
.markdown p { margin: 8px 0; }
.markdown strong { color: var(--fg); }
.markdown em { color: var(--fg-dim); font-style: italic; }
.markdown ul { padding-left: 20px; margin: 8px 0; }
.markdown li { margin: 4px 0; }
.markdown code {
  background: var(--bg); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
}

.tip-card { border-left: 3px solid var(--accent); }
.z50-card { border-left: 3px solid var(--accent-2); }
.z50-card h3::before { content: "📷 "; }
.tip-card h3::before { content: "💡 "; }

/* ---- Quiz ---- */
.quiz-q { margin-bottom: 14px; }
.quiz-q .q { font-weight: 600; margin-bottom: 8px; }
.choice {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 6px; color: var(--fg);
  min-height: var(--tap);
}
.choice.correct { border-color: var(--ok); background: rgba(74,222,128,0.1); }
.choice.wrong { border-color: var(--err); background: rgba(239,68,68,0.1); }
.explain { font-size: 13px; color: var(--fg-dim); margin-top: 6px; padding-left: 4px; }

/* ---- Widgets ---- */
.widget { background: var(--bg); border-radius: 10px; padding: 14px; margin: 10px 0; }
.widget canvas, .widget svg { display: block; margin: 0 auto; max-width: 100%; }
.widget .controls { display: grid; gap: 10px; margin-top: 10px; }
.widget .row { display: flex; align-items: center; gap: 10px; }
.widget label { min-width: 90px; font-size: 13px; color: var(--fg-dim); }
.widget input[type="range"] { flex: 1; accent-color: var(--accent); }
.widget .value { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.widget .stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.widget .stat { background: var(--bg-elev); padding: 8px; border-radius: 8px; text-align: center; }
.widget .stat .l { font-size: 10px; color: var(--fg-faint); text-transform: uppercase; letter-spacing: 1px; }
.widget .stat .v { font-size: 16px; font-weight: 700; }
.widget .side-effects {
  font-size: 13px; color: var(--fg-dim); margin-top: 10px; padding: 8px 10px;
  background: var(--bg-elev); border-radius: 8px; border-left: 3px solid var(--accent);
}
.widget .preview {
  height: 180px; border-radius: 10px; margin-top: 10px; position: relative;
  background: linear-gradient(135deg, #2a2438, #1c2230); overflow: hidden;
}

/* ---- Photo upload + analysis ---- */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; color: var(--fg-dim);
  background: var(--bg-elev);
}
.upload-zone.dragging { border-color: var(--accent); color: var(--accent); }
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
}
.photo-thumb {
  aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--bg-elev); border: 1px solid var(--border); position: relative;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .score {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.65); padding: 2px 6px; border-radius: 6px;
  font-size: 11px; font-weight: 700;
}
.photo-thumb .score.ok { color: var(--ok); }
.photo-thumb .score.warn { color: var(--warn); }
.photo-thumb .score.bad { color: var(--err); }

.analysis .row { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0; }
.analysis .pill {
  background: var(--bg-elev-2); padding: 3px 8px; border-radius: 99px;
  font-size: 11px; color: var(--fg-dim);
}
.analysis h4 { margin: 12px 0 4px 0; font-size: 13px; color: var(--fg-dim); }
.analysis ul { margin: 4px 0; padding-left: 18px; }
.score-big {
  font-size: 36px; font-weight: 800; text-align: center; margin: 4px 0;
}

/* ---- Gallery ---- */
.gallery-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
  margin-top: 8px;
}
.gallery-grid .g {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background: var(--bg-elev-2);
}
.gallery-grid .g img { width: 100%; height: 100%; object-fit: cover; }
.gallery-caption { font-size: 12px; color: var(--fg-dim); margin-top: 6px; }

/* ---- Login ---- */
.login-page {
  min-height: calc(100vh - 24px); display: flex; flex-direction: column;
  justify-content: center; align-items: center; gap: 18px; text-align: center;
}
.login-page .logo-big {
  width: 96px; height: 96px; border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  display: grid; place-items: center; font-size: 44px; color: #1c1410;
  box-shadow: var(--shadow);
}
.login-page h1 { margin: 0; font-size: 28px; }
.login-page p { margin: 0; color: var(--fg-dim); max-width: 280px; }
.login-page input {
  width: 280px; padding: 14px 16px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 10px; color: var(--fg);
}
.login-page .btn { width: 280px; }
.login-error { color: var(--err); font-size: 13px; min-height: 18px; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  z-index: 100; max-width: 88vw; font-size: 14px;
}

/* ---- Misc ---- */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--fg-faint); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty {
  text-align: center; padding: 40px 20px; color: var(--fg-faint);
}
.empty .big { font-size: 36px; margin-bottom: 8px; opacity: 0.6; }

.challenge-card { border-left: 3px solid var(--accent-3); }
.challenge-card h3::before { content: "🎯 "; }
.challenge-card .goal { color: var(--fg); margin: 6px 0; }
.challenge-card .rec { font-size: 13px; color: var(--fg-dim); }
.challenge-card ul.rubric { margin: 6px 0 0 0; padding-left: 18px; font-size: 13px; color: var(--fg-dim); }

.section-anchor { scroll-margin-top: 20px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* ============================================================
   v0.2 — refined UI: badges, progress, jump menu, lesson nav
   ============================================================ */

/* ---- Progress card (home) ---- */
.progress-card { padding: 14px 16px; }
.prog-top { display: flex; justify-content: space-between; align-items: center; }
.prog-main { font-size: 22px; font-weight: 700; }
.prog-main .meta { font-size: 12px; font-weight: 500; }
.prog-bar {
  height: 6px; background: var(--bg); border-radius: 3px;
  margin-top: 10px; overflow: hidden;
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-3));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ---- Lesson tiles (refined) ---- */
.lesson-tile {
  position: relative;
  padding-right: 32px; /* room for chevron */
}
.lesson-tile .chev {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 24px; color: var(--fg-faint);
}
.progress-pill.ip { background: rgba(255,157,58,0.15); color: var(--accent); }

/* ---- Lesson hero (refined) ---- */
.lesson-hero {
  display: flex; gap: 14px; align-items: center;
  margin: 4px 0 14px 0;
}
.lesson-hero .emo {
  width: 60px; height: 60px; border-radius: 16px;
  background: linear-gradient(135deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 30px;
  flex: 0 0 60px;
}
.lesson-hero .hero-body { flex: 1; min-width: 0; }
.lesson-hero h2 { margin: 0 0 2px 0; font-size: 22px; line-height: 1.2; }

.summary-card .meta-label {
  font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--fg-faint); margin-bottom: 4px;
}

/* ---- Jump menu ---- */
.jump-menu {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 14px;
  overflow: hidden;
}
.jump-menu summary {
  padding: 12px 16px; cursor: pointer; font-weight: 600;
  list-style: none; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
}
.jump-menu summary::-webkit-details-marker { display: none; }
.jump-menu summary::after { content: "▾"; color: var(--fg-faint); transition: transform 0.2s; }
.jump-menu[open] summary::after { transform: rotate(180deg); }
.jump-list {
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.jump-btn {
  appearance: none; background: transparent; border: 0; color: var(--fg);
  text-align: left; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.jump-btn:last-child { border-bottom: 0; }
.jump-btn:active { background: var(--bg-elev-2); }
.jump-num {
  flex: 0 0 24px; height: 24px; border-radius: 50%;
  background: var(--bg-elev-2); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: var(--fg-dim);
}
.jump-btn span:nth-child(2) { flex: 1; font-size: 14px; }
.jump-type {
  font-size: 9px; letter-spacing: 0.8px; padding: 2px 6px;
  border-radius: 99px; font-weight: 700;
  background: var(--bg-elev-2); color: var(--fg-dim);
}

/* ---- Section card heads (numbered with type badge) ---- */
.section-card { padding: 16px; margin-bottom: 14px; scroll-margin-top: 16px; }
.sec-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.sec-num {
  flex: 0 0 32px; height: 32px; border-radius: 50%;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--fg);
  position: relative;
}
.sec-num-of {
  display: none; /* keep number badge compact; total shown in hero */
}
.sec-type {
  font-size: 10px; letter-spacing: 1px; padding: 3px 8px;
  border-radius: 99px; font-weight: 700;
  background: var(--bg-elev-2); color: var(--fg-dim);
  text-transform: uppercase;
}
.sec-title {
  flex: 1 0 100%; margin: 0; font-size: 17px; font-weight: 700; line-height: 1.3;
  color: var(--fg);
}

/* Type colours */
.type-text     { background: rgba(76,201,255,0.14); color: var(--accent-2); }
.type-widget   { background: rgba(179,136,255,0.16); color: var(--accent-3); }
.type-tip      { background: rgba(255,157,58,0.16); color: var(--accent); }
.type-z50      { background: rgba(76,201,255,0.16); color: var(--accent-2); }
.type-quiz     { background: rgba(74,222,128,0.16); color: var(--ok); }
.type-gallery  { background: rgba(251,191,36,0.16); color: var(--warn); }
.type-challenge{ background: rgba(179,136,255,0.18); color: var(--accent-3); }

.section-card.tip-card { border-left: 3px solid var(--accent); }
.section-card.z50-card { border-left: 3px solid var(--accent-2); }
.section-card.widget-card { border-left: 3px solid var(--accent-3); }
.section-card.quiz-card { border-left: 3px solid var(--ok); }
.section-card.gallery-card { border-left: 3px solid var(--warn); }
.section-card.challenge-card { border-left: 3px solid var(--accent-3); }

/* Flash highlight when scrolled to via jump menu */
.section-card.flash {
  animation: flash 1.4s ease;
}
@keyframes flash {
  0%   { box-shadow: 0 0 0 0 rgba(255,157,58,0.6), var(--shadow); }
  30%  { box-shadow: 0 0 0 4px rgba(255,157,58,0.45), var(--shadow); }
  100% { box-shadow: 0 0 0 0 rgba(255,157,58,0), var(--shadow); }
}

/* Override old tip/z50/challenge head emojis (we now use type badges) */
.tip-card h3::before, .z50-card h3::before, .challenge-card h3::before { content: ""; }

/* ---- Lesson bottom (complete + nav) ---- */
.lesson-bottom { margin-top: 20px; }
.lesson-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 12px;
}
.nav-btn {
  display: block; padding: 12px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg); text-decoration: none;
  min-height: var(--tap);
}
.nav-btn.next { text-align: right; }
.nav-btn .nav-dir {
  font-size: 11px; color: var(--fg-faint); letter-spacing: 0.8px; text-transform: uppercase;
}
.nav-btn .nav-title {
  font-size: 13px; font-weight: 600; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- Smaller refinements ---- */
.markdown p { margin: 8px 0; line-height: 1.65; }
.markdown ul { line-height: 1.65; }
.section-title { margin: 22px 4px 10px; font-size: 11px; }

/* Photo thumbs slightly larger on phones */
@media (max-width: 480px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}

