/*
 * Stylesheet für Bibelheld (modern, kinderfreundlich)
 * - Warme Farben, große Klickflächen
 * - Sticky Navbar mit sanfter Dropdown-Animation
 * - Zentrierter Content-Bereich
 * - Verbesserte Darstellung von Kapiteln und Bildern
 */

/* Dyslexic-friendly font (OpenDyslexic via jsdelivr) */
/* Base */
html { box-sizing: border-box; font-size: 16px; }
*, *::before, *::after { box-sizing: inherit; }
/* Brand tokens */
:root{
  --color-brand: #2259be; /* Book Blue */
  --color-cape: #9c2222;  /* Coral */
  --color-gold: #FFC145;  /* Gold */
  --color-leaf: #2EB67D;  /* Leaf */
  --color-ink: #1E1E2A;   /* Text */
  --color-warm-paper: #FFF9F2; /* Warm background */
  --color-cloud: #F3F6FB; /* Light card */
  --color-stone: #C7CCD6; /* Lines */
  --shadow-1: 0 2px 8px rgba(0,0,0,.06);
  --radius-card: 16px;
}
/* Ensure outer document doesn't scroll; iframe provides scrolling */
/* Limit no-scroll rule to the app shell (parent), not stories in the iframe */
html.bh-shell, body.bh-shell { height: 100%; overflow: hidden; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; line-height: 1.5; background: var(--color-warm-paper); color: var(--color-ink); display: flex; flex-direction: column; min-height: 100dvh; }
/* Reserve space for icon glyphs before the icon font loads to avoid CLS */
i.bi { display: inline-block; width: 1em; height: 1em; }
/* Global heading typography: use system font to avoid CLS */
h1, h2, h3, h4, h5, h6, .card-title {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  letter-spacing: .01em;
}
h1 { font-weight: 800; }
h2, h3, h4, h5, h6, .card-title { font-weight: 700; }
/* Reserve viewport for iframe area to avoid CLS */
/* Conservative default (navbar + footer) to reduce early shifts */
:root { --bh-chrome: 120px; --bh-vh: 100vh; }
/* Use dynamic viewport height where supported, fallback to JS-updated --bh-vh */
#contentWrap { min-height: calc(var(--bh-vh) - var(--bh-chrome)); }
#storyFrame { min-height: calc(var(--bh-vh) - var(--bh-chrome)); }
@supports (height: 100dvh) {
  #contentWrap { min-height: calc(100dvh - var(--bh-chrome)); }
  #storyFrame { min-height: calc(100dvh - var(--bh-chrome)); }
}
/* Respect iOS safe area so footer is not obscured by home indicator */
.footer { padding-bottom: calc(env(safe-area-inset-bottom, 0px)); margin-bottom: var(--bh-ios-bottom, 0px); }

