:root {
  --font-scale: 1;
  
  /* Modern Professional Palette */
  --primary: #2563eb;       /* Vibrant Blue */
  --primary-dark: #1e40af;  /* Deep Blue */
  --primary-soft: #eff6ff;  /* Light Blue bg */
  --accent: #f59e0b;        /* Amber/Gold for highlights */
  
  --bg-body: #f8fafc;       /* Very light slate */
  --bg-card: #ffffff;
  --text-main: #0f172a;     /* Slate 900 */
  --text-muted: #64748b;    /* Slate 500 */
  --border: #e2e8f0;        /* Slate 200 */
  
  --success: #10b981;       /* Emerald */
  --success-bg: #ecfdf5;
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 16px;
}

html {
  font-size: calc(16px * var(--font-scale));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text-main);
  font-family: "Noto Sans Telugu", sans-serif;
  font-size: 1rem;
  background: var(--bg-body);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2 {
  margin-bottom: 10px;
}

.page-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 6px 12px 14px;
}

.view {
  display: none;
}

.view.visible {
  display: block;
}

#view-choices.view.visible {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 24px);
}

#view-choices .card {
  width: min(860px, 100%);
  min-height: min(560px, 82dvh);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

/* Compact login card to avoid oversized controls on wide screens */
.card.login-card {
  max-width: 420px;
  margin: 0 auto;
  padding: 18px;
}

.card.login-card .text-input,
.card.login-card .primary-btn,
.card.login-card .ghost-btn {
  max-width: 420px;
}

/* Brand header moved from inline styles */
.brand-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-header img {
  width: 64px;
  height: 64px;
  margin-bottom: 0.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.brand-header h1 {
  margin: 0;
}

/* Ensure small icon spacing on tile buttons and section icons */
.tile-btn svg,
.section-head svg {
  margin-bottom: 0.5rem;
}

.centered {
  text-align: center;
}

.muted {
  color: var(--text-muted);
  margin-bottom: 14px;
}

label {
  display: block;
  margin: 10px 0 6px;
  font-size: 0.95rem;
}

.text-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 12px;
  font-size: 1rem;
  color: var(--text-main);
  background: #fff;
}

.primary-btn,
.ghost-btn,
.tile-btn,
.tab-btn {
  font-family: inherit;
  cursor: pointer;
}

button,
input,
select {
  font: inherit;
}

