:root{
  color-scheme: light dark;

  /* Background */
  --bg: #0b0f19;

  /* Surfaces */
  --panel: rgba(17,24,39,0.72);
  --panel-solid: #111827;
  --card-bg: rgba(17,24,39,0.78);

  /* Text */
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.70);

  /* Lines */
  --border: rgba(255,255,255,0.14);
  --border-strong: rgba(255,255,255,0.22);

  /* Accents */
  --accent: #7c3aed;
  --accent-strong: #a78bfa;
  --accent-2: #22c55e;

  --shadow: 0 10px 25px rgba(0,0,0,0.35);
  --focus: rgba(167,139,250,0.92);
}

*{ box-sizing: border-box; }

html, body{ height: 100%; overflow-x: hidden; }

html{
  /* Fluid type scale: readable on mobile, restrained on desktop */
  font-size: clamp(15px, 0.35vw + 14px, 17px);
  text-size-adjust: 100%;
}

body{
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.55;
  color: var(--text);

  /* Use background-color + background-image. Add a large base gradient so the backdrop doesn't "cut" mid-scroll. */
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 20% -10%, rgba(124,58,237,0.46), transparent 60%),
    radial-gradient(1000px 600px at 90% 0%, rgba(34,197,94,0.18), transparent 55%),
    linear-gradient(180deg, rgba(0,0,0,0.00), rgba(0,0,0,0.35));
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

a{ color: inherit; text-decoration: none; }
a:hover{ text-decoration: underline; }

