/* Śiva-temple theme + responsive layout layer. Loaded after the base styles.
   One rule governs alignment everywhere: every direct child of #app, the header and the footer
   share the same gutter and max width, so nothing drifts at any screen size. */
:root {
  --night: #0d1418; --night2: #16222a; --stone: #f2eee3; --saffron: #e09a3e;
  --paper: #f2eee3; --paper-card: #faf7ef; --orange: #b5622a; --green: #1d3a36; --line: #ddd7c6;
  --gutter: clamp(16px, 5vw, 56px);
  --maxw: 1120px;
  --edge: max(var(--gutter), calc((100% - var(--maxw)) / 2));
}
@media (min-width: 1700px) { :root { --maxw: 1320px; } }
@media (min-width: 2200px) { :root { --maxw: 1520px; } }

html { -webkit-text-size-adjust: 100%; }
body { background: var(--stone); }
img, svg, canvas, video { max-width: 100%; }

/* ---- Shared alignment: header, content, footer ---- */
.wrap { max-width: none; width: 100%; padding: 32px 0 72px; }
#app > *:not(.temple-hero) { margin-left: var(--edge); margin-right: var(--edge); min-width: 0; }
header { height: auto; min-height: 64px; padding: 8px var(--edge); gap: 16px; background: var(--night); border-bottom: 1px solid #25343b; backdrop-filter: none; }
.page-footer { padding: 24px var(--edge); background: var(--night); color: #7f918e; border-top: 0; justify-content: center; }
.page-footer span:last-child { display: none; }

/* ---- Header ---- */
.brand { color: #f1ead9; font-size: 22px; letter-spacing: .5px; flex-shrink: 0; }
.seal { color: var(--saffron); font-size: 26px; }
nav { gap: clamp(16px, 2.4vw, 32px); }
nav button { color: #9fb0ad; font-size: 14px; white-space: nowrap; }
nav button:hover { color: #f1ead9; }
nav button.active { color: var(--saffron); }
nav button.active::after { background: var(--saffron); }
nav [data-page="journey"], .stats, .story-feature, .band, #toggleSanskritBtn, #audioInfo,
.section-head .actions { display: none !important; }
.pill { background: transparent; border-color: #34464d; color: #b7c4c1; white-space: nowrap; }
.header-pills button.pill:hover { background: #1b2a31; border-color: var(--saffron); color: #f1ead9; }

/* ---- Home hero: a temple at night ---- */
.temple-hero { position: relative; margin: -32px 0 0; min-height: 540px; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
  background:
    radial-gradient(1.2px 1.2px at 8% 18%, #fff, transparent), radial-gradient(1px 1px at 22% 38%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 41% 12%, #fff, transparent), radial-gradient(1px 1px at 55% 30%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 73% 9%, #fff, transparent), radial-gradient(1px 1px at 90% 26%, #fff, transparent),
    linear-gradient(#091016, #1f3641 75%, #2a4450); }
.temple-hero-text { position: relative; z-index: 2; padding: 72px var(--edge) 28px; max-width: calc(var(--edge) + 640px); color: #f1ead9; box-sizing: content-box; }
.temple-hero-text > * { max-width: 560px; }
.temple-hero .eyebrow { color: var(--saffron); letter-spacing: 3px; }
.temple-hero h1 { font-size: clamp(36px, 5.2vw, 62px); margin: 14px 0 16px; }
.temple-hero p { color: #c3cfcc; font-size: clamp(15px, 1.4vw, 17px); margin: 0; }
.temple-art { position: relative; z-index: 1; display: block; width: 100%; height: auto; aspect-ratio: 1200 / 560; margin-top: -24px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); }
@media (min-width: 900px) {
  .temple-hero { min-height: 600px; }
  .temple-hero-text { padding-bottom: 72px; }
  .temple-art { position: absolute; bottom: 0; right: max(0px, calc((100% - var(--maxw)) / 2 - 140px)); width: min(1200px, 100%); margin: 0; z-index: 1; }
  .temple-hero::after { content: ""; position: absolute; inset: 0; z-index: 1; background: linear-gradient(90deg, rgba(8,13,17,.7), transparent 55%); pointer-events: none; }
}
.btn { min-height: 44px; }
.btn.gold { background: var(--saffron); border-color: var(--saffron); color: #1a1209; font-weight: 600; }
.btn.gold:hover { background: #eaa94f; }
.btn.ghost { background: transparent; border-color: #55696d; color: #f1ead9; }
.btn.ghost:hover { background: rgba(255,255,255,.08); }
.flame { animation: fl 2.4s ease-in-out infinite alternate; }
.tw circle { animation: tw 4s ease-in-out infinite alternate; }
.tw circle:nth-child(3n) { animation-delay: -1.3s; } .tw circle:nth-child(3n+1) { animation-delay: -2.6s; }
@keyframes fl { to { opacity: .55; } }
@keyframes tw { to { opacity: .25; } }

/* ---- Home sections ---- */
.home-sec { margin-top: clamp(40px, 7vw, 72px); }
.home-sec h2 { font-size: clamp(24px, 3vw, 30px); margin: 6px 0 20px; }
.stories-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.story-card { position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 220px; padding: 22px; border-radius: 12px; color: #f1ead9; overflow: hidden; background: linear-gradient(160deg, var(--g1), var(--g2)); transition: transform .2s ease; }
.story-card:hover { transform: translateY(-3px); }
.story-card .glyph { position: absolute; top: 12px; right: 20px; font-size: 60px; opacity: .22; font-family: Georgia, serif; }
.story-card .chip { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--saffron); font-weight: 700; }
.story-card h3 { margin: 6px 0 4px; font-size: 21px; color: #fff; }
.story-card span.sub { font-size: 13px; color: #b9c7c4; }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.card { padding: 22px; box-shadow: none; }
.card footer { display: none; }
.card p { margin: 4px 0 0; }

/* ---- Inner pages: grids that can shrink (fixes cards bleeding off the right edge) ---- */
.story-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; }
.lesson-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.notes-grid { grid-template-columns: minmax(0, 1fr); }
.notes-grid .panel:nth-child(2) { display: none; }
.story-layout > *, .lesson-grid > *, .notes-grid > *, .cinema, .cinema-wrap, .panel, .card { min-width: 0; }
.story-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.story-picker a { padding: 9px 16px; border: 1px solid var(--line); border-radius: 22px; font-size: 13.5px; color: var(--muted); background: #fff; white-space: nowrap; }
.story-picker a.on { background: var(--night); border-color: var(--night); color: #f1ead9; }
.cinema-wrap { transition: none; box-shadow: 0 12px 40px rgba(8,13,17,.3); }
.cinema, .movie-subtitles, .movie-controls { background: var(--night2); }
.movie-subtitles { border-top-color: #22333a; }
.sub-sanskrit { color: var(--saffron); }
.movie-controls.single-bar { flex-wrap: wrap; }
.movie-controls.single-bar #movieSeek { flex: 1 1 140px; min-width: 100px; }
.movie-controls .control-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.search, .label { max-width: 100%; }

/* ---- Tablet ---- */
@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .story-layout, .lesson-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Phone: slim header, thumb-reach bottom navigation ---- */
@media (max-width: 720px) {
  header { flex-wrap: nowrap; justify-content: space-between; padding-top: 6px; padding-bottom: 6px; min-height: 56px; }
  .brand { font-size: 20px; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 150; width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; overflow: visible; white-space: normal;
    background: var(--night); border-top: 1px solid #25343b; padding-bottom: env(safe-area-inset-bottom); }
  nav button { padding: 12px 2px 10px; font-size: 11.5px; text-align: center; min-height: 52px; }
  nav button.active::after { top: 0; bottom: auto; height: 3px; left: 20%; right: 20%; }
  .page-footer { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .wrap { padding-top: 24px; }
  .temple-hero { margin-top: -24px; min-height: 0; }
  .temple-hero-text { padding-top: 48px; }
  .stories-row, .cards { grid-template-columns: minmax(0, 1fr); }
  .story-card { min-height: 170px; }
  .story-picker { flex-wrap: nowrap; overflow-x: auto; margin-inline: calc(var(--edge) * -1); padding: 0 var(--edge) 6px; scrollbar-width: none; }
  .story-picker::-webkit-scrollbar { display: none; }
  .movie-controls button, .movie-controls select { min-height: 40px; }
  .movie-controls .control-group { margin-left: 0; width: 100%; }
  .movie-subtitles { padding: 14px 16px; min-height: 0; font-size: 15px; }
  .toast { bottom: 76px; }
}
@media (max-width: 380px) { nav button { font-size: 10.5px; } .temple-hero h1 { font-size: 32px; } }
@media (prefers-reduced-motion: reduce) { .flame, .tw circle { animation: none; } * { scroll-behavior: auto !important; } }

/* ---- Fixes from the screen-size audit ---- */
#app > .search, #app > input.search { display: block; width: calc(100% - 2 * var(--edge)); box-sizing: border-box; }
.player { flex-wrap: wrap; row-gap: 8px; }
.player input[type="range"] { flex: 1 1 90px; min-width: 70px; }
.player button, .player select { min-height: 40px; }
@media (max-width: 899px) { .temple-art { aspect-ratio: auto; height: clamp(170px, 36vw, 290px); } }
.cinema-tabs { flex-wrap: nowrap; }
@media (max-width: 720px) {
  .story-header-nav { gap: 10px; }
  .cinema-tabs { width: 100%; }
  .cinema-tabs .pill-btn { flex: 1 1 0; padding: 9px 8px; font-size: 12.5px; min-height: 40px; }
}
@media (max-width: 899px) { .temple-art { margin-top: 0; } .temple-hero-text { background: linear-gradient(#17282f, #0d1a20); } }
