/* ==========================================================================
   03 · APP SHELL
   Topbar (brand · context chip · mode switch · settings)
   Rail    (grouped navigation, collapsible)
   Drawer  (profile library)
   Wizard  (step-by-step chart entry)
   Modal · Toast · Command palette
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: auto auto;
  grid-template-areas: "brand topbar" "rail  main";
  /* Document scrolls (WKWebView). Clip horizontal bleed here — never on
     html/body (that kills iOS vertical scroll). */
  min-height: 100dvh;
  height: auto;
  overflow-x: clip;
  overflow-y: visible;
}
.app.rail-collapsed { grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr); }
.app.gmp-only,
body.gmp-only .app {
  grid-template-columns: minmax(0, 1fr) !important;
}
.app.gmp-only .rail,
.app.gmp-only .rail-toggle,
.app.gmp-only #mode-switch,
.app.gmp-only #ctx-chip,
.app.gmp-only .page-head,
.app.gmp-only .mobile-nav {
  display: none !important;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.brand-cell {
  grid-area: brand;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--s-3);
  background: var(--th-card);
  border-right: 1px solid var(--th-line);
  border-bottom: 1px solid var(--th-line);
  position: sticky; top: 0; z-index: var(--z-topbar);
}
.brand-logo {
  width: 3.5rem; height: 3.5rem; flex: 0 0 auto;
  border-radius: var(--r-md);
  object-fit: cover;
  box-shadow: 0 2px 12px var(--th-shadow);
}
.brand-mark {
  display: none;
}
.brand-text { min-width: 0; }
.brand-title {
  font-family: var(--font-display); font-size: var(--text-md);
  color: var(--th-label); margin: 0; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub {
  font: 500 var(--text-2xs)/1 var(--font-mono);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  color: var(--th-text-dim); margin: 2px 0 0;
}
.rail-collapsed .brand-text { display: none; }

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: var(--s-3);
  padding: env(safe-area-inset-top, 0px) var(--s-4) 0;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  background: var(--th-header);
  color: var(--th-header-text);
  border-bottom: 1px solid var(--th-line);
  position: sticky; top: 0; z-index: var(--z-topbar);
}
.topbar-spacer { flex: 1 1 auto; }

