/* The Morning Brief: looks and motion.
   Motion rules: only transform and opacity move; entrances use a strong ease-out;
   presses shrink to 0.97; everything has a gentler version for "reduce motion". */

:root {
  --paper: #f7f3ea;
  --card: #fffdf8;
  --ink: #1d1b16;
  --muted: #6b655a;
  --rule: #e4dccb;
  --accent: #8a2b1f;
  --star: #e8a317;
  --shadow: 0 1px 2px rgb(60 40 10 / 0.06), 0 4px 14px rgb(60 40 10 / 0.05);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121110;
    --card: #1c1a17;
    --ink: #ede7da;
    --muted: #a39b8a;
    --rule: #2f2b25;
    --accent: #e5917c;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  }
}

/* Category colours (lighter versions in dark mode) */
[data-cat="india"]    { --cat: #d9480f; }
[data-cat="world"]    { --cat: #1971c2; }
[data-cat="us"]       { --cat: #5f3dc4; }
[data-cat="business"] { --cat: #2b8a3e; }
[data-cat="tech"]     { --cat: #0c8599; }
[data-cat="science"]  { --cat: #9c36b5; }
[data-cat="fun"]      { --cat: #e67700; }
[data-cat="random"]   { --cat: #c2255c; }
[data-cat="all"]      { --cat: var(--ink); }
@media (prefers-color-scheme: dark) {
  [data-cat="india"]    { --cat: #ff8a50; }
  [data-cat="world"]    { --cat: #74c0fc; }
  [data-cat="us"]       { --cat: #b197fc; }
  [data-cat="business"] { --cat: #69db7c; }
  [data-cat="tech"]     { --cat: #66d9e8; }
  [data-cat="science"]  { --cat: #e599f7; }
  [data-cat="fun"]      { --cat: #ffc078; }
  [data-cat="random"]   { --cat: #faa2c1; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
body:has(dialog[open]) { overflow: hidden; }
button { font: inherit; color: inherit; }
img { display: block; }
img.broken { display: none; }

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
}
.top h1 { font: 700 clamp(1.35rem, 6vw, 2.1rem)/1.1 var(--serif); margin: 0; letter-spacing: 0.005em; }
.dateline { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--card);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.icon-btn:active { transform: scale(0.97); }
.icon-btn.loading svg { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.actions { display: flex; gap: 8px; flex: none; }
.saved-btn { position: relative; color: var(--muted); }
.saved-btn svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.saved-btn[aria-pressed="true"] { color: var(--star); border-color: var(--star); }
.saved-btn[aria-pressed="true"] svg { fill: currentColor; }
.saved-btn .count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--star);
  color: #1d1b16;
  font: 700 11px/19px var(--sans);
  text-align: center;
}
.saved-btn .count:empty { display: none; }

/* ---------- Day picker: each day's paper ---------- */

.days {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 16px 10px;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: none;
  min-height: 32px;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    background-color 150ms ease,
    color 150ms ease;
}
.day:active { transform: scale(0.97); }
.day[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

/* 📅 Pick a date: the real date box is invisible; the button opens the phone's calendar. */
.pick-wrap { position: relative; flex: none; }
.pick-wrap input { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* ---------- Search ---------- */

.search-row { max-width: 720px; margin: 0 auto; padding: 0 16px 8px; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
  transition: border-color 150ms ease;
}
.search:focus-within { border-color: var(--ink); }
.search svg { flex: none; color: var(--muted); }
.search input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font: 16px var(--sans); /* 16px stops phones zooming in when you tap it */
}
.search input::-webkit-search-cancel-button { display: none; }
.search .clear {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--rule);
  color: var(--ink);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.search .clear:active { transform: scale(0.97); }
mark { background: color-mix(in srgb, var(--star) 38%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.day-head { margin: 20px 0 2px; font: 600 12.5px var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* ---------- Category chips ---------- */

.chips {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 10px max(16px, calc((100% - 720px) / 2 + 16px));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--card);
  font-size: 14px;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    background-color 150ms ease,
    border-color 150ms ease;
}
.chip:active { transform: scale(0.97); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat); }
.chip .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] {
  border-color: var(--cat);
  background: color-mix(in srgb, var(--cat) 15%, var(--card));
  font-weight: 600;
}

/* ---------- Page content ---------- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 16px calc(110px + env(safe-area-inset-bottom));
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 26px 0 4px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--cat);
}
.section-head h2 { font: 700 1.3rem/1.2 var(--serif); margin: 0; }
.section-head .n { color: var(--muted); font-size: 13px; }

.show-all {
  display: block;
  width: 100%;
  margin: 6px 0 0;
  padding: 11px;
  border: 1px dashed var(--rule);
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.show-all:active { transform: scale(0.97); }

/* A story card. The whole card opens the story sheet. */
.card {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 10px 0;
  padding: 13px 13px 13px 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--cat);
}
.card:active { transform: scale(0.97); }
.card .text { flex: 1; min-width: 0; }
.card h3 { margin: 0 0 6px; font: 600 1.02rem/1.32 var(--serif); }
.open-btn {
  all: unset;
  cursor: pointer;
}
.open-btn::after { content: ""; position: absolute; inset: 0; border-radius: 14px; } /* whole card is the button */
.open-btn:focus-visible::after { outline: 2px solid var(--cat); outline-offset: 2px; }
.meta { font-size: 12.5px; color: var(--muted); }
.meta-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }

/* The star sits above the card's tap area, so tapping it saves instead of opening. */
.star {
  position: relative;
  z-index: 1;
  flex: none;
  width: 38px;
  height: 38px;
  margin: -9px -8px -9px 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    color 150ms ease;
}
.star:active { transform: scale(0.97); }
.star svg { width: 20px; height: 20px; fill: transparent; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; transition: fill 150ms ease; }
.star[aria-pressed="true"] { color: var(--star); }
.star[aria-pressed="true"] svg { fill: currentColor; }
#sheet-save[aria-pressed="true"] { color: var(--star); border-color: var(--star); }
.meta .tag { color: var(--cat); font-weight: 600; }
.badge { color: var(--accent); font-weight: 600; }
.thumb {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--rule);
}

/* Big stories: a row you swipe sideways */
.carousel-head { margin: 18px 0 8px; font: 700 1.3rem/1.2 var(--serif); }
.carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 2px 16px 10px;
}
.carousel::-webkit-scrollbar { display: none; }
.big {
  position: relative;
  flex: 0 0 82%;
  max-width: 330px;
  scroll-snap-align: start;
  scroll-margin-left: 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.big:active { transform: scale(0.97); }
.big .pic {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: linear-gradient(135deg, var(--cat), color-mix(in srgb, var(--cat) 35%, var(--paper)));
}
.big .body { padding: 10px 13px 13px; }
.big h3 { margin: 4px 0 6px; font: 600 1.05rem/1.3 var(--serif); }
.big .open-btn::after { border-radius: 16px; }

/* Random facts */
.potd {
  position: relative;
  margin: 12px 0;
  border-radius: 16px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.potd:active { transform: scale(0.97); }
.potd img { width: 100%; max-height: 300px; object-fit: cover; background: var(--rule); }
.potd .body { padding: 11px 14px 14px; }
.potd h3 { margin: 2px 0 4px; font: 600 1.05rem/1.3 var(--serif); }
.potd p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cat); }

.fact .year {
  flex: none;
  min-width: 58px;
  font: 700 1.35rem/1.1 var(--serif);
  color: var(--cat);
  font-variant-numeric: tabular-nums;
}
.fact h3 { font-weight: 400; font-size: 1rem; }

/* Messages */
.notice {
  margin: 18px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
}
.notice h2 { margin: 0 0 6px; font: 700 1.15rem/1.3 var(--serif); }
.notice p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.notice input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: 15px var(--sans);
}
.notice .btn { margin-top: 10px; }

.skeleton { height: 96px; margin: 10px 0; border-radius: 14px; background: var(--card); border: 1px solid var(--rule); }

.footer-note { margin: 28px 0 0; text-align: center; font-size: 12.5px; color: var(--muted); }
.app-link { margin: 14px 0 0; text-align: center; }

/* ---------- Entrance: cards rise in with a short stagger ---------- */
/* Only when the app opens or you change category, never while you scroll. */

.enter { animation: rise 300ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  font: 600 15px var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.ghost { background: none; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 6;
  min-height: 50px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: 600 15px var(--sans);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.22);
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.fab:active { transform: scale(0.97); }

/* "Fresh news is ready" pill and the toast slide in, and leave the way they came. */
.pill {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  z-index: 7;
  padding: 9px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: 600 14px var(--sans);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.2);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, -16px);
  pointer-events: none;
  transition: opacity 400ms ease, transform 400ms ease;
}
.pill.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 7;
  max-width: 420px;
  margin: 0 auto;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
  transition: opacity 400ms ease, transform 400ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- The story sheet (slides up from the bottom) ---------- */

dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 640px;
  max-height: 88dvh;
  padding: 0 0 env(safe-area-inset-bottom);
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--ink);
  overflow: auto;
  transform: translateY(100%);
  transition:
    transform 250ms var(--ease-drawer),
    overlay 250ms var(--ease-drawer) allow-discrete,
    display 250ms var(--ease-drawer) allow-discrete;
}
dialog.sheet[open] { transform: translateY(0); }
@starting-style {
  dialog.sheet[open] { transform: translateY(100%); }
}
dialog.sheet::backdrop {
  background-color: rgb(0 0 0 / 0);
  transition:
    background-color 250ms var(--ease-drawer),
    overlay 250ms var(--ease-drawer) allow-discrete,
    display 250ms var(--ease-drawer) allow-discrete;
}
dialog.sheet[open]::backdrop { background-color: rgb(0 0 0 / 0.45); }
@starting-style {
  dialog.sheet[open]::backdrop { background-color: rgb(0 0 0 / 0); }
}

.grab { width: 40px; height: 5px; margin: 10px auto 4px; border-radius: 3px; background: var(--rule); }
.sheet-body { padding: 6px 18px 4px; }
.sheet-body .hero { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin: 6px 0 12px; background: var(--rule); }
.sheet-body h2 { margin: 6px 0 10px; font: 700 1.35rem/1.28 var(--serif); }
.sheet-body .year-big { font: 700 2.6rem/1 var(--serif); color: var(--cat); margin: 8px 0 6px; }
.sheet-body p { margin: 0 0 10px; font-size: 15.5px; line-height: 1.55; }
.sheet-body .meta { margin-bottom: 4px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 18px 18px; }
.sheet-actions .primary { flex: 1 1 100%; }
.sheet-actions .btn:not(.primary) { flex: 1; }

/* ---------- Gentler motion when the phone asks for it ---------- */

@media (prefers-reduced-motion: reduce) {
  .enter { animation: fade 200ms ease both; animation-delay: 0ms; }
  @keyframes fade { from { opacity: 0; } }
  .icon-btn.loading svg { animation: none; opacity: 0.5; }
  .pill, .pill.show { transform: translate(-50%, 0); }
  .toast, .toast.show { transform: none; }
  dialog.sheet, dialog.sheet[open] { transform: none; }
  dialog.sheet {
    opacity: 0;
    transition: opacity 200ms ease, overlay 200ms allow-discrete, display 200ms allow-discrete;
  }
  dialog.sheet[open] { opacity: 1; }
  @starting-style {
    dialog.sheet[open] { opacity: 0; }
  }
}