a:focus-visible,
button:focus-visible{
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.container{
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(14px, 2.2vw, 24px);
}

.appShell{
  display: grid;
  grid-template-columns: 1fr minmax(260px, 320px); /* main first, archive on the right */
  gap: clamp(12px, 1.6vw, 18px);
  align-items: start;
  min-width: 0;
}

.topBar{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.topBarRight{
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 2px;
  flex-wrap: wrap;
}

.cityLabel{
  font-size: 0.8rem;
  color: var(--muted);
}

.citySelect{
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 10px;
  height: 36px;
  padding: 0 10px;
  min-width: 160px;
}

.hamburgerButton{
  display: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  width: 40px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
}
.hamburgerButton:hover{ background: rgba(255,255,255,0.07); }

.hamburgerIcon{
  display: inline-block;
  width: 18px;
  height: 12px;
  position: relative;
}
.hamburgerIcon::before,
.hamburgerIcon::after{
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.9;
}
.hamburgerIcon::before{ top: 0; box-shadow: 0 5px 0 currentColor, 0 10px 0 currentColor; }

.metaSmall{ font-size: 0.875rem; }

.brandTitle{
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo{
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.brand h1{
  font-size: clamp(1.1rem, 0.65vw + 1rem, 1.35rem);
  letter-spacing: 0.2px;
  margin: 0;
}
.brand .sub{
  margin: 3px 0 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  max-width: 62ch;
}

.panel{
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  min-width: 0;
}

/* Slight inner stroke for better separation against the gradient */
.panel::before{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}

.sidebar{
  position: sticky;
  top: 16px;
  padding: 14px;
  grid-column: 2;
  grid-row: 1;
}

.drawerBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  display: grid;
  justify-items: end;
  padding: 14px;
}

.drawer{
  width: min(420px, 92vw);
  max-height: calc(100vh - 28px);
  overflow: hidden;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.drawerHeader{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 2px 10px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.drawerTitle{
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--muted);
}

.drawerClose{
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  width: 36px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
  font-size: 22px;
}

.drawer .dayList{
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.sidebarHeader{
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sidebarHeader h2{
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.dayList{
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding-right: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.dayButton{
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.dayButton:hover{ border-color: var(--border); background: rgba(255,255,255,0.06); }
.dayButton:active{ transform: translateY(0.5px); }
.dayButton[aria-current="true"]{
  border-color: rgba(167,139,250,0.70);
  background: linear-gradient(90deg, rgba(124,58,237,0.30), rgba(124,58,237,0.14));
}

.pill{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.statusDot{
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.15);
}

.main{
  padding: 14px;
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}

.digestHeader{
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 4px 2px 12px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.digestHeaderCompact{
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.digestHeader h2{
  margin: 0;
  font-size: clamp(1.05rem, 0.5vw + 0.95rem, 1.25rem);
}

.muted{ color: var(--muted); }

.card{
  position: relative;
  border: 1px solid var(--border-strong);
  background: var(--card-bg);
  border-radius: 16px;
  padding: 14px;
  margin: 12px 0;
  box-shadow: 0 6px 18px rgba(0,0,0,0.24);
}

/* Clearer separation between stories */
.card + .card{
  margin-top: 14px;
}

.storyList{
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.storyCard{
  margin: 0;
  border-color: var(--border-strong);
  background: var(--card-bg);
}
.storyCard::before{
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent-strong), rgba(124,58,237,0));
  opacity: 0.9;
}

.linkDomain{ font-weight: 600; }

.sourcesLine{
  font-size: 13px;
  line-height: 1.35;
}

.storyMeta{
  display: block;
  font-size: 13px;
  line-height: 1.35;
}

.metaSep{
  opacity: 0.6;
}

.homeDigestStack{
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.homeDigestSection .storyList{
  gap: 12px;
}

.card::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.22);
}

.card h3{
  margin: 0 0 8px 0;
  font-size: clamp(1rem, 0.3vw + 0.95rem, 1.1rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* Typography defaults inside digest */
.main p{ margin: 0 0 10px 0; overflow-wrap: anywhere; }
.main p:last-child{ margin-bottom: 0; }

.badge{
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  margin-right: 10px;
  border: 1px solid var(--border);
  color: rgba(255,255,255,0.90);
  background: rgba(255,255,255,0.04);
  vertical-align: middle;
}

.links{
  margin: 8px 0 0 0;
  padding-left: 18px;
}
.links a{ color: rgba(255,255,255,0.88); word-break: break-word; }

/* Inline sources line */
.linkDomain{ font-weight: 600; }

.skeleton{
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.10), rgba(255,255,255,0.04));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer{
  0%{ background-position: 0% 0; }
  100%{ background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce){
  .skeleton{ animation: none; }
  .dayList{ scroll-behavior: auto; }
}

@media (prefers-color-scheme: light){
  :root{
    --bg: #f6f7fb;

    --panel: rgba(255,255,255,0.80);
    --panel-solid: #ffffff;
    --card-bg: rgba(255,255,255,0.92);

    --text: rgba(17,24,39,0.92);
    --muted: rgba(17,24,39,0.64);

    --border: rgba(17,24,39,0.12);
    --border-strong: rgba(17,24,39,0.18);

    --accent: #6d28d9;
    --accent-strong: #7c3aed;
    --accent-2: #16a34a;

    --shadow: 0 10px 25px rgba(17,24,39,0.12);
    --focus: rgba(109,40,217,0.8);
  }

  body{
    background-image:
      radial-gradient(1200px 600px at 20% -10%, rgba(124,58,237,0.18), transparent 62%),
      radial-gradient(1000px 600px at 90% 0%, rgba(34,197,94,0.10), transparent 58%),
      linear-gradient(180deg, rgba(255,255,255,0.00), rgba(17,24,39,0.06));
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
  }

  .panel::before{ box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55); }
  .card{ box-shadow: 0 8px 22px rgba(17,24,39,0.10); }
  .card::after{ box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55); }
  .badge{ color: rgba(17,24,39,0.84); background: rgba(17,24,39,0.03); }
  .links a{ color: rgba(17,24,39,0.80); }
  .dayButton{ background: rgba(17,24,39,0.03); }
  .dayButton:hover{ background: rgba(17,24,39,0.05); }
  .dayButton[aria-current="true"]{ background: linear-gradient(90deg, rgba(124,58,237,0.16), rgba(124,58,237,0.08)); }
}

@media (max-width: 900px){
  .appShell{ grid-template-columns: 1fr; }
  .sidebar{ display: none; }
  .hamburgerButton{ display: inline-flex; align-items: center; justify-content: center; }

  .cityLabel{ display: none; }
  .citySelect{ min-width: min(62vw, 220px); }

  /* iOS/Safari can get janky with fixed backgrounds while scrolling. */
  body{ background-attachment: scroll; }

  .topBar{ flex-direction: column; align-items: stretch; }
  .topBarRight{ justify-content: space-between; }

  .panel{ border-radius: 14px; }
  .card{ border-radius: 14px; }
}

@media (max-width: 520px){
  .sidebar{ padding: 12px; }
  .main{ padding: 12px; }
  .brandTitle{ gap: 8px; }
  .logo{ width: 26px; height: 26px; }
}

/* ===== Story Modal ===== */
.storyModalBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease-out;
}

.storyModal {
  position: relative;
  background: var(--panel-solid, #1a1a2e);
  border-radius: 16px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.2s ease-out;
}

.storyModalContent {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(85vh - 3rem);
}

.storyModalClose {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 10;
}

.storyModalClose:hover {
  background: rgba(255, 255, 255, 0.2);
}

.storyModalLoading,
.storyModalError {
  min-height: 200px;
}

.contextButton:hover {
  text-decoration: underline;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 520px) {
  .storyModal {
    max-height: 90vh;
    border-radius: 12px;
  }
  .storyModalContent {
    padding: 1rem;
    max-height: calc(90vh - 2.5rem);
  }
}
