/* Worship Tiles: base styles, mobile fundamentals, menus */

:root {
  --navy-900: #050b1f;
  --navy-800: #0b1a3a;
  --navy-600: #1b3269;
  --gold: #f2c460;
  --gold-deep: #d9a441;
  --cream: #fbf3dc;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Mobile fundamentals (MDD 2.2) ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;           /* no pull-to-refresh / rubber-band */
  background: var(--navy-800);        /* matches the stage, so no dark strip can show at the edges */
}

body {
  position: fixed;                     /* stops iOS from scrolling the page */
  inset: 0;
  display: flex;
  justify-content: center;
  font-family: var(--font-sans);
  color: var(--cream);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; touch-action: manipulation; }

/* ---------- Stage: fixed portrait ratio, scaled by JS via font-size ---------- */
#stage {
  position: relative;
  height: 100%;                              /* fills the fixed body (full screen, incl. the home-indicator area) */
  width: min(100vw, calc(100vh * 0.5625));  /* max 9:16, letterboxed beyond that */
  font-size: 16px;                           /* JS rescales this; all UI sizes use em */
  overflow: hidden;
  background: var(--navy-800);
}

.screen {
  isolation: isolate;
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding:
    calc(env(safe-area-inset-top, 0px) + 1em)
    calc(env(safe-area-inset-right, 0px) + 1.25em)
    calc(env(safe-area-inset-bottom, 0px) + 1em)
    calc(env(safe-area-inset-left, 0px) + 1.25em);
}
.screen.is-active { display: flex; }

.screen--plain {
  background: linear-gradient(180deg, var(--navy-800), var(--navy-600));
  gap: 1em;
}
.screen--plain > .btn--small { align-self: flex-start; }
.screen-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.9em;
  color: var(--gold);
  text-align: center;
}
.placeholder { margin: auto 0; opacity: .7; }

/* ---------- Buttons ---------- */
.btn {
  width: 100%;
  min-height: 3.4em;
  padding: .6em 1.2em;
  border: 1px solid rgba(242, 196, 96, .55);
  border-radius: 1em;
  background: rgba(11, 26, 58, .55);
  color: var(--cream);
  font-size: 1.1em;
  font-weight: 600;
  letter-spacing: .03em;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}
