/* ==========================================================
   Layouts beyond the phone (styles.css is the phone baseline)

   Chosen by screen SHAPE, not just width:
   1. Tablet portrait   iPad / iPad Pro portrait, Galaxy Fold opened
                        upright: stacked, editorial two-column footer.
   2. Split             iPad landscape, Fold opened sideways, laptops,
                        desktops: copy left, particle Bible right.
   3. Landscape phone   any phone on its side, Fold cover screen
                        sideways: compact split.
   4. Dual screen       Surface Duo / Fold / Flip across a hinge,
                        side-by-side or top-and-bottom: content and
                        Bible on separate screens, never on the hinge.
   ========================================================== */

/* Elements that only exist on larger screens */
.nav,
.scroll-cue { display: none; }

/* Shared look of the scroll cue wherever it appears */
.scroll-cue {
  align-items: center;
  gap: 16px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  transition: color 0.3s;
}

.scroll-cue:lang(ta),
.scroll-cue :lang(ta) {
  font-size: 13px;
  letter-spacing: 0.01em;
  text-transform: none;
}

.scroll-cue:hover { color: var(--fg); }

.scroll-cue__line {
  position: relative;
  flex: none;
  width: 56px;
  height: 1px;
  overflow: hidden;
  background: var(--faint);
}

.scroll-cue__line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--fg);
  transform: translateX(-100%);
  animation: cue 2.4s var(--ease-out) infinite;
}

@keyframes cue {
  0% { transform: translateX(-100%); }
  55% { transform: translateX(0); }
  100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-cue__line::after { animation: none; transform: none; }
}

/* Narrow phones and the Galaxy Fold cover screen (~344–359px):
   buttons share the row evenly instead of wrapping unevenly */
@media (max-width: 359px) {
  :root { --pad: 16px; }
  .actions .btn { flex: 1 1 auto; padding: 0 14px; letter-spacing: 0.1em; }
}

/* ==========================================================
   1. TABLET PORTRAIT
   ========================================================== */
@media (min-width: 600px) and (min-height: 700px) and (max-aspect-ratio: 1/1) and (max-width: 1279px) {
  :root { --pad: clamp(32px, 5.5vw, 96px); }

  .header { padding-top: max(28px, env(safe-area-inset-top)); }
  .logo { font-size: 36px; }
  .logo__sub { font-size: 15px; }
  .header__actions { gap: 12px; }
  .pill { height: 40px; padding: 0 18px; }
  .theme-toggle { width: 40px; height: 40px; }

  .stage { min-height: 40vh; cursor: pointer; }

  /* Copy: full-width headline, then verse (left) beside the buttons (right) */
  .content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: clamp(32px, 5vw, 64px);
    padding-bottom: 28px;
  }

  .content > .eyebrow { grid-column: 1 / -1; }

  .content > .actions {
    grid-column: 2;
    grid-row: 4 / 6;
    align-self: end;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-top: 0;
  }

  .eyebrow { font-size: 12px; }

  .actions .btn {
    height: 56px;
    padding: 0 30px;
    font-size: 12.5px;
  }

  .actions .btn:lang(ta) { font-size: 14px; }

  .scroll-cue {
    display: inline-flex;
    align-self: flex-start;
    padding: 0 var(--pad) max(32px, env(safe-area-inset-bottom));
  }

  .langmenu__list { top: calc(100% + 12px); }
}

/* Shorter tablet-portrait screens (Fold inner, iPad mini in Safari): smaller stage */
@media (min-width: 600px) and (min-height: 700px) and (max-height: 900px) and (max-aspect-ratio: 1/1) {
  .stage { min-height: 32vh; }
  .scroll-cue { padding-bottom: 20px; }
}

/* Smaller tablet-portrait screens (Fold inner, iPad mini): buttons stay a pair */
@media (min-width: 600px) and (max-width: 719px) and (min-height: 700px) and (max-aspect-ratio: 1/1) {
  .content > .actions .btn { padding: 0 22px; }
}

