:root {
  --paper: #f5efe3;
  --paper-light: #fbf8f1;
  --paper-deep: #e8dec9;
  --paper-outer: #ece3d1;
  --ink: #141210;
  --ink-soft: #2e2923;
  --ink-muted: #64594c;
  --rule: #211c17;
  --rule-soft: rgba(24, 20, 16, 0.14);
  --rule-mid: rgba(24, 20, 16, 0.28);
  --crimson: #8b1e1a;
  --brass: #916927;
  --emerald: #266349;
  --frame-bg: #e5d9c0;
  --radius-xs: 3px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.22, 1.15, 0.36, 1);
  --dur-fast: 160ms;
  --dur-med: 240ms;
  --font-masthead: "Playfair Display SC", "Playfair Display", Georgia, serif;
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-condensed: "Oswald", "Arial Narrow", Impact, sans-serif;
  --font-body: "PT Serif", Georgia, "Times New Roman", serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

button, a, [role="button"], summary, label.toggle-line {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  min-height: 100svh;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: clip;
}

body.is-lightbox-open,
body.is-modal-open {
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  background: var(--paper-outer);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.58;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.svg-ico {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: -0.18em;
  flex-shrink: 0;
}

.svg-ico--lg {
  width: 20px;
  height: 20px;
}

.svg-ico--moon {
  width: 16px;
  height: 16px;
}

/* Weather ambient overlay (GPU transform::before so scrolling never repaints) */
.weather-fx {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.weather-fx::before {
  content: "";
  position: absolute;
  inset: -140px 0;
  will-change: transform;
}

body:not(.is-paper-view) .weather-fx {
  opacity: 0 !important;
}

.weather-fx.fx-rain {
  opacity: 0.18;
}

.weather-fx.fx-rain::before {
  background-image: repeating-linear-gradient(
    -75deg,
    transparent 0 18px,
    rgba(110, 100, 86, 0.22) 18px 19px
  );
  animation: fx-fall 0.85s linear infinite;
}

.weather-fx.fx-snow {
  opacity: 0.13;
}

.weather-fx.fx-snow::before {
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff 60%, transparent),
    radial-gradient(2px 2px at 80px 90px, #fff 60%, transparent),
    radial-gradient(1.5px 1.5px at 140px 50px, #fff 60%, transparent);
  background-size: 160px 140px;
  animation: fx-drift 12s linear infinite;
}

.weather-fx.fx-fog {
  opacity: 0.16;
}

.weather-fx.fx-fog::before {
  background: linear-gradient(180deg, rgba(220, 214, 200, 0.36), transparent 45%, rgba(220, 214, 200, 0.16));
}

.weather-fx.fx-storm {
  opacity: 0.22;
}

.weather-fx.fx-storm::before {
  background-image: repeating-linear-gradient(
    -72deg,
    transparent 0 14px,
    rgba(110, 100, 86, 0.28) 14px 15px
  );
  animation: fx-fall 0.55s linear infinite;
}

@keyframes fx-fall {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-24px, 48px, 0); }
}

@keyframes fx-drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, 140px, 0); }
}

@keyframes dp-shimmer {
  from { transform: translate3d(-100%, 0, 0); }
  to { transform: translate3d(100%, 0, 0); }
}

@keyframes dp-view-in {
  from { opacity: 0; transform: translate3d(0, 8px, 0); }
  to { opacity: 1; transform: none; }
}