/* ---- the always-visible context chip ---- */
.ctx-chip {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0.3rem 0.35rem 0.3rem 0.75rem;
  border-radius: var(--r-full);
  border: 1px solid var(--th-line);
  background: var(--th-card);
  box-shadow: var(--e-1);
  cursor: pointer; max-width: min(46rem, 60vw);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.ctx-chip:hover { border-color: var(--th-accent); box-shadow: var(--e-2); }
.ctx-chip[data-empty="true"] {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--th-accent) 45%, transparent);
  background: var(--th-accent-soft);
}
.ctx-avatar {
  width: 1.85rem; height: 1.85rem; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--th-accent-soft); color: var(--th-label);
  font: 600 var(--text-xs)/1 var(--font-body);
}
.ctx-body { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ctx-name {
  font-size: var(--text-sm); font-weight: 600; color: var(--th-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctx-meta {
  font: 400 var(--text-2xs)/1.3 var(--font-mono);
  color: var(--th-text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctx-meta b { color: var(--th-label); font-weight: 600; }
.ctx-caret { color: var(--th-text-dim); font-size: 0.7rem; padding-right: var(--s-2); }

/* ---- natal / now switch ---- */
.mode-switch { flex: 0 0 auto; }
.mode-switch button { min-width: 4.2rem; }
.mode-switch button.is-on[data-mode="now"] {
  color: var(--ok); background: var(--th-card);
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  animation: jv-pulse 1.8s ease-in-out infinite;
}
@keyframes jv-pulse { 50% { opacity: 0.25; transform: scale(0.75); } }

.topbar-status {
  font: 400 var(--text-xs)/1 var(--font-mono);
  color: var(--th-text-dim);
  padding: 0.3rem 0.6rem; border-radius: var(--r-full);
  background: var(--th-accent-soft);
  min-height: 1.5rem; display: inline-flex; align-items: center;
}
.topbar-status:empty { display: none; }
.topbar-status.err { color: var(--danger); background: var(--danger-soft); }

/* ==========================================================================
   Navigation rail
   ========================================================================== */
.rail {
  grid-area: rail;
  background: var(--th-card);
  border-right: 1px solid var(--th-line);
  overflow-y: auto; overflow-x: hidden;
  padding: var(--s-3) var(--s-2) var(--s-5);
  position: sticky; top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  z-index: var(--z-rail);
}
.rail-group { margin-bottom: var(--s-3); }

.rail-group-title {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; padding: var(--s-1) var(--s-3);
  border: 0; background: transparent; border-radius: var(--r-sm);
  font: 600 var(--text-2xs)/1.6 var(--font-mono);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  color: var(--th-text-dim);
}
.rail-group-title:hover { background: var(--th-hover); border-color: transparent; }
.rail-group-title span:first-child { flex: 1; text-align: left; }
.rail-group-chevron {
  display: grid; place-items: center; width: 1rem; height: 1rem;
  transition: transform var(--dur-2) var(--ease);
}
.rail-group-chevron svg { width: 0.85rem; height: 0.85rem; }
.rail-group.is-shut .rail-group-chevron { transform: rotate(-90deg); }

.rail-group-body {
  display: grid; grid-template-rows: 1fr;
  transition: grid-template-rows var(--dur-2) var(--ease);
}
.rail-group-body > * { overflow: hidden; }
.rail-group.is-shut .rail-group-body { grid-template-rows: 0fr; }

.rail-item {
  /* fixed icon column + flexible label — this grid is what keeps every
     row's text on the same x position regardless of glyph */
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  align-items: center; gap: var(--s-3);
  width: 100%; padding: 0.45rem var(--s-3);
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--th-text);
  font-size: var(--text-sm); text-align: left;
  position: relative;
}
.rail-item:hover { background: var(--th-hover); border-color: transparent; }
.rail-item.is-active {
  background: var(--th-selected); color: var(--th-label); font-weight: 600;
}
.rail-item.is-active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: var(--r-full); background: var(--th-accent);
}

/* one shared icon box — every SVG lands on the same 1.5rem grid cell */
.rail-icon, .tile-icon, .palette-icon, .now-sec-title,
.btn-icon, .ico, .ctx-caret, .ctx-avatar {
  display: inline-grid; place-items: center;
}
.rail-icon { width: 1.5rem; height: 1.5rem; }
.rail-icon svg { width: 1.15rem; height: 1.15rem; }
.rail-item.is-active .rail-icon { color: var(--th-accent); }

.rail-label { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.rail-label-main {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-label-sub {
  font-size: var(--text-2xs); color: var(--th-text-dim); font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-item.is-active .rail-label-sub { color: var(--th-label); opacity: 0.8; }

.rail-collapsed .rail-label,
.rail-collapsed .rail-group-title span:first-child,
.rail-collapsed .rail-group-chevron { display: none; }
.rail-collapsed .rail-item { grid-template-columns: 1fr; justify-items: center; padding-inline: 0; }
.rail-collapsed .rail-group-title { justify-content: center; padding-inline: 0; }
.rail-collapsed .rail-group-title::after {
  content: ""; display: block; width: 1.25rem; height: 1px;
  background: var(--th-line);
}
.rail-collapsed .rail-group.is-shut .rail-group-body { grid-template-rows: 1fr; }

.rail-foot {
  border-top: 1px solid var(--th-line-soft);
  margin-top: var(--s-3); padding-top: var(--s-3);
}

/* generic icon sizing outside the rail */
.btn-icon svg, .ico svg { width: 1.1rem; height: 1.1rem; }
.btn-topbar { gap: var(--s-2); }
.btn-topbar .ico { width: 1.1rem; height: 1.1rem; }
.tile-icon { width: 2rem; height: 2rem; color: var(--th-accent); }
.tile-icon svg { width: 1.5rem; height: 1.5rem; }
.palette-icon { width: 1.25rem; height: 1.25rem; color: var(--th-text-dim); }
.palette-icon svg { width: 1.05rem; height: 1.05rem; }
.profile-actions svg { width: 1rem; height: 1rem; }
.star-on { color: var(--warn); }
.ctx-name .star-on svg { width: 0.8rem; height: 0.8rem; fill: currentColor; }

/* ==========================================================================
   Main content
   ========================================================================== */
.main {
  grid-area: main;
  min-width: 0;
  overflow: visible;
  padding: var(--s-4) clamp(var(--s-3), 2vw, var(--s-5)) var(--s-7);
}
.main-inner { max-width: var(--content-max); margin: 0 auto; }
main.main-wide, .main.main-wide .main-inner { max-width: none; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap;
}
.page-head-main { flex: 1 1 12rem; min-width: 0; }
.page-title { margin: 0; font-size: var(--text-xl); }
.page-sub { margin: 2px 0 0; font-size: var(--text-xs); color: var(--th-text-dim); }
.page-head-actions {
  display: flex; align-items: center; gap: 0.35rem; flex: 0 0 auto;
}
.page-nav-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  min-width: 2.4rem; min-height: 2.4rem; padding: 0.35rem 0.55rem;
  border: 1px solid var(--th-line); border-radius: var(--r-sm);
  background: var(--th-card); color: var(--th-text); cursor: pointer;
}
.page-nav-btn:hover:not(:disabled) {
  border-color: var(--th-accent, var(--marigold)); background: var(--th-hover);
}
.page-nav-btn:disabled { opacity: 0.35; cursor: default; }
.page-nav-btn .ico, .page-nav-btn svg {
  width: 1.15rem; height: 1.15rem; display: block;
}
.page-nav-home .page-nav-label {
  font-size: var(--text-xs); font-weight: 600;
}
.page-research-bar {
  margin-top: 0.45rem; display: flex; flex-wrap: wrap; gap: 0.4rem;
  align-items: center;
}
.page-research-bar.hidden { display: none !important; }
.page-research-bar label {
  display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--th-text-dim);
}
.page-research-bar select {
  min-width: 11rem; max-width: min(20rem, 72vw);
  font-size: var(--text-sm); padding: 0.35rem 0.5rem;
  border: 1px solid var(--th-line); border-radius: var(--r-sm);
  background: var(--th-page, var(--ink-deep)); color: var(--th-text);
}
.page-head--home .page-sub { display: none; }

html.is-phone .page-nav-home .page-nav-label,
html.is-capacitor .page-nav-home .page-nav-label { display: none; }
html.is-phone .page-research-bar select,
html.is-capacitor .page-research-bar select {
  min-width: 9rem; max-width: calc(100vw - 7rem);
}

/* ==========================================================================
   Drawer — profile library
   ========================================================================== */
.drawer-scrim {
  position: fixed; inset: 0; z-index: var(--z-drawer);
  background: color-mix(in srgb, #000 45%, transparent);
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), visibility var(--dur-2);
}
.drawer-scrim.open { opacity: 1; visibility: visible; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(26rem, 92vw); z-index: calc(var(--z-drawer) + 1);
  background: var(--th-card);
  border-right: 1px solid var(--th-line);
  box-shadow: var(--e-4);
  display: flex; flex-direction: column;
  transform: translateX(-102%);
  transition: transform var(--dur-3) var(--ease);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4); border-bottom: 1px solid var(--th-line);
}
.drawer-head h2 { margin: 0; flex: 1; font-size: var(--text-lg); }
.drawer-search { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--th-line-soft); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-2); }
.drawer-foot {
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--th-line);
  display: flex; gap: var(--s-2);
}

