/* ── Viralah (VRL) — byte-size Malaysian news ───────────────── */

:root {
  --bg: #0b0d12;
  --surface: #131722;
  --surface-2: #1b2130;
  --cream: #fbf5dd;          /* VRL logo background */
  --text: #fbf5dd;
  --text-dim: #a3a091;
  --line: rgba(251, 245, 221, .12);
  --accent: #ee3c30;         /* VRL logo red */

  --c-general: #4aa8ff;
  --c-politics: #ffb648;
  --c-food: #ff6b8a;
  --c-travel: #45d9a4;
  --c-business: #c9b16b;
  --c-tech: #8f7dff;
  --c-sports: #3fd0c9;
  --c-showbiz: #ff8ad4;

  --app-h: 100dvh;
  --topbar-h: 106px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(.22, .61, .36, 1);
}

@supports not (height: 100dvh) {
  :root { --app-h: 100vh; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, a { font: inherit; }
[hidden] { display: none !important; }

/* ── Brand ──────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -.02em;
}

/* The logo lockup: red VRL on the cream card it lives on in the wild. */
.brand__mark {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  padding: 4px 8px 5px;
  border-radius: 7px;
  background: var(--cream);
  color: var(--accent);
  font-size: 15px;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -.045em;
  line-height: 1;
}

.brand__mark i { color: #000; font-style: italic; }

.brand__name { font-size: 17px; }

.brand--lg .brand__mark {
  font-size: 30px;
  padding: 8px 14px 10px;
  border-radius: 12px;
}

.brand--lg .brand__name { font-size: 22px; }

/* ── Top bar ────────────────────────────────────────────────── */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  padding: calc(10px + var(--safe-t)) 16px 8px;
  background: linear-gradient(180deg, rgba(11, 13, 18, .96) 55%, rgba(11, 13, 18, 0));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.topbar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.counter {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  letter-spacing: .02em;
}

.iconbtn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  cursor: pointer;
  transition: background .18s var(--ease), transform .18s var(--ease);
}

.iconbtn:hover { background: rgba(255, 255, 255, .16); }
.iconbtn:active { transform: scale(.92); }
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn--ghost { background: rgba(255, 255, 255, .06); border: 1px solid var(--line); }

/* ── Topic chips ────────────────────────────────────────────── */

/* Eight topics plus "For you" need about 900px in a row — more than double a
   phone's width — and the scrollbar is hidden, so anything past the third chip
   was unreachable and invisible. Wrapping shows every topic at once. The
   topbar is a fixed overlay (--topbar-h is not used for layout), so the extra
   row costs no space in the card beneath it. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding-bottom: 2px;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  /* Tightened from 7px/14px/13.5px so nine chips wrap to two rows rather than
     three — the topbar is an overlay, and a third row starts covering the
     headline of the card underneath. */
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all .18s var(--ease);
}

.chip:hover { color: var(--text); border-color: rgba(255, 255, 255, .24); }

.chip[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: #0b0d12;
}

/* ── Feed & snapping ────────────────────────────────────────── */

.feed {
  height: var(--app-h);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  outline: none;
}

.feed::-webkit-scrollbar { display: none; }

@media (prefers-reduced-motion: reduce) {
  .feed { scroll-behavior: auto; }
}

/* ── Story card ─────────────────────────────────────────────── */

.card {
  position: relative;
  height: var(--app-h);
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  background: var(--bg);
}

.card__media {
  position: absolute;
  inset: 0 0 auto;
  height: 54%;
  background: linear-gradient(150deg, var(--surface-2), var(--surface));
}

.card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .45s var(--ease);
}

.card__img.is-loaded { opacity: 1; }

/* Video fills more of the card than a still does — it's the point of the post. */
.card--video .card__media { height: 66%; }

/* Never fade video in on `loadeddata`: with preload="metadata" that event may
   not fire until playback starts, which left the card fully transparent. */
.card__video {
  background: #000;
  opacity: 1;
}

/* Shown only when the browser refuses to autoplay (iOS Low Power Mode). */
.card__play {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  border: 0;
  background: rgba(11, 13, 18, .35);
  color: var(--cream);
  cursor: pointer;
}

.card--needs-tap .card__play { display: grid; }

.card__play span {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding-left: 5px;
  border-radius: 50%;
  background: var(--accent);
  font-size: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

.card__tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Two classes, so this wins over the plain .tag rule defined further down. */
.tag.tag--original {
  color: var(--cream);
  background: var(--accent);
  border-color: var(--accent);
}

.card__scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(11, 13, 18, .72) 0%, rgba(11, 13, 18, .18) 32%, rgba(11, 13, 18, .82) 78%, var(--bg) 100%);
}