@keyframes dp-card-in {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

@keyframes dp-reveal {
  from { opacity: 0; transform: translate3d(0, -5px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

@keyframes dp-modal-in {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(0.97); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes dp-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dp-toast-in {
  from { opacity: 0; transform: translate3d(-50%, 14px, 0) scale(0.97); }
  to { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1); }
}

@keyframes dp-pop-in {
  0% { opacity: 0; transform: scale(0.86); }
  65% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes dp-highlight-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

.is-view-entering {
  animation: dp-view-in var(--dur-med) var(--ease-out-expo);
}

@media (prefers-reduced-motion: reduce) {
  .weather-fx::before,
  .skel-bar::after,
  .skel-media::after,
  .skel-row::after,
  .is-view-entering,
  .story-card-anim,
  .ribbon-indicator,
  .media-fade,
  .widget-drawer,
  .search-drawer,
  .sync-callout,
  .status-msg,
  .feed-empty-box,
  .dp-modal-backdrop,
  .dp-modal-card,
  .lightbox-backdrop,
  .lightbox-img,
  .toast,
  .save-badge,
  .react-btn,
  .is-highlighted { animation: none !important; transition: none !important; }
  .media-fade { opacity: 1 !important; }
}

/* Full-Bleed Modern Broadsheet Canvas (Wide Desktop, Zero Dark Side Voids) */
.sheet {
  position: relative;
  width: 100%;
  max-width: 1380px;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(clamp(12px, 1.8vw, 24px) + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px))
    calc(clamp(16px, 3vw, 44px) + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)))
    calc(clamp(28px, 3.2vw, 48px) + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)))
    calc(clamp(16px, 3vw, 44px) + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)));
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(255, 253, 248, 0.55) 0%, transparent 65%);
  border-left: 1px solid var(--rule-soft);
  border-right: 1px solid var(--rule-soft);
}

/* Persistent Sub-View Utility Bar (Back + Theme, Search, Editorial Desk, Settings) */
.web-back-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: -4px 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-soft);
}

.web-back-left {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.web-back-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-condensed);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 40px;
  padding: 8px 10px 8px 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring);
}

.web-back-btn:hover {
  color: var(--ink);
}

.web-back-btn:active {
  transform: translate3d(-2px, 0, 0);
}

.subbar-brand {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 2px;
  color: var(--ink);
  font-family: var(--font-masthead);
  font-size: 0.94rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.web-back-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn--sm {
  width: 38px;
  height: 38px;
}

.icon-btn--sm .svg-ico {
  width: 18px;
  height: 18px;
}

/* Seasonal Masthead Ornament */
.season-ornament {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -2px 0 6px;
  color: var(--brass);
  pointer-events: none;
}

.season-ornament-rule {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass), transparent);
  opacity: 0.58;
}

.season-ornament-emblem {
  flex: 0 0 auto;
  color: var(--brass);
}

/* Top Newspaper Dateline */
.masthead-dateline {
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule-soft);
  text-align: center;
  font-family: var(--font-condensed);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* Modern NYT-Inspired Editorial Masthead */
.masthead {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 6px 0 14px;
  border-bottom: 3px double var(--rule);
}

.masthead-crest {
  justify-self: start;
  width: 54px;
  height: auto;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.masthead-brand {
  justify-self: center;
  text-align: center;
  min-width: 0;
}

.paper-name {
  margin: 0;
  font-family: var(--font-masthead);
  font-weight: 900;
  font-size: clamp(1.24rem, 3.8vw, 3.35rem);
  line-height: 1.02;
  letter-spacing: 0.025em;
}

.motto {
  margin: 4px 0 0;
  font-style: italic;
  font-size: clamp(0.74rem, 1.15vw, 0.9rem);
  color: var(--ink-muted);
}

.masthead-actions {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius-sm);
  background: rgba(255, 253, 248, 0.58);
  color: var(--ink);
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring);
}

.icon-btn--desk {
  width: auto;
  padding: 0 12px;
  gap: 6px;
  border-color: rgba(145, 105, 39, 0.52);
  background: rgba(145, 105, 39, 0.09);
  color: var(--ink);
  font-family: var(--font-condensed);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.icon-btn--desk .svg-ico {
  width: 17px;
  height: 17px;
  color: var(--brass);
}

.icon-btn:hover {
  background: var(--ink);
  color: var(--paper-light);
  border-color: var(--ink);
}

.icon-btn--desk:hover .svg-ico {
  color: var(--paper-light);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn:focus-visible,
.micro-pill:focus-visible,
.web-back-btn:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* Top Reading Progress Bar */
.read-progress {
  position: fixed;
  top: calc(max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  height: 3px;
  z-index: 90;
  background: rgba(20, 18, 16, 0.1);
}

.read-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--brass);
  transform-origin: left center;
  transform: scaleX(0);
  will-change: transform;
  transition: transform 60ms linear;
}

/* Broadsheet Utility & Micro-Widgets Strip (Date • Weather • Gringotts • Moon) */
.meta-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule-mid);
  font-family: var(--font-condensed);
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.meta-date {
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
}

