:root {
  --bg: #f6f8fc;
  --binder: #c4d8fb;      /* the soft blue around the page */
  --divider: #9ebffa;     /* closed divider tabs */
  --divider-text: #17428f;
  --bar: #e3edfe;         /* the light-blue bottom bar */
  --surface: #ffffff;
  --text: #1c2333;
  --muted: #5d6679;
  --accent: #2f6fed;
  --accent-soft: #e6eefe;
  --sun: #ffb020;
  --border: #dfe4ee;
  --error: #e5484d;
  --shadow: 0 2px 10px rgba(28, 35, 51, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--binder);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px 0;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--binder);
}
.brand {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--divider-text); font-weight: 800; font-size: 34px; line-height: 1.1; margin-bottom: 12px;
}
.brand img { width: 46px; height: 46px; }

/* Grade dividers: tabs sticking up like binder dividers. The open one is
   white and joins the white page of that grade's news below it. */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: end;
}
.tabs button {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 2px 6px;
  margin-top: 6px; /* closed tabs sit a little lower */
  background: var(--divider);
  color: var(--divider-text);
  border: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: inset 0 -6px 8px -6px rgba(0, 0, 0, 0.25);
  transition: background 0.15s, margin 0.15s, padding 0.15s;
}
@media (hover: hover) {
  .tabs button:not([aria-pressed="true"]):hover { background: #b3cdfb; }
}
.tabs button:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.tabs .g { font-size: 20px; font-weight: 800; line-height: 1.2; }
.tabs .ages { font-size: 12px; white-space: nowrap; opacity: 0.9; }
.tabs button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  margin-top: 0;
  padding-bottom: 12px;
  box-shadow: none;
}
.tabs button[aria-pressed="true"] .ages { color: var(--muted); opacity: 1; }

/* The divider's page: white, joined to the open tab above. */
.page {
  min-height: calc(100vh - 200px);
  /* Same width as the row of tabs above; room below for the bottom bar. */
  margin: 0 max(12px, (100% - 1200px) / 2) calc(96px + env(safe-area-inset-bottom));
  padding: 20px 16px 28px;
  box-shadow: 0 4px 16px rgba(23, 66, 143, 0.12);
  background: var(--surface);
  border-radius: 0 0 18px 18px;
}
.page h1 { font-size: 28px; line-height: 1.15; margin: 2px 0 14px; }
.kicker { margin: 0; color: var(--accent); font-weight: 800; font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; }
.kicker:empty { display: none; }
.back {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 700;
  padding: 4px 0;
  margin-bottom: 8px;
}

/* Previous news: one button per day */
.days { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.days:empty { display: none; }
.days button {
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  padding: 6px 14px;
  border-radius: 999px;
}
.days button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#previous-date { margin-bottom: 10px; }

/* Bottom bar: Today / Yesterday / Last week / More news */
.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 2px solid var(--divider);
}
.bottom-bar button {
  display: flex; flex-direction: column; align-items: center;
  min-width: 76px;
  padding: 4px 10px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--divider-text);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.bottom-bar .i { font-size: 20px; line-height: 1.2; }
.bottom-bar button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgba(23, 66, 143, 0.15); }

/* News list */
.stories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 14px;
  align-items: start;
}
.stories .note { grid-column: 1 / -1; }

/* News photos at the top of a story */
.pics { margin: -4px -6px 12px; display: grid; gap: 6px; }
.pics.n2 { grid-template-columns: 1fr 1fr; }
/* Pictures always show whole, never cropped. */
.pics img { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; border-radius: 12px; background: var(--border); display: block; }
.pics figcaption { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-top: -2px; }
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.card h2 { font-size: 20px; line-height: 1.3; margin: 0 0 8px; }
.card p { margin: 10px 0; }
.card ul { margin: 6px 0; padding-left: 20px; }
.card li { margin: 4px 0; }
.card.note { background: var(--accent-soft); border-color: transparent; }
.card .loading { padding: 0; }

.loading { color: var(--muted); font-style: italic; display: flex; align-items: center; gap: 10px; padding: 24px 4px; }
.dots span {
  display: inline-block; width: 8px; height: 8px; margin-right: 4px;
  border-radius: 50%; background: var(--sun);
  animation: bounce 1s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

/* Read-aloud buttons: stay just under the grade tabs while reading. */
.read-aloud {
  position: sticky;
  top: var(--top-h, 0px);
  z-index: 1;
  display: flex;
  gap: 8px;
  margin: 0 -16px 14px;
  padding: 8px 16px;
  background: var(--surface);
}
.listen {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  padding: 10px 18px;
  border-radius: 999px;
}
#stop-btn { background: var(--accent-soft); color: var(--accent); }

/* Words being read aloud: the sentence lightly, the word brightly. */
.w { border-radius: 4px; transition: background 0.1s; }
.w.reading { background: #fff4c7; }
.w.speaking { background: #ffd447; box-shadow: 0 0 0 2px #ffd447; }
.card .from { margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.card .from a { color: var(--accent); }