/* ---- profile list ---- */
.profile-card {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: var(--s-3);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; text-align: left; margin-bottom: 2px;
}
.profile-card:hover { background: var(--th-hover); border-color: var(--th-line); }
.profile-card.is-active {
  background: var(--th-selected);
  border-color: color-mix(in srgb, var(--th-accent) 40%, transparent);
}
.profile-avatar {
  width: 2.25rem; height: 2.25rem; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--th-accent-soft); color: var(--th-label);
  font: 600 var(--text-sm)/1 var(--font-body);
}
.profile-info { flex: 1; min-width: 0; }
.profile-name {
  font-size: var(--text-sm); font-weight: 600; color: var(--th-text);
  display: flex; align-items: center; gap: var(--s-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-meta {
  font: 400 var(--text-2xs)/1.4 var(--font-mono);
  color: var(--th-text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur-1); }
.profile-card:hover .profile-actions,
.profile-card.is-active .profile-actions { opacity: 1; }
.star-on { color: var(--warn); }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-scrim {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--s-4);
  background: color-mix(in srgb, #000 52%, transparent);
  backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), visibility var(--dur-2);
}
.modal-scrim.open { opacity: 1; visibility: visible; pointer-events: auto; }
.modal {
  width: min(46rem, 100%); max-height: min(92vh, 54rem);
  display: flex; flex-direction: column;
  background: var(--th-card);
  border: 1px solid var(--th-line);
  border-radius: var(--r-lg);
  box-shadow: var(--e-4);
  transform: translateY(12px) scale(0.985);
  transition: transform var(--dur-3) var(--ease);
}
.modal-scrim.open .modal { transform: none; }
.modal-head {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-4) var(--s-5) var(--s-3);
  border-bottom: 1px solid var(--th-line-soft);
}
.modal-head h2 { margin: 0; }
.modal-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.modal-foot {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-5) var(--s-4);
  border-top: 1px solid var(--th-line-soft);
}
.modal-foot .spacer { flex: 1; }

/* ==========================================================================
   Wizard
   ========================================================================== */
.wizard-steps {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--th-line-soft);
  background: var(--th-page-alt);
}
.wstep {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--text-xs); color: var(--th-text-dim);
  white-space: nowrap;
}
.wstep-dot {
  width: 1.5rem; height: 1.5rem; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--th-line); background: var(--th-card);
  font: 600 var(--text-2xs)/1 var(--font-mono);
  transition: all var(--dur-2) var(--ease);
}
.wstep.is-current { color: var(--th-label); font-weight: 600; }
.wstep.is-current .wstep-dot {
  background: var(--th-accent); border-color: var(--th-accent);
  color: var(--th-btn-text);
  box-shadow: 0 0 0 4px var(--th-ring);
}
.wstep.is-done .wstep-dot {
  background: var(--ok-soft); border-color: var(--ok); color: var(--ok);
}
.wstep-line {
  flex: 1 1 1.5rem; height: 1px; min-width: 0.75rem;
  background: var(--th-line);
}
.wstep.is-done + .wstep-line { background: var(--ok); }
@media (max-width: 640px) {
  .wstep-label { display: none; }
}

.wpanel { display: none; animation: jv-fade var(--dur-3) var(--ease); }
.wpanel.is-current { display: block; }
@keyframes jv-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.wpanel-lead {
  font-size: var(--text-sm); color: var(--th-text-dim);
  margin: 0 0 var(--s-4); max-width: 52ch;
}
.wpanel h3 { font-size: var(--text-lg); margin-bottom: var(--s-1); }

/* place picker inside the wizard */
.place-search-row { display: flex; gap: var(--s-2); align-items: flex-end; }
.place-search-row .field { flex: 1; }
.place-hits {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: var(--s-2); max-height: 15rem; overflow-y: auto;
  border: 1px solid var(--th-line); border-radius: var(--r-sm);
  padding: var(--s-1);
}
.place-hits:empty { display: none; }
.place-hit {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; padding: var(--s-2) var(--s-3); text-align: left;
  border: 0; border-radius: var(--r-sm); background: transparent;
}
.place-hit:hover { background: var(--th-hover); border-color: transparent; }
.place-hit-name { font-size: var(--text-sm); color: var(--th-text); }
.place-hit-meta { font: 400 var(--text-2xs)/1.3 var(--font-mono); color: var(--th-text-dim); }

.saved-places {
  display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3);
}
.saved-place {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 0.3rem 0.7rem; border-radius: var(--r-full);
  border: 1px solid var(--th-line); background: var(--th-page-alt);
  font-size: var(--text-xs);
}
.saved-place:hover { border-color: var(--th-accent); background: var(--th-hover); }
.saved-place.is-selected {
  background: var(--th-selected); border-color: var(--th-accent);
  color: var(--th-label); font-weight: 600;
}

.quick-row { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }

/* review step */
.review-list {
  display: grid; grid-template-columns: max-content 1fr;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-4); border-radius: var(--r-md);
  background: var(--th-page-alt); border: 1px solid var(--th-line-soft);
}
.review-list dt {
  font: 600 var(--text-2xs)/1.6 var(--font-mono);
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--th-text-dim);
}
.review-list dd { margin: 0; font-size: var(--text-sm); color: var(--th-text); }

/* ==========================================================================
   Now panel — editable query moment
   ========================================================================== */
