/* ===== 3 Creator Themes ===== */
:root,
:root[data-theme="cinematic"] {
  --theme-name: "Cinematic Dark";
  --bg: #060b18;
  --bg-grad:
    radial-gradient(120% 90% at 78% 12%, rgba(91, 184, 245, 0.16), transparent 55%),
    radial-gradient(90% 80% at 12% 88%, rgba(255, 203, 45, 0.1), transparent 55%),
    radial-gradient(120% 120% at 50% 0%, #0d1c38 0%, #0a1426 38%, #060b18 78%);
  --gold: #ffcb2d;
  --gold2: #ffe08a;
  --cyan: #5bb8f5;
  --cyan2: #8fd0ff;
  --ink: #eaf0ff;
  --muted: rgba(234, 240, 255, 0.62);
  --faint: rgba(234, 240, 255, 0.45);
  --line: rgba(143, 208, 255, 0.14);
  --line-2: rgba(143, 208, 255, 0.28);
  --card: rgba(143, 208, 255, 0.045);
  --panel: rgba(8, 16, 34, 0.55);
  --shine: linear-gradient(100deg, #ffcb2d 10%, #ffe08a 45%, #8fd0ff 95%);
  --solid-bg: linear-gradient(180deg, #ffe08a, #ffcb2d);
  --solid-ink: #1a1305;
  --success: #43d17a;
  --accent-soft: rgba(91, 184, 245, 0.12);
  --hud-font: "Rajdhani", system-ui, sans-serif;
  --thai: "Kanit", system-ui, sans-serif;
  --radius: 1.15rem;
  --shadow: 0 20px 50px -30px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

:root[data-theme="editorial"] {
  --theme-name: "Editorial Luxury";
  --bg: #f5f0e4;
  --bg-grad:
    radial-gradient(1100px 620px at 82% -10%, rgba(169, 133, 47, 0.1), transparent 60%),
    radial-gradient(900px 560px at 6% 2%, rgba(47, 110, 168, 0.06), transparent 55%),
    linear-gradient(180deg, #faf6ec, #f1ebdc);
  --gold: #a9852f;
  --gold2: #8a6a1e;
  --cyan: #2f6ea8;
  --cyan2: #3f7fb8;
  --ink: #2c3446;
  --muted: #6b6555;
  --faint: #6f695b;
  --line: #e2d7c0;
  --line-2: #d8cbb0;
  --card: #fffdf7;
  --panel: rgba(255, 253, 247, 0.92);
  --shine: linear-gradient(100deg, #a9852f 6%, #c9a24a 42%, #2f6ea8 96%);
  --solid-bg: linear-gradient(180deg, #f6e6b8, #efd68d);
  --solid-ink: #3a2c08;
  --success: #2f7a4a;
  --accent-soft: rgba(169, 133, 47, 0.1);
  --shadow: 0 18px 40px -28px rgba(80, 60, 20, 0.35);
  color-scheme: light;
}

:root[data-theme="fresh"] {
  --theme-name: "Fresh Brand";
  --bg: #f7f9fc;
  --bg-grad:
    radial-gradient(900px 500px at 90% 0%, rgba(255, 122, 102, 0.14), transparent 55%),
    radial-gradient(800px 480px at 0% 20%, rgba(91, 184, 245, 0.14), transparent 50%),
    linear-gradient(180deg, #ffffff, #eef4fb 70%, #f7f9fc);
  --gold: #ff7a66;
  --gold2: #ffb4a8;
  --cyan: #2f9bff;
  --cyan2: #6cbcff;
  --ink: #1a2433;
  --muted: #5a6678;
  --faint: #7a8699;
  --line: #d9e3f0;
  --line-2: #c3d2e6;
  --card: rgba(255, 255, 255, 0.88);
  --panel: #ffffff;
  --shine: linear-gradient(100deg, #ff7a66 8%, #ffb347 45%, #2f9bff 95%);
  --solid-bg: linear-gradient(180deg, #ff9a8b, #ff7a66);
  --solid-ink: #2a0c08;
  --success: #1f9d62;
  --accent-soft: rgba(47, 155, 255, 0.1);
  --shadow: 0 16px 36px -24px rgba(40, 80, 140, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--thai);
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  line-height: 1.55;
}

.bg-glow {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
}

.topbar, main, .site-footer, .lesson-nav { position: relative; z-index: 1; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.mark {
  width: 2.35rem; height: 2.35rem; display: grid; place-items: center;
  border-radius: 0.7rem; font-family: var(--hud-font); font-weight: 700;
  color: var(--solid-ink); background: var(--solid-bg);
  box-shadow: 0 8px 24px -10px color-mix(in srgb, var(--gold) 55%, transparent);
  flex-shrink: 0;
}
.brand-title { font-family: var(--hud-font); font-weight: 700; letter-spacing: 0.1em; font-size: 0.92rem; }
.brand-sub { color: var(--muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }

.progress-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.32rem 0.65rem; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--panel);
  font-family: var(--hud-font); font-weight: 700; font-size: 0.85rem;
}
.progress-pill .dot {
  width: 0.45rem; height: 0.45rem; border-radius: 50%;
  background: var(--cyan); box-shadow: 0 0 10px var(--cyan);
}

.btn {
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  border-radius: 0.65rem; padding: 0.4rem 0.75rem; font-family: var(--thai);
  font-size: 0.86rem; cursor: pointer; transition: 0.15s ease;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); }
.btn.solid {
  border: none; background: var(--solid-bg); color: var(--solid-ink); font-weight: 600;
}
.btn.active {
  border-color: var(--gold); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 40%, transparent);
}

/* Theme switcher chips */
.theme-switch {
  display: flex; gap: 0.35rem; padding: 0.2rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
}
.theme-switch button {
  border: none; background: transparent; color: var(--muted);
  border-radius: 999px; padding: 0.35rem 0.65rem; font-family: var(--thai);
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.theme-switch button.active {
  background: var(--solid-bg); color: var(--solid-ink);
}

/* Layout */
main {
  width: min(1040px, calc(100% - 1.4rem));
  margin: 1rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.2rem 1.15rem 1.3rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.hero h1 {
  margin: 0.2rem 0 0.7rem;
  font-size: clamp(1.7rem, 4.8vw, 2.55rem);
  line-height: 1.15; font-weight: 700;
}
.shine {
  background: var(--shine);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.eyebrow {
  margin: 0; font-family: var(--hud-font); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--cyan); font-size: 0.8rem; font-weight: 700;
}
.lede, .lede-sm { color: var(--muted); margin: 0 0 0.9rem; }
.lede strong { color: var(--ink); }

/* Lesson nav */
.lesson-nav {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.lesson-nav a, .toc a {
  text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.32rem 0.7rem; font-size: 0.8rem; background: var(--panel);
}
.lesson-nav a:hover, .toc a:hover { border-color: var(--gold); color: var(--gold); }
.lesson-nav a.active {
  background: var(--solid-bg); color: var(--solid-ink); border-color: transparent;
}

/* Stats */
.hero-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.55rem; margin: 1rem 0;
}
.stat {
  border: 1px solid var(--line); border-radius: 0.85rem; padding: 0.65rem 0.5rem;
  text-align: center; background: var(--panel);
}
.stat-n {
  font-family: var(--hud-font); font-size: 1.45rem; font-weight: 700; color: var(--ink);
}
.stat-l { color: var(--muted); font-size: 0.76rem; }

h2 {
  margin: 0 0 0.9rem; font-size: 1.2rem;
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.num {
  font-family: var(--hud-font); font-weight: 700; color: var(--gold);
  letter-spacing: 0.06em; font-size: 0.92rem;
}
.lesson-tag {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--cyan); border: 1px solid var(--line);
}
.subh { margin: 1rem 0 0.5rem; font-size: 1rem; color: var(--cyan); }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }

.tile {
  border: 1px solid var(--line); border-radius: 0.95rem; padding: 0.85rem; background: var(--panel);
}
.tile h3 { margin: 0 0 0.35rem; font-size: 0.98rem; }
.tile p, .tile li { color: var(--muted); font-size: 0.9rem; }
.tile ul, .tile ol { margin: 0.35rem 0 0; padding-left: 1.05rem; }
.tile.pick {
  cursor: pointer; transition: 0.15s ease;
}
.tile.pick:hover, .tile.pick.selected {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 25%, transparent);
}

/* Theme gallery */
.theme-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
.theme-card {
  border: 1px solid var(--line); border-radius: 1rem; overflow: hidden;
  background: var(--panel); cursor: pointer; transition: 0.15s ease; text-align: left;
  padding: 0; font: inherit; color: inherit; width: 100%;
}
.theme-card:hover, .theme-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 35%, transparent);
}
.theme-card img {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
}
.theme-card .body { padding: 0.75rem 0.85rem 0.9rem; }
.theme-card .tag {
  display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em;
  padding: 0.12rem 0.45rem; border-radius: 999px; margin-bottom: 0.3rem;
  background: var(--solid-bg); color: var(--solid-ink);
}
.theme-card h3 { margin: 0 0 0.25rem; font-size: 0.98rem; }
.theme-card p { margin: 0; color: var(--muted); font-size: 0.84rem; }

.swatches { display: flex; gap: 0.35rem; margin-top: 0.55rem; }
.swatch {
  width: 1.15rem; height: 1.15rem; border-radius: 999px; border: 1px solid var(--line-2);
}

.callout {
  margin-top: 0.9rem; padding: 0.8rem 0.9rem; border-radius: 0.85rem;
  border: 1px solid var(--line-2); background: var(--accent-soft); font-size: 0.93rem;
}
.callout.warn { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.teach {
  border-left: 3px solid var(--gold);
  padding: 0.75rem 0.9rem;
  margin: 0.8rem 0 0;
  background: var(--panel);
  border-radius: 0 0.75rem 0.75rem 0;
  color: var(--muted);
  font-size: 0.92rem;
}
.teach strong { color: var(--ink); }

.table-wrap {
  overflow-x: auto; border-radius: 0.85rem; border: 1px solid var(--line);
}
table { width: 100%; border-collapse: collapse; min-width: 540px; font-size: 0.9rem; }
th, td {
  text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top;
}
th {
  font-family: var(--hud-font); letter-spacing: 0.05em; text-transform: uppercase;
  font-size: 0.75rem; color: var(--muted); background: var(--panel);
}
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 0.12rem 0.45rem; font-size: 0.7rem; border: 1px solid var(--line-2);
  font-family: var(--hud-font); font-weight: 700;
}
.badge.gold { color: var(--solid-ink); background: var(--solid-bg); border: none; }
.badge.cyan {
  color: #041018; background: linear-gradient(180deg, var(--cyan2), var(--cyan)); border: none;
}

.note { color: var(--faint); font-size: 0.84rem; margin: 0.65rem 0 0; }

.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.check-list label {
  display: flex; gap: 0.6rem; align-items: flex-start;
  padding: 0.5rem 0.65rem; border-radius: 0.7rem;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.check-list input {
  margin-top: 0.18rem; accent-color: var(--gold);
  width: 1.05rem; height: 1.05rem; flex-shrink: 0;
}
.check-list label:has(input:checked) {
  border-color: color-mix(in srgb, var(--success) 50%, var(--line));
  background: color-mix(in srgb, var(--success) 10%, transparent);
  text-decoration: line-through; color: var(--muted);
}

.rank-list { margin: 0; padding-left: 1.15rem; }
.rank-list li { margin: 0.32rem 0; color: var(--muted); }
.rank-list strong { color: var(--ink); }

.prompt-box {
  margin-top: 0.7rem; padding: 0.85rem 0.95rem; border-radius: 0.85rem;
  border: 1px dashed var(--line-2); background: var(--panel);
  font-size: 0.88rem; color: var(--muted); white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.45;
}
.copy-row { display: flex; gap: 0.5rem; margin-top: 0.5rem; align-items: center; }
.copy-hint { color: var(--success); font-size: 0.82rem; }

.field { display: grid; gap: 0.3rem; margin-top: 0.7rem; }
.field span { color: var(--muted); font-size: 0.86rem; }
.field input, .field select, .field textarea {
  width: 100%; border-radius: 0.75rem; border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--bg) 70%, #000);
  color: var(--ink); font-family: var(--thai); font-size: 0.94rem; padding: 0.65rem 0.75rem;
}
:root[data-theme="editorial"] .field input,
:root[data-theme="editorial"] .field select,
:root[data-theme="editorial"] .field textarea,
:root[data-theme="fresh"] .field input,
:root[data-theme="fresh"] .field select,
:root[data-theme="fresh"] .field textarea {
  background: #fff;
}
.field textarea { resize: vertical; min-height: 6.5rem; }

.row-actions { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.8rem; }
.save-hint { color: var(--success); font-size: 0.86rem; }

.day-grid { display: grid; gap: 0.55rem; }
.day-card {
  border: 1px solid var(--line); border-radius: 0.85rem; padding: 0.75rem 0.85rem; background: var(--panel);
}
.day-card h4 {
  margin: 0 0 0.3rem; font-size: 0.95rem; display: flex; gap: 0.45rem; align-items: center;
}
.day-card p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.site-footer {
  width: min(1040px, calc(100% - 1.4rem));
  margin: 0 auto 2rem;
  display: flex; justify-content: space-between; gap: 0.5rem;
  color: var(--faint); font-size: 0.78rem; font-family: var(--hud-font); letter-spacing: 0.05em;
}

@media (max-width: 860px) {
  .grid-3, .grid-2, .hero-stats, .theme-gallery { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: space-between; }
  .grid-3, .grid-2, .hero-stats, .theme-gallery { grid-template-columns: 1fr; }
  .theme-switch { width: 100%; justify-content: space-between; }
  main { width: min(1040px, calc(100% - 0.9rem)); }
}

/* ===== App Shell · Sidebar + Bottom Tabs + PWA ===== */
:root {
  --side-w: 272px;
  --mbar-h: 52px;
  --tabbar-h: 58px;
}

.app-mobilebar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  align-items: center;
  gap: 0.55rem;
  min-height: var(--mbar-h);
  padding: 0.4rem 0.7rem;
  padding-top: max(0.4rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.app-mobilebar .menu-btn {
  width: 2.6rem; height: 2.6rem; border-radius: 0.75rem;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  font-size: 1.15rem; cursor: pointer; flex-shrink: 0;
  touch-action: manipulation;
}
.app-mobilebar .mbar-title { flex: 1; min-width: 0; display: grid; line-height: 1.2; }
.app-mobilebar .mbar-title strong {
  font-family: var(--hud-font); letter-spacing: 0.06em; font-size: 0.92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-mobilebar .mbar-title span {
  color: var(--muted); font-size: 0.7rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-mobilebar .menu-install {
  padding: 0.4rem 0.7rem; font-size: 0.8rem;
  min-height: 2.4rem; touch-action: manipulation;
}

/* Bottom tab bar (mobile) */
.app-tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 80;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0.25rem 0.2rem calc(0.25rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
  gap: 0;
  box-shadow: 0 -8px 28px -18px rgba(0, 0, 0, 0.45);
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  text-decoration: none;
  color: var(--muted);
  border: none;
  background: transparent;
  font-family: var(--thai);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  border-radius: 0.65rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0.2rem 0.1rem;
}
.tab-item:active { background: var(--accent-soft); }
.tab-item.active {
  color: var(--gold);
}
.tab-item.active .tab-ico {
  transform: translateY(-1px);
}
.tab-ico { font-size: 1.15rem; line-height: 1; }
.tab-lbl {
  letter-spacing: 0.01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(var(--side-w), 88vw);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.85rem 0.7rem 1rem;
  padding-top: max(0.85rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 96%, #000 4%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.side-brand {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.35rem 0.4rem 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.35rem;
}
.side-brand > div { flex: 1; min-width: 0; }
.side-close {
  display: none;
  width: 2.2rem; height: 2.2rem; border-radius: 0.6rem;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 1rem; cursor: pointer; flex-shrink: 0;
  touch-action: manipulation;
}
.side-nav { display: grid; gap: 0.25rem; }
.side-link {
  display: flex; align-items: center; gap: 0.6rem;
  text-decoration: none; color: var(--ink);
  border: 1px solid transparent; border-radius: 0.75rem;
  padding: 0.55rem 0.55rem;
  min-height: 48px;
  transition: 0.12s ease;
  touch-action: manipulation;
}
.side-link:hover { border-color: var(--line); background: var(--panel); }
.side-link.active {
  border-color: color-mix(in srgb, var(--gold) 50%, var(--line));
  background: var(--accent-soft);
}
.side-link-soft { opacity: 0.92; }
.side-ico {
  width: 2rem; height: 2rem; border-radius: 0.55rem;
  display: grid; place-items: center; flex-shrink: 0;
  font-family: var(--hud-font); font-weight: 700; font-size: 0.72rem;
  letter-spacing: 0.02em;
  background: var(--panel); border: 1px solid var(--line); color: var(--cyan);
}
.side-link.active .side-ico {
  background: var(--solid-bg); color: var(--solid-ink); border-color: transparent;
}
.side-txt { display: grid; min-width: 0; line-height: 1.2; }
.side-label { font-size: 0.9rem; font-weight: 600; }
.side-sub { font-size: 0.72rem; color: var(--muted); }

.side-section { margin-top: 0.65rem; padding-top: 0.55rem; border-top: 1px solid var(--line); }
.side-section-title {
  font-family: var(--hud-font); font-size: 0.72rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--faint); padding: 0 0.4rem 0.4rem;
}
.side-lessons { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0 0.15rem; }
.side-lesson {
  text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.65rem; font-size: 0.76rem; background: var(--panel);
  min-height: 36px; display: inline-flex; align-items: center;
  touch-action: manipulation;
}
.side-lesson:hover { border-color: var(--gold); color: var(--gold); }

.side-quick {
  display: grid; gap: 0.4rem; margin-top: 0.55rem; padding: 0 0.15rem;
}
.side-quick .btn {
  text-align: center; text-decoration: none;
  min-height: 44px; display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}

.side-foot {
  margin-top: auto; padding-top: 0.75rem;
  display: grid; gap: 0.4rem;
  border-top: 1px solid var(--line);
}
.side-install, .side-theme-cycle {
  width: 100%; text-align: center;
  min-height: 44px; touch-action: manipulation;
}
.side-ext {
  text-align: center; font-size: 0.75rem; color: var(--muted); text-decoration: none;
  padding: 0.35rem;
}
.side-ext:hover { color: var(--cyan); }

.app-scrim {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Desktop: push content right of sidebar */
@media (min-width: 961px) {
  html.has-app-shell body.app-body {
    padding-left: var(--side-w);
  }
  .app-mobilebar,
  .app-tabbar { display: none !important; }
  .app-scrim { display: none !important; }
  .app-sidebar { transform: none !important; }
  .side-close { display: none !important; }
}

/* Mobile / tablet: drawer + bottom tabs */
@media (max-width: 960px) {
  .app-mobilebar { display: flex; }
  .app-tabbar { display: grid; }

  html.has-app-shell body.app-body {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 0.5rem);
  }

  .app-sidebar {
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 40px -20px rgba(0, 0, 0, 0.55);
    /* leave room above tab bar so close + last items usable */
    bottom: 0;
    z-index: 90;
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .app-tabbar { opacity: 0.35; pointer-events: none; }
  .side-close { display: grid; place-items: center; }

  /* Compact page topbar — mobilebar already shows title */
  html.has-app-shell .topbar {
    position: relative;
    top: 0;
    padding: 0.55rem 0.75rem;
  }
  html.has-app-shell .topbar .brand {
    display: none;
  }
  html.has-app-shell .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  html.has-app-shell main {
    width: min(1040px, calc(100% - 0.85rem));
    margin-top: 0.65rem;
    margin-bottom: 1rem;
  }
  html.has-app-shell .site-footer {
    width: min(1040px, calc(100% - 0.85rem));
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
  }

  /* Touch-friendlier cards / buttons */
  html.has-app-shell .btn {
    min-height: 40px;
    padding: 0.45rem 0.8rem;
    touch-action: manipulation;
  }
  html.has-app-shell .card {
    padding: 1rem 0.9rem 1.1rem;
    border-radius: 1rem;
  }
  html.has-app-shell .hero h1 {
    font-size: clamp(1.45rem, 6.5vw, 2rem);
  }
  html.has-app-shell .lesson-nav a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
  }

  /* Hub grids tighter on phone */
  html.has-app-shell .hub-grid {
    grid-template-columns: 1fr !important;
  }
  html.has-app-shell .thumb {
    aspect-ratio: 16/10;
  }
  html.has-app-shell .vid {
    max-height: 48vh;
  }

  /* Lightbox above tab bar */
  html.has-app-shell #lb {
    z-index: 120;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  }
}

@media (max-width: 560px) {
  html.has-app-shell .topbar {
    flex-direction: row;
    align-items: center;
  }
  html.has-app-shell .hero-stats {
    grid-template-columns: 1fr 1fr;
  }
}

/* standalone PWA */
@media (display-mode: standalone) {
  .app-mobilebar {
    padding-top: max(0.55rem, env(safe-area-inset-top));
  }
  .app-sidebar {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  .app-tabbar {
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  }
}
html.is-standalone body {
  /* subtle full-bleed feel when installed */
  overscroll-behavior-y: contain;
}
