/* ==========================================================================
   PsiJulia — Base reset + App Shell layout
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text-base);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

img, svg, video { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--brand); text-decoration: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

h1,h2,h3,h4 { color: var(--text-strong); line-height: var(--lh-tight); font-weight: var(--fw-semibold); }
h1 { font-size: var(--fs-2xl); letter-spacing: -.02em; }
h2 { font-size: var(--fs-xl); letter-spacing: -.01em; }
h3 { font-size: var(--fs-lg); }
small { font-size: var(--fs-sm); }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

/* ---- App shell: a centered phone-like column ---- */
.app-shell {
  position: relative;
  width: 100%;
  max-width: var(--shell-max);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 560px) {
  body { background: var(--bg-sunken); }
  .app-shell {
    min-height: min(900px, 100dvh);
    margin-top: max(0px, calc((100dvh - 900px) / 2));
    border-radius: 0;
    box-shadow: var(--sh-lg);
    border: 1px solid var(--border);
    overflow: hidden;
  }
}

/* ---- Header ---- */
.app-header {
  position: sticky; top: 0;
  z-index: var(--z-header);
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; gap: var(--sp-3);
  padding-left: var(--sp-4); padding-right: var(--sp-4);
  background: color-mix(in srgb, var(--bg-surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-strong); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header__back { width: 38px; height: 38px; border-radius: var(--r-full); display:grid; place-items:center; color: var(--text-base); margin-left: -8px; transition: background var(--dur-fast); }
.app-header__back:active { background: var(--bg-surface-2); }
.app-header__action { width: 38px; height: 38px; border-radius: var(--r-full); display:grid; place-items:center; color: var(--text-base); transition: background var(--dur-fast); }
.app-header__action:active { background: var(--bg-surface-2); }

/* ---- Scrollable content viewport ---- */
.app-view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-4) var(--sp-4) calc(var(--nav-h) + var(--safe-bottom) + var(--sp-6));
  scroll-behavior: smooth;
}
.app-view--flush { padding-left: 0; padding-right: 0; }

/* ---- Bottom navigation (fixed within shell) ---- */
.bottom-nav {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: var(--z-nav);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: color-mix(in srgb, var(--bg-surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}
.bottom-nav__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-muted); font-size: 10.5px; font-weight: var(--fw-medium);
  position: relative; transition: color var(--dur-fast); user-select: none;
}
.bottom-nav__item .ico { width: 24px; height: 24px; transition: transform var(--dur-base) var(--ease-spring); }
.bottom-nav__item[aria-current="page"] { color: var(--brand); }
.bottom-nav__item[aria-current="page"] .ico { transform: translateY(-1px) scale(1.06); }
.bottom-nav__item:active .ico { transform: scale(.88); }
.bottom-nav__item[aria-current="page"]::before {
  content: ""; position: absolute; top: 6px; width: 34px; height: 30px;
  background: var(--brand-soft); border-radius: var(--r-full); z-index: -1;
}

/* ---- Page transition ---- */
.app-view > .screen { animation: screen-in var(--dur-base) var(--ease-out) both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Utility ---- */
.stack { display: flex; flex-direction: column; }
.stack-2 > * + * { margin-top: var(--sp-2); }
.stack-3 > * + * { margin-top: var(--sp-3); }
.stack-4 > * + * { margin-top: var(--sp-4); }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.flex-1 { flex: 1; min-width: 0; }
.section-title { font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin: var(--sp-2) var(--sp-1); }
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.center { display: grid; place-items: center; }