.primary-btn,
.ghost-btn {
  width: 100%;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 11px 12px;
  margin-top: 10px;
  font-size: 0.96rem;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.ghost-btn {
  background: #fff;
  color: var(--text-main);
  border-color: var(--border);
}

.ghost-btn:hover,
.tab-btn:hover,
.tile-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.compact-btn {
  max-width: 320px;
}

.control-btn {
  width: auto;
  margin: 0;
  padding: 8px 10px;
}

.selector-btn {
  width: auto;
  margin: 0;
  padding: 8px 12px;
}

.message {
  min-height: 24px;
  margin-top: 12px;
  color: #ef4444;
}

.message.success {
  color: var(--success);
}

.otp-panel {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.choice-grid,
.tutorial-grid,
.book-grid,
.chapter-grid,
.playlist {
  display: grid;
  gap: 10px;
}

.choice-grid {
  grid-template-columns: 1fr;
  margin-top: 2px;
  width: min(760px, 100%);
}

.tile-btn {
  width: 100%;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  min-height: 138px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.tile-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
  border-color: var(--primary);
}

.tile-btn:focus-visible {
  outline: 2px solid #c29c57;
  outline-offset: 2px;
}

.tile-title {
  display: block;
  font-weight: 700;
  margin-bottom: 7px;
  font-size: 1.25rem;
}

.tile-subtitle {
  display: block;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.section-head {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.section-head .ghost-btn {
  width: auto;
  margin-top: 0;
  padding: 8px 10px;
}

.font-scale-trigger {
  margin-left: auto;
  width: auto;
  padding: 8px 12px;
  font-weight: 700;
}

.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  justify-content: center;
}

.tab-btn {
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 12px;
  border-radius: 999px;
}

.tab-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
}

.book-grid {
  /* Strict 2 columns on mobile to prevent messiness */
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.chapter-grid {
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  margin-top: 10px;
  gap: 10px;
}

.book-btn,
.chapter-btn,
.playlist-item,
.tutorial-card {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  transition: all 0.15s ease;
}

.book-btn:active, .chapter-btn:active {
  background: var(--primary-soft);
}

.book-btn,
.chapter-btn {
  padding: 10px;
  text-align: center;
}

.book-btn {
  min-height: 54px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.book-btn.active,
.chapter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chapter-view {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.chapter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.chapter-head .ghost-btn {
  width: auto;
  margin: 0;
  padding: 8px;
  font-size: 0.86rem;
}

.chapter-switchers {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.switch-btn {
  width: auto;
  margin: 0;
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.verses-list {
  display: grid;
  gap: 10px;
}

.section-divider {
  margin: 12px 0 2px;
  padding: 7px 10px;
  border-top: 1px solid var(--border);
  border-bottom: 1px dashed var(--border);
  color: var(--text-muted);
  font-weight: 700;
  background: var(--bg-body);
  text-align: center;
}

.verse-row {
  padding: 11px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  line-height: 1.62;
}

.verse-no {
  font-weight: 700;
  color: #982626;
  margin-right: 6px;
}

.tutorial-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.tutorial-card {
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 215px;
}

.tutorial-card h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.tutorial-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.tutorial-card .primary-btn {
  margin-top: 0;
  align-self: stretch;
}

.watch-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.watch-btn:hover {
  background: var(--primary-dark);
}

.progress-chip {
  display: inline-flex;
  justify-content: center;
  width: 100%;
  background: var(--bg-body);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.82rem;
  margin-bottom: 10px;
}

.tutorial-card.completed {
  border-color: var(--success);
  background: var(--success-bg);
}

.completed-chip {
  display: inline-block;
  color: var(--success);
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
}

#view-player .card {
  display: grid;
  gap: 10px;
}

.player-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1fr);
  grid-template-areas: "list player";
  gap: 12px;
  align-items: start;
}

.playlist-panel {
  grid-area: list;
  min-width: 0;
}

.player-panel {
  grid-area: player;
  min-width: 0;
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  z-index: 110;
  align-self: start;
}

.player-head {
  margin-bottom: 0;
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 120;
  background: var(--bg-card);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
}

.video-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  background: #110808;
  min-height: 220px;
}

#yt-player,
#yt-player iframe {
  width: 100%;
  height: 100%;
  pointer-events: auto !important;
}

.custom-player-ui {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.01);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 1;
  transition: opacity 0.3s ease;
  cursor: pointer;
}

.custom-player-ui.user-inactive .cp-center-btn,
.custom-player-ui.user-inactive .cp-bottom-bar {
  opacity: 0;
  pointer-events: none;
}

.cp-center-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease, background 0.2s, opacity 0.3s ease;
  z-index: 20;
}

.cp-center-btn:active {
  transform: translate(-50%, -50%) scale(0.95);
  background: rgba(0, 0, 0, 0.8);
}

.cp-icon {
  width: 42px;
  height: 42px;
  color: #fff;
  fill: currentColor;
  stroke: none;
}

.cp-bottom-bar {
  margin-top: auto;
  padding: 10px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  transition: opacity 0.3s ease;
  z-index: 20;
}

.cp-fs-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
  padding-right: 4px;
}

.cp-icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  padding: 10px;
  cursor: pointer;
  opacity: 0.9;
}

.cp-icon-btn:hover {
  opacity: 1;
  transform: scale(1.1);
  background: rgba(0, 0, 0, 0.5);
}

.cp-icon-btn svg {
  width: 28px;
  height: 28px;
}

.cp-seek {
  width: 100%;
  height: 4px;
  cursor: pointer;
  accent-color: var(--primary);
  display: block;
  margin-bottom: 6px;
}

