/* ==========================================================================
   SkipBoard v2 — base: reset, app shell, navigation, page furniture, a11y
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--t-16);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 84px 84px;
  mask-image: radial-gradient(90% 60% at 50% 0%, #000 0%, transparent 80%);
  z-index: 0;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
img, canvas, video { max-width: 100%; }
svg { flex-shrink: 0; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); color: var(--text); }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 120;
  background: var(--surface); color: var(--text); padding: 10px 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line); box-shadow: var(--e-2);
}
.skip-link:focus { left: 8px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------- App shell ------------------------------ */
.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + var(--s-4));
  outline: none;
  flex: 1;
}
.screen:focus { outline: none; }
body.has-tabbar .screen { padding-bottom: calc(var(--nav-h) + var(--s-6)); }
body.is-flow .screen { padding-bottom: env(safe-area-inset-bottom); }
body.is-flow .tabbar { display: none; }

/* Route transition */
.screen.route-enter { animation: route-in var(--dur-2) var(--ease) both; }
@keyframes route-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen.route-enter { animation: none; }
}

/* ------------------------------- Tab bar -------------------------------- */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  z-index: var(--z-nav);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  height: var(--nav-h);
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-deep) 86%, transparent);
  border-top: 1px solid var(--line-soft);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 52px; border-radius: 14px;
  color: var(--muted); text-decoration: none;
  font-size: var(--t-11); font-weight: 600; letter-spacing: 0.01em;
  position: relative;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.tab svg { width: 24px; height: 24px; }
.tab.is-active { color: var(--accent); }
.tab.is-active svg { filter: drop-shadow(0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent)); }
.tab.is-active::after {
  content: ''; position: absolute; top: 2px; width: 26px; height: 3px; border-radius: 2px;
  background: var(--accent);
}
.tab:active { background: var(--surface-2); }

/* ------------------------------- Sidebar (desktop) ---------------------- */
.app-sidebar { display: none; }
.app-main { flex: 1; width: 100%; }

@media (min-width: 900px) {
  body.has-tabbar .screen { padding-bottom: var(--s-10); }
  .tabbar { display: none; }

  .app { flex-direction: row; max-width: 1440px; margin: 0 auto; padding: 0 20px; gap: 32px; }
  .app-sidebar {
    display: flex; flex-direction: column; gap: 8px;
    width: 248px; flex-shrink: 0; position: sticky; top: 0; align-self: flex-start;
    height: 100dvh; padding: 28px 8px 24px;
  }
  .app-main { flex: 1; min-width: 0; }
  .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 0 10px 20px; color: var(--text);
  }
  .brand-mark {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--e-1);
  }
  .brand-name { font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: -0.02em; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; }
  .side-link {
    display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px;
    border-radius: 12px; color: var(--muted); font-size: var(--t-15); font-weight: 600;
  }
  .side-link:hover { background: var(--surface-2); color: var(--text); }
  .side-link.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--e-1); }
  .side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
  .screen { max-width: 960px; padding-bottom: 48px; }
  .screen.screen-fill, .screen.screen-review, .screen.screen-scan,
  .screen.screen-welcome, .screen.screen-corners, .screen.screen-boxes,
  .screen.screen-page, .screen.screen-done { max-width: 760px; }
}

@media (min-width: 1200px) {
  .screen { max-width: 1080px; }
}

/* ------------------------------ Page furniture -------------------------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s-3); padding: var(--s-5) var(--gutter) var(--s-2);
}
.page-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-head h1 {
  font-family: var(--font-display);
  font-size: clamp(26px, 6vw, 32px);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.08;
}
.eyebrow {
  font-size: var(--t-11);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow.is-muted { color: var(--muted); }
.subhead { font-size: var(--t-15); color: var(--muted); }

.section { padding: var(--s-3) var(--gutter) 0; }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  margin: var(--s-5) 0 var(--s-3);
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: var(--t-20); font-weight: 650; letter-spacing: -0.02em;
}
.section-head a, .section-head button { font-size: var(--t-13); font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-3) var(--gutter) var(--s-6); }
.stack-tight { display: flex; flex-direction: column; gap: var(--s-2); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--t-13); }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider { height: 1px; background: var(--line-soft); border: 0; margin: 0; }

/* ------------------------------ Status chrome --------------------------- */
.offline-pill {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 90; display: none; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line);
  font-size: var(--t-13); font-weight: 600; box-shadow: var(--e-1);
}
body.is-offline .offline-pill { display: inline-flex; }

.install-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 10px);
  z-index: 25; display: none; align-items: center; gap: 12px;
  width: calc(100% - 24px); max-width: 520px;
  padding: 12px 12px 12px 16px; border-radius: var(--r-card);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--e-2);
}
body.has-install .install-bar { display: flex; }
.install-bar p { flex: 1; font-size: var(--t-13); color: var(--muted); }
.install-bar strong { display: block; color: var(--text); font-size: var(--t-15); }

/* ------------------------------- Flow chrome ---------------------------- */
.flow { display: flex; flex-direction: column; min-height: 100dvh; }
.flow-head {
  position: sticky; top: 0; z-index: 12;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: env(safe-area-inset-top);
}
.flow-bar {
  display: flex; align-items: center; gap: 6px;
  min-height: 60px; padding: 6px 10px;
}
.flow-title { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; gap: 1px; }
.flow-title.left { text-align: left; padding-left: 4px; }
.flow-title h1 {
  font-family: var(--font-display); font-size: var(--t-20); font-weight: 650;
  letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.flow-title span { font-size: var(--t-13); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-body { flex: 1; padding: var(--s-4) var(--gutter) var(--s-8); }
.flow-foot {
  position: sticky; bottom: 0; z-index: 14;
  display: flex; gap: var(--s-3); align-items: center;
  padding: var(--s-3) var(--gutter) calc(var(--s-3) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-top: 1px solid var(--line-soft);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.flow-foot .btn { flex-shrink: 0; }
/* The main action takes the room that's left and may shrink, so a long label never runs off a phone. */
.flow-foot .btn.grow { flex: 1 1 0; min-width: 0; padding-inline: 16px; }
@media (max-width: 400px) {
  .flow-foot .btn-lg { font-size: var(--t-16); }
}

/* ------------------------------- Utilities ------------------------------ */
.icon-btn {
  width: var(--tap); height: var(--tap); min-width: var(--tap); min-height: var(--tap);
  border-radius: var(--r-pill); border: 0; background: transparent; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn-spacer { width: var(--tap); height: var(--tap); flex-shrink: 0; }

.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.px { padding-left: var(--gutter); padding-right: var(--gutter); }

@media print {
  body::before, .tabbar, .app-sidebar, .flow-foot, .offline-pill, .install-bar { display: none !important; }
  .screen { max-width: none; padding: 0; }
}

/* The crawler/no-JS text in index.html stays hidden while the app starts; shown only if the app never replaces it. */
.js .boot-text { visibility: hidden; animation: boot-text-show 0s 5s forwards; }
@keyframes boot-text-show { to { visibility: visible; } }
