/* Ilm Exhibit — Design v4 "Sideways info, timeline base".  [Design v4]
   Load AFTER exhibit.css (which supplies the v1 card chrome). This file:
   - regrids the card to media|body on top, full-width timeline below
   - adds the sideways accordion that lives INSIDE the body column
     (Overview fold first, facts after) — labels are slim vertical strips,
     activating one slides its text out to the RIGHT within the fixed card.
   The card itself does not grow or shrink. */

/* ---------------- Card grid: two columns + full-width timeline -------- */

.v4-card {
  max-width: 1060px; /* thinner now that the timeline carries the dates */
  /* a touch taller than content-sized, but never full-viewport:
     capped at 520px so the card doesn't outgrow its text */
  height: min(calc(100dvh - var(--header-h, 64px) - var(--space-md, 1rem) - var(--space-lg, 2rem)), 650px);
  min-height: 430px;
  /* image rail matches the event-date block width for visual continuity */
  grid-template-columns: 22.5% minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "media body"
    "media timeline";
}
.v4-card .ilm-media.v4-media { grid-area: media; }
.v4-card .ilm-body { grid-area: body; }
.v4-card .v4-timeline { grid-area: timeline; }

/* ---------------- Body ---------------- */

.v4-body {
  display: flex;
  flex-direction: column;
}

/* Kicker sits below the origins line as a full-width bar, squared corners */
.v4-card .ilm-kicker {
  align-self: stretch;
  border-radius: 6px;
  margin: var(--space-xs) 0 var(--space-sm);
}

/* Thicker gold inner frame on v4 cards */
.v4-card::before {
  border-width: 2px;
}

/* Mark-as-read toggle: replaces the Arabic title in the title row's right
   corner; plain styling since the card head sits on the off-white panel */
