:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --paper: #fffdf8;
  --ink: #1f1c18;
  --muted: #746b61;
  --line: #ded4c7;
  --accent: #b3262e;
  --accent-strong: #7b1b22;
  --focus: #0b6e69;
  --soft-fill: #f3ede5;
  --shadow: 0 12px 32px rgba(34, 24, 16, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  padding-top: var(--safe-area-top);
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Devanagari", system-ui, -apple-system, BlinkMacSystemFont, "Nirmala UI", sans-serif;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --topbar-content-height: 57px;
  --topbar-height: var(--topbar-content-height);
  --bottom-bar-height: 56px;
  --bottom-bar-bottom-gap: 0px;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--safe-area-top);
  z-index: 100;
  background: rgba(247, 244, 239, 0.96);
  backdrop-filter: blur(14px);
  pointer-events: none;
}

button,
input,
select {
  font: inherit;
  touch-action: manipulation;
}

.topbar {
  position: relative;
  top: 0 !important;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px clamp(10px, 3vw, 28px);
  background: rgba(247, 244, 239, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  max-width: 100vw;
  height: var(--topbar-height);
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  justify-self: start;
}

.logo-title > div {
  min-width: 0;
}

.app-logo {
  flex-shrink: 0;
  height: 32px;
  width: auto;
  max-width: 100%;
}

.eyebrow,
.meta,
.field span {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(0.98rem, 3.4vw, 1.35rem);
  line-height: 1.15;
}

h2 {
  font-size: clamp(1.22rem, 4.5vw, 2rem);
  line-height: 1.22;
}

.icon-button,
.nav-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--accent-strong);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(34, 24, 16, 0.08);
}

.icon-button {
  font-size: 1.12rem;
}

.nav-button {
  font-size: 1.6rem;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(31, 28, 24, 0);
  transition: background 180ms ease;
}

.drawer-overlay.is-open {
  background: rgba(31, 28, 24, 0.38);
}

.mobile-only { display: none !important; }

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: min(360px, 88vw);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 180ms ease;
  max-width: 100vw;
}

.drawer.is-open {
  transform: translateX(0);
}

.bhajan-browser {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(var(--bottom-bar-height) + var(--bottom-bar-bottom-gap) + env(safe-area-inset-bottom));
  z-index: 34;
  width: min(720px, calc(100vw - 16px));
  height: 60vh;
  max-height: calc(100dvh - var(--safe-area-top) - var(--topbar-height) - var(--bottom-bar-height) - var(--bottom-bar-bottom-gap) - env(safe-area-inset-bottom));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(34, 24, 16, 0.16);
  transform: translateY(calc(100% + 84px));
  transition: transform 180ms ease;
}

.bhajan-browser.is-open {
  transform: translateY(0);
}

.browser-overlay {
  position: fixed;
  top: calc(var(--safe-area-top) + var(--topbar-height));
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-bar-height) + var(--bottom-bar-bottom-gap) + env(safe-area-inset-bottom));
  z-index: 33;
  background: rgba(31, 28, 24, 0);
}

.app-menu {
  inset: 0 0 auto 0;
  width: 100%;
  border-right: 0;
  border-left: 0;
  border-bottom: 1px solid var(--line);
  transform: translateY(-105%);
}