.card__body {
  position: relative;
  z-index: 2;
  padding: 0 22px calc(30px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* body sits below the image band */
  margin-top: auto;
  min-height: 52%;
  justify-content: flex-end;
}

.tag {
  align-self: flex-start;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--cat, var(--accent));
  background: color-mix(in srgb, var(--cat, var(--accent)) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--cat, var(--accent)) 38%, transparent);
}

.card__headline {
  margin: 0;
  font-size: clamp(24px, 6.4vw, 31px);
  line-height: 1.16;
  letter-spacing: -.025em;
  font-weight: 800;
  text-wrap: balance;
}

.card__summary {
  margin: 0;
  font-size: clamp(15.5px, 4.1vw, 17.5px);
  line-height: 1.6;
  color: #e6e0cc;
}

.card__meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
}

.card__source { font-weight: 600; color: #c9c3ad; }

.card__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform .18s var(--ease), background .18s var(--ease), opacity .18s var(--ease);
}

.btn:active { transform: scale(.97); }

.btn--read {
  flex: 1;
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--line);
  color: var(--text);
  backdrop-filter: blur(8px);
}

.btn--read:hover { background: rgba(255, 255, 255, .18); }

.btn--primary {
  width: 100%;
  padding: 16px 20px;
  background: var(--text);
  color: #0b0d12;
  font-size: 16px;
}

.btn--primary:disabled { opacity: .35; cursor: not-allowed; }

/* ── End card ───────────────────────────────────────────────── */

.card--end {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  background: radial-gradient(120% 80% at 50% 30%, #1a2030 0%, var(--bg) 70%);
}

.card--end .end__tick {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  margin: 0 auto 20px;
  background: color-mix(in srgb, var(--c-travel) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-travel) 45%, transparent);
  color: var(--c-travel);
  font-size: 27px;
}

.card--end h2 {
  margin: 0 0 8px;
  font-size: 25px;
  letter-spacing: -.02em;
}

.card--end p {
  margin: 0 0 22px;
  color: var(--text-dim);
  max-width: 32ch;
}

.card--end .btn { background: rgba(255, 255, 255, .1); border: 1px solid var(--line); color: var(--text); }

/* ── Empty state ────────────────────────────────────────────── */

.empty {
  height: var(--app-h);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-dim);
}

.empty h2 { color: var(--text); margin: 0; font-size: 22px; }

/* ── Swipe hint ─────────────────────────────────────────────── */

.hint {
  position: fixed;
  left: 50%;
  /* floats low over the image band, clear of the headline and buttons */
  top: calc((100dvh - var(--app-h)) / 2 + var(--app-h) * 0.44);
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(20, 24, 34, .82);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  font-size: 12.5px;
  color: var(--text-dim);
  animation: floaty 2.2s var(--ease) infinite;
  pointer-events: none;
}

.hint__arrow {
  width: 8px;
  height: 8px;
  border-left: 2px solid var(--accent);
  border-top: 2px solid var(--accent);
  transform: rotate(45deg);
  display: block;
}

@keyframes floaty {
  0%, 100% { transform: translate(-50%, 0); opacity: .9; }
  50% { transform: translate(-50%, -6px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
}

/* ── Onboarding ─────────────────────────────────────────────── */

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: radial-gradient(130% 90% at 50% 0%, #1c2233 0%, var(--bg) 62%);
  display: flex;
  justify-content: center;
  padding: 28px 22px calc(28px + var(--safe-b));
  overflow-y: auto;
  overflow-x: hidden;
}

.onboarding__inner {
  width: 100%;
  min-width: 0;
  max-width: 420px;
  /* Centres like align-items would, but stays scrollable to the very top when
     the eight topic tiles make this taller than a short phone screen. */
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.onboarding__tagline {
  margin: 12px 0 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--accent);
}

.onboarding__title {
  margin: 6px 0 0;
  font-size: clamp(30px, 8.6vw, 40px);
  line-height: 1.1;
  letter-spacing: -.035em;
  font-weight: 800;
}

.onboarding__sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 15.5px;
}

.picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0 4px;
}

.niche {
  position: relative;
  text-align: left;
  padding: 15px 14px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  cursor: pointer;
  transition: all .18s var(--ease);
}

.niche:hover { border-color: rgba(255, 255, 255, .3); }

.niche[aria-pressed="true"] {
  border-color: var(--cat);
  background: color-mix(in srgb, var(--cat) 15%, transparent);
}

.niche__emoji { font-size: 21px; display: block; margin-bottom: 5px; }
.niche__label { font-weight: 700; font-size: 15px; display: block; }
.niche__desc { font-size: 12px; color: var(--text-dim); }

.niche__check {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cat);
  color: #0b0d12;
  font-size: 12px;
  font-weight: 900;
  opacity: 0;
  transform: scale(.6);
  transition: all .18s var(--ease);
}

