/* 1765 Regina — the app shell. Tokens come from /assets/css/tokens.css (both themes); components from kit.css.
   This file: the shell (header, screens, tabs), the five tabs, the reader, onboarding, the splash.
   Motion is transform/opacity only; prefers-reduced-motion turns it off. Text scales with --ts (profile.textScale). */

/* Safe areas: the larger of env() and Capacitor's --safe-area-inset-* (its SystemBars plugin sets them on <html>
   because Android WebView < 140 reports env() as 0 while drawing edge to edge). Resolved on body too, where
   Capacitor may set them. */
:root, body {
  --safe-top: max(var(--safe-area-inset-top, 0px), env(safe-area-inset-top, 0px));
  --safe-bottom: max(var(--safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
}
:root { --ts: 1; --tab-h: 58px; --hdr-h: 52px; }
/* the kit's sheets and toasts read env() alone: inside the app they follow the same insets */
.rk-sheet__actions { padding-bottom: max(18px, var(--safe-bottom)); }
/* no actions footer under the body: it carries the inset (specific enough to beat kit.css's env()-only rule) */
.rk-layer .rk-sheet > .rk-sheet__body:last-child { padding-bottom: max(22px, var(--safe-bottom)); }
.rk-sheet { max-height: calc(100% - var(--safe-top) - 8px); }
.rk-toasts { bottom: max(18px, calc(var(--safe-bottom) + 12px)) !important; }
/* a toast never sits on a sheet's buttons (it took the tap meant for Save): while a sheet is open toasts show at
   the top, and a toast with no action of its own lets a tap through to what is under it */
body:has(> .rk-layer) .rk-toasts { top: calc(var(--safe-top) + 12px); bottom: auto !important; }
.rk-toast:not(:has(.rk-toast__act)) { pointer-events: none; }
/* every control a finger uses is at least 44 px tall in the app (the kit's chips and segments run 36-40) */
#app .rk-chip, .rk-layer .rk-chip, #app .rk-seg__opt, .rk-layer .rk-seg__opt { min-height: 44px; }
/* a label that wraps (narrow phone, Larger text) keeps its lines apart */
#app .rk-btn, .rk-layer .rk-btn { line-height: 1.3; padding-top: 8px; padding-bottom: 8px; text-align: center; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 400 calc(17px * var(--ts)) / 1.55 var(--f-body); overflow: hidden; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility;
}
button, a, [role=tab], .rk-item, .rk-chip { touch-action: manipulation; }
a { color: var(--accent-bright); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.rk-sr { position: absolute !important; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- shell ---------- */
#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
#app.is-full { grid-template-rows: minmax(0, 1fr); }
.app-header {
  position: relative; z-index: 3; padding-top: var(--safe-top); background: var(--bg);
  
  border-bottom: 1px solid transparent; transition: border-color 160ms var(--ease);
  user-select: none; -webkit-user-select: none;
}
.app-header.is-scrolled { border-bottom-color: var(--line); }
.app-header__in { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr); align-items: center; height: var(--hdr-h); padding: 0 16px; column-gap: 8px; }
.app-header__start { display: flex; align-items: center; min-width: 0; }
.app-header.is-sub .app-header__in { grid-template-columns: auto minmax(0, 1fr) 44px; }
.app-mark { color: var(--accent); display: inline-flex; align-items: center; gap: 9px; }
.app-mark__word { white-space: nowrap; font: 600 11px/1 var(--f-inscr); letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink); transition: opacity 160ms var(--ease); }
.app-header.is-scrolled .app-mark__word { opacity: 0; }
.app-header__title {
  margin: 0; text-align: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font: 600 12px/1 var(--f-inscr); letter-spacing: 0.24em; text-transform: uppercase; color: var(--ink);
  opacity: 0; transform: translateY(4px); transition: opacity 160ms var(--ease), transform 160ms var(--ease); pointer-events: none;
}
.app-header.is-scrolled .app-header__title, .app-header.is-sub .app-header__title { opacity: 1; transform: none; }
.app-back {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; min-width: 44px; margin-left: -10px; padding: 0 10px 0 4px;
  background: none; border: 0; border-radius: var(--r-2); color: var(--accent-bright); cursor: pointer;
  font: 600 11.5px/1 var(--f-inscr); letter-spacing: 0.14em; text-transform: uppercase; position: relative; z-index: 1;
}
.app-back.is-pressed { opacity: 0.6; }
.app-screens { position: relative; overflow: hidden; min-height: 0; }
.app-screen {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding-bottom: 28px; outline: none; background: var(--bg); contain: strict;
}
#app.is-full .app-screen { padding-top: var(--safe-top); padding-bottom: calc(24px + var(--safe-bottom)); }
.app-screen[data-enter="push"] { animation: app-push 180ms var(--ease-out) both; }
@keyframes app-in { from { opacity: 0.4; } to { opacity: 1; } }
@keyframes app-push { from { opacity: 0.5; transform: translate3d(18px, 0, 0); } to { opacity: 1; transform: none; } }

.app-tabs {
  position: relative; z-index: 3; padding-bottom: var(--safe-bottom); background: var(--bg);
  
  border-top: 1px solid var(--line); user-select: none; -webkit-user-select: none;
}
.app-tabs__in { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tab-h); max-width: 640px; margin: 0 auto; }
.app-tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: none; border: 0; padding: 0; color: var(--ink-mute); cursor: pointer;
  font: 600 9.5px/1 var(--f-inscr); letter-spacing: 0.14em; text-transform: uppercase;
}
.app-tab__icon { display: inline-flex; transition: transform 90ms var(--ease); }
.app-tab.is-pressed .app-tab__icon { transform: scale(0.88); }
.app-tab.is-active { color: var(--accent-bright); }
.app-tab.is-active::before { content: ""; position: absolute; top: -1px; left: 30%; right: 30%; height: 2px; border-radius: 0 0 2px 2px; background: var(--accent-bright); }

