/* The base of JE Builder: page, text, links, focus. Every value comes from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: var(--scheme); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* The shell asks for the whole screen (viewport-fit=cover), so the frame keeps
   clear of the notch and the home indicator itself. Every fixed or sticky
   edge of the app is placed with these. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-text);
  font-size: var(--fs-m);
  line-height: var(--lh-text);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-title); color: var(--c-ink); line-height: var(--lh-title); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-xl); font-weight: 700; }
h2 { font-size: var(--fs-l); font-weight: 700; }
h3 { font-size: var(--fs-m); font-weight: 650; }
p, ul, ol, dl { margin: 0 0 var(--s-3); }
ul, ol { padding-left: var(--s-5); }
a { color: var(--c-accent-text); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--c-ink); }
code, pre, .mono { font-family: var(--font-mono); font-size: var(--fs-s); }
code { background: var(--c-sunken); border-radius: var(--radius-s); padding: 0.05em 0.3em; }
pre { margin: 0 0 var(--s-3); white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--c-line); margin: var(--s-2) 0; }
img, svg { max-width: 100%; }
small { font-size: var(--fs-xs); }
strong { color: var(--c-ink); font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; border-radius: var(--radius-s); }
main:focus { outline: none; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--c-muted); }
.prose { white-space: pre-wrap; margin: 0 0 var(--s-3); max-width: 46rem; }
.prose.mono { background: var(--c-sunken); padding: var(--s-3); border-radius: var(--radius-m); max-width: none; overflow-x: auto; }
.plain { list-style: none; padding: 0; }
.plain li { margin-bottom: var(--s-1); }
.only-phone, .btn.only-phone { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .spinner { animation: spin 0.9s linear infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── The frame: rail, bar, banner, page ─────────────────────────────────── */

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { flex: 1; min-width: 0; padding: var(--s-5) max(var(--s-5), var(--safe-right)) calc(var(--s-7) + var(--safe-bottom)) max(var(--s-5), var(--safe-left)); }