.niche[aria-pressed="true"] .niche__check { opacity: 1; transform: scale(1); }

.onboarding__fine {
  margin: 2px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: #7d7a6d;
  text-align: center;
}

/* ── Desktop: present it as a phone ─────────────────────────── */

@media (min-width: 760px) and (min-height: 620px) {
  :root { --app-h: min(880px, 92dvh); }

  body {
    background:
      radial-gradient(60% 50% at 50% 0%, #171d2b 0%, #07080c 70%);
    display: block;
  }

  .feed,
  .topbar {
    width: 420px;
    left: 50%;
    transform: translateX(-50%);
  }

  .feed {
    position: relative;
    margin: calc((100dvh - var(--app-h)) / 2) 0;
    border-radius: 30px;
    box-shadow: 0 40px 90px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .07);
  }

  .topbar {
    top: calc((100dvh - var(--app-h)) / 2);
    border-radius: 30px 30px 0 0;
    padding-top: 16px;
  }

  .card { border-radius: 30px; }
}

/* ── Community ──────────────────────────────────────────────────
   Hidden entirely when there is no API behind the app; see state.social. */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.card__social {
  display: flex;
  gap: 18px;
  align-items: center;
  margin: 2px 0 -2px;
}

.social {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color .18s var(--ease), transform .18s var(--ease);
}

.social svg { width: 21px; height: 21px; }
.social:hover { color: var(--text); }
.social:active { transform: scale(.92); }

.social.is-on { color: var(--accent); }
.social.is-on svg { fill: var(--accent); stroke: var(--accent); }

/* ── Sheets ─────────────────────────────────────────────────── */

body.sheet-open { overflow: hidden; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  opacity: 0;
  transition: opacity .2s var(--ease);
}

.sheet.is-open .sheet__backdrop { opacity: 1; }

.sheet__panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding-bottom: var(--safe-b);
  transform: translateY(100%);
  transition: transform .24s var(--ease);
}

.sheet.is-open .sheet__panel { transform: translateY(0); }
.sheet__panel--short { max-height: none; }

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}

.sheet__title { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -.01em; }

.sheet__close {
  background: none;
  border: 0;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}

.sheet__context {
  margin: 0;
  padding: 10px 18px;
  font-size: 12.5px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  /* One line only: the sheet is for the conversation, not a second copy of
     the card the reader just swiped to. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet__body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 18px 12px;
  flex: 1;
}

.sheet__body--pad { padding: 16px 18px 20px; }
.sheet__empty { color: var(--text-dim); font-size: 13.5px; padding: 18px 0; margin: 0; }

/* ── Comments ───────────────────────────────────────────────── */

.comment { padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: 0; }

.comment__head { display: flex; align-items: baseline; gap: 8px; }
.comment__who { font-size: 13.5px; font-weight: 700; }
.comment__when { font-size: 11.5px; color: var(--text-dim); }

.comment__body {
  margin: 5px 0 0;
  font-size: 14.5px;
  line-height: 1.5;
  /* Reader-supplied, so a pasted URL must not stretch the sheet. */
  overflow-wrap: anywhere;
}

.comment__tools { display: flex; gap: 14px; margin-top: 7px; }

.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.linkbtn:hover { color: var(--text); }

/* ── Composer ───────────────────────────────────────────────── */

.composer { border-top: 1px solid var(--line); padding: 12px 18px 14px; }

.composer textarea,
#authForm input {
  width: 100%;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 10px 12px;
  /* 16px keeps iOS Safari from zooming the page when the field is focused. */
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
}

.composer textarea:focus,
#authForm input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.composer__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
}

.composer__count { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.btn--send {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.btn--send:disabled { opacity: .55; cursor: default; }

.composer__note,
.auth__note {
  margin: 9px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.composer__note.is-error,
.auth__note.is-error { color: var(--accent); }

.auth__blurb { margin: 0 0 14px; font-size: 14px; line-height: 1.55; color: var(--text-dim); }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm .btn--send { align-self: flex-start; }

@media (prefers-reduced-motion: reduce) {
  .sheet__panel, .sheet__backdrop, .social { transition: none; }
}

/* ── YouTube cards ──────────────────────────────────────────────
   The publisher's player, embedded and linked back to — there is no media
   file in the feed to host, and re-hosting would not be ours to do. */

/* Give the embed the same taller band as our own video posts. */
.card--yt .card__media { height: 62%; }

.card__embed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  z-index: 4;
  background: #000;
}

/* The facade's play button is always shown on a YouTube card — unlike our own
   videos, where it only appears if autoplay was refused. */
.card__play--yt { display: grid; }
.card--yt.is-playing .card__play--yt { display: none; }
.card--yt.is-playing .card__ytbadge { display: none; }

.card__ytbadge {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: 12px;
  z-index: 3;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(11, 13, 18, .72);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