/* Critical ratio utility (Bootstrap-lite) to avoid CLS before Bootstrap loads */
.ratio { position: relative; width: 100%; }
.ratio::before { display: block; padding-top: var(--bs-aspect-ratio, 56.25%); content: ""; }
.ratio > * { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.ratio-1x1 { --bs-aspect-ratio: 100%; }
.ratio-4x3 { --bs-aspect-ratio: calc(3/4 * 100%); }
.ratio-16x9 { --bs-aspect-ratio: calc(9/16 * 100%); }
.ratio-21x9 { --bs-aspect-ratio: calc(9/21 * 100%); }

/* Stabilize major chrome heights early */
.navbar { min-height: 56px; }
#storyToolbar { min-height: 48px; }
#bhCenterControls { white-space: nowrap; }
.footer { min-height: 64px; }

/* Skip link helper: hidden until focused */
.visually-hidden-focusable:not(:focus):not(:focus-within) {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Mode toggles */
/* Kid Mode scales root font size so rem-based headings remain larger */
html.bh-kid-mode { font-size: 18px; }
html.bh-kid-mode .bh-tile-summary { display: none !important; }
html.bh-kid-mode [data-bh-music] { display: none !important; }
html.bh-kid-mode .bh-filter-row,
html.bh-kid-mode .bh-tag-suggestions { display: none !important; }
/* Ensure headings are larger than subtitles in Kid Mode */
html.bh-kid-mode h5,
html.bh-kid-mode .h5,
html.bh-kid-mode .card-title { font-size: 1.4rem; line-height: 1.3; }
html.bh-kid-mode .bh-tile-subtitle { font-size: 1rem; }

/* Navbar */
.navbar { background-color: var(--color-warm-paper); border-bottom: 1px solid #E9ECF2; }
.navbar > .container { position: relative; }
.navbar .navbar-brand { font-weight: 800; color: var(--color-ink); display: inline-flex; align-items: center; gap: .5rem; }
.navbar .navbar-brand:hover { color: var(--color-ink); }
.navbar .navbar-brand span { color: var(--color-brand); text-transform: uppercase; }
/* When brand is used as a primary button, ensure text is white */
.navbar .navbar-brand.btn { color: #fff; }
.navbar .navbar-brand.btn:hover { color: #fff; }
.navbar .navbar-brand.btn span { color: #fff; }
.navbar .nav-link { color: var(--color-ink); border-radius: .5rem; font-weight: 600; }
.navbar .nav-link:hover, .navbar .nav-link.active { background: rgba(58,124,247,.12); color: var(--color-ink); }
.navbar .navbar-toggler { border-color: rgba(0,0,0,.15); }
.navbar .navbar-toggler-icon { filter: invert(0.3); }
/* Show hamburger menu only under 450px. Between 450px and 992px keep navbar expanded. */
@media (max-width: 991.98px) {
  .navbar .navbar-toggler { display: none !important; }
}
@media (max-width: 449.98px) {
  /* No hamburger on small screens; show small language dropdown instead */
  .navbar .navbar-toggler { display: none !important; }
  #langDropdownSm { display: inline-block !important; }
}
@media (min-width: 450px) {
  #langDropdownSm { display: none !important; }
}
/* Keep collapse on the same row between 450px and 992px */
@media (min-width: 450px) and (max-width: 991.98px) {
  .navbar .navbar-collapse {
    display: flex !important;
    flex-basis: auto !important;
    align-items: center !important;
    width: auto !important;
  }
}

/* Center the Kid Mode button in the main navbar on >=450px */
@media (min-width: 450px) {
  #btnKidMode {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2; /* stay above background */
  }
}
@media (max-width: 449.98px) {
  #btnKidMode { position: static; transform: none; display: none !important; }
  #langDropdown, #langBtn, #langMenu { display: none !important; }
}
/* Stretch navbar containers to full width on small/mid screens to free horizontal space */
@media (max-width: 991.98px) {
  .navbar > .container { max-width: 100% !important; padding-left: .5rem; padding-right: .5rem; }
}

/* Dropdown animation (CSS only) */
.dropdown-menu { opacity: 0; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; border-radius: .5rem; }
.dropdown-menu.show { opacity: 1; transform: translateY(0); }
.dropdown-menu { max-height: 60vh; overflow-y: auto; }

/* Buttons */
.btn { border-radius: 12px; padding: 10px 14px; font-weight: 700; border-width: 2px; }
.form-control,
.form-select,
input,
select,
button,
.btn { font-family: inherit; }
.btn-outline-primary { color: var(--color-brand); border-color: var(--color-brand); background: #fff; }
.btn-outline-primary:hover { background-color: var(--color-brand); color: #fff; }
.btn-primary { background-color: var(--color-brand); border-color: var(--color-brand); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { filter: saturate(110%); }
/* Accessible outline button: strong contrast on white, dark red */
:root { --color-cape-strong: #B22222; }
.btn-outline-secondary { color: var(--color-cape-strong); border-color: var(--color-cape-strong); background: #fff; }
.btn-outline-secondary:hover, .btn-outline-secondary:focus { background: var(--color-cape-strong); color: #fff; border-color: var(--color-cape-strong); }

/* Welcome & iframe container */
#contentWrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#contentWrap > .row { flex: 1 1 auto; min-height: 0; display: flex; }
#contentWrap > .row > [class^="col-"],
#contentWrap > .row > [class*=" col-"] { min-height: 0; display: flex; }
#storyFrame { background: #fff; border-radius: .5rem; box-shadow: 0 2px 4px rgba(0,0,0,.1); min-height: 0; flex: 1 1 auto; height: auto; }
#welcomeMessage, #storyTiles { display: none !important; }
#welcomeMessage { background: #fff9f0; border-radius: .5rem; box-shadow: 0 2px 4px rgba(0,0,0,.1); }

/* Active story link */
.story-link.active { font-weight: 700; color: #b32f45; }

/* Story content helpers (applies inside iframe, too, when classes exist) */
.main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.header { margin-top: 1.25rem; }
.chapter .row { margin-bottom: 1.5rem; }
.chapter .col-md-6 img { width: 100%; height: auto; border-radius: .5rem; display: block; }
.verse, .crafts, .games, .summary, .prayer, .song, .takeaway, .reflections { background: #fff; border-radius: .5rem; box-shadow: 0 1px 2px rgba(0,0,0,.06); padding: 1rem; margin-top: 1rem; }
/* Highlight Bible verse blocks consistently (match PDF coral accent) */
.verse { border-left: 6px solid var(--color-cape); margin-bottom: 10px; }
.verse h4.bh-section-title { color: var(--color-cape); margin-top: 0; }
/* Back-compat if a story still uses a leading <strong> label */
.verse strong { color: var(--color-cape); }

/* Hero + Tags */
.bh-hero h2 { color: #333; }
.bh-tag { display: inline-block; padding: .2rem .6rem; border-radius: 999px; background: #fff; border: 1px solid #E9ECF2; color: var(--color-ink); font-size: .8rem; line-height: 1.2; box-shadow: var(--shadow-1); font-family: inherit; }

/* Tile tag overlays */
.bh-tile-media { position: relative; overflow: hidden; }
.bh-tile-media .bh-tile-tags { position: absolute; inset: 0; pointer-events: none; }
/* Ensure image fills and centers within ratio for consistent cropping */
.bh-tile-media > img.card-img-top {
  display: block;
  position: absolute !important;
  top: 50%;
  left: 50%;
  right: auto !important;
  bottom: auto !important;
  transform: translate(-50%, -50%);
  height: 100%;
  width: auto;
  min-width: 100%;
  min-height: 100%;
}
.bh-tile-media .bh-tag { position: absolute; z-index: 2; background: rgba(255,255,255,.9); -webkit-backdrop-filter: saturate(120%) blur(2px); backdrop-filter: saturate(120%) blur(2px); border-color: rgba(0,0,0,.1); }
/* For safety: neutralize Bootstrap .ratio > * rule for tags if they are direct children in other contexts */
.ratio > .bh-tag { position: absolute; top: auto !important; right: auto !important; bottom: auto !important; left: auto !important; width: auto !important; height: auto !important; }
.bh-tag--date { top: 8px; left: 8px; right: auto; bottom: auto; }
.bh-tag--hero { top: 8px; right: 8px; left: auto; bottom: auto; }
.bh-tag--age { bottom: 8px; left: 8px; top: auto; right: auto; opacity: 1; transform: none; }

/* Detail view tags under subtitle */
.bh-detail-tags { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .25rem; }

/* Footer */
.footer { background: var(--color-warm-paper); color: var(--color-ink); border-top: 1px solid #E9ECF2; margin-top: auto; }
/* Centering anchor for absolute-positioned audio controls; be robust to container variants */
.footer > .container,
.footer > .container-fluid,
.footer .container,
.footer .container-fluid { position: relative; }
.footer #bhFooterActions { display: flex; gap: .5rem; align-items: center; }
/* Danke uses same base button sizing as Share; only colors differ */
.footer #bhFooterActions .btn,
.footer #bhFooterActions .bmc-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1; padding: 10px 14px; border-width: 2px; }
.footer #bhFooterActions .bmc-btn { background-color: #FFDD00; color: #000; border: 2px solid #000; border-radius: 12px; font-weight: 700; text-decoration: none; }
.footer #bhFooterActions .bmc-btn:hover { filter: brightness(0.95); color: #000; }
.footer #bhFooterActions .bmc-btn img { height: 1.1rem; width: auto; display: inline-block; }
.footer #bhFooterActions .btn i { font-size: 1.1rem; line-height: 1; display: inline-block; }
/* Under 770px show icon-only (hide text labels) to keep one row */
@media (max-width: 769.98px) {
  .footer #bhFooterActions .btn span { display: none !important; }
}
/* Hide Danke button on very small screens (<400px) */
@media (max-width: 399.98px) {
  .footer #bhFooterActions .bmc-btn { display: none !important; }
}
/* Under 992px hide copyright text; show only copyright button */
@media (max-width: 991.98px) {
  .footer .bh-copyright-text { display: none !important; }
}
/* On touch devices (iOS/Android), always hide long copyright text to free space */
@media (hover: none) and (pointer: coarse) {
  .footer .bh-copyright-text { display: none !important; }
}

/* Footer audio controls centered */
.footer .bh-audio-controls { position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: .5rem; }
.footer .bh-audio-controls .btn { padding: 8px 12px; border-radius: 999px; }
.footer .bh-audio-controls .btn i { font-size: 1.25rem; line-height: 1; }
@media (max-width: 575.98px) {
  .footer .bh-audio-controls { gap: .25rem; }
}
.card { border-radius: var(--radius-card); box-shadow: var(--shadow-1); border: 1px solid #E9ECF2; overflow: hidden; }

/* Focus visible for accessibility */
:focus-visible { outline: 3px solid var(--color-gold); outline-offset: 2px; }

/* Story toolbar layout helpers */
#storyToolbar .container { position: relative; }
#bhCenterControls { position: absolute; left: 50%; transform: translateX(-50%); }
#storyToolbar .vr { display: none !important; }

/* Print (used by our export) */
@media print { .navbar, .footer, #exportBtn { display: none !important; } }

/* Small screens */
@media (max-width: 768px) {
  .navbar .nav-link { margin-bottom: .25rem; }
}

/* Mobile optimizations */
/* Under 800px: hide tile summaries and tile button labels (icons only) */
@media (max-width: 800px) {
  .bh-tile-summary { display: none !important; }
  .bh-tile-btn-label { display: none !important; }
}
/* Under 1423px: keep tile buttons single-line by hiding labels when space is tight */
@media (max-width: 1423px) {
  .bh-tile-btn-label { display: none !important; }
}
/* Hide bottom gallery on small screens (<800px) */
@media (max-width: 799.98px) {
  .bh-bottom-gallery { display: none !important; }
}

/* Interleave-on-mobile styles (also injected in iframe by JS) */
/* Default: duplicates hidden on larger screens */
img.bh-inline-img { display: none !important; }
@media (max-width: 790px) {
  /* Hide original left-column images only when row is marked as interleaved */
  .chapter .row[data-bh-interleaved="1"] .col-md-6:first-child img { display: none !important; }
  /* Show inline duplicates inside text on small screens; keep natural aspect */
  img.bh-inline-img { display: block !important; max-width: 100%; width: auto; height: auto; object-fit: contain; }
}

/* (reverted svg icon baseline; using icon font) */

/* Avoid two-line tile buttons between ~1016px and 1225px: show icons only */
@media (min-width: 1016px) and (max-width: 1225px) {
  .bh-tile-btn-label { display: none !important; }
}

/* Toolbar tweaks for very small screens */
@media (max-width: 650px) {
  /* Back button: show icon only to avoid overlap */
  #storyToolbar .container { flex-wrap: wrap; }
  #storyToolbar #btnBack { font-size: 0; }
  #storyToolbar #btnBack i { font-size: 1rem; margin-right: 0; }
  /* Export: icon only */
  #storyToolbar #btnExport { font-size: 0; }
  #storyToolbar #btnExport i { font-size: 1rem; margin-right: 0; }
  /* Reading: icon only */
  #storyToolbar #btnReading { font-size: 0; }
  #storyToolbar #btnReading i { font-size: 1rem; margin-right: 0; }
  /* Center controls should flow in layout */
  #bhCenterControls { position: static; transform: none; margin-left: auto; margin-right: auto; }
}
/* Early base toggles to prevent FOUC while Bootstrap CSS defers */
.collapse:not(.show) { display: none; }
.dropdown-menu { display: none; position: absolute; }
.dropdown-menu.show { display: block; }

/* Music services dropdown: keep custom caret icon, hide Bootstrap's default ::after caret */
[data-bh-music-menu] .dropdown-toggle::after { display: none !important; }
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-dialog { margin: 1rem; max-width: 90vw; width: auto; }
.modal-content { background: #fff; border-radius: .5rem; box-shadow: 0 10px 20px rgba(0,0,0,.15); max-height: 90vh; overflow: auto; }
.modal-header, .modal-body, .modal-footer { padding: 1rem; }
.modal-header { border-bottom: 1px solid #eee; }
.modal-footer { border-top: 1px solid #eee; }
#pdfOptionsModal .modal-dialog { width: 75vw; max-width: 75vw; margin-left: auto; margin-right: auto; }
@media (min-width: 1500px) {
  #pdfOptionsModal .modal-dialog { width: 33.333vw; max-width: 33.333vw; }
}