/* ---------- headings ---------- */
.app-head { padding: 22px 20px 6px; max-width: 712px; margin: 0 auto; }
.app-head .rk-eyebrow, .app-hero .rk-eyebrow { font-size: 10.5px; }
.app-h1 { font: 600 calc(34px * var(--ts)) / 1.08 var(--f-display); margin: 0 0 10px; color: var(--ink); letter-spacing: -0.005em; }
.app-h1 em { font-style: italic; font-weight: 500; color: var(--accent-bright); }
.app-lede { font-size: calc(16.5px * var(--ts)); line-height: 1.55; color: var(--ink-dim); margin: 0 0 6px; }
.app-body { padding: 0 16px; max-width: 712px; margin: 0 auto; }
.app-sec { margin: 24px 0 0; content-visibility: auto; contain-intrinsic-size: auto 320px; }
.app-az__group { content-visibility: auto; contain-intrinsic-size: auto 400px; }
.app-sec__label { font: 600 10.5px/1.2 var(--f-inscr); letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink-mute); margin: 0 4px 10px; }
.app-body .rk-list { margin: 0; }
.app-body .rk-item { font-size: calc(17px * var(--ts)); min-height: 60px; }
.app-body .rk-item__sub { font-size: calc(14.5px * var(--ts)); }
.app-body .rk-text { font-size: calc(16.5px * var(--ts)); }
.app-row--quiet { background: transparent; }
.app-row--quiet .rk-item__icon { color: var(--alert); }
.app-row--kept .rk-item__icon { color: var(--lit-green); }
:root[data-theme="light"] .app-row--kept .rk-item__icon { color: #3E5A38; }
.app-quiet { margin: 28px 0 8px; }
.app-quiet .rk-list { background: transparent; border-style: dashed; }
.app-note { font-size: 14px; color: var(--ink-mute); min-height: 1.4em; margin: 8px 0 0; }

/* ---------- today ---------- */
.app-hero {
  --season: var(--rg-gold); position: relative; padding: 24px 20px 22px; overflow: hidden;
  background: radial-gradient(120% 90% at 85% -10%, color-mix(in srgb, var(--season) 26%, transparent), transparent 62%), linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
}
.app-hero::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--season); }
.app-hero::after {
  content: ""; position: absolute; right: -18px; bottom: -34px; width: 150px; height: 150px; opacity: 0.05; pointer-events: none;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23E0BC62' stroke-width='1' stroke-linejoin='round'%3E%3Cpath d='M3.5 18 2.6 7.6l5.2 4.3L12 4.5l4.2 7.4 5.2-4.3-.9 10.4z'/%3E%3Cpath d='M4 21h16'/%3E%3C/svg%3E");
}
.app-hero > * { position: relative; max-width: 672px; margin-left: auto; margin-right: auto; }
.app-hero__title { font: 600 calc(31px * var(--ts)) / 1.1 var(--f-display); margin: 0 0 6px; color: var(--ink); }
.app-hero__saint { font: italic 500 calc(19px * var(--ts)) / 1.35 var(--f-display); color: var(--accent-bright); margin: 0 0 12px; }
.app-hero__meta { list-style: none; padding: 0; margin: 12px auto 0; display: flex; flex-wrap: wrap; gap: 8px; }
.app-hero__meta li {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line-2);
  font-size: calc(13.5px * var(--ts)); color: var(--ink-dim); background: color-mix(in srgb, var(--bg) 40%, transparent); text-transform: none;
}
.app-hero__meta li.is-alert { border-color: color-mix(in srgb, var(--alert) 55%, transparent); color: var(--alert); }
.app-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--season); box-shadow: 0 0 0 1px var(--line-2); }
.app-feature { display: block; margin: 18px 0 0; color: var(--ink); text-decoration: none; }
.app-feature .rk-card__title { font-size: calc(24px * var(--ts)); }
.app-feature .rk-btn { margin-top: 4px; pointer-events: none; }
.app-feature.is-pressed { transform: scale(0.99); }
.app-noon { margin: 18px 0 0; }
.app-meter { height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; margin: 8px 0 12px; }
.app-meter span { display: block; height: 100%; background: var(--btn-gold-bg); transform-origin: left center; }

