:root {
  --clr-bg: #fdf6f0;
  --clr-surface: #ffffff;
  --clr-primary: #c0392b;
  --clr-primary-light: #e74c3c;
  --clr-text: #2c1810;
  --clr-text-muted: #6b5345;
  --clr-accent: #d4a574;
  --clr-border: #e8d5c4;
  --clr-glow: rgba(192, 57, 43, 0.12);
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Reused inside the embedded app shell */
  --bg: var(--clr-surface);
  --bg-soft: #f7eee5;
  --fg: var(--clr-text);
  --fg-soft: var(--clr-text-muted);
  --divider: var(--clr-border);
  --tint: var(--clr-primary);
  --tint-bg: var(--clr-glow);
  --pill-bg: rgba(192, 57, 43, 0.06);
  --pill-border: var(--clr-border);

  --header-h: 48px;
  --footer-h: 110px;
  --chrome-anim-ms: 240ms;
}
@media (max-width: 520px) {
  :root {
    --header-h: 44px;
    --footer-h: 96px;
  }
}

html.dark {
  --clr-bg: #1b1410;
  --clr-surface: #2c211a;
  --clr-text: #f3e9dc;
  --clr-text-muted: #c1a48d;
  --clr-border: rgba(232, 213, 196, 0.18);
  --clr-glow: rgba(231, 76, 60, 0.18);
  --bg: var(--clr-surface);
  --bg-soft: #382a22;
  --fg: var(--clr-text);
  --fg-soft: var(--clr-text-muted);
  --divider: var(--clr-border);
  --pill-bg: rgba(255, 255, 255, 0.06);
  --pill-border: var(--clr-border);
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  background: var(--clr-bg);
  color: var(--clr-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01";
  overflow: hidden; /* the app middle is the only scroll surface */
}

/* ── HEADER ─────────────────────────────────────────────────────── */
#site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(253, 246, 240, 0.92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--clr-border);
  transition: transform var(--chrome-anim-ms) ease;
}
body.chrome-hidden #site-header {
  transform: translateY(-100%);
}
html.dark #site-header {
  background: rgba(27, 20, 16, 0.92);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  height: var(--header-h);
}
@media (max-width: 520px) {
  .header-inner {
    padding: 0 0.9rem;
  }
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--clr-primary);
  letter-spacing: -0.02em;
  text-decoration: none;
  line-height: 1;
}
@media (max-width: 520px) {
  .logo {
    font-size: 1.05rem;
  }
}
.logo span {
  color: var(--clr-accent);
}

.lang-switcher {
  display: flex;
  gap: 4px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 100px;
  padding: 4px;
  box-shadow: 0 1px 4px rgba(44, 24, 16, 0.06);
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 0;
  border-radius: 100px;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--clr-text-muted);
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}
.lang-btn:hover {
  color: var(--clr-text);
  background: rgba(212, 165, 116, 0.12);
}
.lang-btn.active {
  background: var(--clr-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(192, 57, 43, 0.3);
}
.lang-btn .flag {
  font-size: 1.1rem;
  line-height: 1;
}
@media (max-width: 520px) {
  .lang-btn {
    padding: 7px 12px;
    font-size: 0.78rem;
  }
  .lang-btn .label {
    display: none;
  }
  .lang-btn .flag {
    font-size: 1.25rem;
  }
}

/* ── APP (the scrollable iframe-like middle) ────────────────────── */
#app {
  position: fixed;
  top: var(--header-h);
  bottom: var(--footer-h);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  background: var(--bg);
  transition: top var(--chrome-anim-ms) ease,
    bottom var(--chrome-anim-ms) ease;
}
body.chrome-hidden #app {
  top: 0;
  bottom: 0;
}

/* When the cookie banner is showing, lift the app off the banner. */
body.cookie-shown #app {
  bottom: calc(var(--footer-h) + 64px);
}

.topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
  flex-shrink: 0;
}

.back-btn {
  background: transparent;
  border: 0;
  font-size: 30px;
  color: var(--fg);
  cursor: pointer;
  padding: 0 10px 4px;
  visibility: hidden;
}
.back-btn.visible {
  visibility: visible;
}

.title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--fg);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  line-height: 1;
}
.icon-btn:hover {
  color: var(--tint);
}
.icon-btn.active {
  color: var(--tint);
}
.icon-btn svg {
  display: block;
}