/* ==========================================================
   2. SPLIT: iPad landscape, Fold opened sideways, laptop, desktop
   ========================================================== */
@media (min-width: 720px) and (min-height: 560px) and (min-aspect-ratio: 1/1), (min-width: 1280px) {
  :root {
    /* side gutter; on very wide screens the layout stays within 1560px */
    --gutter: max(clamp(32px, 5.5vw, 96px), calc((100vw - 1560px) / 2));
  }

  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    min-height: max(560px, 100vh);
    min-height: max(560px, 100svh);
  }

  .header {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: max(24px, env(safe-area-inset-top)) var(--gutter) 0;
  }

  .logo { font-size: 36px; }
  .logo__sub { font-size: 15px; }
  .header__actions { gap: 12px; }
  .pill { height: 40px; padding: 0 18px; }
  .theme-toggle { width: 40px; height: 40px; }

  /* Particle stage: right column, full height */
  .stage {
    grid-column: 2;
    grid-row: 1 / -1;
    min-height: 0;
    cursor: pointer; /* click the Bible to skip ahead */
  }

  /* Copy: left column, vertically centred */
  .content {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    /* the gutter sits inside the column, so add it to the text measure */
    max-width: calc(var(--gutter) + 660px);
    padding: 40px 24px 40px var(--gutter);
  }

  .eyebrow { font-size: 12px; }

  .actions { gap: 14px; margin-top: 34px; }

  .actions .btn {
    height: 56px;
    padding: 0 30px;
    font-size: 12.5px;
  }

  .actions .btn:lang(ta) { font-size: 14px; }

  /* Scroll cue (bottom-left) */
  .scroll-cue {
    grid-column: 1;
    grid-row: 3;
    display: inline-flex;
    justify-self: start;
    padding: 0 0 max(32px, env(safe-area-inset-bottom)) var(--gutter);
  }

  .langmenu__list { top: calc(100% + 12px); }
}

/* Narrow split screens (Fold opened sideways, small tablets): keep the buttons a pair */
@media (min-width: 720px) and (max-width: 1023px) and (min-height: 560px) and (min-aspect-ratio: 1/1) {
  .actions .btn {
    height: 50px;
    padding: 0 20px;
    font-size: 11.5px;
    letter-spacing: 0.12em;
  }

  .actions .btn:lang(ta) { font-size: 13px; letter-spacing: 0.01em; }
}

/* Wide screens: give the Bible a little more room and show the nav */
@media (min-width: 1100px) and (min-height: 560px) and (min-aspect-ratio: 1/1), (min-width: 1280px) {
  .hero { grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); }
  .header { padding-top: 28px; }
  .logo { font-size: 38px; }
  .logo__sub { font-size: 16px; }
  .burger { display: none; }

  .nav {
    position: absolute;
    left: 50%;
    top: calc(28px + 4px);
    display: flex;
    gap: clamp(22px, 2.6vw, 44px);
    transform: translateX(-50%);
  }

  .nav a {
    position: relative;
    padding: 12px 0;
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--muted);
    white-space: nowrap;
    transition: color 0.3s;
  }

  .nav a::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    height: 1px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform 0.45s var(--ease-out);
  }

  .nav a:hover,
  .nav a:focus-visible { color: var(--fg); }

  .nav a:hover::after,
  .nav a:focus-visible::after {
    transform: scaleX(1);
    transform-origin: left center;
  }

  .nav a:lang(ta) {
    font-size: 13.5px;
    letter-spacing: 0.01em;
    text-transform: none;
  }
}

/* Short split screens (laptops with browser chrome, iPad landscape in Safari) */
@media (min-width: 720px) and (min-height: 560px) and (max-height: 820px) and (min-aspect-ratio: 1/1) {
  .actions { margin-top: 24px; }
  .content { padding-top: 20px; padding-bottom: 20px; }
}

/* ==========================================================
   3. LANDSCAPE PHONE (and Fold cover screen turned sideways)
   ========================================================== */