.btn:active { transform: scale(.97); background: rgba(27, 50, 105, .75); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn--primary {
  background: linear-gradient(180deg, #ffe2a0, var(--gold-deep));
  border-color: #fff0c2;
  color: #2a1c05;
  font-size: 1.3em;
  box-shadow: 0 .3em 1.2em rgba(242, 196, 96, .35);
}
.btn--primary:active { background: linear-gradient(180deg, #f5d283, #c4902f); }
.btn--small { width: auto; min-height: 2.75em; padding: .4em 1em; font-size: 1em; }

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 2.75em;
  height: 2.75em;
  border: 1px solid rgba(242, 196, 96, .45);
  border-radius: 50%;
  background: rgba(11, 26, 58, .45);
  font-size: 1.1em;
  cursor: pointer;
}
.icon { width: 1.5em; height: 1.5em; }

/* ---------- Main Menu (MDD 4.1) ---------- */
#screen-menu { justify-content: space-between; }

.menu-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  /* deep navy -> gold dawn */
  background:
    radial-gradient(ellipse 90% 45% at 50% 100%, rgba(255, 226, 160, .75), transparent 70%),
    linear-gradient(180deg, #060f2b 0%, #12285a 40%, #5c4a5e 72%, #e0a84a 100%);
}
/* soft light rays fanning up from the horizon, swaying slowly */
.menu-bg::before {
  content: "";
  position: absolute;
  left: -100%;
  right: -100%;
  bottom: 0;
  height: 200%;
  transform-origin: 50% 100%;
  background: repeating-conic-gradient(from -45deg at 50% 100%,
    rgba(255, 228, 170, .16) 0 4deg, transparent 4deg 12deg);
  -webkit-mask-image: linear-gradient(to top, #000, transparent 55%);
  mask-image: linear-gradient(to top, #000, transparent 55%);
  animation: rays 48s ease-in-out infinite alternate;
}
@keyframes rays {
  from { transform: rotate(-5deg); opacity: .65; }
  to   { transform: rotate(5deg);  opacity: 1; }
}

.topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bank {
  display: flex;
  align-items: center;
  gap: .4em;
  padding: .3em .8em .3em .5em;
  border-radius: 2em;
  background: rgba(11, 26, 58, .45);
  border: 1px solid rgba(242, 196, 96, .45);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#sound-toggle { color: var(--gold); }
#sound-toggle .sound-off { display: none; }
#sound-toggle[aria-pressed="false"] .sound-on { display: none; }
#sound-toggle[aria-pressed="false"] .sound-off { display: inline; }

.hero { text-align: center; }
.cross { width: 2.2em; height: auto; filter: drop-shadow(0 0 .6em rgba(255, 226, 160, .7)); }
.title {
  margin: .15em 0 0;
  font-family: var(--font-serif);
  font-size: 2.9em;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: .02em;
  background: linear-gradient(180deg, #fff6d8, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 .06em .25em rgba(0, 0, 0, .45));
}

.menu-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .8em;
}

.verse {
  text-align: center;
  font-family: var(--font-serif);
  font-size: .95em;
  line-height: 1.4;
  color: var(--navy-800);
  text-shadow: 0 0 .5em rgba(255, 240, 200, .6);
}
.verse p { margin: 0; font-style: italic; }
.verse cite { display: block; margin-top: .2em; font-size: .85em; opacity: .85; }
.sc { font-variant: small-caps; }

/* ---------- How to Play (MDD 4.3) ---------- */
#screen-howto { gap: .75em; }
.cards {
  flex: 1;
  min-height: 0;
  width: calc(100% + 2.5em);           /* bleed to the stage edges for full-width swipes */
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;                 /* the only scroller in the app */
  overscroll-behavior: contain;
}
.cards::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 100%;
  scroll-snap-align: center;
  padding: 0 1.25em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .9em;
  text-align: center;
}
.card-art {
  width: 100%;
  max-height: 46%;
  aspect-ratio: 1;
  border-radius: 1.25em;
  background: rgba(5, 11, 31, .45);
  border: 1px solid rgba(242, 196, 96, .3);
}
.card-step { margin: 0; font-size: .8em; letter-spacing: .15em; text-transform: uppercase; color: var(--gold); }
.card h3 { margin: 0; font-family: var(--font-serif); font-size: 1.6em; }
.card p { margin: 0; line-height: 1.45; opacity: .9; }

.howto-nav { display: flex; align-items: center; gap: 1em; }
.dots { display: flex; gap: .5em; }
.dot { width: .6em; height: .6em; border-radius: 50%; background: rgba(251, 243, 220, .3); transition: background .2s, transform .2s; }
.dot.is-on { background: var(--gold); transform: scale(1.3); }

/* card illustrations */
.art-tile { fill: #f6dc9a; stroke: #fff6d8; stroke-width: 1.5; }
.art-line { stroke: var(--gold); stroke-width: 3; }
.fall { animation: fall 3.2s linear infinite; }
.fall.d2 { animation-delay: -1.1s; }
.fall.d3 { animation-delay: -2.2s; }
@keyframes fall { from { transform: translateY(-70px); } to { transform: translateY(210px); } }
.tap-ring { transform-origin: center; transform-box: fill-box; animation: ring 1.6s ease-out infinite; }
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

/* ---------- Landscape overlay (MDD 2.1): touch devices only ---------- */
#rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  background: var(--navy-900);
  color: var(--cream);
  font-family: var(--font-serif);
  font-size: 1.3rem;
  text-align: center;
}
#rotate-overlay p { margin: 0; padding: 0 1.5em; }
@media (orientation: landscape) and (pointer: coarse) {
  #rotate-overlay { display: flex; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .menu-bg::before, .fall, .tap-ring { animation: none; }
  .btn, .dot { transition: none; }
}

/* ---------- Song Library ---------- */
.song-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: .75em; }
.song-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1em;
  padding: .8em 1em; border: 1px solid rgba(242, 196, 96, .35); border-radius: 1em; background: rgba(5, 11, 31, .4);
}
.song-row div { display: flex; flex-direction: column; gap: .15em; min-width: 0; }
.song-row span { font-size: .85em; opacity: .7; }
.song-row .btn { flex: none; }

/* ---------- Gameplay ---------- */
.screen--game { padding: 0; background: var(--navy-900); }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.pause-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + .5em);
  right: calc(env(safe-area-inset-right, 0px) + 1em);
  color: var(--gold);
}
.pause-btn[hidden], .overlay[hidden], .game-loading[hidden] { display: none; }
.game-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-family: var(--font-serif); font-size: 1.4em; color: var(--gold); }
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .9em;
  padding: 2em 2em; background: rgba(5, 11, 31, .78);
}
.overlay .btn { max-width: 16em; }