.micro-widgets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  min-width: 0;
}

.micro-sep {
  width: 1px;
  height: 13px;
  background: var(--rule-mid);
  flex-shrink: 0;
}

.micro-pill {
  position: relative;
  z-index: 2;
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-condensed);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 10px;
  min-height: 30px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease, transform var(--dur-fast) var(--ease-spring);
}

.micro-pill-top {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.1;
}

.micro-pill-sub {
  color: var(--ink-muted);
  font-weight: 500;
  line-height: 1.1;
}

.micro-pill .svg-ico {
  color: var(--brass);
}

.micro-pill:hover {
  background: rgba(24, 20, 16, 0.06);
  color: var(--ink);
}

.micro-pill:active {
  transform: scale(0.97);
}

.micro-pill[aria-expanded="true"] {
  background: rgba(145, 105, 39, 0.14);
  border-color: rgba(145, 105, 39, 0.55);
  color: var(--ink);
}

.weather-loc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

/* Expandable Micro-Widget Drawers (Weather, Gringotts Exchange, Lunar Almanac) */
.widget-drawer {
  margin: 8px 0 4px;
  padding: 12px 14px;
  border: 1px solid var(--rule-soft);
  border-left: 3px solid var(--brass);
  border-radius: var(--radius-sm);
  background: var(--paper-light);
  color: var(--ink-soft);
  animation: dp-reveal var(--dur-med) var(--ease-out-expo) both;
}

.weather-dispatch {
  font-size: 0.9rem;
  font-style: italic;
}

.widget-drawer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  margin-bottom: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--rule-soft);
}

.widget-drawer-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-condensed);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink);
}

.widget-drawer-title .svg-ico {
  color: var(--brass);
}

.widget-drawer-badge {
  font-family: var(--font-condensed);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 2px 7px;
  border: 1px solid var(--rule-soft);
  border-radius: 999px;
}

.gringotts-grid,
.moon-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.gringotts-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  background: rgba(24, 20, 16, 0.035);
  border: 1px solid var(--rule-soft);
}

.gringotts-label {
  font-family: var(--font-condensed);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.gringotts-val {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.gringotts-sub {
  font-family: var(--font-condensed);
  font-size: 0.68rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.widget-drawer-note {
  margin: 9px 0 0;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--ink-muted);
}

@media (max-width: 720px) {
  body {
    background: var(--paper);
    font-size: 15px;
  }
  .sheet {
    min-height: var(--tg-viewport-stable-height, 100svh);
    border: 0;
    padding:
      calc(10px + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px))
      calc(14px + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)))
      calc(24px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)))
      calc(14px + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)));
  }
  .masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 10px 10px;
    padding: 4px 0 10px;
  }
  .masthead-crest {
    width: 38px;
    flex-shrink: 0;
  }
  .masthead-brand {
    flex: 1 1 200px;
    min-width: 0;
    text-align: left;
  }
  .masthead-actions {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  .masthead-actions .icon-btn--desk {
    width: auto;
    margin-right: auto;
    height: 40px;
    padding: 0 12px;
    font-size: 0.74rem;
  }
  .icon-btn--sm {
    width: 38px;
    height: 38px;
  }
  .web-back-btn {
    font-size: 0.78rem;
    letter-spacing: 0.06em;
  }
  .web-back-actions .icon-btn--desk {
    width: 38px;
    padding: 0;
  }
  .web-back-actions .icon-btn--desk .icon-btn-label {
    display: none;
  }
  .meta-strip {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px 0 10px;
  }
  .micro-widgets {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }
  .micro-sep {
    display: none;
  }
  .micro-pill {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 7px 6px;
    border-radius: var(--radius-sm);
    background: var(--paper-light);
    border-color: var(--rule-soft);
    font-size: 0.72rem;
    text-align: center;
  }
  .micro-pill-top {
    max-width: 100%;
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .micro-pill-sub {
    max-width: 100%;
    font-size: 0.62rem;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .gringotts-grid,
  .moon-stats {
    grid-template-columns: 1fr;
    gap: 7px;
  }
  .gringotts-cell {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
  }
  .gringotts-sub {
    display: none;
  }
}