@media (max-height: 540px) and (min-width: 560px) and (min-aspect-ratio: 3/2) {
  :root { --pad: max(20px, env(safe-area-inset-left)); }

  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    min-height: 100svh;
  }

  .header {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 10px max(var(--pad), env(safe-area-inset-right)) 0 var(--pad);
  }

  .logo { font-size: 26px; }

  .stage {
    grid-column: 2;
    grid-row: 1 / -1;
    min-height: 0;
  }

  .content {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    padding: 8px 12px 14px var(--pad);
  }

  .eyebrow { font-size: 10px; }
  .actions { margin-top: 14px; gap: 10px; }
  .actions .btn { height: 42px; padding: 0 18px; font-size: 11px; }
}

/* Very short landscape (Fold cover sideways, small phones): drop the extras */
@media (max-height: 400px) and (min-width: 560px) and (min-aspect-ratio: 3/2) {
  .eyebrow { display: none; }
}

/* ==========================================================
   4a. DUAL SCREEN, SIDE BY SIDE (hinge runs top to bottom)
   Surface Duo spanned, Fold spanned in book posture.
   Copy on the left screen, the Bible on the right screen.
   ========================================================== */
@media (horizontal-viewport-segments: 2) {
  :root { --gutter: 28px; }

  .hero {
    display: grid;
    grid-template-columns:
      env(viewport-segment-width 0 0, 1fr)
      calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px))
      env(viewport-segment-width 1 0, 1fr);
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
    min-height: 100svh;
  }

  .header { grid-column: 1 / -1; padding: 20px var(--gutter) 0; }
  .nav { display: none; }
  .burger { display: grid; }

  .stage { grid-column: 3; grid-row: 1 / -1; }

  .content {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    max-width: none;
    padding: 24px var(--gutter);
  }

  .scroll-cue {
    grid-column: 1;
    grid-row: 3;
    display: inline-flex;
    padding: 0 var(--gutter) 24px;
  }

  /* Language menu opens on the right screen, clear of the hinge */
  .langmenu__list { right: 0; }
}

/* ==========================================================
   4b. DUAL SCREEN, TOP AND BOTTOM (hinge runs left to right)
   Galaxy Flip / Fold half-open on a table ("flex mode"),
   Surface Duo rotated. Bible on the top screen, copy below.
   ========================================================== */
@media (vertical-viewport-segments: 2) {
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
      env(viewport-segment-height 0 0, 50vh)
      calc(env(viewport-segment-top 0 1, 0px) - env(viewport-segment-bottom 0 0, 0px))
      env(viewport-segment-height 0 1, 50vh);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .header { grid-column: 1; grid-row: 1; align-self: start; }
  .nav { display: none; }
  .burger { display: grid; }

  .stage { grid-column: 1; grid-row: 1; min-height: 0; }

  .content {
    grid-column: 1;
    grid-row: 3;
    display: block;
    overflow-y: auto;
    max-width: none;
    padding: 18px var(--pad) 18px;
  }

  .content > .actions { flex-direction: row; }
  .eyebrow { font-size: 10px; }
  .actions { margin-top: 14px; }
  .actions .btn { height: 44px; }
  .scroll-cue { display: none; }
}

/* ==========================================================
   Sections below the hero: contained column and a centred
   dialog on tablets and up, until they get their own design.
   ========================================================== */
@media (min-width: 640px) and (min-height: 560px) {
  .finder {
    padding-inline: max(var(--pad), calc((100% - 600px) / 2));
  }

  .popular__row {
    flex-wrap: wrap;
    margin: 12px 0 0;
    padding: 2px 0;
    overflow: visible;
    -webkit-mask-image: none;
            mask-image: none;
  }

  /* bottom sheet becomes a centred dialog */
  .sheet__panel {
    top: 50%;
    bottom: auto;
    left: 0;
    right: 0;
    width: min(560px, calc(100% - 48px));
    height: min(720px, 86vh);
    margin-inline: auto;
    padding-bottom: 0;
    border-bottom: 1px solid rgba(var(--ink), 0.14);
    border-radius: 26px;
    opacity: 0;
    transform: translateY(-46%) scale(0.98);
    transition: transform 0.5s var(--ease-out), opacity 0.3s ease;
  }

  .sheet.is-open .sheet__panel {
    opacity: 1;
    transform: translateY(-50%);
  }

  .sheet__handle { visibility: hidden; height: 0; margin: 6px auto 0; }
  .sheet__grab { cursor: default; }
}