/* Main scroll surface */
.view {
  flex: 1;
  overflow-y: auto;
  /* Bottom padding leaves room for the floating tab-bar AND, on
     song-details, the pinned prev/next nav-row that sits above
     it. Without this the last lines of lyrics would be hidden
     behind the pinned controls. */
  padding: 24px 22px 170px;
  /* Stop scroll chaining + rubber-band bounces at the edges. On
     short songs the previous version would let iOS Safari elastic-
     bounce the content, and the rubber-band motion was triggering
     our chrome show/hide listener in an infinite loop. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-soft);
  margin: 18px 0 6px;
}

.flag-bar {
  display: flex;
  /* Wrap to a second row instead of overflowing horizontally when the
     screen is too narrow to fit all language flags. */
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 22px;
  padding: 6px 0 18px;
}
.flag-bar .flag {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 6px;
  font-size: 34px;
  line-height: 1;
  border-radius: 50%;
  transition: transform 120ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.flag-bar .flag.globe {
  color: var(--tint);
}
.flag-bar .flag.globe svg {
  display: block;
  width: 34px;
  height: 34px;
}

/* Tablet / small-desktop: shrink so the row still fits without wrap */
@media (max-width: 720px) {
  .flag-bar { gap: 14px; }
  .flag-bar .flag { font-size: 28px; padding: 4px; }
  .flag-bar .flag.globe svg { width: 28px; height: 28px; }
}

/* Phones */
@media (max-width: 520px) {
  .flag-bar { gap: 10px; padding: 6px 6px 14px; }
  .flag-bar .flag { font-size: 24px; padding: 3px; }
  .flag-bar .flag.globe svg { width: 24px; height: 24px; }
  .flag-bar .flag.selected { transform: scale(1.3); }
}
.flag-bar .flag:hover {
  transform: scale(1.1);
}
.flag-bar .flag.selected {
  transform: scale(1.4);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.18));
}

.books-list,
.songs-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.book-row,
.song-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 6px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  transition: background 120ms ease;
}
.book-row:hover,
.song-row:hover {
  background: var(--bg-soft);
}

.book-icon {
  color: var(--tint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.book-icon svg {
  display: block;
}
.book-flag {
  font-size: 22px;
  line-height: 1;
}

.book-name,
.song-name {
  flex: 1;
  font-size: 17px;
  color: var(--fg);
  font-weight: 500;
}

.heart {
  font-size: 22px;
  color: var(--tint);
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 4px 6px;
  display: inline-flex;
  align-items: center;
}
.heart svg {
  display: block;
}

.songs-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.search-pill {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--pill-bg);
  border-radius: 24px;
  padding: 8px 14px;
}
.search-pill input {
  flex: 1;
  background: transparent;
  color: var(--fg);
  border: 0;
  outline: none;
  font-size: 15px;
}

.dropdown {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--pill-bg);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%236b5345' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  color: var(--fg);
  border: 0;
  padding: 8px 36px 8px 16px;
  border-radius: 24px;
  font-size: 14px;
  cursor: pointer;
  width: auto;
  min-width: 160px;
}
html.dark .dropdown {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23c1a48d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

.song-details {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 0 40px;
}

.lyrics {
  white-space: pre-wrap;
  font-family: "Times New Roman", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.2px;
  line-height: 1.65;
  padding: 8px 0 48px;
}

.font-slider {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 24px;
  padding: 8px 16px;
}
.font-slider input[type="range"] {
  accent-color: var(--tint);
  flex: 1;
}

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 24px;
  padding: 8px 16px;
}
.player audio {
  width: 100%;
  max-width: 360px;
}

.image-viewer {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  display: block;
  border-radius: 12px;
}

.nav-row {
  display: flex;
  justify-content: space-between;
  margin-top: 28px;
  gap: 12px;
}
/* When the nav-row is pinned (rendered as a direct child of #app)
   it sits absolutely at the bottom of the screen, above the
   floating tab-bar, regardless of the lyrics scroll position. */
.nav-row.pinned {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 90px;
  margin-top: 0;
  pointer-events: none;
  z-index: 4;
}
.nav-row.pinned .nav-btn {
  pointer-events: auto;
  background: var(--bg);
  box-shadow: 0 8px 20px rgba(44, 24, 16, 0.10),
    0 1px 0 var(--divider) inset;
}
html.dark .nav-row.pinned .nav-btn {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
}
.nav-btn {
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  color: var(--fg);
  font-size: 24px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  cursor: pointer;
}
.nav-btn[disabled] {
  visibility: hidden;
}

