/* ==========================================================================
   Practice Gita — design system
   Warm paper, ink text, one kumkum accent. Hindi first: Devanagari is never
   letter-spaced or italicised, and reading text is never below 16px.
   ========================================================================== */

/* 1. TOKENS -------------------------------------------------------------- */
:root {
  --bg: #FAF8F5;              /* page: warm paper */
  --card-bg: #FFFFFF;         /* raised surfaces */
  --surface-2: #F2EEE8;       /* quiet fills: pressed, segmented tracks */
  --text: #1F1B17;            /* ink */
  --muted: #6B635B;           /* secondary text, 5.6:1 on paper */
  --line: rgba(31, 27, 23, 0.10);
  --line-strong: rgba(31, 27, 23, 0.18);
  --border: var(--line);      /* legacy name used by page styles */
  --accent: #C62828;          /* kumkum red */
  --accent-soft: rgba(198, 40, 40, 0.08);
  --on-accent: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(31, 27, 23, 0.05);
  --shadow-md: 0 1px 2px rgba(31, 27, 23, 0.04), 0 8px 24px rgba(31, 27, 23, 0.06);
  --shadow-lg: 0 12px 40px rgba(31, 27, 23, 0.18);

  --font: 'Noto Sans Devanagari', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 20px;
  --tap: 48px;
  --nav-h: 60px;
}