.rail {
  width: var(--w-rail); flex: none; background: var(--c-surface); border-right: 1px solid var(--c-line);
  padding: calc(var(--s-3) + var(--safe-top)) var(--s-3) calc(var(--s-3) + var(--safe-bottom)) max(var(--s-3), var(--safe-left)); display: flex; flex-direction: column; gap: var(--s-3);
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.rail-shade { display: none; }
.brand { display: flex; align-items: center; gap: var(--s-2); font-family: var(--font-title); font-weight: 750; font-size: var(--fs-l); color: var(--c-ink); text-decoration: none; padding: var(--s-1) var(--s-2); }
.brand-mark { display: inline-grid; place-items: center; min-width: 1.5rem; height: 1.5rem; padding: 0 0.2rem; border-radius: 6px; background: var(--c-primary); color: var(--c-on-primary); font-size: var(--fs-xs); font-weight: 800; letter-spacing: 0; }
.rail .menu-wrap { display: block; }
.switcher {
  width: 100%; display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 0 var(--s-2); align-items: center;
  background: var(--c-bg); border: 1px solid var(--c-line); border-radius: var(--radius-m); padding: var(--s-2) var(--s-3); cursor: pointer;
}
.switcher:hover { border-color: var(--c-line-strong); }
.switcher-label { grid-column: 1; font-size: var(--fs-xs); color: var(--c-muted); }
.switcher-value { grid-column: 1; font-weight: 600; color: var(--c-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switcher .icon { grid-column: 2; grid-row: 1 / span 2; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-foot { margin-top: auto; border-top: 1px solid var(--c-line); padding-top: var(--s-3); }
.nav-link { display: flex; align-items: center; gap: var(--s-2); padding: 0.4rem var(--s-2); border-radius: var(--radius-m); color: var(--c-text); text-decoration: none; min-height: 2rem; }
.nav-link:hover { background: var(--c-sunken); color: var(--c-ink); }
.nav-link[aria-current] { background: var(--c-accent-tint); color: var(--c-ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--c-primary); }

.topbar { display: flex; align-items: center; gap: var(--s-3); padding: calc(var(--s-2) + var(--safe-top)) max(var(--s-5), var(--safe-right)) var(--s-2) max(var(--s-5), var(--safe-left)); border-bottom: 1px solid var(--c-line); background: var(--c-surface); min-height: 3.25rem; position: sticky; top: 0; z-index: 5; }
.crumbs { flex: 1; min-width: 0; display: flex; gap: var(--s-2); align-items: center; white-space: nowrap; overflow: hidden; color: var(--c-muted); }
.crumbs a { color: var(--c-muted); text-decoration: none; }
.crumbs a:hover { color: var(--c-ink); text-decoration: underline; }
.crumbs > :last-child { color: var(--c-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-tools { display: flex; align-items: center; gap: var(--s-1); margin-left: auto; }

.banner { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) max(var(--s-5), var(--safe-right)) var(--s-3) max(var(--s-5), var(--safe-left)); background: var(--c-danger-tint); color: var(--c-danger); border-bottom: 1px solid var(--c-danger); font-weight: 500; }
.banner-text { flex: 1; }

.page { max-width: var(--w-page); margin: 0 auto; }
.page-board { max-width: none; }
.page-narrow, .narrow { max-width: 46rem; margin: 0 auto; }
.narrow { padding-top: var(--s-5); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.page-title p { margin: var(--s-1) 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.back { display: inline-block; font-size: var(--fs-s); color: var(--c-muted); text-decoration: none; margin-bottom: var(--s-1); }
.back:hover { color: var(--c-ink); text-decoration: underline; }
.section { margin-bottom: var(--s-5); }
.section-title { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-m); margin-bottom: var(--s-2); }
.small-title { font-size: var(--fs-s); text-transform: uppercase; letter-spacing: 0.04em; color: var(--c-muted); margin: var(--s-3) 0 var(--s-2); font-family: var(--font-text); font-weight: 600; }

#toasts { position: fixed; right: max(var(--s-4), var(--safe-right)); bottom: calc(var(--s-4) + var(--safe-bottom) + var(--kb, 0px)); display: flex; flex-direction: column; gap: var(--s-2); z-index: 50; max-width: min(24rem, calc(100vw - 2rem)); }
.toast { background: var(--c-ink); color: var(--c-bg); padding: var(--s-3) var(--s-4); border-radius: var(--radius-m); box-shadow: var(--c-shadow); }
.toast-danger { background: var(--c-danger); color: var(--c-surface); }
.toast-success { background: var(--c-success); color: var(--c-surface); }

@media (max-width: 56rem) {
  .only-phone, .btn.only-phone { display: inline-flex; }
  /* What a phone reaches another way (the button under the thumb) takes no room in a page head there. */
  .only-wide, .btn.only-wide { display: none; }
  /* The page under an open drawer, menu or dialog stays where it is (sheet.js). */
  html.locked { overflow: hidden; }
  .rail { position: fixed; z-index: 20; left: 0; top: 0; transform: translateX(-100%); width: min(18rem, 86vw); box-shadow: var(--c-shadow); visibility: hidden; overscroll-behavior: contain; }
  .rail-open .rail { transform: none; visibility: visible; }
  .rail-open .rail-shade { display: block; position: fixed; inset: 0; background: var(--c-overlay); border: 0; z-index: 15; }
  main { padding: var(--s-4) max(var(--s-4), var(--safe-right)) calc(var(--s-6) + var(--safe-bottom)) max(var(--s-4), var(--safe-left)); }
  .topbar { padding: calc(var(--s-2) + var(--safe-top)) max(var(--s-3), var(--safe-right)) var(--s-2) max(var(--s-3), var(--safe-left)); gap: var(--s-2); }
  .crumbs > :not(:last-child) { display: none; }
  .banner { padding: var(--s-3) max(var(--s-4), var(--safe-right)) var(--s-3) max(var(--s-4), var(--safe-left)); flex-wrap: wrap; }
  .nav-link, .brand { min-height: var(--w-target-touch); }
  .back { display: inline-flex; align-items: center; min-height: var(--w-target-touch); min-width: var(--w-target-touch); margin-bottom: 0; }
  /* A line that opens (details) is pressed on its whole height. */
  summary { min-height: var(--w-target-touch); padding-block: var(--s-3); }
  .crumbs a { display: inline-flex; align-items: center; min-height: var(--w-target-touch); min-width: var(--w-target-touch); }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 56rem) {
  .rail { transition: transform var(--t-fast); }
}