/* ---------- library ---------- */
.app-searchbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; margin: 14px -16px 0; padding: 10px 16px;
  background: var(--bg); color: var(--accent);
}
.app-searchbar .rk-icon { position: absolute; left: 30px; pointer-events: none; }
.app-search { padding-left: 42px; -webkit-appearance: none; appearance: none; font-size: max(16px, calc(17px * var(--ts))); }
.app-chips { flex-wrap: nowrap; overflow-x: auto; margin: 4px -16px 0; padding: 4px 16px 8px; scrollbar-width: none; }
.app-chips::-webkit-scrollbar { display: none; }
.app-chips .rk-chip { flex: none; min-height: 40px; }
.app-count { font-size: 13.5px; color: var(--ink-mute); margin: 6px 4px 0; }
.app-az__letter { font: 600 13px/1 var(--f-inscr); letter-spacing: 0.2em; color: var(--accent); margin: 22px 4px 10px; }

/* ---------- reader ---------- */
.app-body--read { padding-top: 18px; }
.app-reader { font-size: calc(18.5px * var(--ts)); line-height: 1.72; user-select: text; -webkit-user-select: text; max-width: 640px; }
.app-reader h1 { font: 600 calc(31px * var(--ts)) / 1.12 var(--f-display); margin: 18px 0 12px; }
.app-reader h1 em, .app-reader h2 em { color: var(--accent-bright); font-weight: 500; }
.app-reader h2 { font-size: calc(25px * var(--ts)); }
.app-reader h3 { font-size: calc(21px * var(--ts)); }
.app-reader img { max-width: 100%; height: auto; border-radius: var(--r-2); }
.app-reader a { color: var(--accent-bright); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.app-reader ul, .app-reader ol { padding-left: 1.3em; }
.app-reader li { margin: 0 0 0.4em; }
.app-reader table { border-collapse: collapse; width: 100%; font-size: 0.9em; display: block; overflow-x: auto; }
.app-reader td, .app-reader th { border: 1px solid var(--line-2); padding: 6px 8px; text-align: left; }
.app-reader .rd-ccc-notice, .app-reader .rd-sources, .app-reader .rd-source { font-size: 0.82em; color: var(--ink-mute); }
.app-reader .rd-lede { font-size: 1.04em; color: var(--ink-dim); }
.app-reader .rd-eyebrow, .app-reader .rd-rg-eyebrow { font: 600 11px/1.3 var(--f-inscr); letter-spacing: 0.24em; text-transform: uppercase; color: var(--accent); }
.app-reader .rd-rubric { color: var(--alert); font-style: italic; }
.app-reader__src { margin: 36px 0 12px; padding-top: 16px; border-top: 1px solid var(--line); font: 600 11px/1.4 var(--f-inscr); letter-spacing: 0.18em; text-transform: uppercase; }
.app-prose { margin: 4px 0 18px; }
.app-prose p { margin: 0 0 0.9em; }

/* ---------- tools ---------- */
.app-tool { zoom: var(--ts); padding: 14px 16px 24px; max-width: 712px; margin: 0 auto; min-height: 60%; }
.app-loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 56px 0; color: var(--ink-mute); font-size: 16px; }
.app-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent-bright); animation: app-spin 0.8s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }
.app-problem { margin: 16px 0; }

