:root, [data-theme="light"] {
  --bg: #F4F7FA; --card: #FFFFFF; --ink: #10222F; --muted: #5E7180; --line: #DDE5EC;
  --blue: #0B3C5D; --blue2: #1F78C8; --orange: #FF7A3D; --orange-soft: #FFE8DC;
  --bubble: #FFFFFF; --bubble-me: #DCEBFA; --lock: rgba(244,247,250,.86);
}
[data-theme="dark"] {
  --bg: #0A1620; --card: #12222F; --ink: #E7EEF4; --muted: #8AA0B0; --line: #1F3445;
  --blue: #5BA8E8; --blue2: #5BA8E8; --orange: #FF8A52; --orange-soft: #3A2418;
  --bubble: #162A39; --bubble-me: #1C3C58; --lock: rgba(10,22,32,.88);
}
/* Night mode: no blue light, red on black */
[data-theme="red"] {
  --bg: #000000; --card: #120303; --ink: #FF5A4A; --muted: #A8352B; --line: #2A0806;
  --blue: #FF5A4A; --blue2: #FF5A4A; --orange: #FF7A3D; --orange-soft: #2A0806;
  --bubble: #160404; --bubble-me: #2A0806; --lock: rgba(0,0,0,.9);
}
[data-theme="red"] img, [data-theme="red"] iframe, [data-theme="red"] .logo { filter: grayscale(1) sepia(1) saturate(6) hue-rotate(-50deg) brightness(.7); }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; }
a { color: var(--blue2); text-decoration: none; }
button { font: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); font-size: .9rem; }