.now-modal { max-width: 32rem; }
.now-sec { padding-bottom: var(--s-4); }
.now-sec + .now-sec {
  border-top: 1px solid var(--th-line-soft);
  padding-top: var(--s-4);
}
.now-sec-head {
  display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2);
}
.now-sec-title {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font: 600 var(--text-sm)/1 var(--font-body); color: var(--th-label);
}
.now-sec-title svg { width: 1.05rem; height: 1.05rem; }
.now-current {
  margin: 0 0 var(--s-3); font-size: var(--text-md); color: var(--th-text);
  display: flex; flex-direction: column; gap: 2px;
}
.now-place-row { display: flex; gap: var(--s-2); align-items: stretch; }
.now-place-row input { flex: 1; }
.now-place-row .btn-sm { flex: 0 0 auto; padding-inline: var(--s-3); }
.now-freeze-switch { margin-bottom: var(--s-3); }
.now-clock {
  font-size: var(--text-2xl); font-weight: 500; color: var(--th-label);
  margin: 0 0 var(--s-1); font-variant-numeric: tabular-nums;
}
.mode-switch.has-override button.is-on[data-mode="now"] {
  box-shadow: 0 0 0 2px var(--th-ring), var(--e-1);
}
.mode-caret { display: inline-grid; place-items: center; margin-left: 2px; }
.mode-caret svg { width: 0.7rem; height: 0.7rem; }
.mode-switch button svg { width: 0.85rem; height: 0.85rem; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-stack {
  position: fixed; bottom: var(--s-4); right: var(--s-4);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--s-2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--th-card); color: var(--th-text);
  border: 1px solid var(--th-line);
  box-shadow: var(--e-3);
  font-size: var(--text-sm);
  animation: jv-toast-in var(--dur-3) var(--ease);
  pointer-events: auto;
}
.toast--ok { border-left: 3px solid var(--ok); }
.toast--err { border-left: 3px solid var(--danger); }
@keyframes jv-toast-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}

/* ==========================================================================
   Command palette
   ========================================================================== */
.palette {
  width: min(34rem, 100%); align-self: start; margin-top: 12vh;
  background: var(--th-card); border: 1px solid var(--th-line);
  border-radius: var(--r-lg); box-shadow: var(--e-4); overflow: hidden;
}
.palette input {
  border: 0; border-bottom: 1px solid var(--th-line-soft);
  border-radius: 0; padding: var(--s-4); font-size: var(--text-md);
}
.palette input:focus { box-shadow: none; }
.palette-list { max-height: 24rem; overflow-y: auto; padding: var(--s-2); }
.palette-item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: var(--s-2) var(--s-3); text-align: left;
  border: 0; border-radius: var(--r-sm); background: transparent;
  font-size: var(--text-sm);
}
.palette-item:hover, .palette-item.is-active {
  background: var(--th-selected); border-color: transparent;
}
.palette-item-kind {
  margin-left: auto; font: 400 var(--text-2xs)/1 var(--font-mono);
  color: var(--th-text-dim);
}

/* ==========================================================================
   Home dashboard
   ========================================================================== */
.hero {
  padding: var(--s-6) var(--s-5);
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--th-card) 0%, var(--th-card-alt) 100%);
  border: 1px solid var(--th-line);
  box-shadow: var(--e-2);
  margin-bottom: var(--s-4);
}
.hero h2 { font-size: var(--text-2xl); margin-bottom: var(--s-2); }
.hero p { color: var(--th-text-dim); max-width: 60ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-4); }
.hero-picker { display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--s-2); margin-top: var(--s-3); }
.hero-picker label { color: var(--th-text-dim); font-size: var(--text-sm); }
.hero-picker select { min-width: 16rem; max-width: 100%; }

.home-sections {
  display: flex; flex-direction: column; gap: var(--s-5);
}
.home-domain-section {
  display: flex; flex-direction: column; gap: var(--s-2);
}
.home-domain-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 0.35rem;
  border-bottom: 1.5px solid var(--th-line-soft);
}
.home-domain-title {
  font-size: var(--text-sm); font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--th-accent);
}
.tile-grid {
  display: grid; gap: var(--s-3);
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem;
  padding: 1rem 1.15rem; text-align: left;
  border: 1px solid var(--th-line); border-radius: var(--r-md);
  background: var(--th-card); box-shadow: var(--e-1);
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
  position: relative;
}
.tile:hover {
  border-color: var(--th-accent); transform: translateY(-2px);
  box-shadow: var(--e-3); background: var(--th-card);
}
.tile-top {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; margin-bottom: 0.25rem;
}
.tile-icon-box {
  width: 2.25rem; height: 2.25rem; border-radius: var(--r-sm);
  display: inline-grid; place-items: center;
  background: color-mix(in srgb, var(--th-accent) 12%, transparent);
  color: var(--th-accent);
  transition: transform var(--dur-2) var(--ease);
}
.tile:hover .tile-icon-box { transform: scale(1.08); }
.tile-icon-box svg { width: 1.35rem; height: 1.35rem; }
.tile-badge {
  font-size: 0.68rem; font-weight: 600; padding: 0.15rem 0.5rem;
  border-radius: var(--r-full);
  background: var(--th-page-alt);
  color: var(--th-text-dim);
  border: 1px solid var(--th-line-soft);
}
.tile-icon { font-size: 1.4rem; }
.tile-title { font-size: var(--text-md); font-weight: 700; color: var(--th-label); line-height: 1.3; }
.tile-desc { font-size: var(--text-xs); color: var(--th-text-dim); line-height: 1.4; }

