/* ============================================================================
   Daily AI News: the newspaper view
   The same page and the same stories, set as one sheet of newsprint on a warm
   desk: the title and today's date to its left, a calendar to its right.
   Everything here is scoped to body.is-newspaper except the view toggle and
   the hiding of the paper-only parts in the feed view.
   ========================================================================== */

/* The masthead face: Chomsky, a free newspaper masthead font in the style of
   the New York Times nameplate (SIL Open Font License; see
   static/fonts/chomsky/LICENSE.txt). */
@font-face {
  font-family: "Chomsky";
  src: url("../fonts/chomsky/Chomsky.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---------- the toggle, shown in both views ---------- */
.news-view-toggle {
  display: flex;
  width: max-content;
  margin: 0 auto clamp(28px, 4vw, 44px);
  padding: 3px;
  border-radius: 980px;
  background: rgba(118, 118, 128, 0.12);
}

.news-view-toggle button {
  padding: 7px 18px;
  border: 0;
  border-radius: 980px;
  background: transparent;
  color: #1d1d1f;
  font: 500 14px/1.2 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.news-view-toggle button[aria-pressed="true"] {
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
}

.news-view-toggle button:focus-visible {
  outline: 2px solid #0071e3;
  outline-offset: 2px;
}

/* ---------- the feed view keeps its own look ---------- */
.ai-news-page:not(.is-newspaper) .paper-rail,
.ai-news-page:not(.is-newspaper) .paper-masthead,
.ai-news-page:not(.is-newspaper) .paper-dateline,
.ai-news-page:not(.is-newspaper) .paper-footer,
.ai-news-page:not(.is-newspaper) .paper-editions,
.ai-news-page:not(.is-newspaper) .room-light,
.ai-news-page:not(.is-newspaper) .paper-canvas {
  display: none;
}

/* The feed keeps a day's Computer Science articles together after its
   other stories, without the newspaper's section front. */
.news-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.ai-news-page:not(.is-newspaper) .paper-section-head {
  display: none;
}

/* The sheet fades its top-right content under the rolled corner; none of
   that applies to the feed. */
.ai-news-page:not(.is-newspaper) .news-paper > * {
  -webkit-mask-image: none !important;
  mask-image: none !important;
}

/* ---------- the desk ---------- */
.is-newspaper {
  --paper-ink: #23231f;
  --paper-text: #3a3933;
  --paper-muted: #7c786b;
  --paper-rule: #d6d2c6;
  --paper-rule-strong: #383831;
  --paper-sheet: #fbfaf5;
  --paper-serif: Georgia, "Times New Roman", serif;
  --paper-sans: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  /* The desk: a soft pool of light over pale limed oak (painted by
     ai-news-paper/desk.js), with the prototype's linen weave beneath it until
     the oak arrives, or for good where WebGL is unavailable. */
  background-color: #eeeae2;
  background-image:
    radial-gradient(ellipse 120% 90% at 50% 18%, #f3efe7 0%, rgba(243, 239, 231, 0) 70%),
    var(--paper-desk-image, none),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='w' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9 .045' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .32 0 0 0 0 .27 .5 0 0 0 -.19'/%3E%3C/filter%3E%3Cfilter id='f' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.045 .9' numOctaves='2' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .32 0 0 0 0 .27 .5 0 0 0 -.2'/%3E%3C/filter%3E%3Cfilter id='g' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.6' numOctaves='1' seed='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .2 0 0 0 0 .18 0 0 0 0 .15 .32 0 0 0 -.1'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23w)'/%3E%3Crect width='240' height='240' filter='url(%23f)'/%3E%3Crect width='240' height='240' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: auto, var(--paper-desk-size, 2000px 1400px), 240px 240px;
  background-position: 0 0, center top, 0 0;
  background-repeat: no-repeat, repeat, repeat;
}

/* ---------- daylight through a window (ai-news-paper/light.js) ---------- */
.is-newspaper .room-light {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  display: block;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.is-newspaper .room-light.leaves {
  top: -3vh;
  left: -3vw;
  width: 106vw;
  height: 106vh;
  opacity: 0;
  transform-origin: var(--leaf-origin, 0 0);
  transition: opacity 1.2s ease;
}

.is-newspaper .room-light.leaves.ready {
  opacity: 1;
  animation: paper-leaf-sway 9s ease-in-out infinite alternate;
}

@keyframes paper-leaf-sway {
  from { transform: rotate(0deg) translate(0, 0); }
  to { transform: rotate(0.6deg) translate(-0.4vw, 0.3vh); }
}

.is-newspaper .news-shell {
  max-width: 1440px;
}

.is-newspaper .news-view-toggle {
  background: rgba(120, 108, 84, 0.12);
}

/* The page title stays for screen readers; the masthead is what you see. */
.is-newspaper .news-hero {
  margin: 0;
}

.is-newspaper .news-hero > :not(h1) {
  display: none;
}

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

.is-newspaper .news-signup {
  display: none;
}

.is-newspaper .news-desk {
  display: grid;
  grid-template-columns: minmax(140px, 190px) minmax(0, 880px) minmax(150px, 196px);
  justify-content: center;
  align-items: start;
  gap: clamp(28px, 3.2vw, 48px);
}

/* ---------- left: the title and today ---------- */
.is-newspaper .paper-rail {
  position: sticky;
  top: 100px;
  color: var(--paper-ink);
}

.is-newspaper .paper-rail p {
  margin: 0;
}

.is-newspaper .paper-rail-title {
  padding-bottom: 14px;
  border-bottom: 1px solid #b9b2a2;
  font: 700 11px/1.3 var(--paper-sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.is-newspaper .paper-rail-day {
  margin-top: 14px !important;
  font: 300 76px/0.95 var(--paper-sans);
  letter-spacing: -0.04em;
}

.is-newspaper .paper-rail-weekday {
  margin-top: 8px !important;
  font: italic 19px/1.3 var(--paper-serif);
}

.is-newspaper .paper-rail-month {
  margin-top: 4px !important;
  color: var(--paper-muted);
  font: 600 11px/1.3 var(--paper-sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------- right: the calendar ---------- */
.is-newspaper .paper-calendar {
  padding-top: 12px;
  border-top: 1px solid #b9b2a2;
  font-family: var(--paper-sans);
}

.paper-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.paper-cal-title {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.paper-cal-arrow {
  padding: 2px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--paper-ink);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.paper-cal-arrow:hover {
  background: rgba(120, 108, 84, 0.12);
}

.paper-cal-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  text-align: center;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.paper-cal-grid th {
  padding: 4px 0 6px;
  color: var(--paper-muted);
  font-weight: 500;
}

.paper-cal-grid td {
  height: 27px;
  padding: 0;
}

.paper-cal-day {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: rgba(35, 35, 31, 0.42);
  text-decoration: none;
}

/* A day with stories reads darker, carries a dot, and jumps to its page. */
.paper-cal-day.has-stories {
  color: var(--paper-ink);
  font-weight: 700;
}

.paper-cal-day.has-stories::after {
  content: "";
  position: absolute;
  bottom: 1px;
  left: 50%;
  width: 3px;
  height: 3px;
  margin-left: -1.5px;
  border-radius: 50%;
  background: #9b2c1f;
}

a.paper-cal-day:hover {
  background: rgba(120, 108, 84, 0.14);
}

.paper-cal-day.is-today {
  background: #294f62;
  color: #ffffff;
  font-weight: 700;
}

.paper-cal-day.is-today::after {
  background: #ffffff;
}

/* The edition on the page. */
.paper-cal-day.is-selected:not(.is-today) {
  box-shadow: inset 0 0 0 1.5px #294f62;
}

a.paper-cal-day:focus-visible,
.paper-cal-arrow:focus-visible {
  outline: 2px solid #294f62;
  outline-offset: 2px;
}

.paper-cal-legend {
  margin-top: 10px !important;
  color: var(--paper-muted);
  font-size: 11px;
}

/* ---------- the sheet ---------- */
.is-newspaper .news-paper {
  position: relative;
  isolation: isolate;
  padding: 30px clamp(26px, 4vw, 52px) 34px;
  border: 1px solid #fffefc;
  border-right-color: #dfddd6;
  border-bottom-color: #dedbd3;
  /* Fallback stock: cream, a little darker at the margins, with a fine
     tooth. The WebGL sheet replaces all of this when it is ready. */
  background:
    radial-gradient(ellipse 150px 160px at 100% 0%, rgba(173, 159, 131, 0.1), transparent 90%),
    radial-gradient(ellipse 190px 180px at 100% 100%, rgba(173, 159, 131, 0.08), transparent 90%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .36 0 0 0 0 .3 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E"),
    #fffefa;
  box-shadow:
    1px 2px 2px rgba(28, 53, 67, 0.2),
    5px 9px 15px rgba(28, 53, 67, 0.17),
    13px 21px 30px rgba(28, 53, 67, 0.1);
}

/* The WebGL sheet (ai-news-paper/sheet.js): it draws the paper, its shadow
   and the rolled corner on a canvas just larger than the sheet. */
.is-newspaper .news-paper.paper-webgl {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.is-newspaper .news-paper.paper-webgl::after {
  display: none;
}

.is-newspaper .paper-canvas {
  position: absolute;
  top: -64px;
  left: -64px;
  z-index: -1;
  display: block;
  width: calc(100% + 128px);
  max-width: none;
  height: calc(100% + 128px);
  pointer-events: none;
  visibility: hidden;
}

/* A turned corner, bottom right. */
.is-newspaper .news-paper::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, transparent 47%, #e4e1d8 50%, #fffef9 60%, #f6f4ed 80%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  filter: drop-shadow(-2px -2px 1px rgba(102, 94, 56, 0.13));
  pointer-events: none;
}

.is-newspaper .paper-masthead {
  padding: 20px 0 14px;
  border-top: 2px solid var(--paper-ink);
  text-align: center;
}

.is-newspaper .paper-title {
  margin: 0;
  color: var(--paper-ink);
  font-family: "Chomsky", "Old English Text MT", Georgia, serif;
  font-size: clamp(44px, 7vw, 90px);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.1;
}

.is-newspaper .paper-dateline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-bottom: 30px;
  padding: 10px 0 11px;
  border-top: 1px solid var(--paper-rule);
  border-bottom: 3px double var(--paper-rule-strong);
  color: #55544b;
  font: 12px/1.4 var(--paper-sans);
}

.is-newspaper .paper-section-jump {
  color: var(--paper-ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.is-newspaper .paper-section-jump[hidden] {
  display: none;
}

.is-newspaper .news-section--cs {
  scroll-margin-top: 96px;
}

.is-newspaper .paper-dateline strong {
  color: var(--paper-ink);
  font-weight: 700;
}

/* ---------- the stories, set as newsprint ---------- */
.is-newspaper .news-feed {
  gap: 40px;
}

.is-newspaper .news-day {
  gap: 20px;
  scroll-margin-top: 96px;
}

.is-newspaper .news-day:not(.is-edition),
.is-newspaper .news-day-head {
  display: none;
}

.is-newspaper .news-paper {
  scroll-margin-top: 150px;
}

.is-newspaper .news-day-head {
  position: static;
  margin: 0;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--paper-rule-strong);
  background: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: var(--paper-ink);
  font: 700 24px/1.15 var(--paper-serif);
  letter-spacing: -0.01em;
}

/* Two columns with a hairline between them. */
.is-newspaper .news-list {
  gap: 28px 52px;
  background: linear-gradient(var(--paper-rule), var(--paper-rule)) 50% 0 / 1px 100% no-repeat;
}

/* Stories read in rows, left to right. Each card spans three shared rows
   (headline, photo, text), so within a row the headlines, photos, summaries
   and links all line up, and every row is as tall as its tallest story. A
   rule under each row separates it from the next. */
.is-newspaper .news-card {
  grid-row: span 3;
  grid-template-rows: subgrid;
  row-gap: 0;
  height: auto;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--paper-rule);
}

/* ---------- Section B: Computer Science ----------
   A section front like a printed paper's: a heavy rule over a thin one, the
   section letter, its name set large, and how many articles it holds. */
.is-newspaper .news-section--cs {
  gap: 26px;
  margin-top: 46px;
}

.is-newspaper .paper-section-head {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 16px;
  padding: 18px 0 14px;
  border-top: 3px solid var(--paper-rule-strong);
  border-bottom: 1px solid var(--paper-rule-strong);
}

.is-newspaper .paper-section-head::before {
  content: "";
  position: absolute;
  top: 3px;
  right: 0;
  left: 0;
  height: 1px;
  background: var(--paper-rule-strong);
}

.is-newspaper .paper-section-letter,
.is-newspaper .paper-section-count {
  color: var(--paper-muted);
  font: 700 10.5px/1.3 var(--paper-sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.is-newspaper .paper-section-count {
  text-align: right;
}

.is-newspaper .paper-section-title {
  margin: 0;
  color: var(--paper-ink);
  font: 700 clamp(28px, 3.4vw, 40px)/1.05 var(--paper-serif);
  letter-spacing: -0.015em;
  text-align: center;
}

/* Inside the section every article is Computer Science; the tag on each
   card would only repeat the section front. */
.is-newspaper .news-section--cs .news-audience {
  display: none;
}

/* No rule under the last row: the edition's double rule follows. */
.is-newspaper .news-card:last-child,
.is-newspaper .news-card:nth-last-child(2):nth-child(odd) {
  padding-bottom: 0;
  border-bottom: 0;
}

.is-newspaper .news-card,
.is-newspaper .news-card--ds {
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.is-newspaper .news-card:hover,
.is-newspaper .news-card:focus-within {
  box-shadow: none;
  transform: none;
}

.is-newspaper .news-card-header {
  padding: 0 0 12px;
}

.is-newspaper .news-audience {
  margin-bottom: 7px;
  color: #9b2c1f;
  font: 700 9.5px/1.3 var(--paper-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.is-newspaper .news-title {
  color: var(--paper-ink);
  font: 700 21px/1.22 var(--paper-serif);
  letter-spacing: -0.01em;
}

.is-newspaper .news-card-top {
  margin-top: 8px;
  color: var(--paper-muted);
  font: 10px/1.4 var(--paper-sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.is-newspaper .news-card-media {
  background: #ece8dd;
}

.is-newspaper .news-card-fallback {
  color: #bdb6a5;
  font: 700 22px/1 var(--paper-serif);
  letter-spacing: 0.08em;
}

.is-newspaper .news-card-image {
  filter: saturate(0.82) contrast(1.03);
}

.is-newspaper .news-card:hover .news-card-image {
  transform: none;
}

.is-newspaper .news-card-content {
  gap: 12px;
  padding: 12px 0 0;
}

.is-newspaper .news-summary {
  color: var(--paper-text);
  font: 15px/1.58 var(--paper-serif);
}

.is-newspaper .news-link {
  color: var(--paper-ink);
  font: 600 11px/1.3 var(--paper-sans);
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.is-newspaper .news-link:focus-visible {
  outline-color: var(--paper-ink);
}

.is-newspaper .paper-editions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 34px;
  padding-top: 14px;
  border-top: 3px double var(--paper-rule-strong);
}

.paper-edition-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--paper-ink);
  font: italic 16px/1.3 var(--paper-serif);
  cursor: pointer;
}

.paper-edition-btn:hover:not(:disabled) {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.paper-edition-btn:disabled {
  color: rgba(35, 35, 31, 0.32);
  cursor: default;
}

.paper-edition-btn:focus-visible {
  outline: 2px solid #294f62;
  outline-offset: 3px;
}

.is-newspaper .paper-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--paper-rule);
  color: #827b6c;
  font: 10px/1.4 var(--paper-sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.is-newspaper .paper-footer a {
  color: var(--paper-ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

@media (prefers-reduced-motion: no-preference) {
  html:has(body.is-newspaper) {
    scroll-behavior: smooth;
  }
}

/* ---------- narrower screens: the sheet alone ---------- */
@media (max-width: 1100px) {
  .is-newspaper .news-desk {
    display: block;
  }

  .is-newspaper .paper-rail {
    display: none;
  }
}

@media (max-width: 760px) {
  .is-newspaper .news-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .is-newspaper .news-paper {
    padding: 20px 18px 26px;
  }

  .is-newspaper .paper-dateline {
    justify-content: center;
    text-align: center;
  }

  .is-newspaper .news-list {
    grid-template-columns: 1fr;
    gap: 26px;
    background: none;
  }

  .is-newspaper .paper-section-head {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "title title" "letter count";
    row-gap: 8px;
  }

  .is-newspaper .paper-section-title { grid-area: title; }
  .is-newspaper .paper-section-letter { grid-area: letter; }
  .is-newspaper .paper-section-count { grid-area: count; }

  /* One column: the last story is the last row. */
  .is-newspaper .news-card:nth-last-child(2):nth-child(odd) {
    padding-bottom: 28px;
    border-bottom: 1px solid var(--paper-rule);
  }

  .is-newspaper .news-day-head {
    top: auto;
    margin: 0;
    padding: 0 0 10px;
    font-size: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .news-view-toggle button {
    transition: none;
  }

  .is-newspaper .room-light.leaves.ready {
    animation: none;
  }
}
