/* =========================================================================
   Cabinhub News — live layer
   Loaded AFTER the design system's files (see index.html). Scoped entirely
   to the three surfaces live.js mounts, so it cannot reach the feed, the
   chrome or the operator page.

   Design rules inherited from css/cards.css, not re-decided here:
     - a story is text separated by a hairline: no card border, no shadow,
       no fill, no radius;
     - one accent, used for a rule or a kicker, never as a background wash;
     - hierarchy is carried by type size and space.

   Theme: no palette of its own. Every rule reads the design system's tokens
   through the alias block below, so light, explicit dark and OS dark arrive
   already resolved by css/tokens.css. An earlier draft carried its own dark
   map keyed on `:root[data-theme="dark"]`; that missed the OS-preference path
   (which sets no attribute) and painted light surfaces on a dark page.

   Motion: transform + opacity only, --dur-2, removed under
   prefers-reduced-motion. Nothing loops; nothing pulses.
   ========================================================================= */

.live-pill,
.live-breaking,
.live-latest {
  --bg: var(--paper, #F7F5F2);
  --fg: var(--ink, #1C1714);
  --fg-2: var(--ink-soft, #514942);
  --fg-3: var(--ink-faint, #6D6259);
  --line: var(--rule, #D6CBC2);
  --raised: var(--canvas, #FFFFFF);
  --mark: var(--accent, #BC3E0D);
  --focus-ring: var(--focus, #D64221);
  --live-ease: var(--ease, cubic-bezier(0.22, 0.68, 0.16, 1));
  --live-dur: var(--dur-2, 250ms);
}

/* ============================================================== the pill == */

/* Bottom centre, not top: the top of this page already carries the masthead,
   the navigation and a sticky control bar, and a pill pinned there covers
   something the reader may want. The bottom is empty at every width, is where
   a thumb rests on a phone, and is where the reader is looking when they
   finish a card. It is the one raised surface in this file, because it floats
   over content instead of sitting in the column. */
.live-pill {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.1rem);
  transform: translateX(-50%);
  z-index: 7;
  max-width: calc(100vw - 2rem);
  animation: live-rise-centred var(--live-dur) var(--live-ease) both;
}

.live-pill__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  /* The pill is a button a thumb presses, and it measured 100x36 on a coarse
     pointer (n3_tap t39, zh 768 feed — the row shows up only when new stories
     arrive during the measure, which is why earlier sweeps missed it). */
  min-height: var(--tap, 44px);
  padding: 0.35rem 0.95rem 0.35rem 0.8rem;
  border: 0;
  border-radius: var(--r-sm, 6px);
  background: var(--raised);
  color: var(--fg);
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  cursor: pointer;
  /* The design system draws a raised surface with a ring, not a shadow
     (css/chrome.css: `.locale-switch__btn[aria-pressed="true"]`). */
  box-shadow: 0 0 0 1px var(--line);
  transition: box-shadow var(--dur-1, 150ms) var(--live-ease), color var(--dur-1, 150ms) var(--live-ease);
}

.live-pill__dot {
  width: 5px;
  height: 5px;
  background: var(--mark);
  flex: none;
}

/* A long label on a narrow phone must not push the pill wider than the screen. */
.live-pill__text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (hover: hover) and (pointer: fine) {
  .live-pill__btn:hover { box-shadow: 0 0 0 1px var(--fg-3); }
}

.live-pill__btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

/* ========================================================== breaking == */

/* An alarm in this newsroom is a rule and a kicker, not a red box: the same
   restraint the rest of the page uses. The 3px rule is the only colour, so it
   still reads as urgent at a glance without shouting over the story. */
.live-breaking {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "kicker close"
    "title  close"
    "meta   close";
  align-items: start;
  gap: 0.15rem 1rem;
  margin: 0 0 clamp(1.1rem, 2.2vw, 1.8rem);
  padding: 0.15rem 0 0.25rem 1rem;
  color: var(--fg);
  border-left: 3px solid var(--mark);
  animation: live-rise var(--live-dur) var(--live-ease) both;
}

.live-breaking__kicker {
  grid-area: kicker;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--mark);
}

.live-breaking__title {
  grid-area: title;
  font-family: var(--font-display, Georgia, serif);
  font-size: var(--fs-sub, 1.25rem);
  line-height: 1.2;
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
  max-width: var(--measure-deck, 52ch);
}

.live-breaking__title:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .live-breaking__title:hover { color: var(--mark); }
}

.live-breaking__meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.2rem;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.live-breaking__dot { color: var(--line); }

.live-breaking__close {
  grid-area: close;
  appearance: none;
  border: 0;
  border-radius: var(--r-xs, 4px);
  background: none;
  color: var(--fg-3);
  font-family: var(--font-ui, sans-serif);
  font-size: 1.1rem;
  line-height: 1;
  width: var(--tap, 44px);
  height: var(--tap, 44px);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color var(--dur-1, 150ms) var(--live-ease), background-color var(--dur-1, 150ms) var(--live-ease);
}

@media (hover: hover) and (pointer: fine) {
  .live-breaking__close:hover { color: var(--fg); background: var(--bg); }
}

.live-breaking__close:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 0;
}

/* ============================================================== arrivals == */

/* A list, not a box: one hairline above, one below, and rows on hairlines.
   This is the same contract as the rail index, so an accepted arrival reads
   as part of the page instead of an overlay that happened to land in it. */
.live-latest {
  margin: 0 0 clamp(1.1rem, 2.2vw, 1.8rem);
  padding: 0.4rem 0 0;
  color: var(--fg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.live-latest__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--fg-3);
}

.live-latest__mark {
  width: 12px;
  height: 2px;
  background: var(--mark);
  flex: none;
}

.live-latest__label { color: var(--fg); }

.live-latest__rule {
  flex: 1;
  height: 1px;
  background: var(--line);
}

.live-latest__count { white-space: nowrap; }

.live-latest__rows {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.live-latest__row {
  border-bottom: 1px solid var(--line);
  opacity: 0;
  transform: translateY(4px);
}

.live-latest.is-in .live-latest__row {
  animation: live-row var(--live-dur) var(--live-ease) both;
  animation-delay: calc(var(--i, 1) * 40ms);
}

.live-latest__link {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  grid-template-areas:
    "time cat"
    "time title";
  align-items: baseline;
  gap: 0.1rem 1rem;
  padding: 0.6rem 0.15rem;
  color: inherit;
  text-decoration: none;
  transition: background-color var(--dur-1, 150ms) var(--live-ease);
}

.live-latest__link time {
  grid-area: time;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--mark);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live-latest__cat {
  grid-area: cat;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--fg-3);
}

.live-latest__title {
  grid-area: title;
  font-family: var(--font-display, Georgia, serif);
  font-size: var(--fs-body, 1.0625rem);
  line-height: 1.3;
  color: var(--fg);
}

@media (hover: hover) and (pointer: fine) {
  .live-latest__link:hover { background: var(--bg); }
  .live-latest__link:hover .live-latest__title { color: var(--mark); }
}

.live-latest__link:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
}

.live-latest__more {
  padding: 0.55rem 0.15rem 0.15rem;
  font-family: var(--font-ui, -apple-system, "Segoe UI", system-ui, sans-serif);
  font-size: var(--fs-micro, 0.75rem);
  color: var(--fg-3);
}

/* =============================================================== motion == */

@keyframes live-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes live-row {
  to { opacity: 1; transform: translateY(0); }
}

/* The pill keeps its horizontal centring through the animation, so it never
   jumps sideways when the keyframes end. */
@keyframes live-rise-centred {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .live-pill,
  .live-breaking,
  .live-latest__row,
  .live-latest.is-in .live-latest__row {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    transition-duration: 0.001ms !important;
  }
  .live-pill { transform: translateX(-50%); }
}

/* ============================================================ phones == */

@media (max-width: 759px) {
  .live-pill { bottom: calc(env(safe-area-inset-bottom, 0px) + 0.85rem); }

  .live-breaking { padding-left: 0.85rem; }
  .live-breaking__title { font-size: var(--fs-body, 1.0625rem); }

  /* The timestamp sits above the headline on a narrow column, where two
     columns would starve the headline. */
  .live-latest__link {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "time"
      "title";
    gap: 0.15rem;
  }
  .live-latest__cat { display: none; }
}

/* ============================================================== chinese == */

/* CJK needs no uppercase transform (it does nothing) and does need a wider
   tracking reset, or the mono meta line reads as Latin spacing. */
html[lang="zh-Hans"] .live-pill__btn,
html[lang="zh-Hans"] .live-breaking__kicker,
html[lang="zh-Hans"] .live-breaking__meta,
html[lang="zh-Hans"] .live-latest__head,
html[lang="zh-Hans"] .live-latest__link time,
html[lang="zh-Hans"] .live-latest__cat,
html[lang="zh-Hans"] .live-latest__more {
  text-transform: none;
  letter-spacing: 0.02em;
}

/* Standalone chronological edition and the reader's device library. */
.bulletin, .saved-edition { padding-bottom: clamp(3rem,8vw,7rem); }
.bulletin .intro, .saved-edition .intro { padding-bottom: 1rem; }
.bulletin__controls { display:flex; flex-wrap:wrap; gap:.7rem 1.5rem; align-items:center; justify-content:space-between; border-top:2px solid var(--ink); border-bottom:1px solid var(--rule); padding:.65rem 0; }
.bulletin__controls p,.saved-edition__state,.saved-edition__meta { margin:0; }
.bulletin__controls #connection,.saved-edition__state { color:var(--accent); font-weight:650; }
#received,.saved-edition__state,.saved-edition__meta { font-size:var(--fs-label); }
#received,.saved-edition__meta { color:var(--ink-soft); }
.bulletin__buttons { display:flex; gap:.5rem; flex-wrap:wrap; }
.bulletin__buttons #accept { color:var(--accent-ink); background:var(--accent); border-color:var(--accent); }
.bulletin__day { font:600 clamp(1.15rem,2vw,1.6rem)/1.3 var(--font-display); margin:1.7rem 0 .6rem; }
.bulletin__list,#saved-library { margin:0; padding:0; list-style:none; }
.bulletin__item { display:grid; grid-template-columns:minmax(5.25rem,8rem) minmax(0,1fr); border-block-start:1px solid var(--rule); }
.bulletin__item time { padding:.9rem .65rem .9rem 0; font-size:var(--fs-meta); font-variant-numeric:tabular-nums; }
.bulletin__item>div { border-inline-start:1px solid var(--accent); padding:.85rem clamp(.7rem,2vw,1.65rem) 1.1rem; }
.bulletin__item h3, .saved-edition__title { margin:0; font:600 clamp(1.14rem,2.4vw,2rem)/1.24 var(--font-display); }
.bulletin__item h3 a,.saved-edition__title { color:var(--ink); text-decoration:none; }
.bulletin__item h3 a:hover,.saved-edition__title[href]:hover { text-decoration:underline; text-underline-offset:.16em; }
.bulletin__item p { max-width:68ch; margin:.35rem 0; }
.bulletin__item small { color:var(--ink-faint); }
.saved-edition__row { display:flex; align-items:center; justify-content:space-between; gap:.8rem; padding:1.05rem 0; border-top:1px solid var(--rule); }
.saved-edition__row:first-child { border-top:2px solid var(--ink); }
.saved-edition__title { display:inline-flex; align-items:center; min-height:44px; }
.saved-edition__download { flex:none; }
@media (max-width:599px) {
  .bulletin__item { grid-template-columns:4.4rem minmax(0,1fr); }
  .bulletin__item time { font-size:var(--fs-label); }
  .saved-edition__row { align-items:start; flex-wrap:wrap; }
}

.saved-edition__download:disabled { color:var(--ink-faint); border-color:var(--rule); cursor:not-allowed; }