.recent-list { display: flex; flex-direction: column; gap: 2px; }
.recent-item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: var(--s-2) var(--s-3); text-align: left;
  border: 0; border-radius: var(--r-sm); background: transparent;
  font-size: var(--text-sm);
}
.recent-item:hover { background: var(--th-hover); border-color: transparent; }
.recent-when {
  margin-left: auto; font: 400 var(--text-2xs)/1 var(--font-mono);
  color: var(--th-text-dim);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .app { grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr); }
  .rail-label, .rail-group-title, .brand-text { display: none; }
  .rail-item { justify-content: center; padding-inline: 0; }
}
@media (max-width: 720px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "topbar" "main";
  }
  .brand-cell, .rail { display: none; }
  .topbar { padding-inline: var(--s-3); gap: var(--s-2); }
  .ctx-chip { max-width: none; flex: 1; min-width: 0; }
  .ctx-meta { font-size: 0.6rem; }
  .main { padding: var(--s-3) var(--s-3) calc(5.5rem + env(safe-area-inset-bottom, 0px)); }
  .mobile-nav { display: flex; }
  /* On phones the rail is gone — this chevron is Home, not "collapse sidebar". */
  .rail-toggle { transform: none; }
}

/* bottom bar on phones — horizontally scrollable, all search screens */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: var(--th-card); border-top: 1px solid var(--th-line);
  padding: var(--s-1) var(--s-1) calc(var(--s-1) + env(safe-area-inset-bottom, 0px));
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* Claim horizontal pans so the bar scrolls; page still gets vertical. */
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  box-shadow: 0 -2px 10px color-mix(in srgb, var(--th-shadow, #4a2e18) 8%, transparent);
}
.mobile-nav button {
  /* Must stay 0 0 auto so many Tamil chips overflow and can scroll.
     flex-grow would eat free space and hide the need to swipe. */
  flex: 0 0 auto;
  min-width: 3.55rem;
  flex-direction: column; gap: 2px;
  border: 0; background: transparent; padding: var(--s-2) 0.22rem;
  font-size: 0.52rem; color: var(--th-text-dim);
  /* Do NOT use manipulation — it blocks parent overflow-x pan in WebView
     when the gesture starts on a button (the whole bar is buttons). */
  touch-action: pan-x;
}
html.is-phone .mobile-nav,
html.is-capacitor .mobile-nav {
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 0;
  scrollbar-width: none;
  touch-action: pan-x;
}
html.is-phone .mobile-nav::-webkit-scrollbar,
html.is-capacitor .mobile-nav::-webkit-scrollbar { display: none; }
html.is-phone .mobile-nav button,
html.is-capacitor .mobile-nav button {
  min-width: 3.35rem;
  max-width: 4.2rem;
  flex: 0 0 auto;
  padding-inline: 0.15rem;
  overflow: hidden;
  touch-action: pan-x;
}
html.is-phone .mobile-nav button span,
html.is-capacitor .mobile-nav button span,
html.is-phone .mobile-nav .rail-label,
html.is-capacitor .mobile-nav .rail-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-nav button.is-active { color: var(--th-accent); }
.mobile-nav .rail-icon { font-size: var(--text-lg); }

/* --------------------------------------------------------------------------
   Phone / Capacitor — DOCUMENT scroll (WKWebView UIScrollView).
   Critical: never overflow-x:hidden on html/body (blocks iOS Y-scroll).
   -------------------------------------------------------------------------- */
html.is-phone,
html.is-capacitor {
  height: auto;
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}
html.is-phone body,
html.is-capacitor body {
  position: static;
  height: auto;
  min-height: 100%;
  width: 100%;
  overflow: visible;
  /* Clear fixed bottom nav so the last cards are reachable. */
  padding-bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px));
}
html.is-phone .app,
html.is-capacitor .app {
  position: relative;
  display: block;
  height: auto;
  min-height: 100%;
  width: 100%;
  /* Clip X only — keeps WKWebView document Y-scroll healthy on iOS.
     Jamakkol outer labels stay inside wrap padding so they aren't clipped. */
  overflow-x: clip;
  overflow-y: visible;
  grid-template-columns: unset;
  grid-template-rows: unset;
  grid-template-areas: unset;
  touch-action: pan-x pan-y;
}
html.is-phone .brand-cell,
html.is-phone .rail,
html.is-capacitor .brand-cell,
html.is-capacitor .rail { display: none !important; }
html.is-phone .topbar,
html.is-capacitor .topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding-top: max(var(--s-2), env(safe-area-inset-top, 0px));
}
html.is-phone .main,
html.is-capacitor .main {
  position: relative;
  top: auto;
  bottom: auto;
  left: auto;
  right: auto;
  height: auto;
  min-width: 0;
  max-width: 100%;
  overflow: visible;
  padding: var(--s-3);
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  touch-action: pan-y;
}
html.is-phone .modal.open,
html.is-capacitor .modal.open {
  /* keep modal sheet itself from trapping the whole page incorrectly */
  overscroll-behavior: contain;
}
html.is-phone .page-head,
html.is-capacitor .page-head {
  margin-bottom: var(--s-3);
  scroll-margin-top: calc(3.75rem + env(safe-area-inset-top, 0px));
}
html.is-phone .card,
html.is-capacitor .card {
  scroll-margin-top: calc(3.75rem + env(safe-area-inset-top, 0px));
  overflow: visible;
  padding: var(--s-3);
  min-width: 0;
  max-width: 100%;
}
html.is-phone .card > h2,
html.is-capacitor .card > h2 {
  margin-top: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
html.is-phone .tile-grid,
html.is-capacitor .tile-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-2);
}
html.is-phone .table-scroll,
html.is-capacitor .table-scroll {
  margin-inline: 0;
  padding-inline: 0;
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  min-width: 0;
}
html.is-phone .table-scroll > table,
html.is-capacitor .table-scroll > table {
  width: max-content;
  min-width: 100%;
  border: 0;
}
html.is-phone .modal,
html.is-capacitor .modal {
  width: calc(100vw - 1rem);
  max-width: min(100vw - 1rem, 36rem);
  max-height: min(92dvh, 44rem);
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
html.is-phone .modal-body,
html.is-capacitor .modal-body {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(70dvh, 32rem);
  overscroll-behavior: contain;
  touch-action: pan-y;
}
html.is-phone .an-subnav,
html.is-capacitor .an-subnav,
html.is-phone #ck-subnav,
html.is-capacitor #ck-subnav {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  padding-bottom: 0.35rem;
  margin-inline: 0;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: thin;
}
html.is-phone .an-subnav .an-sub,
html.is-capacitor .an-subnav .an-sub,
html.is-phone .an-subnav .kp-sub,
html.is-capacitor .an-subnav .kp-sub,
html.is-phone .an-subnav .gmp-sub,
html.is-capacitor .an-subnav .gmp-sub,
html.is-phone #ck-subnav button,
html.is-capacitor #ck-subnav button {
  flex: 0 0 auto;
}
html.is-phone .natal-row,
html.is-capacitor .natal-row {
  grid-template-columns: minmax(5.5rem, 32%) 1fr;
  gap: 0.35rem 0.65rem;
  padding: 0.4rem 0;
}
html.is-phone .natal-row dt,
html.is-capacitor .natal-row dt,
html.is-phone .natal-row dd,
html.is-capacitor .natal-row dd {
  font-size: 0.8rem;
  line-height: 1.4;
}
html.is-phone .quick-row,
html.is-capacitor .quick-row {
  flex-direction: column;
  align-items: stretch;
}
html.is-phone .quick-row .btn-sm,
html.is-capacitor .quick-row .btn-sm {
  width: 100%;
  justify-content: center;
}
.theme-auto-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 0.55rem;
  margin-top: 0.55rem;
  font-size: var(--text-sm);
  color: var(--th-text);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.theme-auto-label input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex: 0 0 auto;
  align-self: center;
  accent-color: var(--th-accent, var(--marigold));
}
.theme-auto-label span {
  flex: 1 1 auto;
  line-height: 1.3;
}
html.is-phone .jv-scroll,
html.is-capacitor .jv-scroll {
  position: static;
  height: auto;
  width: auto;
  overflow: visible;
  padding: 0;
  transform: none;
  background: transparent;
}
html.is-phone.scroll-snap-sections,
html.is-capacitor.scroll-snap-sections {
  scroll-snap-type: none !important;
}
html.is-phone .mobile-nav,
html.is-capacitor .mobile-nav { display: flex; }