/* ── Tab bar (floating pill at the bottom of the middle area) ─── */
.tabbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 32px;
  padding: 6px 8px;
  box-shadow: 0 12px 24px rgba(44, 24, 16, 0.10),
    0 1px 0 rgba(255, 255, 255, 0.5) inset;
  z-index: 5;
}
html.dark .tabbar {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

.tab {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--fg-soft);
  font-size: 12px;
  min-width: 76px;
}
.tab .tab-icon {
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
}
.tab .tab-icon svg {
  display: block;
}
.tab.active {
  color: var(--fg);
}
.tab.active .tab-icon {
  color: var(--tint);
}

/* ── Settings ──────────────────────────────────────────────────── */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 6px;
  border-bottom: 1px solid var(--divider);
}
.toggle {
  appearance: none;
  width: 44px;
  height: 26px;
  background: var(--pill-bg);
  border-radius: 13px;
  border: 1px solid var(--pill-border);
  cursor: pointer;
  position: relative;
  outline: none;
}
.toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 120ms ease;
}
.toggle:checked {
  background: var(--tint);
}
.toggle:checked::before {
  transform: translateX(18px);
}

.version-footer {
  text-align: center;
  color: var(--fg-soft);
  font-size: 13px;
  margin-top: 24px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 12px;
  color: var(--fg-soft);
  gap: 8px;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--divider);
  border-top-color: var(--tint);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Cookie banner ─────────────────────────────────────────────── */
#cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--footer-h);
  z-index: 200;
  transition: bottom var(--chrome-anim-ms) ease;
  background: rgba(253, 246, 240, 0.96);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--clr-border);
  padding: 0.9rem 1.5rem;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  box-shadow: 0 -2px 16px rgba(44, 24, 16, 0.07);
}
html.dark #cookie-banner {
  background: rgba(27, 20, 16, 0.96);
}
#cookie-banner.visible {
  display: flex;
  animation: cookieIn 0.35s ease;
}
@keyframes cookieIn {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.cookie-text {
  font-size: 0.85rem;
  color: var(--clr-text-muted);
  line-height: 1.5;
  max-width: 640px;
}
.cookie-accept {
  padding: 8px 22px;
  border-radius: 100px;
  background: var(--clr-primary);
  color: #fff;
  border: 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(192, 57, 43, 0.3);
}
.cookie-accept:hover {
  background: var(--clr-primary-light);
}

/* ── Footer ────────────────────────────────────────────────────── */
#site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  text-align: center;
  padding: 0.55rem 0.8rem;
  border-top: 1px solid var(--clr-border);
  color: var(--clr-text-muted);
  font-size: 0.78rem;
  background: var(--clr-bg);
  height: var(--footer-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
  transition: transform var(--chrome-anim-ms) ease;
}
body.chrome-hidden #site-footer {
  transform: translateY(100%);
}
body.chrome-hidden #cookie-banner {
  bottom: 0;
}
#site-footer p {
  margin: 0;
}
#site-footer .footer-family {
  font-size: 0.74rem;
}
@media (max-width: 520px) {
  #site-footer {
    font-size: 0.72rem;
    padding: 0.4rem 0.6rem;
  }
  #site-footer .footer-family {
    font-size: 0.68rem;
  }
}

.store-badges {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.store-badge {
  display: inline-flex;
  align-items: center;
  transition: transform 120ms ease, opacity 120ms ease;
}
.store-badge img {
  height: 34px;
  display: block;
}
.store-badge.google img {
  /* Google badge image is bundled with extra whitespace; scale a bit
     larger so the visual cap height matches the Apple badge */
  height: 50px;
  margin: -8px 0;
}
.store-badge:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}
@media (max-width: 520px) {
  .store-badges { gap: 8px; }
  .store-badge img { height: 28px; }
  .store-badge.google img { height: 42px; margin: -7px 0; }
}
#site-footer .footer-family a {
  color: var(--clr-primary);
  text-decoration: none;
}
#site-footer .footer-family a:hover {
  color: var(--clr-primary-light);
}

@media (max-width: 600px) {
  #cookie-banner {
    padding: 0.8rem 1rem;
    gap: 0.8rem;
  }
  .cookie-text {
    font-size: 0.8rem;
  }
  .cookie-accept {
    padding: 7px 18px;
    font-size: 0.82rem;
  }
}