/* ---------- Results ---------- */
.res-song { margin: 0; opacity: .8; }
.res-score { margin: 0; font-family: var(--font-serif); font-size: 3.4em; color: var(--gold); line-height: 1; }
.res-stats { width: 100%; margin: .5em 0; display: grid; grid-template-columns: 1fr 1fr; gap: .6em; }
.res-stats div { padding: .6em .8em; border-radius: .8em; background: rgba(5, 11, 31, .4); border: 1px solid rgba(242, 196, 96, .25); }
.res-stats dt { font-size: .8em; opacity: .7; }
.res-stats dd { margin: 0; font-size: 1.4em; font-weight: 700; font-variant-numeric: tabular-nums; }
.screen--plain > .btn:not(.btn--small) { max-width: 20em; }

/* ---------- Library rows + bottom sheet (Phase 3b) ---------- */
button.song-row { width: 100%; text-align: left; align-items: flex-start; flex-direction: column; justify-content: center; color: inherit; cursor: pointer; font: inherit; }
.song-row strong { font-size: 1.1em; }
.sheet { position: absolute; inset: 0; z-index: 10; display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 11, 31, .6); }
.sheet-panel {
  position: relative; width: 100%; display: flex; flex-direction: column; gap: .8em;
  padding: 1.25em 1.25em calc(env(safe-area-inset-bottom, 0px) + 1.25em);
  border-radius: 1.25em 1.25em 0 0; background: linear-gradient(180deg, #14265a, var(--navy-800));
  border-top: 1px solid rgba(242, 196, 96, .5);
}
.sheet-title { margin: 0; font-family: var(--font-serif); font-size: 1.6em; color: var(--gold); }
.sheet-credit, .sheet-reward { margin: 0; font-size: .9em; opacity: .75; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5em; }
.seg { min-height: 2.75em; border-radius: .8em; border: 1px solid rgba(242, 196, 96, .5); background: rgba(5, 11, 31, .5); font-weight: 600; cursor: pointer; }
.seg[aria-pressed="true"] { background: linear-gradient(180deg, #ffe2a0, var(--gold-deep)); color: #2a1c05; }
.seg:disabled { opacity: .5; cursor: not-allowed; }
.sheet-stats { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .5em; text-align: center; }
.sheet-stats dt { font-size: .75em; opacity: .7; }
.sheet-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.res-stars { margin: 0; font-size: 1.8em; letter-spacing: .15em; color: var(--gold); }
.star { display: inline-block; opacity: .25; transform: scale(.5); transition: opacity .3s, transform .35s cubic-bezier(.2, 1.6, .4, 1); }
.star.is-on { opacity: 1; transform: scale(1); }
.res-reward { margin: 0; font-size: .9em; opacity: .8; }
.res-stats { grid-template-columns: 1fr 1fr 1fr; }
.res-stats dd { font-size: 1.2em; }
.res-stats dt { font-size: .7em; }

/* ---------- Economy: store, settings, dialog, results (Phase 5) ---------- */
.song-list { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; align-content: start; }
.song-list > li { flex: none; }
.song-list .empty { text-align: center; opacity: .75; padding: 2em 0; }
.list-heading { margin-top: .5em; font-size: .8em; letter-spacing: .15em; text-transform: uppercase; color: var(--gold); opacity: .8; }
.song-row.locked { background: rgba(5, 11, 31, .25); border-style: dashed; }
.song-row.locked > div { opacity: .55; }
.store-top { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.status { margin: 0; min-height: 1.4em; font-size: .9em; color: var(--gold); text-align: center; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn--danger { border-color: rgba(229, 138, 138, .7); color: #f3b5b5; }
.settings-heading { align-self: flex-start; margin: .5em 0 0; font-family: var(--font-serif); color: var(--gold); }
.settings-note { margin: 0; font-size: .9em; line-height: 1.4; opacity: .75; }
.dialog { z-index: 50; background: rgba(5, 11, 31, .8); }
.dialog-panel {
  width: 100%; display: flex; flex-direction: column; gap: .8em; padding: 1.4em; text-align: center;
  border-radius: 1.2em; background: linear-gradient(180deg, #14265a, var(--navy-800)); border: 1px solid rgba(242, 196, 96, .5);
}
.dialog-panel h3 { margin: 0; font-family: var(--font-serif); font-size: 1.35em; color: var(--gold); }
.dialog-panel p { margin: 0; opacity: .8; line-height: 1.4; }
.scrolls { overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; justify-content: flex-start; }
.res-high { margin: 0; padding: .3em .9em; border-radius: 2em; font-weight: 700; color: #2a1c05; background: linear-gradient(180deg, #ffe2a0, var(--gold-deep)); }
.res-high[hidden] { display: none; }
.res-reward strong { color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- Polish: sliders, calibration, tap targets, contrast (Phase 6) ---------- */
.slider-label { align-self: stretch; display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.slider-label output { color: var(--gold); font-variant-numeric: tabular-nums; }
.slider { width: 100%; height: max(44px, 2.75em); margin: 0; accent-color: var(--gold); touch-action: pan-y; cursor: pointer; }
.cal-stage { flex: 1; min-height: 0; width: 100%; border: 1px solid rgba(242, 196, 96, .3); border-radius: 1em; overflow: hidden; touch-action: none; position: relative; }
.cal-stage canvas { position: absolute; inset: 0; display: block; }
.cal-result { width: 100%; display: flex; flex-direction: column; align-items: center; gap: .6em; }
.cal-average { margin: 0; text-align: center; font-weight: 600; }

/* every control is at least 44x44 CSS px, even when the stage is scaled down on small phones */
.btn { min-height: max(44px, 3.4em); }
.btn--small, .seg { min-height: max(44px, 2.75em); min-width: 44px; }
.icon-btn { min-width: max(44px, 2.75em); height: max(44px, 2.75em); }
.song-row.locked > div { opacity: .75; }
.btn:disabled { opacity: .7; }
.btn--danger { color: #f6c4c4; }

@media (prefers-reduced-motion: reduce) {
  .star { transition: none; }
}
.scrolls > * { flex-shrink: 0 } /* scrolling screens keep each control's full size instead of squeezing it */
.slider { min-height: max(44px, 2.75em); }
.cal-result[hidden] { display: none; }

/* ---------- PWA: update banner, version label ---------- */
.update-banner {
  position: absolute; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + .5em); width: calc(100% - 2.5em);
  min-height: max(44px, 2.75em); padding: .5em 1em; border-radius: 1em; border: 1px solid #fff0c2;
  background: linear-gradient(180deg, #ffe2a0, var(--gold-deep)); color: #2a1c05; font-weight: 700; cursor: pointer;
  box-shadow: 0 .4em 1.2em rgba(0, 0, 0, .4);
}
.update-banner[hidden] { display: none; }
.version { margin: .5em 0 0; text-align: center; font-size: .8em; opacity: .7; }