html.modal-open {
  /* Lock background scroll without breaking iOS WKWebView after close */
  overscroll-behavior: none;
}
html.modal-open body {
  /* Do not set overflow:hidden here on Capacitor — see shell.js modal.open */
}

/* Palette must scroll inside the dialog on phone */
html.is-phone .palette,
html.is-capacitor .palette {
  max-height: min(78vh, 36rem);
  display: flex;
  flex-direction: column;
  margin-top: 8vh;
}
html.is-phone .palette-list,
html.is-capacitor .palette-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Chart section pager (Summary → Charts → Positions) — top only, no overlay */
.chart-pager {
  display: none;
  align-items: center;
  gap: 0.25rem;
  margin: 0 0 0.75rem;
  padding: 0.2rem;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--th-accent-soft) 70%, var(--th-card));
  border: 1px solid var(--th-line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.chart-pager button {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: var(--r-full);
  padding: 0.5rem 0.35rem;
  font-size: var(--text-xs);
  color: var(--th-text-dim);
  min-height: 2.25rem;
}
.chart-pager button.is-on {
  background: var(--th-card);
  color: var(--th-label);
  font-weight: 600;
  box-shadow: var(--e-1);
}
.chart-pager .chart-pager-step {
  flex: 0 0 2.4rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--th-label);
}
.chart-pager .chart-pager-step:disabled {
  opacity: 0.35;
}
.chart-pair-tabs {
  display: none;
  gap: 0.35rem;
  margin: 0 0 0.65rem;
}
.chart-pair-tabs button {
  flex: 1;
  border: 1px solid var(--th-line);
  background: var(--th-page);
  color: var(--th-text-dim);
  border-radius: var(--r-sm);
  padding: 0.45rem 0.5rem;
  font-size: var(--text-sm);
  font-weight: 600;
}
.chart-pair-tabs button.is-on {
  background: var(--th-accent);
  border-color: var(--th-accent);
  color: var(--th-btn-text);
}
html.chart-paging .chart-pager { display: flex; }
html.chart-paging .chart-pair-tabs { display: flex; }
html.chart-paging .chart-page:not(.is-on) { display: none; }
html.chart-paging .chart-layout {
  grid-template-columns: 1fr;
}
html.chart-paging .page-head { margin-bottom: 0.4rem; }
html.chart-paging .page-title { font-size: var(--text-lg); }
html.chart-paging .page-sub { display: none; }
/* One chart at a time on phone — readable size + room to scroll the other */
html.chart-paging .chart-pair {
  grid-template-columns: 1fr;
}
html.chart-paging .chart-pair[data-pair-focus="d1"] [data-pair-box="div"],
html.chart-paging .chart-pair[data-pair-focus="div"] [data-pair-box="d1"] {
  display: none;
}
html.chart-paging .chart-pair [data-pair-box] h2 { display: none; }
html.chart-paging .chart-pair[data-pair-focus="div"] [data-pair-box="div"] h2 {
  display: flex;
  margin-bottom: 0.45rem;
}