.v4-read {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
/* Button keeps the site-standard .post-read-toggle look from style.css.
   Only the label's glow (the #faf2e2 stroke/shadow added for busy
   backgrounds on post pages) is neutralized here. */
.v4-read .post-read-toggle-label {
  -webkit-text-stroke: 0;
  text-shadow: none;
}



/* Card number badge: sits over the image rail's top-left corner.
   Large numeral + small CARD label, framed in the card's accent. */
.v4-media {
  position: relative;
}
.v4-card-num {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 6px 14px 8px;
  background: rgba(16, 19, 26, 0.78);
  border: 1.5px solid var(--v4accent, #d4a843);
  border-radius: 8px;
  color: #f5edd6;
  pointer-events: none;
}
.v4-card-num-n {
  font-family: var(--font-heading);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  color: var(--v4accent, #d4a843);
}
.v4-card-num-t {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #f5edd6;
}

/* ---------------- Horizontal accordion inside the body ---------------- */

.v4-hacc {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 8px;
  /* stretch to fill the body column's remaining height */
  flex: 1;
  min-height: 0;
  margin: var(--space-sm) 0;
}

.v4-hacc-item {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  /* Base state: collapsed to the tab width */
  flex: 0 0 52px;
  min-width: 52px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.02);
  /* Smooth easing curve on flex changes */
  transition: flex 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.3s ease,
              background-color 0.3s ease;
  will-change: flex;
}

.v4-hacc-item.is-open {
  /* Expands smoothly to take remaining space */
  flex: 1 1 0%;
  border-color: color-mix(in srgb, var(--v4accent, #d4a843) 45%, var(--color-border));
  background: rgba(255, 255, 255, 0.04);
}

/* Closed strip: slim vertical label */
.v4-hacc-tab {
  position: relative;
  flex: 0 0 52px;
  width: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) 0;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  color: var(--color-text-muted);
  transition: color 0.25s ease, background 0.25s ease;
}

.v4-hacc-item.is-open .v4-hacc-tab {
  color: var(--v4accent, #d4a843);
}

/* Collapsed tabs: hover affordance so they read as clickable */
.v4-hacc-item:not(.is-open) .v4-hacc-tab:hover {
  color: var(--color-text);
  background: color-mix(in srgb, var(--v4accent, #d4a843) 12%, transparent);
}
.v4-hacc-item:not(.is-open) .v4-hacc-tab:hover::before {
  opacity: 1;
}

.v4-hacc-tab::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
  background: var(--v4accent, rgba(184, 134, 11, 0.6));
  opacity: 0;
  transition: opacity 0.25s ease;
}

.v4-hacc-item.is-open .v4-hacc-tab::before {
  opacity: 1;
}

.v4-hacc-tab:focus-visible {
  outline: 2px solid var(--v4accent, var(--color-secondary));
  outline-offset: -3px;
}

.v4-hacc-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  max-height: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Open panel: static padding, GPU-accelerated reveal */
.v4-hacc-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--space-md);
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateX(12px);
  /* Fast fade-out on close */
  transition: opacity 0.15s ease,
              transform 0.15s ease,
              visibility 0.15s;
}

.v4-hacc-item.is-open .v4-hacc-panel {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  /* Delayed fade-in so text emerges after the panel begins expanding */
  transition: opacity 0.35s ease 0.12s,
              transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.08s;
}

.v4-hacc-text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
  min-width: 240px; /* Prevents text from reflowing and jumping mid-animation */
  max-width: 46em;
}

/* Heading echoed at the top of the open panel - mirrors the tab's label */
.v4-hacc-title {
  margin: 0 0 0.6rem;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text);
}

/* Optional related-reading link shown at the bottom of each accordion section */
.v4-hacc-link {
  margin-top: auto;
  margin-bottom: -0.5rem; /* pull closer to the section bottom (panel has 1rem padding) */
  padding-top: 0.9rem;
  text-align: right;
}
.v4-hacc-book {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  color: var(--color-secondary);
  text-decoration: none;
}
.v4-hacc-book svg {
  flex: none;
  align-self: center;
}
.v4-hacc-book-label {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  line-height: 1;
  margin-left: 3px; /* 1px tighter than before (0.25rem was 4px) */
  margin-right: -0.07em; /* cancel trailing letter-spacing so it centers on the icon */
}
.v4-hacc-book-q {
  color: var(--color-text-light); /* medium gray, distinct from black text */
  font-size: 0.9rem;
  line-height: 1.7;
  font-style: italic;
  margin-right: 0.5rem; /* keep current spacing to the book icon */
}
.v4-hacc-book:hover {
  color: var(--color-primary);
}
.v4-hacc-book:hover .v4-hacc-book-q {
  color: var(--color-primary);
}
[dir="rtl"] .v4-card .v4-hacc-link {
  direction: ltr;
}

/* Sources fold: collapsed tab only as wide as its rotated text needs —
   roughly 1/3 the width of the regular 52px tabs */
.v4-hacc-item--sources {
  flex: 0 0 22px;
  min-width: 22px;
}
.v4-hacc-item--sources.is-open {
  flex: 1 1 0%;
  min-width: 0;
}
.v4-hacc-item--sources .v4-hacc-tab {
  flex: 0 0 22px;
  width: 22px;
}
.v4-hacc-item--sources .v4-hacc-label {
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  line-height: 22px; /* text box matches the strip width */
  max-height: none;
}
.v4-hacc-item--sources .v4-hacc-panel {
  background: none;
}
.v4-hacc-text--sources {
  font-size: 0.74rem;
  line-height: 1.65;
  color: var(--color-text);
  margin: 0;
  padding: 0;
  list-style: none;
}
.v4-hacc-text--sources li {
  margin-bottom: 0.3rem;
}

/* Mobile fallback (<900px): stacks vertically */
@media (max-width: 900px) {
  .v4-hacc {
    flex-direction: column;
    height: auto;
  }
  .v4-hacc-item,
  .v4-hacc-item.is-open {
    flex: none;
    min-width: 0;
    flex-direction: column;
    transition: border-color 0.3s ease;
  }
  .v4-hacc-tab {
    width: 100%;
    flex: none;
    padding: 0.55rem var(--space-sm);
  }
  .v4-hacc-label {
    writing-mode: horizontal-tb;
    max-height: none;
  }
  /* Sources strip: return to a normal full-width row on mobile */
  .v4-hacc-item--sources {
    flex: none;
    min-width: 0;
  }
  .v4-hacc-item--sources .v4-hacc-tab {
    flex: none;
    width: 100%;
  }
  .v4-hacc-item--sources .v4-hacc-label {
    font-size: 0.68rem;
    line-height: normal;
    letter-spacing: 0.06em;
  }
  .v4-hacc-tab::before {
    top: 0; left: 0; right: 0; bottom: auto;
    width: auto; height: 3px;
  }
  .v4-hacc-panel {
    display: none;
    padding: var(--space-sm);
    transform: none;
  }
  .v4-hacc-item.is-open .v4-hacc-panel {
    display: block;
    opacity: 1;
    visibility: visible;
  }
  .v4-hacc-text {
    min-width: 0;
  }
}

/* ---------------- Timeline strip (all dates, full width) --------------- */

.v4-timeline {
  display: flex;
  align-items: stretch;
  background: linear-gradient(160deg, rgba(16, 19, 26, 0.96), rgba(26, 34, 48, 0.93));
  border-top: 1px solid rgba(212, 168, 67, 0.4);
  min-height: 160px;
}

/* The event date overlays the image rail; west and gap split the
   remaining strip (57 / 20.5 of the old full-width ratio). */
.v4-tl-west { flex: 0 0 73.6%; }
.v4-tl-gap { flex: 0 0 26.4%; }

.v4-tl-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  padding: var(--space-md) var(--space-lg);
  border-right: 1px solid rgba(212, 168, 67, 0.22);
}
.v4-timeline .v4-tl-block:last-child {
  border-right: 0; /* no divider on the final block */
}

