/* ==========================================================================
   Salafi Lessons display: the timetable page and the homepage blocks.
   The face, lines, stone, accent and radius come from the values the theme
   publishes (--scm-*, the app's D-344 (16)), so a theme change carries
   through. Each falls back to the token copied from Salafi Prayer Times, so a
   site without them looks as before; the compositions are Lessons' own
   (SL-D-091). Scoped to .sld, never :root. Dark is opt-in per block
   (theme="dark"). Every layout change is a container query on the block, so
   it fits the column it sits in.
   ========================================================================== */

.sld {
  --sld-text: #1f1e1c;
  --sld-muted: #5b5955;
  --sld-card: #ffffff;
  --sld-well: var(--scm-stone, #f4f3f0);
  --sld-line: var(--scm-line, #e6e4df);
  --sld-line-strong: rgba(31, 30, 28, 0.16);
  --sld-accent: var(--scm-accent, var(--sld-text));
  --sld-shadow: 0 1px 2px rgba(31, 30, 28, 0.05), 0 12px 32px -12px rgba(31, 30, 28, 0.14);
  --sld-r-xs: var(--scm-radius, 8px);
  --sld-r-sm: var(--scm-radius, 12px);
  --sld-r: var(--scm-radius, 16px);
  --sld-ease: cubic-bezier(0.23, 1, 0.32, 1);
  --sld-font: var(--scm-font, Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif);

  container-type: inline-size;
  color: var(--sld-text);
  font-family: var(--sld-font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

.sld[data-theme="dark"] {
  color-scheme: dark;
  --sld-text: #f2f1ee;
  --sld-muted: #c9c6bf;
  --sld-card: #1b1a19;
  --sld-well: rgba(255, 255, 255, 0.07);
  --sld-line: rgba(255, 255, 255, 0.12);
  --sld-line-strong: rgba(255, 255, 255, 0.22);
  /* The theme's accent is chosen for a light ground; an accent attribute is lifted for dark in PHP. */
  --sld-accent: var(--sld-text);
  --sld-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -14px rgba(0, 0, 0, 0.55);
}

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

/* The theme styles bare headings, paragraphs and lists; these start clean. */
.sld :is(h3, h4, p, ul, li, figure) {
  margin: 0;
  padding: 0;
  font-family: inherit;
  letter-spacing: 0;
  text-transform: none;
}

/* Times are left-aligned, so their figures are proportional: a tabular 1 is wide ("1 1 am"). */
.sld time {
  font-variant-numeric: proportional-nums;
}

.sld :focus-visible {
  outline: 2px solid var(--sld-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sld .sld-empty {
  color: var(--sld-muted);
  font-size: 0.9375rem;
}

.sld .sld-empty + .sld-empty {
  margin-top: 0.25rem;
}

.sld .sld-empty a {
  color: var(--sld-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* ---- One row, three densities -------------------------------------------- */

.sld-rows {
  display: flex;
  flex-direction: column;
}

/* A narrow column puts the time above its class, so a range has the line to itself. */
.sld-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.125rem 0.75rem;
  align-items: start;
  padding: 0.75rem 0;
  border-top: 1px solid var(--sld-line);
}

.sld-rows > .sld-row:first-child {
  border-top-color: transparent;
}

/* A range sits on one line, "7:30 pm – 9:30 pm" (SL-D-110): above its class, or in a 10rem column. */
.sld-when {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.3em;
  padding-top: 0.0625rem;
}

/* The end time reads as part of the time, at the start time's size. */
.sld .sld-start,
.sld .sld-end {
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.sld-what {
  min-width: 0;
}

/* Lesson covers (SL-D-096) show only on the wide agenda, in the container query below. */
.sld-thumb {
  display: none;
}

.sld .sld-title {
  color: var(--sld-text);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sld .sld-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--sld-line-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color 150ms ease;
}

.sld .sld-link:hover,
.sld .sld-link:focus-visible {
  text-decoration-color: currentColor;
}

.sld .sld-meta {
  margin-top: 0.125rem;
  color: var(--sld-muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.sld .sld-note {
  margin-top: 0.1875rem;
  font-size: 0.8125rem;
  line-height: 1.4;
}

/* Today is the week's one mark, in the accent; earlier days step back (the app's D-344 (19)). */
.sld .is-today :is(.sld-day-name, .sld-cday-name) {
  color: var(--sld-accent);
}

.sld .is-past :is(.sld-day-head, .sld-start, .sld-end, .sld-title, .sld-cday-name, .sld-ctitle) {
  color: var(--sld-muted);
}

/* ---- view="week": an agenda ----------------------------------------------- */

.sld-week {
  container-name: sld-week;
  max-width: 72rem;
}

.sld-week.sld:not(.is-frameless) {
  padding: 1.25rem;
  background: var(--sld-card);
  border: 1px solid var(--sld-line);
  border-radius: var(--sld-r);
  box-shadow: var(--sld-shadow);
}

.sld-week-grid {
  display: grid;
  gap: 1.75rem;
  align-items: start;
}

.sld-week-main {
  min-width: 0;
}

.sld .sld-range {
  margin-bottom: 1rem;
  color: var(--sld-muted);
  font-size: 0.9375rem;
  font-weight: 600;
}

.sld-days {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* layout="cards" (SL-D-110): each day is a soft card holding its classes on divided rows. */
.sld[data-layout="cards"] .sld-day {
  padding: 0.25rem 1rem 0.375rem;
  border-radius: var(--sld-r);
  background: var(--sld-well);
}

.sld[data-layout="cards"] .sld-day .sld-rows > .sld-row:first-child {
  border-top-color: var(--sld-line);
}

/* Deep page zoom narrows the page (INC-142): a day gives up its well and padding,
   so a long word in the live face ("Comprehensive", 7.5rem) has the column's width. */
@container sld-week (max-width: 11rem) {
  .sld[data-layout="cards"] .sld-day {
    padding-inline: 0;
    background: none;
  }
}

/* mobile="compact" (SL-D-095): a narrow page shows the compact week; the full
   rows return when there is room for the agenda. */
.sld-week .sld-cdays {
  display: none;
}

.sld-week.has-compact .sld-days {
  display: none;
}

.sld-week.has-compact .sld-cdays {
  display: flex;
}

.sld .sld-day-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.125rem 0.5rem;
  padding: 0.875rem 0 0.625rem;
  color: var(--sld-text);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.sld-day-date {
  color: var(--sld-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.sld-poster {
  display: grid;
  gap: 0.625rem;
  width: 100%;
  max-width: 22rem;
}

.sld .sld-poster-open {
  display: block;
  overflow: hidden;
  border-radius: var(--sld-r-sm);
  background: var(--sld-well);
  box-shadow: var(--sld-shadow);
  line-height: 0;
}

.sld .sld-poster-open img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1080 / 1350;
}

.sld .sld-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.625rem 1rem;
  border: 1px solid var(--sld-line-strong);
  border-radius: var(--sld-r-sm);
  color: var(--sld-text);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  transition: transform 120ms var(--sld-ease);
}

.sld .sld-download:active {
  transform: scale(0.97);
}

.sld-download svg {
  flex: none;
}

/* Room for it: the day moves to a left column, like a printed timetable. */
@container sld-week (min-width: 38rem) {
  .sld[data-layout="cards"] .sld-day {
    padding: 0.375rem 1.5rem 0.5rem;
  }

  .sld-week.has-compact .sld-days {
    display: flex;
  }

  .sld-week.has-compact .sld-cdays {
    display: none;
  }

  .sld-row {
    grid-template-columns: 10rem minmax(0, 1fr);
    column-gap: 1.25rem;
  }

  /* Every row gets the same square, so the names start in one line. */
  .sld-week.has-thumbs .sld-row {
    grid-template-columns: 10rem 3rem minmax(0, 1fr);
  }

  .sld-week.has-thumbs .sld-thumb {
    display: block;
    width: 3rem;
    height: 3rem;
    overflow: hidden;
    border-radius: var(--sld-r-xs);
    background: var(--sld-well);
    box-shadow: inset 0 0 0 1px var(--sld-line);
  }

  .sld-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

/* Wider still: the poster becomes a rail beside the week and stays in view. */
@container sld-week (min-width: 60rem) {
  .sld-week-grid {
    grid-template-columns: minmax(0, 1fr) 17.5rem;
    column-gap: 3rem;
  }

  .sld-poster {
    position: sticky;
    top: 1.5rem;
  }
}

/* ---- view="poster": the poster alone -------------------------------------- */

.sld-poster-only .sld-poster {
  max-width: 28rem;
  padding-inline: 0;
}

/* ---- The homepage blocks --------------------------------------------------- */

.sld-block {
  container-name: sld-block;
  padding: 1.125rem;
  background: var(--sld-card);
  border: 1px solid var(--sld-line);
  border-radius: var(--sld-r);
  box-shadow: var(--sld-shadow);
}

.sld-block[data-layout="cards"]:not(.is-frameless) {
  background: var(--sld-well);
  border-color: transparent;
  box-shadow: none;
}

.sld-block.is-frameless {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.sld-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.125rem 1rem;
  margin-bottom: 0.5rem;
}

.sld .sld-block-title {
  color: var(--sld-text);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.012em;
  line-height: 1.25;
}

.sld .sld-block-date {
  color: var(--sld-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

/* The compact week's line stands clear of its first day (the app's P-168). */
.sld-compact .sld-block-date {
  margin-bottom: 1rem;
}

.sld .sld-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 44px;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--sld-line);
  color: var(--sld-text);
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
}

.sld-more svg {
  flex: none;
  color: var(--sld-muted);
  transition: transform 150ms var(--sld-ease), color 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .sld-more:hover svg {
    color: var(--sld-accent);
    transform: translateX(2px);
  }
}

/* view="compact": one line a class, the days with classes down the side, each named in text. */
.sld-cdays {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--sld-line);
}

.sld-cday {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  column-gap: 0.75rem;
  padding-block: 0.75rem;
  border-top: 1px solid var(--sld-line);
}

/* An empty day shows only in the seven columns, by its name alone; the short name until then. */
.sld-cday.is-empty,
.sld-cday-long {
  display: none;
}

.sld .sld-cday-name {
  padding-top: 0.125rem;
  color: var(--sld-text);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25rem;
}

.sld .sld-clist {
  display: grid;
  gap: 0.125rem;
  list-style: none;
}

.sld .sld-clist li {
  display: grid;
  grid-template-columns: 4.25rem minmax(0, 1fr);
  column-gap: 0.5rem;
  padding: 0.125rem 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.sld-clist time {
  color: var(--sld-muted);
  font-weight: 500;
  white-space: nowrap;
}

.sld-ctitle {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* The Today block lists its classes in one column (SL-D-094); a wide one
   gives the times more room. */
@container sld-block (min-width: 36rem) {
  .sld-row {
    grid-template-columns: 10rem minmax(0, 1fr);
    column-gap: 1rem;
  }

  .sld .sld-clist li {
    grid-template-columns: 5rem minmax(0, 1fr);
    column-gap: 0.75rem;
  }
}

/* Page zoom narrows the block (INC-106): the day goes above its classes, then
   each time above its title, so no word splits. Beside the day and time, a title
   keeps at least 7rem, room for a long word or "al-" held to its word (SLP-79). */
@container sld-block (max-width: 17rem) {
  .sld-cday {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.25rem;
  }
}

@container sld-block (max-width: 11rem) {
  .sld .sld-clist li {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* From a 60rem block the compact week is seven columns under one hairline,
   each day named in full (the app's D-344 (15)). */
@container sld-block (min-width: 60rem) {
  .sld-cdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    column-gap: 1rem;
    border-top: 1px solid var(--sld-line);
    border-bottom: 0;
  }

  .sld-cday,
  .sld-cday.is-empty {
    display: block;
    border-top: 0;
  }

  .sld-cday-long {
    display: inline;
  }

  .sld-cday-short {
    display: none;
  }

  .sld .sld-clist {
    gap: 0.75rem;
    margin-top: 0.5rem;
  }

  .sld .sld-clist li {
    display: block;
    padding: 0;
  }

  .sld-clist time {
    display: block;
  }
}

/* ---- layout="calendar" (SL-D-110): a date tile per day, each time above its class ---- */

.sld-tile {
  display: none;
}

.sld[data-layout="calendar"] .sld-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 4rem;
  border-radius: 0.875rem;
  background: var(--sld-well);
  color: var(--sld-text);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.sld[data-layout="calendar"] .is-today .sld-tile {
  background: var(--sld-accent);
  color: var(--sld-card);
}

.sld[data-layout="calendar"] .is-past .sld-tile {
  color: var(--sld-muted);
}

.sld[data-layout="calendar"] .sld-tile-day {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.85;
}

.sld[data-layout="calendar"] .sld-tile-num {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* The tile shows the day; its heading stays for screen readers. */
.sld[data-layout="calendar"] .sld-day-head,
.sld[data-layout="calendar"].sld-today .sld-block-date {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sld[data-layout="calendar"] .sld-days {
  gap: 0;
}

.sld[data-layout="calendar"] .sld-day,
.sld[data-layout="calendar"] .sld-today-day {
  position: relative;
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  column-gap: 1rem;
  align-items: start;
}

.sld[data-layout="calendar"] .sld-day {
  padding-block: 1.125rem;
}

.sld[data-layout="calendar"] .sld-today-day {
  padding-block: 0.25rem 0.125rem;
}

.sld[data-layout="calendar"] .sld-days > .sld-day + .sld-day {
  border-top: 1px solid var(--sld-line);
}

.sld[data-layout="calendar"] .sld-rows {
  gap: 0.5rem;
}

/* A day shorter than its tile sits centred beside it; a longer one starts at the top. */
.sld[data-layout="calendar"] .sld-day .sld-rows,
.sld[data-layout="calendar"] .sld-today-day .sld-rows {
  min-height: 4rem;
  justify-content: center;
}

/* Page zoom narrows the block (INC-142): the tile goes above its classes, so a
   title has the column's whole width and no word splits. */
@container sld-week (max-width: 13rem) {
  .sld[data-layout="calendar"] .sld-day {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.625rem;
  }

  .sld[data-layout="calendar"] .sld-day .sld-rows {
    min-height: 0;
  }
}

@container sld-block (max-width: 13rem) {
  .sld[data-layout="calendar"] .sld-today-day {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.625rem;
  }

  .sld[data-layout="calendar"] .sld-today-day .sld-rows {
    min-height: 0;
  }
}

.sld[data-layout="calendar"] .sld-row {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.125rem 0;
  border-top: 0;
}

.sld[data-layout="calendar"] .sld-start,
.sld[data-layout="calendar"] .sld-end {
  font-size: 0.875rem;
  font-weight: 600;
}

.sld[data-layout="calendar"] .sld-title {
  font-size: 1.0625rem;
}

/* At deep zoom a title takes the blocks' usual size, so a long word fits a framed block. */
@container sld-week (max-width: 11rem) {
  .sld[data-layout="calendar"] .sld-title {
    font-size: 1rem;
  }
}

@container sld-block (max-width: 11rem) {
  .sld[data-layout="calendar"] .sld-title {
    font-size: 1rem;
  }
}

@container sld-week (min-width: 38rem) {
  .sld[data-layout="calendar"] .sld-day {
    grid-template-columns: 4.5rem minmax(0, 1fr);
    column-gap: 1.75rem;
    padding-block: 1.375rem;
  }

  .sld[data-layout="calendar"] .sld-day .sld-tile {
    width: 4.5rem;
    height: 5rem;
    border-radius: 1rem;
  }

  .sld[data-layout="calendar"] .sld-day .sld-tile-num {
    font-size: 1.75rem;
  }

  .sld[data-layout="calendar"] .sld-rows {
    gap: 0.75rem;
  }

  .sld[data-layout="calendar"] .sld-day .sld-rows {
    min-height: 5rem;
  }

  .sld[data-layout="calendar"] .sld-row {
    display: grid;
    grid-template-columns: 10rem minmax(0, 1fr);
    column-gap: 1.25rem;
    align-items: baseline;
  }

  .sld[data-layout="calendar"].has-thumbs .sld-row {
    grid-template-columns: 10rem 3rem minmax(0, 1fr);
    align-items: start;
  }

  .sld[data-layout="calendar"] .sld-start,
  .sld[data-layout="calendar"] .sld-end {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sld,
  .sld * {
    transition: none !important;
  }
}