/* Capacitor / phone chrome — always (portrait + landscape) */
html.is-phone .ctx-chip[data-empty="true"],
html.is-capacitor .ctx-chip[data-empty="true"] { display: none; }
html.is-phone .btn-topbar .btn-text,
html.is-capacitor .btn-topbar .btn-text { display: none; }
/* Keep Settings visible in portrait — language/ayanamsa live there.
   Saved-charts (drawer) stays reachable from Home / empty chip. */
html.is-phone .topbar .btn-icon[data-action="open-drawer"],
html.is-capacitor .topbar .btn-icon[data-action="open-drawer"] { display: none; }

/* Landscape phone — less chrome, one large chart */
@media (orientation: landscape) and (max-height: 520px) {
  html.is-phone .topbar,
  html.is-capacitor .topbar {
    min-height: 2.4rem;
    padding-top: max(0.15rem, env(safe-area-inset-top, 0px));
  }
  html.is-phone .main,
  html.is-capacitor .main {
    padding: 0.35rem max(0.65rem, env(safe-area-inset-left, 0px)) 0.35rem max(0.65rem, env(safe-area-inset-right, 0px));
  }
  .page-head {
    display: flex !important;
    margin-bottom: 0.35rem;
  }
  .page-head .page-sub { display: none; }
  .page-nav-btn { min-width: 2.1rem; min-height: 2.1rem; padding: 0.25rem; }
  .page-research-bar { margin-top: 0.25rem; }
  .mobile-nav {
    padding-top: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-nav button { padding: 0.15rem 0; font-size: 0.5rem; }
  .mobile-nav .rail-icon { font-size: var(--text-sm); }
  .chart-pager { margin-bottom: 0.35rem; }
  .chart-pager button { padding: 0.3rem 0.25rem; min-height: 1.9rem; }
  .chart-pair-tabs { margin-bottom: 0.35rem; }
  .chart-pair-tabs button { padding: 0.3rem 0.4rem; font-size: var(--text-xs); }
  html.chart-paging .si-chart.chart-fixed {
    max-height: calc(100dvh - 7rem);
    width: min(100%, calc(100dvh - 7rem));
    margin-inline: auto;
  }
  .natal-card { padding: 0.55rem 0.7rem; }
  .natal-row { grid-template-columns: minmax(6rem, 28%) 1fr; }
}

/* ---------- calculation settings (JHora preference mirror) ---------- */
.settings-calc-head { display: flex; align-items: center; gap: var(--s-3);
  margin-top: 1.5rem; }
.settings-calc-head h3 { flex: 1; }
.settings-calc-head .hint { font-weight: 400; margin-left: 0.5rem; }
.settings-calc-head .hint.is-dirty { color: var(--marigold, #b45309); font-weight: 600; }
.settings-search { width: 100%; margin: 0.5rem 0 0.75rem; }
.settings-calc { display: flex; flex-direction: column; gap: 0.35rem; }
.opt-group { border: 1px solid var(--th-border); border-radius: 8px;
  background: var(--th-surface); }
.opt-group > summary { cursor: pointer; padding: 0.55rem 0.75rem;
  display: flex; align-items: center; gap: 0.5rem; font-weight: 600;
  list-style: none; }
.opt-group > summary::-webkit-details-marker { display: none; }
.opt-group > summary::before { content: "▸"; opacity: 0.6; }
.opt-group[open] > summary::before { content: "▾"; }
.opt-group > summary > span:first-of-type { flex: 1; }
.opt-group-meta { font-size: var(--text-xs); color: var(--th-text-dim);
  font-weight: 400; white-space: nowrap; }
.opt-group-body { padding: 0.25rem 0.75rem 0.75rem; display: flex;
  flex-direction: column; gap: 0.7rem; }
.opt-row { display: flex; flex-direction: column; gap: 0.2rem; }
.opt-label { font-size: var(--text-sm); color: var(--th-text-dim);
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.opt-row select, .opt-row input[type="number"] { width: 100%; }
.opt-check { display: flex; align-items: flex-start; gap: 0.45rem;
  font-size: var(--text-sm); }
.opt-row--bool { flex-direction: row; align-items: center; flex-wrap: wrap;
  gap: 0.4rem; }
.opt-badge { font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 0 0.35rem; border-radius: 999px;
  border: 1px solid var(--th-border); color: var(--th-text-dim);
  white-space: nowrap; }
.opt-note { font-size: var(--text-xs); color: var(--th-text-dim);
  margin: 0.1rem 0 0; line-height: 1.45; flex-basis: 100%; }

/* ---------- content zoom (web / iOS / Android) ---------- */
:root { --jv-content-zoom: 1; }
.jv-zoom-fab {
  position: fixed;
  right: max(0.65rem, env(safe-area-inset-right, 0px));
  bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  z-index: 160;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0.18rem;
  opacity: 0.72;
  transition: opacity 0.15s;
  border-radius: 999px;
  background: color-mix(in srgb, var(--th-card, #fdf8ef) 92%, transparent);
  border: 1px solid var(--th-line, var(--th-border, #d9cbb8));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--th-shadow, #4a2e18) 16%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
/* smaller and half-faded so it covers less of the page; full strength when used */
.jv-zoom-fab:hover, .jv-zoom-fab:focus-within, .jv-zoom-fab:active { opacity: 1; }
html.is-phone .jv-zoom-fab,
html.is-capacitor .jv-zoom-fab {
  /* Sit above the bottom nav */
  bottom: calc(3.6rem + env(safe-area-inset-bottom, 0px) + 0.45rem);
}
.jv-zoom-btn {
  width: 1.75rem;
  height: 1.75rem;
  border: 0;
  border-radius: 999px;
  background: var(--th-surface, #fff);
  color: var(--th-text, #3a2a1a);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  font: 600 0.72rem/1 var(--font-ui, Inter, system-ui, sans-serif);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--th-border, #d9cbb8) 70%, transparent);
}
.jv-zoom-btn:active { transform: translateY(1px); }
.jv-zoom-btn svg {
  width: 0.9rem;
  height: 0.9rem;
}
.jv-zoom-pct {
  width: 1.75rem;
  height: 1.35rem;
  font-size: 0.52rem;
  letter-spacing: 0.02em;
  color: var(--th-accent, #8b4513);
}
html.jv-zoomed .jv-zoom-pct {
  background: color-mix(in srgb, var(--th-accent, #8b4513) 14%, var(--th-surface, #fff));
}
/* Keep page content clear of the floating zoom control */
html.jv-zoomed .main-inner {
  padding-right: 2.4rem;
}
html.is-phone.jv-zoomed .main,
html.is-capacitor.jv-zoomed .main {
  padding-right: 2.4rem;
}
/* iOS transform zoom: layout stays full-width, visual overflows — allow pan */
html.jv-zoom-transform .main,
html.jv-zoom-transform .jv-scroll,
html.jv-zoom-ios .main,
html.jv-zoom-ios .jv-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Enlarge type on data cards without inflating chart rem gutters */
html.jv-zoom-ios .jk-point,
html.jv-zoom-ios .jk-outer-lbl,
html.jv-zoom-ios #jk-findings-card,
html.jv-zoom-ios #jk-tables-card,
html.jv-zoom-ios #jk-head {
  font-size: calc(1em * var(--jv-content-zoom, 1));
}
@media (min-width: 900px) {
  .jv-zoom-fab {
    bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }
}


/* ==========================================================================
   Licence footer (same line as KSAstroLite): always on screen and in print
   ========================================================================== */
.legal {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  max-width: none; width: auto; margin: 0;
  padding: 4px 12px calc(4px + env(safe-area-inset-bottom, 0px));
  font-size: 10.5px; line-height: 1.4; text-align: center;
  color: var(--th-text-dim); background: var(--th-card);
  border-top: 1px solid var(--th-line);
  box-shadow: 0 -2px 8px var(--th-shadow);
}
.app { padding-bottom: 28px; }
/* Phones: the bottom nav owns the screen edge, so the licence line sits at
   the end of the page (body padding already clears the bar). */
@media (max-width: 720px) {
  .legal { position: static; box-shadow: none; }
  .app { padding-bottom: 0; }
}
html.is-phone .legal, html.is-capacitor .legal { position: static; box-shadow: none; }
html.is-phone .app, html.is-capacitor .app { padding-bottom: 0; }

/* Phones keep the brand -- logo, name and S.Kathirvel -- as its own row
   above the toolbar, the way the KSAstroLite app does. */
@media (max-width: 720px) {
  .app { grid-template-areas: "brand" "topbar" "main"; }
}
html.is-phone .app .brand-cell,
html.is-capacitor .app .brand-cell,
.app .brand-cell.brand-cell {
  display: flex !important;
}
@media (max-width: 720px) {
  .app .brand-cell {
    position: static; border-right: 0;
    padding: max(var(--s-2), env(safe-area-inset-top, 0px)) var(--s-3) var(--s-2);
  }
  .app .brand-logo { width: 2.5rem; height: 2.5rem; }
  .rail-collapsed .brand-text { display: block; }
}
html.is-phone .app .brand-cell,
html.is-capacitor .app .brand-cell {
  position: static; border-right: 0;
  padding: max(var(--s-2), env(safe-area-inset-top, 0px)) var(--s-3) var(--s-2);
}
html.is-phone .brand-logo, html.is-capacitor .brand-logo { width: 2.5rem; height: 2.5rem; }
html.is-phone .brand-text, html.is-capacitor .brand-text { display: block !important; }
/* The brand row now clears the status bar, so the toolbar needs no inset of
   its own -- it sticks just below the status bar instead. */
html.is-phone .topbar, html.is-capacitor .topbar {
  padding-top: var(--s-2);
  top: env(safe-area-inset-top, 0px);
}

/* ==========================================================================
   iOS PWA & iPhone Assistant
   ========================================================================== */
.ios-pwa-banner {
  position: fixed;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 28rem);
  background: var(--th-card, #ffffff);
  border: 1.5px solid var(--th-primary, #ea580c);
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 120;
  animation: slideUpFade 0.35s ease-out;
}
body:has(.modal-scrim.open) .ios-pwa-banner {
  display: none !important;
}
.ios-pwa-banner.hidden {
  display: none !important;
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.ios-banner-icon img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  display: block;
}
.ios-banner-text {
  flex: 1;
  font-size: 0.85rem;
  line-height: 1.3;
  color: var(--th-fg, #222);
}
.ios-banner-title {
  font-weight: 700;
  display: block;
  color: var(--th-primary, #ea580c);
  margin-bottom: 0.15rem;
}
.ios-share-badge {
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--th-primary, #ea580c) 15%, transparent);
  font-weight: 600;
}
.ios-banner-close {
  background: none;
  border: none;
  color: var(--th-muted, #777);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.ios-banner-close:hover {
  color: var(--th-fg, #000);
}

/* iPhone Connection Modal */
.iphone-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--th-bg-alt, #f7f5f0);
  border-radius: 0.75rem;
  border: 1px dashed var(--th-line, #ccc);
  margin: 1rem 0;
}
.iphone-qr-box svg {
  max-width: 180px;
  max-height: 180px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  background: #ffffff;
  padding: 8px;
}
.iphone-steps {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.iphone-step-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
}
.iphone-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--th-primary, #ea580c);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