/* Gap block: big gold number with "year gap" beneath, centred.
   The note is absolutely positioned so it doesn't offset the centred pair. */
.v4-tl-block.v4-tl-gap {
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
}
.v4-tl-gap .v4-tl-value {
  font-size: clamp(2.6rem, 4.5vw, 3.6rem);
  color: #D4A843;
}
.v4-tl-note {
  position: absolute;
  left: 50%;
  bottom: 0.45rem;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(160, 160, 160, 0.75);
}

.v4-tl-value {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1;
  color: #F5EDD6;
}
.v4-tl-value--then { color: #EDE7DA; opacity: 0.85; }
.v4-tl-value--catch { color: #F5EDD6; }
.ilm-year-era {
  font-size: 0.38em;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-left: 0;
  opacity: 0.75;
}
.v4-tl-value .ilm-year-era { margin-left: 5px; }

.v4-tl-caption {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(245, 237, 214, 0.66);
  display: inline-flex;
  align-items: center;
}
.v4-tl-caption svg {
  width: 20px;
  height: 20px;
  margin-right: 5px;
  color: #D4A843;
}

/* Event block: large, centred, gold. Placed in the same grid row as the
   timeline strip (over the image rail's lower half), so both blocks always
   share exactly the same height whatever the strip's content does. */
.v4-tl-event {
  grid-column: 1;
  grid-row: 2;
  z-index: 1;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-sm) var(--space-sm) var(--space-md);
  background: rgba(16, 19, 26, 0.5);
}
.v4-tl-event .v4-tl-value {
  font-size: clamp(2.6rem, 4.5vw, 3.6rem);
  color: #D4A843;
}

/* Europe block: one grid — caption row shares the exact columns of the
   dates below, so each tag sits directly over its own date. */
.v4-tl-west {
  justify-content: center;
  min-width: 0;
}
.v4-tl-westgrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: clamp(0.8rem, 2.5vw, 2rem);
  row-gap: 0.4rem;
}
.v4-tl-westgrid > .v4-tl-caption { grid-row: 1; }
.v4-tl-westgrid > .v4-tl-caughtup {
  grid-column: 3;
  justify-self: start; /* aligns with the left edge of its stage */
}
.v4-tl-westgrid > .v4-tl-stage:first-of-type { grid-column: 1; grid-row: 2; }
.v4-tl-westgrid > .v4-tl-arrow { grid-column: 2; grid-row: 2; align-self: center; }
.v4-tl-westgrid > .v4-tl-stage:last-of-type { grid-column: 3; grid-row: 2; }
.v4-tl-stage {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  max-width: 26em;
}
.v4-tl-arrow {
  width: 1.6rem;
  height: 1.6rem;
  align-self: center;
  flex: none;
  color: rgba(212, 168, 67, 0.75);
  margin-left: -7px;
}
.v4-tl-text {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.6;
  color: rgba(245, 237, 214, 0.72);
}

/* ---------------- Small screens ---------------------------------------- */

@media (max-width: 900px) {
  .v4-card {
    height: auto;
    min-height: 0;
    grid-template-rows: none;
    grid-template-columns: 1fr;
    grid-template-areas:
      "media"
      "event"
      "body"
      "timeline";
  }
  .v4-media { min-height: 200px; }
  .v4-tl-event {
    grid-column: auto;
    grid-row: auto;
    grid-area: event;
    border-bottom: 1px solid rgba(212, 168, 67, 0.22);
    background: linear-gradient(160deg, rgba(16, 19, 26, 0.96), rgba(26, 34, 48, 0.93));
  }

  /* Timeline stacks */
  .v4-timeline { flex-direction: column; }
  .v4-tl-event, .v4-tl-west { flex: none; }
  .v4-tl-block { border-right: 0; border-bottom: 1px solid rgba(212, 168, 67, 0.22); }
  .v4-timeline .v4-tl-block:last-child { border-bottom: 0; }
}