/* Dual screen side by side: finder on the left screen, dialog on the right */
@media (horizontal-viewport-segments: 2) {
  .finder {
    padding-left: var(--pad);
    padding-right: calc(100vw - env(viewport-segment-right 0 0, 50vw) + var(--pad));
  }

  .sheet__panel {
    left: env(viewport-segment-left 1 0, 50vw);
    right: auto;
    width: calc(env(viewport-segment-width 1 0, 50vw) - 32px);
    margin-left: 16px;
  }
}

/* Dual screen top and bottom: the sheet fills the bottom screen */
@media (vertical-viewport-segments: 2) {
  .sheet__panel {
    top: env(viewport-segment-top 0 1, 50vh);
    bottom: 0;
    width: 100%;
    height: auto;
    border-radius: 0;
    transform: translateY(100%);
    opacity: 1;
  }

  .sheet.is-open .sheet__panel { transform: none; }
}

/* ==========================================================
   VERSE FINDER — DESKTOP & iPAD LANDSCAPE
   One panel, four columns: Books | Chapters | Verses | the verse.
   Everything is visible at once, so the picker dialog isn't needed.
   ========================================================== */

.browser { display: none; }

@media (min-width: 1024px) and (min-height: 600px) and (min-aspect-ratio: 1/1), (min-width: 1280px) {
  .finder {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, auto);
    grid-template-areas:
      "intro popular"
      "stage stage";
    align-items: end;
    column-gap: 56px;
    row-gap: 40px;
    padding: 120px var(--gutter) 120px;
  }

  .finder__intro { grid-area: intro; }

  .finder__title {
    font-size: clamp(44px, 4.2vw, 68px);
    letter-spacing: -0.035em;
  }

  .finder__title:lang(ta) { font-size: clamp(30px, 2.7vw, 44px); }
  .finder__lede { max-width: 46ch; font-size: 16px; }

  /* Popular verses sit to the right of the heading */
  .popular {
    grid-area: popular;
    max-width: 560px;
    margin-top: 0;
    justify-self: end;
  }

  .popular__label { text-align: right; }
  .popular__row { justify-content: flex-end; }

  /* The panel */
  .finder__stage {
    grid-area: stage;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    height: clamp(560px, 70vh, 720px);
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
    background: var(--card);
  }

  [data-theme="light"] .finder__stage { box-shadow: 0 40px 80px -40px rgba(0, 0, 0, 0.18); }

  .browser {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
    min-height: 0;
  }

  .browser__col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--line);
  }

  .browser__head {
    flex: none;
    padding: 22px 18px 14px;
  }

  .browser__label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .browser__label :lang(ta),
  .browser__label:lang(ta) { font-size: 12.5px; letter-spacing: 0.01em; text-transform: none; }

  .browser__count {
    letter-spacing: 0.04em;
    color: rgba(var(--ink), 0.4);
    font-variant-numeric: tabular-nums;
  }

  .browser__head .book-filter { height: 42px; margin-top: 14px; font-size: 14px; }
  .browser__head .seg-toggle { margin-top: 8px; }
  .browser__head .seg-toggle button { height: 32px; font-size: 11.5px; }

  .browser__scroll {
    position: relative; /* offsetTop of items is measured against this */
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 12px 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--ink), 0.2) transparent;
  }

  /* Book rows: compact, selected row filled */
  .browser .book {
    min-height: 52px;
    padding: 8px 10px;
    border-bottom: 0;
    border-radius: 12px;
    transition: background-color 0.2s;
  }

  .browser .book__primary { font-size: 15px; }
  .browser .book__secondary { font-size: 12.5px; }
  .browser .book[aria-selected="true"] { background: rgba(var(--ink), 0.08); }
  .browser .book:focus-visible { outline-offset: -1px; }

  /* Number grids */
  .browser .grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    padding: 4px 6px 0;
  }

  .browser .num {
    border-radius: 12px;
    font-size: 14px;
  }

  /* The verse panel (the mobile card, restyled as the fourth column) */
  .finder__stage .finder__card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 20px 28px 24px;
    border: 0;
    border-radius: 0;
    background: rgba(var(--ink), 0.02);
    box-shadow: none;
  }

  .finder__stage .fields { display: none; }

  .finder__stage .ref { padding: 26px 0 18px; }
  .finder__stage .ref__main { font-size: clamp(28px, 2.4vw, 38px); }

  .finder__stage .passage {
    flex: 1;
    min-height: 0;
    margin: 0 0 18px;
    padding: 22px 6px 6px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--ink), 0.2) transparent;
  }

  /* No cap on desktop: the panel scrolls instead */
  .finder__stage .passage__body,
  [data-lang-mode="both"] .finder__stage .passage__body {
    max-height: none;
    -webkit-mask-image: none;
            mask-image: none;
  }

  .finder__stage .passage__more { display: none !important; }
  .finder__stage .passage__text { font-size: 18px; line-height: 1.8; }
  .finder__stage .passage__text--en { font-size: 16px; line-height: 1.65; }
  [data-lang-mode="en"] .finder__stage .passage__text--en { font-size: 18px; }

  .finder__stage .finder__cta { flex: none; margin-top: auto; }
}

