/* =========================================================
   Social PWA Test — styles
   Mobile first. Desktop layout kicks in at 900px wide.
   ========================================================= */

/* ---------- 1. Colours (light + dark) ---------- */
:root {
  --bg: #f4f3f9;
  --surface: #ffffff;
  --text: #16151f;
  --muted: #6b6880;
  --line: #e6e4ef;
  --primary: #4f46e5;
  --primary-soft: #eceaff;
  --saffron: #ea6a0c;
  --saffron-soft: #fff1e6;
  --up: #e2552b;
  --shadow: 0 1px 2px rgba(20, 18, 40, 0.06), 0 6px 20px rgba(20, 18, 40, 0.06);

  --topbar-h: 56px;
  --tabbar-h: 58px;
  /* iPhone notch / home-bar space (0 on other devices) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0d14;
    --surface: #1a1924;
    --text: #f1f0f7;
    --muted: #a19eb5;
    --line: #2b2938;
    --primary: #8f8aff;
    --primary-soft: #26234d;
    --saffron: #ff9a4d;
    --saffron-soft: #3a2414;
    --up: #ff7a52;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* Dark mode: dark text on the light-purple buttons so they stay readable */
@media (prefers-color-scheme: dark) {
  .pill-btn:not(.ghost), .fab { color: #12111a; }
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden; /* the inner panels scroll, not the page */
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* ---------- 3. App frame (mobile) ---------- */
.app {
  height: 100vh;
  height: 100dvh; /* dvh = the real visible height on phones */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "offline" "views" "tabs";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) max(16px, var(--safe-right)) 0 max(16px, var(--safe-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--line); }
.icon-btn.small { width: 28px; height: 28px; font-size: 13px; }

.pill-btn {
  border: 0; border-radius: 999px;
  padding: 8px 16px;
  background: var(--primary); color: #fff;
  font-weight: 600; font-size: 14px;
}
.pill-btn.ghost { background: transparent; color: var(--muted); }
.pill-btn.wide { width: 100%; padding: 12px; margin-top: 8px; }

.offline-banner {
  grid-area: offline;
  padding: 8px 16px;
  background: #3b3a48; color: #fff;
  font-size: 13px; text-align: center;
}
/* Install button in the header */
.install-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px 7px 10px;
  font-size: 13px;
}

/* ---------- 4. Tabs: bottom bar on mobile ---------- */
.tabs {
  grid-area: tabs;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 2;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--primary); }

/* ---------- 5. Views (each one scrolls by itself) ---------- */
.views { grid-area: views; position: relative; min-height: 0; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sample-note {
  margin: 12px 16px 4px;
  font-size: 12px; color: var(--muted); text-align: center;
}

/* ---------- 6. Trusted: full-screen swipe cards (Inshorts-style) ---------- */
.view-trusted {
  scroll-snap-type: y mandatory;
}
.view-trusted .sample-note { display: none; } /* each card shows a SAMPLE tag instead */
/* "contents" makes each card a direct child of the scrolling view, so height: 100% = one screen */
.view-trusted .trusted-list { display: contents; }

.t-card {
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always; /* one card per swipe */
  display: flex; flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
}
.t-card-img {
  flex: 0 0 40%;
  min-height: 0;
  background: var(--line) center / cover no-repeat;
  position: relative;
}
.t-card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.t-tag {
  position: absolute; left: 16px; top: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92); color: #3a2a8a;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
}
.t-tag .sample { color: var(--saffron); }
.t-card-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 18px 20px 14px;
}
.t-card h3 {
  font-family: var(--serif);
  font-size: 23px; line-height: 1.25; font-weight: 700;
  margin: 0 0 10px; letter-spacing: -0.01em;
}
.t-card p {
  font-size: 16px; line-height: 1.55; color: var(--text); opacity: 0.88;
  margin: 0;
  /* fill the free space; if the text is too long for a small phone, fade it out at the bottom */
  flex: 1 1 auto; min-height: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
}
.t-meta {
  margin-top: auto;
  padding-top: 12px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--muted);
}
.t-source { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.t-source svg { color: var(--primary); }
.swipe-hint {
  margin-top: 6px;
  text-align: center; font-size: 12px; color: var(--muted);
  animation: nudge 1.8s ease-in-out infinite;
  pointer-events: none;
}
/* Short phones (e.g. iPhone SE): smaller picture and text so the story fits */
@media (max-height: 720px) {
  .t-card-img { flex-basis: 34%; }
  .t-card-body { padding: 14px 18px 10px; }
  .t-card h3 { font-size: 20px; margin-bottom: 8px; }
  .t-card p { font-size: 15px; line-height: 1.5; }
}
@keyframes nudge { 0%, 100% { transform: translateY(0); opacity: .6; } 50% { transform: translateY(-6px); opacity: 1; } }
.t-end {
  display: grid; place-content: center; text-align: center; gap: 8px;
  color: var(--muted);
}
.t-end strong { font-size: 18px; color: var(--text); }

/* ---------- 7. Community: Reddit-style feed ---------- */
.community-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.c-post {
  background: var(--surface);
  padding: 14px 16px 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.c-head { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  flex: 0 0 auto;
}
.c-head .who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.c-head .group { color: var(--text); font-weight: 700; }
.c-post h3 { font-size: 17px; line-height: 1.35; margin: 10px 0 6px; }
.c-post p { font-size: 15px; line-height: 1.5; margin: 0 0 10px; white-space: pre-wrap; }
.c-post img {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover;
  border-radius: 12px; display: block; margin-bottom: 10px;
  background: var(--line);
}
.c-actions { display: flex; gap: 4px; margin-left: -8px; }
.act {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 10px;
  border: 0; border-radius: 999px; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.act:active { background: var(--line); }
.act.voted { color: var(--up); }
.local-badge {
  font-size: 11px; font-weight: 700; color: var(--saffron);
  background: var(--saffron-soft); padding: 2px 8px; border-radius: 999px; margin-left: auto;
}

.fab {
  position: sticky; bottom: 16px;
  display: grid; place-items: center;
  width: 56px; height: 56px;
  margin: 0 16px 16px auto;
  border: 0; border-radius: 18px;
  background: var(--primary); color: #fff;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
}

/* ---------- 8. Side panel (desktop only) ---------- */
.side-panel { display: none; }
.status-list {
  display: grid; grid-template-columns: auto 1fr; gap: 8px 14px;
  margin: 0; font-size: 13px;
}
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }
.status-list .good { color: #16a34a; }
.status-list .warn { color: var(--saffron); }
.side-note { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.5; }

/* ---------- 9. Bottom sheets ---------- */
.sheet {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(10, 8, 20, 0.45); }
.sheet[open] { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.field {
  width: 100%;
  padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iPhone zooming in on focus */
  resize: vertical;
}
.field:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Install guide sheet */
.install-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.install-head img { border-radius: 14px; flex: 0 0 auto; }
.install-head h2 { margin: 0 0 2px; }
.install-head p { margin: 0; font-size: 14px; color: var(--muted); }
.install-steps {
  list-style: none; counter-reset: step;
  display: grid; gap: 14px;
  padding: 0; margin: 0 0 8px;
}
.install-steps li {
  counter-increment: step;
  display: flex; align-items: flex-start; gap: 12px;
  font-size: 15px; line-height: 1.5;
}
.install-steps li::before {
  content: counter(step);
  flex: 0 0 26px; height: 26px; margin-top: -1px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 700;
}
/* Looks like the button the user has to tap, e.g. [ ••• ] or [ Share ] */
.key {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 7px; margin: 0 1px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.key svg { color: var(--primary); }
.install-steps small { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.install-note { margin: 10px 0 0; font-size: 13px; line-height: 1.45; color: var(--muted); }

/* ---------- 10. Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
  background: #24232f; color: #fff;
  border-radius: 14px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 10; max-width: calc(100% - 32px);
}
.toast button { border: 0; background: #fff; color: #24232f; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 13px; }

/* =========================================================
   Desktop / tablet landscape (900px and wider)
   ========================================================= */
@media (min-width: 900px) {
  .app {
    grid-template-columns: 1fr 220px minmax(0, 620px) 300px 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "top top top top top"
      "offline offline offline offline offline"
      ". tabs views side .";
    column-gap: 24px;
  }
  .topbar { padding-left: max(24px, calc((100vw - 1212px) / 2)); padding-right: max(24px, calc((100vw - 1212px) / 2)); }

  /* Tabs become a left menu */
  .tabs {
    flex-direction: column; gap: 4px;
    height: auto; padding: 20px 0 0;
    background: transparent; border: 0;
  }
  .tab {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 14px; border-radius: 12px;
    font-size: 15px;
  }
  .tab:hover { background: var(--surface); }
  .tab[aria-current="page"] { background: var(--primary-soft); }

  .views { padding-top: 0; }
  .view { padding: 8px 4px 24px; scrollbar-width: thin; }
  .sample-note { text-align: left; margin: 12px 0; }

  /* Trusted: normal list of wide cards, no snapping */
  .view-trusted { scroll-snap-type: none; }
  .view-trusted .sample-note { display: block; }
  .view-trusted .trusted-list { display: flex; flex-direction: column; gap: 16px; }
  .t-card p { flex: 0 0 auto; -webkit-mask-image: none; mask-image: none; }
  .t-card {
    height: auto;
    flex-direction: row;
    border: 1px solid var(--line); border-radius: 16px;
    overflow: hidden; box-shadow: var(--shadow);
  }
  .t-card-img { flex: 0 0 230px; min-height: 200px; }
  .t-card h3 { font-size: 21px; }
  .t-card p { font-size: 15px; }
  .swipe-hint { display: none; }
  .t-end { padding: 32px; border-radius: 16px; }

  /* Community: rounded cards */
  .community-list { gap: 12px; }
  .c-post { border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
  .c-post img { max-height: 340px; }

  /* Right column */
  .side-panel {
    grid-area: side;
    display: block; align-self: start;
    margin-top: 20px; padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line); border-radius: 16px;
  }
  #infoBtn { display: none; }

  .sheet { margin: auto; border-radius: 20px; padding-bottom: 20px; }
  .toast { bottom: 24px; }
}