.preview-bar { background: var(--orange); color: #fff; font-size: .8rem; padding: 6px 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; }
[data-theme="red"] .preview-bar { background: #2A0806; color: var(--ink); }
.preview-bar select { font-size: .8rem; border-radius: 6px; border: 0; padding: 2px 4px; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
[data-theme="dark"] .topbar { background: #071019; }
[data-theme="red"] .topbar { background: #0A0101; border-bottom: 1px solid var(--line); }
.brand { color: #fff; font-weight: 700; display: flex; gap: 8px; align-items: center; letter-spacing: .2px; }
[data-theme="red"] .brand { color: var(--ink); }
.logo { font-size: 1.4rem; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn { font-size: 1.1rem; }
.avatar-btn img, .av { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--line); display: block; }
.av.sm { width: 28px; height: 28px; } .av.lg { width: 88px; height: 88px; }

.view { max-width: 720px; margin: 0 auto; padding: 14px 14px 96px; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar a { flex: 1; text-align: center; font-size: .7rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; }
.tabbar a span { font-size: 1.25rem; }
.tabbar a.active { color: var(--orange); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.btn { display: inline-block; border: 0; border-radius: 999px; padding: 10px 18px; background: var(--orange); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--blue2); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { display: block; width: 100%; text-align: center; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--orange-soft); color: var(--orange); }
.pill.blue { background: rgba(31,120,200,.12); color: var(--blue2); }
.row { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.grow { flex: 1; }

/* Countdown */
.countdown { background: linear-gradient(135deg, var(--blue), var(--blue2)); color: #fff; border: 0; }
[data-theme="red"] .countdown { background: #160404; color: var(--ink); border: 1px solid var(--line); }
.countdown .timer { display: flex; gap: 10px; margin: 10px 0; }
.countdown .timer div { background: rgba(255,255,255,.14); border-radius: 12px; padding: 8px 0; flex: 1; text-align: center; }
.countdown .timer b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.countdown .timer small { font-size: .7rem; opacity: .85; }
.live-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #FF3B30; margin-right: 6px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Anna feed (Instagram style) */
.post .head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.post .media { margin: 10px -14px; aspect-ratio: 4/5; overflow: hidden; background: var(--line); }
.post .media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post .media.video { aspect-ratio: 16/9; }
.post .media iframe { width: 100%; height: 100%; border: 0; }
.post .pin { font-size: .75rem; color: var(--orange); font-weight: 600; }
.actions { display: flex; gap: 16px; align-items: center; margin-top: 6px; }
.shrimp { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--ink); font-size: .9rem; }
.shrimp.on { background: var(--orange-soft); border-color: var(--orange); color: var(--orange); font-weight: 600; }

/* Tribe chat */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 190px); }
.chat-tabs { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.chat-tabs button { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 14px; font-size: .85rem; white-space: nowrap; }
.chat-tabs button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
[data-theme="red"] .chat-tabs button.on { background: var(--line); color: var(--ink); }
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 6px 2px; }
.msg { display: flex; gap: 8px; align-items: flex-start; }
.msg .body { background: var(--bubble); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; padding: 8px 12px; max-width: 85%; }
.msg.me { flex-direction: row-reverse; }
.msg.me .body { background: var(--bubble-me); border-radius: 16px 4px 16px 16px; }
.msg .who { font-size: .78rem; font-weight: 700; }
.msg .who .t { font-weight: 400; color: var(--muted); margin-left: 6px; }
.msg .body img { width: 100%; border-radius: 10px; margin-top: 6px; display: block; }
.msg .meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.thread-link { font-size: .8rem; font-weight: 600; background: none; border: 0; color: var(--blue2); padding: 0; }
.composer { display: flex; gap: 8px; padding: 8px 0 0; border-top: 1px solid var(--line); background: var(--bg); }
.composer input { flex: 1; border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; background: var(--card); color: var(--ink); font: inherit; }
.composer .clip { background: none; border: 0; font-size: 1.2rem; }
.anna-badge { background: var(--orange); color: #fff; font-size: .62rem; border-radius: 4px; padding: 1px 5px; margin-left: 4px; vertical-align: 1px; }

/* Bottom sheet (threads etc) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg); border-radius: 20px 20px 0 0;
  max-height: 88dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.sheet header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet .sheet-body { overflow-y: auto; padding: 12px 16px; flex: 1; }
.sheet .composer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.reply { margin-left: 22px; border-left: 2px solid var(--line); padding-left: 10px; }

/* Classroom */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; color: var(--ink); position: relative; display: block; }
.tile .cover { aspect-ratio: 1/1; background-size: cover; background-position: center; }
.tile .info { padding: 10px; }
.tile .info b { display: block; font-size: .92rem; line-height: 1.25; }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--orange); }
.locked-overlay { position: absolute; inset: 0; background: var(--lock); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 10px; font-weight: 600; font-size: .85rem; }
.locked-overlay .l { font-size: 1.6rem; }

.course-layout { display: block; }
.page-tree { list-style: none; padding: 0; margin: 0 0 14px; }
.page-tree li a { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; color: var(--ink); font-size: .92rem; }
.page-tree li a.on { background: var(--orange-soft); color: var(--orange); font-weight: 600; }
.page-tree li.child a { padding-left: 30px; }
.page-tree .done { color: #2E9E5B; }
.doc { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.doc .yt { aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: #000; margin: 4px 0 16px; }
.doc .yt iframe { width: 100%; height: 100%; border: 0; }
.doc .callout { background: var(--orange-soft); border-radius: 12px; padding: 10px 14px; margin: 12px 0; display: flex; gap: 10px; }
.doc details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.doc details summary { font-weight: 600; cursor: pointer; }
.doc .todo { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.doc .todo input { width: 18px; height: 18px; accent-color: var(--orange); }

/* Notebook */
.notice { background: rgba(31,120,200,.1); border: 1px solid rgba(31,120,200,.3); border-radius: 12px; padding: 10px 12px; font-size: .88rem; margin-bottom: 14px; }
[data-theme="red"] .notice { background: var(--card); border-color: var(--line); }
.q { margin-bottom: 16px; }
.q label { font-weight: 600; display: block; margin-bottom: 6px; }
.q textarea, .q input, .field { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); color: var(--ink); font: inherit; }
.q textarea { min-height: 84px; resize: vertical; }
.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.steps span { flex: 1; height: 6px; border-radius: 999px; background: var(--line); }
.steps span.on { background: var(--orange); }
.upload { border: 2px dashed var(--line); border-radius: 14px; padding: 22px; text-align: center; color: var(--muted); }

/* Calendar */
.event { display: flex; gap: 12px; align-items: flex-start; position: relative; }
.event .date { background: var(--orange-soft); color: var(--orange); border-radius: 12px; padding: 6px 0; width: 54px; text-align: center; flex-shrink: 0; }
.event .date b { display: block; font-size: 1.3rem; line-height: 1.1; }
.event .date small { font-size: .7rem; text-transform: uppercase; font-weight: 700; }
.event.locked { opacity: .55; }

/* Profile */
.profile-head { text-align: center; }
.profile-head .av { margin: 0 auto 8px; }
.links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }

/* HQ */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .78rem; }
.stat .delta { font-size: .75rem; font-weight: 600; }
.up { color: #2E9E5B; } .down { color: #D9452B; }
table.t { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.hbar { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: .85rem; }
.hbar .lbl { width: 42%; }
.hbar .track { flex: 1; height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--blue2); }
.hbar .n { width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.theme-pick { display: flex; gap: 8px; }
.theme-pick button { flex: 1; border: 2px solid var(--line); border-radius: 12px; padding: 12px 6px; background: var(--card); color: var(--ink); }
.theme-pick button.on { border-color: var(--orange); }

.upsell { text-align: center; background: linear-gradient(160deg, var(--blue), var(--blue2)); color: #fff; border: 0; }
[data-theme="red"] .upsell { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.upsell .price { font-size: 2rem; font-weight: 800; }
.paid-only, .admin-only { }
body[data-tier="free"] .paid-only { display: none !important; }
body:not([data-tier="admin"]) .admin-only { display: none !important; }
html, body { overflow-x: hidden; }
.countdown .timer div, .msg .body, .grow { min-width: 0; }
.post .media .yt { margin: 0; border-radius: 0; height: 100%; aspect-ratio: auto; }
.msg .body { overflow-wrap: anywhere; }