.current-video-title {
  font-weight: 700;
  line-height: 1.3;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-head .current-video-title {
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.playlist {
  margin-top: 0;
  max-height: min(72dvh, 760px);
  overflow-y: auto;
  padding-right: 2px;
  scroll-behavior: smooth;
}

.playlist-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  scroll-margin-top: 12px;
}

.playlist-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.playlist-item.watched {
  background: #f0fdf4;
  border-color: #a8deba;
}

.video-meta {
  display: grid;
  gap: 2px;
}

.video-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.video-wrap.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  border-radius: 0;
  border: 0;
  z-index: 9999;
  aspect-ratio: auto;
  background: #000;
}

body.pseudo-fullscreen-open {
  overflow: hidden;
}

body.pseudo-fullscreen-open .player-head,
body.native-fullscreen-open .player-head {
  visibility: hidden;
  pointer-events: none;
}

.video-cat {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.tick {
  color: var(--success);
  font-weight: 700;
  font-size: 1rem;
}

.rewatch-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 8, 8, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  width: min(940px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  padding: 14px;
}

.small-modal-card {
  width: min(360px, 100%);
}

.reader-modal-card {
  width: min(860px, 100%);
}

.picker-modal-card {
  width: min(700px, 100%);
}

.modal-head {
  position: relative;
  display: block;
  min-height: 36px;
  margin-bottom: 10px;
}

.modal-head h3 {
  text-align: center;
  padding: 0 40px;
  margin: 0;
}

.modal-book-grid {
  margin-top: 8px;
}

.modal-chapter-grid {
  margin-top: 10px;
}

.modal-toolbar {
  margin-bottom: 10px;
}

.font-scale-value {
  margin-top: 8px;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
}

.picker-selected-book {
  text-align: center;
  color: var(--muted);
  margin-bottom: 8px;
}

.icon-btn {
  font-size: 1.6rem;
  line-height: 1;
  width: auto;
  margin: 0;
  padding: 2px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-main);
}

.icon-btn:hover {
  border: 0;
  background: transparent;
  color: var(--primary);
}

.modal-close {
  position: absolute;
  top: 0;
  right: 0;
}

.centered-grid {
  justify-content: center;
}

.centered-grid > * {
  justify-self: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  max-width: 92vw;
  z-index: 120;
}

@media (max-width: 860px) {
  .player-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "player"
      "list";
  }

  .section-head {
    gap: 8px;
  }

  .section-head h2 {
    margin-bottom: 0;
  }

  .player-actions .compact-btn {
    width: auto;
  }

  .player-actions {
    justify-content: space-between;
  }

  .current-video-title {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 0.96rem;
  }
  .player-head .current-video-title {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 0.96rem;
  }

  .page-shell {
    padding: 4px 10px 10px;
  }

  .card {
    border-radius: 14px;
    padding: 12px;
  }

  .chapter-switchers {
    gap: 5px;
  }

  .switch-btn {
    padding: 6px 10px;
    font-size: 0.84rem;
  }
}

@media (min-width: 768px) {
  .page-shell {
    padding: 6px 16px 16px;
  }

  .choice-grid {
    grid-template-columns: 1fr 1fr;
  }

  .card {
    padding: 18px;
  }
  
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

/* Bible Toolbar - Single Row */
.bible-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  overflow-x: auto;
}

.bible-nav-group {
  display: flex;
  align-items: center;
  background: var(--bg-body);
  border-radius: 2rem;
  padding: 0.25rem;
  margin: 0 auto;
  border: 1px solid var(--border);
}

.bible-nav-group .ghost-btn {
  margin: 0;
  padding: 0.5rem;
  color: var(--text-main);
  border: none;
  background: transparent;
}

.bible-nav-group .switch-btn {
  font-weight: 700;
  color: var(--primary);
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
}

/* Grid Fixes for Modals */
.modal-book-grid {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr); /* Mobile First: 2 cols */
  gap: 0.75rem;
  padding: 1rem 0;
}

@media (min-width: 600px) {
  .modal-book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}