.app-menu.is-open {
  transform: translateY(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.bhajan-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.browser-filters {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #fbf7f0;
}

.list-button {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.list-button.is-active {
  background: #f2e4d4;
}

.list-page {
  display: grid;
  place-items: center;
  min-width: 42px;
  height: 38px;
  border-radius: 999px;
  background: #ece3d8;
  color: var(--accent-strong);
  font-weight: 900;
}

.list-title {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  text-decoration: none;
  padding: 0 14px;
  cursor: pointer;
}

.menu-item.is-active,
.menu-item:hover {
  background: var(--soft-fill);
}

.app-shell {
  width: min(980px, 100%);
  max-width: 100vw;
  margin: 0 auto;
  padding: 8px clamp(10px, 3vw, 28px) calc(var(--bottom-bar-height) + var(--bottom-bar-bottom-gap) + 20px + env(safe-area-inset-bottom));
  overflow-x: clip;
}

.reader-panel {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

input,
select {
  width: 64px;
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 8px;
}

.browser-filters input,
.browser-filters select {
  width: 100%;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(11, 110, 105, 0.25);
  border-color: var(--focus);
}

.reader-head {
  position: sticky;
  top: var(--safe-area-top);
  z-index: 20;
  background: var(--paper);
  border-radius: 8px 8px 0 0;
  backdrop-filter: blur(14px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: clamp(12px, 3vw, 22px);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.reader-head.is-pinned {
  border-radius: 0;
  border-top: 1px solid var(--line);
}

.reader-head > div {
  min-width: 0;
}

.reader-head h2 {
  overflow-wrap: anywhere;
}

.lyrics {
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
  padding: clamp(12px, 3vw, 28px);
  font-size: 24px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  touch-action: pan-y;
  -webkit-font-smoothing: antialiased;
}

.lyrics .stanza {
  white-space: pre-wrap;
  margin: 0;
}

.lyrics .stanza + .stanza {
  margin-top: 1.1em;
}


.bottom-bar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-bar-bottom-gap) + env(safe-area-inset-bottom));
  z-index: 35;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right));
  min-height: var(--bottom-bar-height);
  padding: 0;
  transform: translateX(-50%);
}

.bottom-bar .icon-button {
  flex: 0 0 auto;
  width: 72px;
  height: 44px;
}

.text-button {
  font-size: 1rem;
  letter-spacing: 0;
}

.icon-button:active {
  background: var(--soft-fill);
}

@media (hover: hover) {
  .icon-button:hover {
    background: var(--soft-fill);
  }
}

.icon-button:disabled {
  opacity: 0.35;
  pointer-events: none;
}

@media (max-width: 780px) {
  body {
    --topbar-content-height: 51px;
    --bottom-bar-height: 54px;
    --bottom-bar-bottom-gap: 0px;
  }

  .desktop-nav {
    display: none !important;
  }

  .mobile-only {
    display: inline-grid !important;
  }

  .drawer {
    inset: 0;
    width: 100vw;
    border-right: 0;
    transform: translateX(100%);
  }

  .bhajan-browser {
    left: 8px;
    right: 8px;
    bottom: calc(var(--bottom-bar-height) + var(--bottom-bar-bottom-gap) + env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    height: 60vh;
    max-height: calc(100dvh - var(--safe-area-top) - var(--topbar-height) - var(--bottom-bar-height) - var(--bottom-bar-bottom-gap) - env(safe-area-inset-bottom));
    border-radius: 12px 12px 0 0;
  }

  .app-menu {
    inset: 0 0 auto 0;
    border-left: 0;
    transform: translateY(-105%);
  }

  .app-menu.is-open {
    transform: translateY(0);
  }

  .drawer.is-open {
    transform: translateX(0);
  }

  .drawer-head {
    padding: 14px 12px;
  }

  .icon-button,
  .nav-button {
    width: 36px;
    height: 36px;
  }

  .app-shell {
    padding: 8px 8px calc(var(--bottom-bar-height) + 18px + env(safe-area-inset-bottom));
  }

  .reader-panel {
    min-height: 0;
  }

  .field span {
    font-size: 0.65rem;
  }

  input,
  select {
    width: 54px;
    min-height: 34px;
    padding: 0 5px;
  }

  .browser-filters input,
  .browser-filters select {
    width: 100%;
  }

  .reader-head {
    padding: 10px;
  }

  .lyrics {
    padding: 12px;
    line-height: 1.35;
  }
}


@media (max-width: 420px) {
  input {
    width: 52px;
  }

  h2 {
    font-size: 1.08rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  body {
    --bottom-bar-height: 72px;
  }

  .reader-head {
    padding: 6px 12px;
  }

  .bhajan-browser {
    bottom: calc(var(--bottom-bar-height) + var(--bottom-bar-bottom-gap) - env(safe-area-inset-bottom));
  }
}

@media (min-width: 781px) {
  .app-shell {
    display: block;
    width: min(980px, 100%);
    margin: 0 auto;
    padding: 24px;
    position: relative;
  }

  .bhajan-browser {
    position: fixed;
    left: auto;
    width: 380px !important;
    height: 60vh;
    max-height: calc(100vh - var(--topbar-height) - 100px);
    margin: 0;
    
    opacity: 0;
    pointer-events: none;
    transform: translateY(-12px) !important;
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(34, 24, 16, 0.15);
  }

  .bhajan-browser.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) !important;
  }

  .browser-overlay {
    display: none !important;
  }

  .bottom-bar {
    display: none !important;
  }
  
  .reader-panel {
    min-height: 0;
  }
}