/* ---------- you + settings ---------- */
.app-panel { padding: 16px 16px 2px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--bg-2); }
.app-panel .rk-seg { margin-bottom: 18px; }
.app-body--settings .app-head { padding-left: 4px; padding-right: 4px; }
.app-group { margin: 0 0 4px; }
.app-status { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0; color: var(--ink-dim); font-size: calc(16px * var(--ts)); line-height: 1.45; }
.app-status .rk-icon { color: var(--accent); margin-top: 2px; }
.app-status.is-on { color: var(--ink); }
.app-status.is-err { color: var(--alert); }
.app-stack { display: grid; gap: 10px; margin: 16px 0 20px; }
.app-explain { margin-top: 8px; }
.app-key {
  font: 600 19px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.04em; text-align: center; word-break: break-all;
  padding: 16px; margin: 12px 0 14px; border: 1px dashed var(--line-gold-2); border-radius: var(--r-2); color: var(--ink); user-select: all; -webkit-user-select: all;
}
.app-key-input { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.04em; text-transform: uppercase; }
.app-warn { color: var(--ink); }
.app-keys { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.app-keys li { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 14px; color: var(--ink-dim); }
.app-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 18px; font-size: 15.5px; }
.app-facts dt { font: 600 10.5px/2 var(--f-inscr); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-mute); }
.app-facts dd { margin: 0; color: var(--ink-dim); }

/* ---------- onboarding ---------- */
.app-onb { min-height: 100%; display: flex; flex-direction: column; padding: 8px 20px 20px; max-width: 560px; margin: 0 auto; }
.app-onb__top { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.app-onb__dots { display: flex; gap: 8px; }
.app-onb__dots span { width: 22px; height: 3px; border-radius: 2px; background: var(--line-2); }
.app-onb__dots span.is-on { background: var(--accent-bright); }
.app-onb__skip { margin-right: -10px; }
.app-onb__card { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 12px 0 8px; }
.app-onb__card > .rk-btn { margin-top: 26px; }
.app-onb__crown { color: var(--accent-bright); margin: 0 0 18px; display: inline-flex; }
.app-onb__chips { margin-top: 14px; }
.app-onb__chips .rk-chip { min-height: 44px; font-size: 16px; padding: 0 16px; }
.app-onb__kids { margin: 12px 0 0; }
.app-onb__add { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 16px; }
.app-onb .rk-seg { margin-top: 18px; }

/* ---------- splash (painted from HTML before the script runs) ---------- */
#app-splash {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(80% 60% at 50% 38%, #18203A 0%, #090B12 70%); color: #F4EDDF; transition: opacity 320ms var(--ease);
}
#app-splash.is-gone { opacity: 0; pointer-events: none; }
.splash__crown { color: #E0BC62; }
.splash__name { font: 600 22px/1 var(--f-inscr); letter-spacing: 0.42em; margin: 6px 0 0 0.42em; }
.splash__tag { font: italic 500 19px/1.2 var(--f-display); color: #E0BC62; margin: 0; }
.splash__msg { font: 400 15px/1.4 var(--f-body); color: #C9C0AB; margin: 18px 24px 0; text-align: center; min-height: 1.4em; }

@media (prefers-reduced-motion: reduce) {
  .app-screen[data-enter], .app-spinner { animation: none !important; }
  .app-header__title, #app-splash, .app-tab__icon { transition: none !important; }
}
@media (min-width: 900px) {
  .app-h1 { font-size: calc(40px * var(--ts)); }
}