/* ---------------- Right-to-right locales (/ar) --------------------------
   Base exhibit.css carries an RTL override ([dir=rtl] .ilm-card) that re-grids
   cards to the old v1 three-column template. That template has no 'timeline'
   area and higher specificity than .v4-card, so on RTL pages the v4 grid
   collapses. Restore the v4 template at equal-or-higher specificity, then let
   the Arabic CONTENT inside flow RTL (layout chrome stays put). */
[dir="rtl"] .v4-card {
  direction: ltr;
  grid-template-columns: 22.5% minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "media body"
    "media timeline";
}
/* Arabic prose flows RTL inside the fixed frame */
[dir="rtl"] .v4-card .ilm-title,
[dir="rtl"] .v4-card .v4-read .post-read-toggle-label,
[dir="rtl"] .v4-card .ilm-origins,
[dir="rtl"] .v4-card .ilm-kicker,
[dir="rtl"] .v4-card .v4-hacc-label,
[dir="rtl"] .v4-card .v4-hacc-title,
[dir="rtl"] .v4-card .v4-hacc-text,
[dir="rtl"] .v4-card .v4-tl-text,
[dir="rtl"] .v4-card .v4-tl-caption,
[dir="rtl"] .v4-card .v4-tl-note,
[dir="rtl"] .ex-title,
[dir="rtl"] .ex-subtitle,
[dir="rtl"] .ex-intro,
[dir="rtl"] .ex-honesty {
  direction: rtl;
}
/* Left-aligned prose flips; centred blocks stay centred */
[dir="rtl"] .ilm-origins {
  justify-content: flex-end;
}
[dir="rtl"] .v4-card .v4-hacc-text,
[dir="rtl"] .v4-card .v4-tl-stage .v4-tl-text {
  text-align: right;
}
/* West-block dates right-align with their RTL text; each caption sits
   right-aligned over its own date. Captions are inline-flex (icon + text):
   the 5px gap spaces icon from label, and row-reverse puts the icon on the
   right where the reading order expects it. */
[dir="rtl"] .v4-card .v4-tl-stage .v4-tl-value {
  text-align: right;
}
[dir="rtl"] .v4-card .v4-tl-westgrid > .v4-tl-caption {
  justify-self: end;
  text-align: right;
  flex-direction: row-reverse;
  gap: 5px;
}
[dir="rtl"] .v4-card .v4-tl-westgrid > .v4-tl-caughtup {
  justify-self: end;
}
/* Arabic text matches the regular post cards: same Naskh/Amiri stack
   (as inherited by [dir=rtl] body on post pages) and comparable sizes. */
[dir="rtl"] .v4-card .ilm-title,
[dir="rtl"] .v4-card .v4-read .post-read-toggle-label,
[dir="rtl"] .v4-card .ilm-origins,
[dir="rtl"] .v4-card .ilm-kicker,
[dir="rtl"] .v4-card .v4-hacc-label,
[dir="rtl"] .v4-card .v4-hacc-title,
[dir="rtl"] .v4-card .v4-hacc-text,
[dir="rtl"] .v4-card .v4-tl-text,
[dir="rtl"] .v4-card .v4-tl-caption,
[dir="rtl"] .v4-card .v4-tl-note,
[dir="rtl"] .ex-title,
[dir="rtl"] .ex-subtitle,
[dir="rtl"] .ex-intro,
[dir="rtl"] .ex-honesty {
  font-family: 'Noto Naskh Arabic', 'Amiri', serif;
}
[dir="rtl"] .v4-card .ilm-title { font-size: 1.25rem; font-weight: 600; }
[dir="rtl"] .v4-card .v4-hacc-text,
[dir="rtl"] .v4-card .v4-tl-text { font-size: 1rem; }
[dir="rtl"] .v4-card .ilm-kicker,
[dir="rtl"] .v4-card .v4-hacc-label,
[dir="rtl"] .v4-card .v4-tl-caption { font-size: 0.85rem; }
[dir="rtl"] .v4-card .v4-tl-note,
[dir="rtl"] .v4-card .v4-read .post-read-toggle-label { font-size: 0.8rem; }

/* Latin-script citations stay LTR so punctuation orders correctly */
[dir="rtl"] .v4-hacc-text--sources {
  direction: ltr;
  text-align: left;
}