/* Smaller desktops / iPad landscape: tighter columns */
@media (min-width: 1024px) and (max-width: 1279px) and (min-height: 600px) and (min-aspect-ratio: 1/1) {
  .finder { padding-top: 96px; padding-bottom: 96px; column-gap: 40px; }
  .finder__stage { grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr); }
  .browser { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr); }
  .browser__head { padding: 18px 14px 12px; }
  .browser__scroll { padding: 2px 8px 16px; }
  .browser .grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
  .finder__stage .finder__card { padding: 16px 20px 20px; }
  .popular { max-width: 420px; }
}

/* Across a hinge (Surface Duo, Fold spanned): no four-column panel;
   keep the card on the left screen and the picker dialog on the right */
@media (horizontal-viewport-segments: 2) {
  .browser { display: none; }

  .finder {
    display: block;
    padding: 88px calc(100vw - env(viewport-segment-right 0 0, 50vw) + var(--pad)) 72px var(--pad);
  }

  .popular { margin-top: 30px; max-width: none; }
  .popular__label { text-align: left; }
  .popular__row { justify-content: flex-start; }

  .finder__stage {
    display: block;
    height: auto;
    border: 0;
    border-radius: 0;
    overflow: visible;
    background: none;
    box-shadow: none;
  }

  .finder__stage .finder__card {
    display: block;
    margin-top: 30px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: radial-gradient(120% 60% at 50% 0%, rgba(var(--ink), 0.05), transparent 70%), var(--card);
  }

  .finder__stage .fields { display: grid; }
  .finder__stage .passage { overflow: visible; margin: -6px 4px 20px; padding: 18px 14px 4px; }
  .finder__stage .passage__body { max-height: 13.5rem; }
  .finder__stage .passage__more { display: inline-flex !important; }
  .finder__stage .passage__more[hidden] { display: none !important; }
}

/* Landscape tablets and desktop: Bible centred, button centred beneath it */
@media (min-width: 720px) and (min-height: 560px) and (min-aspect-ratio: 1/1), (min-width: 1280px) and (min-height: 560px) {
  .hero { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .stage { grid-column: 1; grid-row: 2; }
  .content { grid-column: 1; grid-row: 3; justify-self: center; max-width: none; padding: 0 0 20px; }
  .actions { margin-top: 0; }
  .scroll-cue { grid-column: 1; grid-row: 4; justify-self: center; padding-left: 0; }
}
