:root {
  --bg: #f7f6f3;
  --ink: #1c1c1c;
  /* Secondary greys are set so they clear WCAG AA (4.5:1) against the most
     strongly tinted corner the ambient wash can produce, not just against
     the flat background. */
  --ink-muted: #454545;
  --ink-faint: #4d4d4d;
  --rule: rgba(28, 28, 28, 0.18);
  --frame-bg: #ebe9e5;
  --error: #8a3b3b;
  --hover-bg: rgba(28, 28, 28, 0.07);

  --serif: "Crimson Text", Georgia, "Times New Roman", serif;
  --max-width: 1100px;

  /* Artwork column width. Widened for landscape works so the picture reads
     at a proper size; portrait keeps the original proportions. */
  --art-col: 340px;
  --art-col-landscape: 520px;
}

:root[data-theme="dark"] {
  --bg: #17181a;
  --ink: #e9e6e0;
  --ink-muted: #bcb7af;
  --ink-faint: #a8a29a;
  --rule: rgba(233, 230, 224, 0.18);
  --frame-bg: #232426;
  --error: #d98b8b;
  --hover-bg: rgba(233, 230, 224, 0.09);
}

/* Registered so the ambient colours can be interpolated rather than snapping
   when the day changes. Browsers without @property still get the colours,
   just switched instantly instead of faded. */
@property --amb-1 { syntax: "<color>"; inherits: false; initial-value: rgba(0, 0, 0, 0); }
@property --amb-2 { syntax: "<color>"; inherits: false; initial-value: rgba(0, 0, 0, 0); }
@property --amb-3 { syntax: "<color>"; inherits: false; initial-value: rgba(0, 0, 0, 0); }

/* Colour drawn from the day's artwork, pooled at the edges of the page so the
   middle — where the reading sits — stays the plain background colour. */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  --amb-1: rgba(0, 0, 0, 0);
  --amb-2: rgba(0, 0, 0, 0);
  --amb-3: rgba(0, 0, 0, 0);
  background:
    radial-gradient(58% 46% at 0% 0%, var(--amb-1) 0%, transparent 72%),
    radial-gradient(54% 42% at 100% 8%, var(--amb-2) 0%, transparent 72%),
    radial-gradient(62% 48% at 100% 100%, var(--amb-1) 0%, transparent 72%),
    radial-gradient(66% 50% at 0% 100%, var(--amb-3) 0%, transparent 72%);
  transition: --amb-1 900ms ease, --amb-2 900ms ease, --amb-3 900ms ease;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  transition: background-color 0.35s ease, color 0.35s ease;
}

.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 32px 80px;
}

/* ---------- Header + theme toggle ---------- */

.site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
  margin-bottom: 56px;
}

.site-header h1 {
  font-weight: 400;
  font-size: 2.1rem;
  letter-spacing: -2px;
  margin: 0;
}

.site-title {
  color: inherit;
  text-decoration: none;
}

.site-title:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}

.site-title:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}

.theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover {
  background: var(--hover-bg);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.icon-moon {
  stroke-linejoin: round;
}

/* Show the icon for the theme you'd switch *to*. */
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

/* ---------- Day navigation ---------- */

.day-nav {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.nav-link {
  background: none;
  border: none;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  padding: 4px;
}

.nav-link:hover {
  text-decoration: underline;
}

.nav-link:disabled {
  color: var(--ink-faint);
  cursor: default;
  text-decoration: none;
}

.current-date {
  font-weight: 400;
  font-size: 1.5rem;
  margin: 0;
  text-align: center;
  flex: 1;
}

/* ---------- Translation tabs ---------- */

.translation-tabs {
  display: flex;
  gap: 28px;
  margin-bottom: 40px;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px 2px;
  transition: color 0.2s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---------- Reading layout ---------- */

.reading {
  display: grid;
  grid-template-columns: var(--art-col) 1fr;
  gap: 56px;
  align-items: start;
  transition: grid-template-columns 0.45s ease;
}

/* Set once the image's real dimensions are known. */
.reading.is-landscape {
  grid-template-columns: minmax(0, var(--art-col-landscape)) 1fr;
}

.artwork {
  margin: 0;
}

.artwork-frame {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  overflow: hidden;
  background: var(--frame-bg);
  cursor: zoom-in;
  font: inherit;
  color: inherit;
}

.artwork-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.artwork-frame:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* Quiet affordance that the picture opens larger. */
.expand-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: rgba(12, 12, 14, 0.55);
  color: #fff;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.expand-hint svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.artwork-frame:hover .expand-hint,
.artwork-frame:focus-visible .expand-hint {
  opacity: 1;
  transform: none;
}

.artwork figcaption {
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.artwork-title {
  font-style: italic;
}

.artwork-meta {
  color: var(--ink-muted);
}

.artwork-pairing {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-style: italic;
  color: var(--ink-muted);
}

.artwork-pairing:empty {
  display: none;
}

/* Why this artwork was chosen — the week's theme and the imagery it shares
   with the reading. */
.artwork-blurb {
  margin: 8px 0 0;
  color: var(--ink-muted);
  line-height: 1.6;
}

.artwork-blurb:empty {
  display: none;
}

.artwork-credit {
  margin-top: 10px;
  color: var(--ink-faint);
}

/* ---------- Passage ---------- */

.passage-reference {
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 0 20px;
}

.passage-body {
  font-size: 1.15rem;
  line-height: 1.75;
}

.passage-body p {
  margin: 0 0 1em;
}

.passage-heading {
  font-weight: 600;
  font-size: 1.1rem;
  margin: 1.4em 0 0.6em;
}

.verse-num {
  font-size: 0.7em;
  margin-right: 0.15em;
  color: var(--ink-muted);
  font-weight: 600;
}

.loading, .error-message {
  color: var(--ink-muted);
  font-style: italic;
}

.error-message {
  color: var(--error);
}

.passage-copyright {
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

/* ---------- Lightbox ---------- */

/* Always dark regardless of theme — artwork reads best against a neutral
   dark surround, and it matches how a gallery lights a wall. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  /* Fully opaque: at any transparency the page's own text ghosts through
     behind the picture and the caption, which is distracting on a phone
     where text fills the whole screen. */
  background: #0b0b0d;
  color: #f2efe9;
  animation: lightbox-in 0.22s ease both;
}

.lightbox[hidden] {
  display: none;
}

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

.lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  flex: 0 0 auto;
}

.lightbox-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(242, 239, 233, 0.3);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-family: var(--serif);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.lightbox-btn:hover {
  background: rgba(242, 239, 233, 0.14);
}

.lightbox-btn:focus-visible {
  outline: 2px solid #f2efe9;
  outline-offset: 2px;
}

.lightbox-close {
  width: 34px;
  padding: 0;
}

.lightbox-close svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.lightbox-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 0 18px;
  min-height: 0;
}

.lightbox-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
  animation: lightbox-img-in 0.3s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes lightbox-img-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* Zoomed: show at natural size and let the stage scroll around it. */
.lightbox-img.is-zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
  animation: none;
}

.lightbox-loading {
  position: absolute;
  margin: 0;
  font-style: italic;
  font-size: 0.9rem;
  color: rgba(242, 239, 233, 0.7);
}

.lightbox-loading[hidden] {
  display: none;
}

.lightbox-caption {
  flex: 0 0 auto;
  padding: 14px 20px 22px;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(242, 239, 233, 0.78);
}

.lightbox-title {
  display: block;
  font-style: italic;
  color: #f2efe9;
}

.lightbox-meta {
  display: block;
}

.lightbox-link {
  display: inline-block;
  margin-top: 6px;
  color: rgba(242, 239, 233, 0.78);
}

.lightbox-link:hover {
  color: #f2efe9;
}

/* ---------- Top-to-bottom reveal ---------- */

@keyframes reveal-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.reveal {
  animation: reveal-in 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .page {
    padding: 32px 20px 64px;
  }

  .site-header {
    margin-bottom: 40px;
  }

  .site-header h1 {
    font-size: 1.6rem;
  }

  .theme-toggle {
    width: 34px;
    height: 34px;
  }

  .day-nav {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    row-gap: 8px;
  }

  .current-date {
    order: -1;
    flex-basis: 100%;
    font-size: 1.3rem;
  }

  /* One column on small screens, so the landscape widening doesn't apply. */
  .reading,
  .reading.is-landscape {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  /* Give the picture as much width as possible on a phone. */
  .lightbox-stage {
    padding: 0 8px;
  }

  .lightbox-caption {
    padding: 12px 16px 18px;
  }

  .passage {
    order: 1;
  }

  .artwork {
    order: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .reading,
  .expand-hint {
    transition: none;
  }

  .reveal,
  .lightbox,
  .lightbox-img {
    animation: none;
  }

  .ambient {
    transition: none;
  }
}
