:root {
  /* Instagram-like dark theme */
  --bg: #000000;
  --surface: #121212;
  --surface-2: #262626;
  --line: #262626;
  --text: #f5f5f5;
  --muted: #a8a8a8;
  --accent: #0095f6;
  --accent-ink: #ffffff;
  --heart: #ff3040;
  --chart-bar: #c97a1e; /* validated for dark surfaces (dataviz) */
  --good: #4ade80;
  --bad: #f87171;
  --tabbar-h: calc(50px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Devanagari", sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0; }

/* ---------- Shared ---------- */
.screen { position: fixed; inset: 0; background: var(--bg); }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; text-align: center; gap: 8px; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: calc(32px + env(safe-area-inset-top)) 16px 120px; }
.pad-x { padding: 0 16px 32px; }
.brand { font-weight: 800; letter-spacing: -0.02em; }
.brand.big { font-size: 40px; margin: 0; }
/* Script wordmark like Instagram's (Grand Hotel is the closest free match to its Billabong-style logo). */
.wordmark { font-family: "Grand Hotel", cursive; font-weight: 400; letter-spacing: 0; font-size: 30px; line-height: 1; }
.brand.big.wordmark { font-size: 56px; }
.logo { border-radius: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center-text { text-align: center; margin-top: 24px; }
.error { color: var(--bad); min-height: 1.4em; margin: 4px 0 0; font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row input { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 11px 18px; font-weight: 600; }
.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.big-icon { display: grid; place-items: center; margin-bottom: 4px; }
.big-icon .ic { width: 48px; height: 48px; stroke-width: 1.5; }
.ava { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 14px; font-weight: 700; color: #fff;
  background: linear-gradient(#000, #000) padding-box, linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5) border-box; border: 2px solid transparent; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 12px; padding: 11px 16px; }
.danger { background: none; border: 1px solid rgba(248,113,113,.4); color: var(--bad); border-radius: 12px; padding: 11px 16px; }
.wide { width: 100%; }
.link { background: none; border: 0; color: var(--accent); padding: 8px; }
.icon-btn { background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; }
.pill-btn { background: rgba(20,20,26,.7); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; backdrop-filter: blur(8px); }
.install-btn { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.chip-toggle { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 14px; }
.chip-toggle[aria-pressed=true] { background: var(--text); border-color: var(--text); color: #000; font-weight: 600; }
.step-label { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.sticky-cta { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }

.segmented { display: flex; gap: 4px; background: var(--surface); border-radius: 12px; padding: 4px; margin: 0 16px 12px; }
.segmented button { flex: 1; background: none; border: 0; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.segmented button[aria-selected=true], .segmented button[aria-checked=true] { background: var(--surface-2); color: var(--text); }
.segmented.small { margin: 0; padding: 3px; }
.segmented.small button { padding: 6px 10px; font-size: 14px; }

.page-head { display: flex; justify-content: space-between; align-items: center; padding: calc(16px + env(safe-area-inset-top)) 16px 12px; }
.page-head h1 { margin: 0; }
.section-title { margin: 28px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.list { list-style: none; padding: 0; margin: 8px 0 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list .grow { flex: 1; min-width: 0; }
.list .sub { font-size: 13px; color: var(--muted); }
.toggle { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line); position: relative; flex: none; padding: 0; border: 0; margin: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: left .15s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { left: 21px; }
.group-title { margin: 18px 0 2px; font-size: 13px; color: var(--muted); font-weight: 600; }
.avatar { width: 40px; height: 40px; border-radius: 10px; background: var(--surface) center/cover; flex: none; object-fit: cover; }
.small-btn { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; color: var(--muted); font-size: 14px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }


/* ---------- App shell ---------- */
#app { position: fixed; inset: 0; }
.view { position: absolute; inset: 0 0 var(--tabbar-h) 0; }
#tabbar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: #000; border-top: 1px solid var(--line); z-index: 5; }
#tabbar button { flex: 1; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; }
#tabbar .ic { width: 26px; height: 26px; stroke-width: 1.8; }
#tabbar button { color: var(--text); }
#tabbar button[aria-current=page] .ic { stroke-width: 2.8; }

/* ---------- Feed ---------- */
#player-wrap { position: absolute; inset: 0; opacity: 0; transition: opacity .2s; pointer-events: none; overflow: hidden; }
#player-wrap.on { opacity: 1; }
/* Oversize the player so YouTube's own title bar and counters fall outside the frame. */
#player-wrap iframe { position: absolute; left: 0; top: -72px; width: 100%; height: calc(100% + 144px); border: 0; }
#player-wrap.wide iframe { top: 50%; height: auto; aspect-ratio: 16 / 9; transform: translateY(-50%); }
.slide.wide .thumb { background-size: contain; }
#feed { position: absolute; inset: 0; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
#feed::-webkit-scrollbar { display: none; }

.slide { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden; }
.slide .thumb { position: absolute; inset: 0; background: #000 center / cover no-repeat; transition: opacity .2s; }
.slide.playing .thumb { opacity: 0; }
.slide .shade { position: absolute; inset: auto 0 0 0; height: 50%; background: linear-gradient(transparent, rgba(0,0,0,.8) 65%, #000); pointer-events: none; }
.slide .tap { position: absolute; inset: 0; }
.slide .meta { position: absolute; left: 12px; right: 72px; bottom: 16px; }
.ava.big { width: 77px; height: 77px; font-size: 30px; object-fit: cover; }
.profile-head { display: flex; gap: 16px; align-items: center; margin: 4px 0 14px; }
.profile-head h2 { margin: 0 0 2px; font-size: 18px; }
.follow-btn { display: flex; justify-content: center; align-items: center; gap: 6px; text-decoration: none; margin-bottom: 14px; }
.tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 0 -16px; }
.tile { position: relative; aspect-ratio: 9 / 16; border: 0; border-radius: 0 !important; padding: 6px; background: #121212 center / cover no-repeat; color: #fff;
  display: flex; align-items: flex-end; text-align: left; font-size: 11px; line-height: 1.25; overflow: hidden; }
.tile.post { aspect-ratio: 1; }
.tile .ic { position: absolute; top: 6px; right: 6px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.who[role="button"] { cursor: pointer; }
.mute-btn { position: absolute; top: calc(env(safe-area-inset-top) + 64px); right: 12px; z-index: 3; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; border: 0; }
.full-btn { display: none; align-items: center; gap: 6px; margin-top: 10px; padding: 8px 14px; border-radius: 8px; width: fit-content;
  background: rgba(255,255,255,.18); backdrop-filter: blur(8px); color: #fff; font-weight: 600; font-size: 14px; text-decoration: none; }
.slide.ended .full-btn { display: inline-flex; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.who strong { min-width: 0; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.who .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.who .sub { font-size: 12px; color: var(--muted); }
.chip { display: inline-block; flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 8px; border: 1px solid rgba(255,255,255,.35); color: #fff; }
.slide .meta h2 { font-size: 14px; font-weight: 400; line-height: 1.4; margin: 8px 0 4px; text-shadow: 0 1px 3px #000;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slide .by { font-size: 12px; color: #d6d6dc; text-shadow: 0 1px 3px #000; }

.rail { position: absolute; right: 6px; bottom: 16px; display: flex; flex-direction: column; gap: 14px; align-items: center; z-index: 2; }
.act { width: 52px; border: 0; background: none; color: #fff; padding: 2px 0; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.act .ic { width: 28px; height: 28px; stroke-width: 1.9; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); transition: transform .15s; }
.act:active .ic { transform: scale(.88); }
.act small { font-size: 12px; font-weight: 500; white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.act.up[aria-pressed=true] .ic { fill: var(--heart); stroke: var(--heart); animation: pop .3s; }
.act.down[aria-pressed=true] .ic, .act.save[aria-pressed=true] .ic { fill: #fff; }
.act.later[aria-pressed=true] .ic { stroke: var(--accent); }
@keyframes pop { 50% { transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { .act .ic { animation: none !important; transition: none; } }

/* Read cards */
.slide.read { background: var(--bg); }
.read .card { position: absolute; inset: calc(60px + env(safe-area-inset-top)) 68px 18px 12px; display: flex; flex-direction: column; justify-content: center; gap: 12px; overflow: hidden; }
.read .source { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.read .badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); }
.read .hero { width: 100%; max-height: 32%; object-fit: cover; border-radius: 4px; background: var(--surface); flex: none; }
.read h2 { font-size: 22px; line-height: 1.25; margin: 0; }
.read .body { color: #dcdce2; font-size: 16px; line-height: 1.55; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 9; }
.read .hook { color: var(--muted); font-size: 14px; margin: 0; }
.read .open { align-self: flex-start; margin-top: 6px; text-decoration: none; color: var(--text); display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 8px 14px; background: var(--surface-2); border: 0; font-weight: 600; font-size: 14px; }

.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; pointer-events: none; background: linear-gradient(rgba(0,0,0,.55), transparent); z-index: 3; }
.topbar > * { pointer-events: auto; }
.pill { position: absolute; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(20,20,26,.75); padding: 6px 14px; border-radius: 999px; font-size: 14px; pointer-events: none; z-index: 3; }

.slide.end { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; background: var(--bg); }


/* ---------- Library ---------- */
.lib-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.lib-item .open-item { display: flex; gap: 12px; align-items: center; flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; }
.lib-thumb { width: 56px; height: 72px; border-radius: 4px; background: var(--surface-2) center/cover; flex: none; display: grid; place-items: center; color: var(--muted); }
.lib-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thought { padding: 14px; background: var(--surface); border-radius: 14px; margin-bottom: 10px; }
.thought p { margin: 0 0 8px; white-space: pre-wrap; }
.thought .ref { font-size: 13px; color: var(--muted); background: none; border: 0; padding: 0; text-align: left; }

/* ---------- Insights ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border-radius: 14px; padding: 14px 12px; }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card-block { background: var(--surface); border-radius: 14px; padding: 16px; margin-top: 12px; }
.card-block h2 { font-size: 15px; margin-bottom: 12px; }
.days { display: flex; justify-content: space-between; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.dot.on { background: var(--chart-bar); border-color: var(--chart-bar); }
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--chart-bar); border-radius: 0 4px 4px 0; min-width: 4px; }
.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* ---------- Sheets ---------- */
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: #262626; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 88dvh; overflow-y: auto; }
.sheet.tall { height: 88dvh; }
.mic { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; }
.mic[aria-pressed=true] { background: var(--bad); border-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(248,113,113,.2); } }
@media (prefers-reduced-motion: reduce) { .mic[aria-pressed=true] { animation: none; } }
.share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.share-opt { display: block; text-align: center; padding: 14px; background: #363636; border: 0; border-radius: 12px; color: var(--text); text-decoration: none; font-weight: 600; }
#viewer-body iframe.wide { aspect-ratio: 16 / 9; }
#viewer-body iframe { width: 100%; aspect-ratio: 9 / 16; max-height: 70dvh; border: 0; border-radius: 14px; background: #000; display: block; margin: 0 auto; }
#viewer-body .full-text { white-space: pre-wrap; line-height: 1.6; color: #dcdce2; }
#summary { z-index: 30; }
.summary-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: min(340px, 100%); margin: 16px 0; }
#summary .primary, #summary .ghost { width: min(340px, 100%); }
#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 40; max-width: calc(100% - 32px); }

/* ---------- Instagram inbox ---------- */
.badge-host { position: relative; color: #fff; }
.badge-dot { position: absolute; top: 6px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--heart);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
#inbox { z-index: 15; }
#inbox .topbar { background: linear-gradient(rgba(0,0,0,.7), transparent); }
#inbox-feed { position: absolute; inset: 0; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
#inbox-feed::-webkit-scrollbar { display: none; }
.dm { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; }
.dm video, .dm img.media { width: 100%; height: 100%; object-fit: cover; background: #000; }
.dm iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.dm .sent-by { position: absolute; left: 12px; right: 12px; top: calc(60px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; z-index: 2;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px); padding: 8px 12px; border-radius: 12px; }
.dm .sent-by img, .dm .sent-by .ava { width: 32px; height: 32px; border-radius: 50%; flex: none; object-fit: cover; }
.dm .sent-by .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.dm .sent-by .sub { font-size: 12px; color: var(--muted); }
.dm .note { position: absolute; left: 12px; right: 72px; bottom: 18px; z-index: 2; font-size: 14px; text-shadow: 0 1px 3px #000;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.dm .fallback { padding: 24px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.ig-steps { margin: 8px 0 12px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.ig-steps li { margin-bottom: 6px; }
.ig-steps code { color: var(--text); word-break: break-all; }