.dark {
  --bg: #141210;
  --card-bg: #1E1B18;
  --surface-2: #2A2622;
  --text: #F2EDE7;
  --muted: #ABA39A;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #FF8A80;
  --accent-soft: rgba(255, 138, 128, 0.12);
  --on-accent: #1B0F0E;
  --shadow-sm: none;
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

@font-face {
  font-family: 'Noto Sans Devanagari';
  /* Trimmed to the characters the app uses, weight axis only: 183 KB instead of 642 KB */
  src: url('./fonts/NotoSansDevanagari.woff') format('woff');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* 2. BASE ---------------------------------------------------------------- */
html {
  height: 100%;
  /* The document is the single scroller; this only stops Android
     pull-to-refresh while a card is being swiped. */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: calc(var(--nav-h) + 20px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

/* Laptops: centre short pages vertically (no swipe wobble on desktop) */
@media (min-width: 1024px) {
  body { justify-content: center; }
}

*, *::before, *::after { box-sizing: border-box; }

button, input, select, textarea { font: inherit; color: inherit; }
button, a, [role="button"], .adhyay-card, .toggle {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Icons: one line-icon set, coloured by the text around it */
.ic {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.ic-sm { width: 18px; height: 18px; }
.ic-lg { width: 28px; height: 28px; }

/* Icon tile: accent icon on a soft accent square */
.tile {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* 3. HEADER ---------------------------------------------------------------- */
.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.nav-left-group, .nav-right-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.icon-btn, .hamburger {
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.icon-btn:active, .hamburger:active { background: var(--surface-2); }

.nav-btn {
  height: 44px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.nav-btn .ic { width: 20px; height: 20px; }
.nav-btn:active { background: var(--surface-2); }

@media (hover: hover) {
  .icon-btn:hover, .hamburger:hover, .nav-btn:hover { background: var(--surface-2); }
}

/* Home header search */
.search-link {
  height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}
.search-link .ic { width: 20px; height: 20px; color: var(--muted); }
.search-link .ic-sm { width: 16px; height: 16px; margin-right: -2px; }
.search-link:has(> span:first-child) { padding: 0 12px 0 16px; gap: 4px; }
.search-link:active { background: var(--surface-2); }

/* 4. SIDEBAR ---------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(calc(88vw / var(--app-zoom, 1)), 330px); /* stays on screen at larger text sizes */
  height: 100%;
  background: var(--card-bg);
  box-shadow: var(--shadow-lg);
  transform: translateX(-105%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .28s;
  z-index: 11000;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 12px calc(16px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
  visibility: hidden;
}
.sidebar.active { transform: translateX(0); visibility: visible; transition-delay: 0s; }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--nav-h);
  padding: 0 0 0 8px;
  flex-shrink: 0;
}
.brand-name, .sidebar-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-links { display: flex; flex-direction: column; }

.sidebar-section-title {
  padding: 18px 8px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
[data-lang^="en"] .sidebar-section-title { text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }

.lang-selector-container { display: flex; flex-direction: column; gap: 4px; }

.lang-option {
  width: 100%;
  min-height: 56px;
  padding: 8px 40px 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  position: relative;
}
.lang-name { font-weight: 600; font-size: 16px; color: var(--text); }
.lang-desc { font-size: 14px; color: var(--muted); }
.lang-check {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  opacity: 0;
}
.lang-option.is-active { background: var(--accent-soft); }
.lang-option.is-active .lang-check { opacity: 1; }

.setting-row {
  width: 100%;
  min-height: 52px;
  padding: 4px 4px 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.setting-row > span:first-child { display: inline-flex; align-items: center; gap: 14px; }
.setting-row .ic { color: var(--muted); }

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 2px;
}
.stepper button {
  width: 48px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
.stepper button:active { background: var(--card-bg); }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper .step-a { font-size: 14px; }
.stepper .step-a-lg { font-size: 19px; }
.stepper button + button { border-left: 1px solid var(--line); border-radius: 0 10px 10px 0; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }

.switch {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  flex-shrink: 0;
  transition: background .2s ease;
  margin-right: 8px;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s ease;
}
[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { transform: translateX(20px); }

.sidebar-link {
  min-height: 52px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
}
.sidebar-link .ic { color: var(--muted); }
.sidebar-link:active, .lang-option:active, .setting-row:active { background: var(--surface-2); }
@media (hover: hover) {
  .sidebar-link:hover, .lang-option:hover, .setting-row:hover { background: var(--surface-2); }
  .lang-option.is-active:hover { background: var(--accent-soft); }
}

.sidebar hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 20px 8px 4px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.38);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: none;
  z-index: 10500;
  opacity: 0;
  transition: opacity .25s ease;
}
.overlay.active { display: block; opacity: 1; }
.dark .overlay { background: rgba(0, 0, 0, 0.6); }
/* The menu's right edge stays clear in both themes */
.sidebar { border-right: 1px solid var(--line); }
.dark .sidebar { background: #24201C; border-right-color: rgba(255, 255, 255, 0.14); box-shadow: 12px 0 40px rgba(0, 0, 0, 0.55); }
/* Keyboard focus only: no ring when the menu is opened by touch */
.sidebar :focus:not(:focus-visible) { outline: none; box-shadow: none; }

/* 5. BUTTONS ------------------------------------------------------------- */
.start-btn, .action-btn, .btn {
  min-height: var(--tap);
  padding: 12px 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease, opacity .2s ease;
}
.start-btn:active, .action-btn:active, .btn:active { transform: scale(.98); }
.start-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.action-btn {
  display: flex;
  width: 100%;
  max-width: 320px;
  margin: 12px auto 0;
}
.action-btn.secondary, .btn.secondary {
  background: transparent;
  color: var(--accent);
}

.icon { /* legacy icon button reset */
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

/* Optical centring: Noto Sans Devanagari reserves room below the baseline for
   lower vowel signs, so labels look high next to icons. Nudge them down a touch. */
.bar-btn > span, .hint-btn > span, .nav-btn > span, .search-link > span,
.shloka-nav-btn > span, .quick-link > span, .sidebar-link > span,
.setting-row > span > span, .btn > span, .start-btn > span {
  position: relative;
  top: .08em;
}
.start-btn, .action-btn, .jump-btn-go, .jump-btn-cancel, .tab-btn { padding-top: 2px; }
.start-btn, .action-btn { padding-bottom: 10px; padding-top: 14px; }

/* 6. PAGE TITLES ------------------------------------------------------------ */
.logo-area { margin-bottom: 24px; text-align: center; }
.logo-area h1 {
  font-size: 32px;
  line-height: 1.3;
  font-weight: 700;
  margin: 4px 0 0;
}
.subtitle {
  font-size: 15px;
  color: var(--accent);
  font-weight: 600;
}
[data-lang^="en"] .subtitle { text-transform: uppercase; letter-spacing: .08em; font-size: 13px; }

.footer {
  margin-top: 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}

/* 7. HOME ---------------------------------------------------------------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.nav-brand { font-size: 17px; font-weight: 700; color: var(--text); margin-left: 4px; white-space: nowrap; }

/* Home reads top-down: verse of the day, continue, then two plain groups */
.content-wrapper.home { justify-content: flex-start; text-align: left; }
@media (min-width: 1024px) { .content-wrapper.home { justify-content: center; } }

.daily-card {
  display: block;
  padding: 14px 16px 16px;
  margin-bottom: 12px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  text-decoration: none;
  text-align: center;
  transition: transform .12s ease, border-color .2s ease;
}
.daily-card[hidden] { display: none; }
.daily-card:active { transform: scale(.985); }
@media (hover: hover) { .daily-card:hover { border-color: var(--line-strong); } }
.daily-label {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 650; color: var(--accent); margin-bottom: 8px;
}
.daily-ref { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.daily-ref::before { content: "·"; margin-right: 6px; color: var(--muted); }
.daily-label .ic-sm { width: 14px; height: 14px; color: var(--muted); margin-left: -2px; }
[data-lang^="en"] .daily-label { text-transform: uppercase; letter-spacing: .08em; font-size: 13px; }
.daily-verse { display: block; font-size: 18px; line-height: 1.6; font-weight: 500; text-wrap: balance; }
.daily-verse .dl { display: block; }
.daily-verse:lang(sa-Latn) { font-size: 17px; }
.daily-foot {
  display: flex; align-items: center; justify-content: center; gap: 2px;
  margin-top: 8px; font-size: 14px; color: var(--muted);
}

.group-label {
  margin: 18px 4px 8px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  color: var(--muted);
}
[data-lang^="en"] .group-label { text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }
.resume-card + .group-label, .daily-card + .group-label { margin-top: 14px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 -2px; }
.group-head .group-label { margin: 0 4px; }
.group-head:not(:has(.group-link:not([hidden]))) { margin: 14px 0 8px; }
.group-link {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 4px 0 8px;
  color: var(--accent); text-decoration: none;
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.group-link[hidden] { display: none; }
.group-link .count {
  min-width: 22px; height: 22px; padding: 0 6px; margin-left: 2px;
  border-radius: 999px; background: var(--accent-soft);
  font-size: 13px; line-height: 22px; text-align: center; font-variant-numeric: tabular-nums;
}
.group-link .ic-sm:last-child { color: var(--muted); }
/* Screens designed to fit (Home, reading, practice): if everything fits there is
   nothing to drag, so no iOS rubber-band bounce; if it does not fit, it still
   scrolls normally. Long pages keep the native bounce. */
html.fit-screen, html.fit-screen body { overscroll-behavior-y: none; }

/* Home ends with the blessing */
.content-wrapper.home > .footer { margin-top: 20px; text-align: center; }

/* Phones and tablets: one fluid rhythm. Card height, gaps, section spacing,
   card padding and verse size all follow one value, --grow (0 = compact).
   fitHome() in index.html picks the largest --grow that still fits one
   screen for this device and this person (returning readers have more
   cards), so Home fills the screen evenly with no empty band. */
@media (max-width: 699px) {
  html.fit-screen body:has(> .content-wrapper.home) {
    padding-top: calc(var(--nav-h) + 12px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}
@media (max-width: 1023px) {
  body:has(> .content-wrapper.home) { min-height: calc(var(--app-h, 100dvh) / var(--app-zoom, 1)); }
  .content-wrapper.home {
    justify-content: flex-start;
    --grow: 0px;
    --card-h: min(96px, calc(62px + var(--grow) * 0.16));
    --gap: min(18px, calc(8px + var(--grow) * 0.05));
    --sec: min(34px, calc(12px + var(--grow) * 0.12));
    --pad: min(28px, calc(12px + var(--grow) * 0.09));
  }
  .content-wrapper.home .daily-card { padding: var(--pad) 16px; margin-top: var(--lift, 0px); margin-bottom: var(--gap); }
  .content-wrapper.home .daily-label { margin-bottom: min(12px, calc(6px + var(--grow) * 0.03)); }
  .content-wrapper.home .daily-verse { font-size: min(22px, calc(18px + var(--grow) * 0.022)); line-height: 1.55; }
  .content-wrapper.home .daily-verse:lang(sa-Latn) { font-size: min(20px, calc(17px + var(--grow) * 0.018)); }
  .content-wrapper.home .menu-item, .content-wrapper.home .resume-card { min-height: var(--card-h); padding-top: 8px; padding-bottom: 8px; }
  .content-wrapper.home .menu-stack { gap: var(--gap); }
  .content-wrapper.home .group-label { margin: var(--sec) 4px calc(var(--gap) - 2px); }
  .content-wrapper.home .group-head { margin: calc(var(--sec) - 10px) 0 -2px; }
  .content-wrapper.home .group-head .group-label { margin: 0 4px; }
  .content-wrapper.home .group-head:not(:has(.group-link:not([hidden]))) { margin: var(--sec) 0 calc(var(--gap) - 2px); }
  .content-wrapper.home > .footer { margin-top: auto; padding-top: var(--gap); }
}
/* Very short screens (iPhone SE with Safari's bars) */
@media (max-width: 699px) and (max-height: 600px) {
  html.fit-screen body:has(> .content-wrapper.home) { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .content-wrapper.home:not([style*="--grow"]) { --card-h: 54px; --gap: 6px; --sec: 8px; --pad: 8px; }
  .content-wrapper.home:not([style*="--grow"]) .daily-verse { font-size: 16.5px; line-height: 1.5; }
}
@media (max-width: 699px) {
  .content-wrapper.home.compact .menu-item .text-box p { display: none; }
  .content-wrapper.home.compact { --card-h: 48px; }
  .content-wrapper.home.compact .menu-item .tile, .content-wrapper.home.compact .resume-card .tile { width: 36px; height: 36px; border-radius: 10px; }
  .content-wrapper.home.compact .menu-item, .content-wrapper.home.compact .resume-card { padding-top: 6px; padding-bottom: 6px; }
}
/* Tablets allow a little more growth, and the whole page (blessing included)
   sits in the middle of the screen rather than pinning the blessing to the bottom */
@media (min-width: 700px) and (max-width: 1023px) {
  .content-wrapper.home > .footer { margin-top: 0; padding-top: var(--sec); }
  .content-wrapper.home {
    --card-h: min(118px, calc(72px + var(--grow) * 0.18));
    --gap: min(22px, calc(12px + var(--grow) * 0.05));
    --sec: min(44px, calc(16px + var(--grow) * 0.12));
    --pad: min(36px, calc(16px + var(--grow) * 0.09));
  }
  .content-wrapper.home .daily-verse { font-size: min(26px, calc(20px + var(--grow) * 0.025)); }
}

.content-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  margin: 0 auto;
  width: min(calc(100% - 32px), 460px);
  text-align: center;
  flex-shrink: 0;
}

.menu-stack { display: flex; flex-direction: column; gap: 12px; }

.menu-item, .resume-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 14px 12px 14px 14px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  text-align: left;
  transition: transform .12s ease, border-color .2s ease;
}
.menu-item:active, .resume-card:active { transform: scale(.985); }
@media (hover: hover) { .menu-item:hover, .resume-card:hover { border-color: var(--line-strong); } }
.menu-item .chev, .resume-card .chev { color: var(--muted); margin-left: auto; }

.icon-box { /* legacy wrapper; now holds a .tile */
  display: inline-flex;
  flex-shrink: 0;
}

.text-box { min-width: 0; flex: 1; }
.text-box h2, .text-box h3 { font-size: 18px; line-height: 1.35; margin: 0; font-weight: 650; }
.text-box p { font-size: 15px; line-height: 1.45; margin: 2px 0 0; color: var(--muted); }

.resume-card {
  margin-bottom: 12px;
  background: var(--accent-soft);
  border-color: transparent;
  box-shadow: none;
}
.resume-card .tile { background: var(--accent); color: var(--on-accent); }
.resume-label { display: block; font-size: 18px; font-weight: 650; line-height: 1.35; }
.resume-where { display: block; font-size: 15px; color: var(--muted); }
.resume-card[hidden] { display: none; }
.menu-stack > .resume-card { margin-bottom: 0; }

/* Saved verses with nothing saved yet: readable, but clearly inactive */
.menu-item.is-disabled { pointer-events: none; box-shadow: none; background: transparent; }
.menu-item.is-disabled .tile { background: var(--surface-2); color: var(--muted); }
.menu-item.is-disabled h2 { color: var(--muted); }
.menu-item.is-disabled .chev { visibility: hidden; }

/* Tablets and laptops: the four modes sit two by two */
@media (min-width: 700px) {
  .content-wrapper { width: min(calc(100% - 48px), 760px); }
  .menu-stack { display: grid; grid-template-columns: 1fr 1fr; }
  .menu-stack > :only-child, .menu-stack > [hidden]:first-child + :last-child { grid-column: 1 / -1; }
  .menu-item { align-items: center; }
}

.quick-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.quick-link {
  min-height: 52px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  min-width: 0;
}
.quick-link .ic { color: var(--accent); }
.quick-link span { min-width: 0; overflow-wrap: anywhere; }
.quick-link:active { background: var(--surface-2); }

/* 8. CHAPTER PICKER ------------------------------------------------------- */
.adhyay-selection {
  margin: 0 auto;
  width: min(calc(100% - 24px), 600px);
  text-align: center;
  position: relative;
  flex-shrink: 0;
}

.select-all {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 500;
}

.adhyay-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.adhyay-card {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--card-bg);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
/* Multi-select (practice): soft; single-select (Adhyay-Path): solid */
.adhyay-card.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.adhyay-grid.single .adhyay-card.selected {
  background: var(--accent);
  color: var(--on-accent);
}

.adhyay-selection .start-btn { width: 100%; max-width: 360px; }
/* Phones: the picker fills the screen like Home does. fitPicker() in theme.js
   sets --pg (0 = compact, 1 = roomy) to the largest value that fits, picks a
   3-column keypad when it fits (easier to scan and to reach with a thumb),
   and shares any space left between the top and the blessing (--plift). */
@media (max-width: 699px) {
  body:has(> .adhyay-selection:not([style*="none"])) { min-height: calc(var(--app-h, 100dvh) / var(--app-zoom, 1)); }
  .adhyay-selection:not([style*="none"]) { display: flex !important; flex-direction: column; align-items: stretch; flex: 1 0 auto; }
  .adhyay-selection > .logo-area { margin: var(--plift, 0px) 0 calc(18px + var(--pg, 0) * 18px); }
  .adhyay-selection > .select-all { margin-bottom: calc(12px + var(--pg, 0) * 8px); }
  .adhyay-selection .adhyay-grid { gap: calc(8px + var(--pg, 0) * 4px); margin-bottom: calc(20px + var(--pg, 0) * 16px); }
  .adhyay-selection .adhyay-card { height: calc(48px + var(--pg, 0) * 8px); }
  .adhyay-selection .adhyay-grid.keypad { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: calc(8px + var(--pg, 0) * 4px) 10px; }
  .adhyay-selection .adhyay-grid.keypad .adhyay-card { height: calc(48px + var(--pg, 0) * 16px); font-size: 20px; }
  .adhyay-selection .start-btn { align-self: center; }
  .adhyay-selection > .footer { margin-top: auto; padding-top: 20px; }
}
@media (max-width: 699px) and (max-height: 600px) {
  .adhyay-selection > .logo-area h1 { font-size: 26px; }
  .adhyay-selection > .logo-area { margin-bottom: 12px; }
  .adhyay-selection .resume-card { margin-bottom: 12px; }
  .adhyay-selection .adhyay-grid { margin-bottom: 14px; }
  .adhyay-selection > .footer { padding-top: 12px; }
}
/* Tablets: the picker sits in the middle of the screen instead of the top */
@media (min-width: 600px) and (min-height: 900px) {
  body:has(.adhyay-selection) { min-height: calc(var(--app-h, 100dvh) / var(--app-zoom, 1)); justify-content: center; }
  .adhyay-selection .adhyay-grid { gap: 12px; margin-bottom: 28px; }
  .adhyay-selection .adhyay-card { height: 64px; font-size: 20px; }
  .adhyay-selection > .logo-area { margin-bottom: 28px; }
  .adhyay-selection > .select-all { margin-bottom: 20px; }
}

.toggle {
  width: 48px;
  height: 28px;
  background: var(--line-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .2s ease;
}
.toggle::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  top: 3px;
  left: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s ease;
}
.toggle::before { content: ""; position: absolute; inset: -10px -6px; } /* 48px touch area */
.toggle.active { background: var(--accent); }
.toggle.active::after { transform: translateX(20px); }

/* 9. STUDY CARD ------------------------------------------------------------ */
.practice-screen, .completion-screen, .reading-screen {
  display: none;
  margin: 0 auto;
  width: min(calc(100% - 24px), 600px);
  text-align: center;
  position: relative;
  flex-shrink: 0;
}

.card {
  /* Fill the screen between the header and the action bar; --app-zoom keeps
     this true when the reader enlarges the text. */
  height: clamp(220px, calc(var(--app-h, 100vh) / var(--app-zoom, 1) - 196px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 760px);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 8px 12px 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
/* --app-h is the real visible height (set by the page head; iOS home-screen
   apps report CSS viewport units inconsistently). The page padding includes
   the iPhone's safe areas (status bar, home bar: zero in Safari, ~59 / ~34 px
   in the installed app), so the card subtracts them and the buttons stay on screen. */

.card-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.card-header > :first-child { min-width: 64px; justify-self: start; text-align: left; }
.card-header > :last-child { min-width: 64px; display: flex; justify-content: flex-end; }
.card-title { display: flex; flex-direction: column; align-items: center; min-width: 0; }

.counter-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.header-text {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  min-width: 0;
}

.timer-container {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  white-space: nowrap;
}
.timer-container .ic { width: 18px; height: 18px; }
.timer-container span { font-size: 14px; font-variant-numeric: tabular-nums; }

.star-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.star-btn.is-on { color: var(--accent); }
.star-btn.is-on .ic { fill: currentColor; }
.star-btn:active { background: var(--surface-2); }

.card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  overflow-y: auto;
  padding: 12px 6px;
  min-height: 0;
  width: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Centre short content, scroll long content */
.card-body::before, .card-body::after { content: ""; margin: auto; }

/* The About card is page content, not a swipe card */
.about-card { height: auto; box-shadow: var(--shadow-sm); }
.about-card .card-body { overflow: visible; overscroll-behavior: auto; }

.center-number {
  font-size: clamp(22px, 4vw + 8px, 30px);
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 8px;
  overflow-wrap: anywhere; /* long IAST compounds never spill past the card */
}

.shloka-text {
  width: 100%;
  font-size: clamp(20px, 2.6vw + 11px, 30px);
  line-height: 1.75;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
  animation: fadeIn .3s ease-out;
}
.shloka-line { display: block; margin-bottom: 6px; }
.shloka-line.speaker {
  font-weight: 600;
  color: var(--accent) !important;
  font-size: .88em;
  margin-bottom: 10px;
}
/* Pronunciation guides like (म्) sit quieter than the verse */
.ph { opacity: .55; font-weight: 400; font-size: .86em; }
/* Verse number stays with the last word and reads as a reference */
.vref { white-space: nowrap; color: var(--muted); font-size: .8em; font-weight: 500; }

.translation-text {
  font-size: clamp(18px, 1.6vw + 12px, 23px) !important;
  line-height: 1.75;
  font-weight: 400;
  color: var(--text);
  text-align: center;
  padding: 4px 8px;
  display: none;
  width: 100%;
}
.translation-text.is-english { font-size: clamp(17px, 1.4vw + 12px, 21px) !important; line-height: 1.65; }

/* Side labels: श्लोक / अनुवाद */
#view-shloka::before,
#view-translation::before,
#shloka-text.is-shloka::before,
#shloka-text.is-pushpika::before {
  content: attr(data-label);
  display: block;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 14px;
  text-align: center;
}
[data-lang^="en"] #view-shloka::before,
[data-lang^="en"] #view-translation::before,
[data-lang^="en"] #shloka-text::before { letter-spacing: .1em; font-size: 13px; }

.card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 4px;
  min-height: 52px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
#prev-shloka { grid-column: 1; grid-row: 1; justify-self: start; }
#next-shloka { grid-column: 3; grid-row: 1; justify-self: end; }

.shloka-nav-btn {
  height: 44px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  visibility: hidden;
}
.shloka-nav-btn .ic { width: 20px; height: 20px; color: var(--muted); }
.shloka-nav-btn:active { background: var(--surface-2); }

.hint-btn {
  grid-column: 2;
  grid-row: 1;
  height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.hint-btn .ic { width: 18px; height: 18px; color: var(--accent); }
.hint-btn.active { background: var(--surface-2); }

.hint-banner {
  grid-column: 1 / span 3;
  grid-row: 2;
  display: none;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  animation: slideIn .25s ease-out;
}

/* Action bar under the card: previous · flip · next */
.action-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}
.bar-btn {
  height: var(--tap);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.bar-btn:not(.primary) { padding: 0 8px; gap: 2px; }
.bar-btn:first-child { justify-self: start; }
.bar-btn:last-child { justify-self: end; }
.bar-btn .ic { width: 22px; height: 22px; }
.bar-btn:active { background: var(--surface-2); }
.bar-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.bar-btn.primary {
  min-width: 124px;
  justify-content: center;
  padding: 0 18px;
  gap: 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
}
.bar-btn.primary:active { transform: scale(.97); background: var(--accent); }
/* When the words don't fit (narrow phone, English, larger text) the bar measures
   itself and Previous/Next keep only their chevrons; the words stay available
   to screen readers. See fitActionBars() in theme.js. */
.action-bar.compact .bar-btn:not(.primary) { padding: 0 9px; }
.action-bar.compact .bar-btn:not(.primary) > span {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.action-bar.compact .bar-btn.primary { min-width: 0; padding: 0 14px; }
/* Last resort (tiny screen + largest text): the main label may wrap to two lines */
.action-bar.tight .bar-btn.primary {
  padding: 0 12px; font-size: 14px; line-height: 1.15;
  white-space: normal; text-align: center; max-width: 9em;
}
.action-bar.tight .bar-btn.primary > span { top: 0; }
.action-bar.tight { gap: 4px; }
.action-bar.tight .bar-btn:not(.primary) { padding: 0 5px; }
@media (hover: hover) {
  .bar-btn:not(.primary):not(:disabled):hover, .shloka-nav-btn:hover, .star-btn:hover { background: var(--surface-2); }
}

/* Completion */
.completion-screen { padding-top: 24px; }
.completion-screen h1, .completion-screen h2 { font-size: 26px; line-height: 1.35; margin: 16px 0 8px; }
.completion-screen p { color: var(--muted); font-size: 16px; margin: 0 0 20px; }
.done-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.done-mark .ic { width: 30px; height: 30px; stroke-width: 2; }

/* Continue-reading card on the chapter picker */
.adhyay-selection .resume-card { width: 100%; max-width: 420px; margin: 0 auto 20px; }

/* 10. DIALOGS --------------------------------------------------------------- */
.jump-overlay, .modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}

/* Quick jump opened from Home is a page of its own: no dimmed backdrop,
   top bar stays live, Home replaces the Close button. */
.jump-overlay.as-page {
  position: static;
  inset: auto;
  background: none;
  padding: 8px 16px 24px;
  z-index: auto;
  width: 100%;
}
.jump-overlay.as-page .jump-card { box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.jump-overlay.as-page .jump-btn-cancel { display: none; }
.jump-overlay.as-page .jump-actions { grid-template-columns: 1fr; display: grid; }

.jump-card, .modal-card {
  background: var(--card-bg);
  border-radius: 24px;
  width: 100%;
  max-width: 400px;
  padding: 24px 20px 20px;
  box-shadow: var(--shadow-lg);
  position: relative;
  text-align: left;
}
.jump-card h3, .modal-card h3 {
  margin: 0 0 16px;
  font-size: 22px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}
.modal-card h3 { margin-bottom: 6px; }
.modal-card p { font-size: 15px; color: var(--muted); margin: 0 0 18px; text-align: center; }

.drop-group { margin-bottom: 16px; }
.drop-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.drop-group select {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  font-size: 17px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  outline: none;
  cursor: pointer;
}
.drop-group select:focus { border-color: var(--accent); }
.drop-group select:disabled { opacity: .5; }

.jump-actions { display: flex; gap: 10px; margin-top: 4px; }
.jump-btn-go, .jump-btn-cancel {
  min-height: var(--tap);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.jump-btn-go { flex: 2; background: var(--accent); color: var(--on-accent); }
.jump-btn-cancel { flex: 1; background: var(--surface-2); color: var(--text); }

.lang-options { display: flex; flex-direction: column; gap: 10px; }
.lang-options button {
  width: 100%;
  min-height: 64px;
  padding: 10px 48px 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  position: relative;
  transition: border-color .15s ease, background .15s ease;
}
.lang-options button:active { background: var(--surface-2); }
.lang-options button.selected { border-color: var(--accent); background: var(--accent-soft); }
.lang-options button strong { font-size: 17px; font-weight: 650; }
.lang-options button span { font-size: 14px; color: var(--muted); }
.check-mark {
  position: absolute;
  right: 14px;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(.6);
  transition: transform .2s ease, opacity .2s ease;
}
.check-mark .ic { width: 16px; height: 16px; stroke-width: 2.5; }
.lang-options button.selected .check-mark { opacity: 1; transform: scale(1); }

/* First-run language box: stacked bilingual title, left-aligned with the option
   text; every option is described in its own language */
.lang-card { padding: 22px 18px 18px; }
.lang-card h3 {
  text-align: left;
  margin: 0 0 16px;
  padding: 0 17px;                 /* = option border + padding, so the left edges line up */
  font-size: 22px;
  line-height: 1.3;
}
.lang-card h3 > span { display: block; }
.lang-card .lang-sub { margin-top: 2px; font-size: 15px; font-weight: 500; color: var(--muted); }
.lang-card .lang-options button { padding-right: 44px; }
.lang-card .lang-options .chev {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted);
}
.modal-overlay { -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }

/* 11. TOAST ------------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(calc(100% - 32px), 360px);
  padding: 11px 18px;
  border-radius: 14px;          /* a pill turns into a blob when the text wraps */
  line-height: 1.45;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  z-index: 12000;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
  box-shadow: var(--shadow-lg);
}

/* 12. MOTION ----------------------------------------------------------------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Even line breaks in headings (avoids a single orphan word) */
h1, h2, h3, .subtitle { text-wrap: balance; }

/* Touch screens: scroll without a visible bar (the momentary indicator on phones
   and tablets). Mouse and trackpad users keep their normal scrollbar. */
@media (pointer: coarse) {
  html, body, * { scrollbar-width: none; -ms-overflow-style: none; }
  html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar {
    display: none; width: 0; height: 0; background: transparent;
  }
}

/* One-time tips: ink callout pointing at the main button, clearly not a control */
.first-tip {
  position: fixed;
  left: 50%;
  z-index: 1200;
  width: min(calc(100% - 32px), 420px);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px 10px 12px;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 15px;
  line-height: 1.45;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.first-tip.show { opacity: 1; transform: translate(-50%, 0); }
/* Taps go through the tip to whatever is under it (and dismiss it); only "Got it" catches taps */
.first-tip .tip-ok { pointer-events: auto; }
.first-tip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-radius: 2px;
  transform: translateX(-50%) rotate(45deg);
}
.tip-gesture {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 16%, transparent);
}
.tip-gesture .ic { width: 20px; height: 20px; }
.tip-gesture.up .ic { animation: tipNudgeY 1.6s ease-in-out infinite; }
.tip-gesture.left .ic { animation: tipNudgeX 1.6s ease-in-out infinite; }
@keyframes tipNudgeY { 0%, 100% { transform: translateY(4px); } 50% { transform: translateY(-4px); } }
@keyframes tipNudgeX { 0%, 100% { transform: translateX(4px); } 50% { transform: translateX(-4px); } }
.tip-text { flex: 1; min-width: 0; }
.tip-ok {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
@media (prefers-reduced-motion: reduce) {
  .first-tip { transition: none; }
  .tip-gesture .ic { animation: none; }
}

/* Hide words until they are in the reader's language (see the head script) */
.i18n-pending [data-cap] { visibility: hidden; }
/* Text size applies from the first paint (theme.js sets the same value later) */
body { zoom: var(--app-zoom, 1); }
