/* Gap in Your App design system, v1.
   One stylesheet shared by gapinyourapp.com and app.gapinyourapp.com.
   Vernacular: the App Store itself. iOS grouped lists, capsule buttons, system type.
   The one loud thing: the gap ruler, a measuring-tape yellow that marks the distance to #1. */

:root {
  /* Color: light */
  --bg: #f2f2f7;            /* iOS grouped background */
  --surface: #ffffff;
  --surface-2: #f8f8fa;
  --ink: #1c1c1e;
  --ink-2: #48484d;         /* secondary text, 9.3:1 on white */
  --ink-3: #6e6e73;         /* tertiary text, 5.0:1 on white */
  --sep: rgba(60, 60, 67, 0.18);
  --sep-strong: rgba(60, 60, 67, 0.32);
  --measure: #ffcc00;       /* the gap ruler */
  --measure-soft: #fff4c2;
  --measure-ink: #3a2e00;
  --up: #1f7a36;            /* rank improved */
  --up-soft: #e3f4e7;
  --down: #c4001a;          /* rank dropped */
  --down-soft: #fde6e8;
  --focus: #1c1c1e;
  --shadow-float: 0 18px 50px -20px rgba(28, 28, 30, 0.35);

  /* Type: the App Store's own system face */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;

  /* Type scale (px), tuned for 17px iOS body */
  --t-xs: 0.75rem;   /* 12 */
  --t-sm: 0.8125rem; /* 13 */
  --t-md: 0.9375rem; /* 15 */
  --t-body: 1.0625rem; /* 17 */
  --t-lg: 1.25rem;   /* 20 */
  --t-xl: 1.5rem;    /* 24 */
  --t-2xl: 1.875rem; /* 30 */
  --t-3xl: 2.5rem;   /* 40 */
  --t-4xl: 3.5rem;   /* 56 */
  --t-rank: clamp(4rem, 12vw, 7.5rem);

  /* Space: 4pt grid */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px; --s24: 96px;

  /* Radius: one per level of hierarchy */
  --r-device: 44px;
  --r-group: 12px;
  --r-field: 12px;
  --r-icon: 22.5%;          /* app icon squircle approximation */
  --r-pill: 999px;

  --measure-w: 72ch;
  --page-w: 1120px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #232326;
    --ink: #f2f2f7;
    --ink-2: #c7c7cc;
    --ink-3: #98989f;
    --sep: rgba(84, 84, 88, 0.55);
    --sep-strong: rgba(120, 120, 128, 0.7);
    --measure: #ffd60a;
    --measure-soft: #3a3100;
    --measure-ink: #ffe680;
    --up: #30d158;
    --up-soft: #0f2a17;
    --down: #ff453a;
    --down-soft: #34100e;
    --focus: #ffd60a;
    --shadow-float: 0 18px 50px -20px rgba(0, 0, 0, 0.8);
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --surface-2: #232326; --ink: #f2f2f7; --ink-2: #c7c7cc; --ink-3: #98989f;
  --sep: rgba(84, 84, 88, 0.55); --sep-strong: rgba(120, 120, 128, 0.7); --measure: #ffd60a; --measure-soft: #3a3100;
  --measure-ink: #ffe680; --up: #30d158; --up-soft: #0f2a17; --down: #ff453a; --down-soft: #34100e; --focus: #ffd60a;
  --shadow-float: 0 18px 50px -20px rgba(0, 0, 0, 0.8);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--t-body)/1.47 var(--font);
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "tnum" 0;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--measure); color: #1c1c1e; }
.num { font-variant-numeric: tabular-nums; }
.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; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ---------- Type ---------- */
.display { font-size: var(--t-4xl); line-height: 1.02; font-weight: 700; letter-spacing: -0.035em; margin: 0; text-wrap: balance; }
.h1 { font-size: var(--t-3xl); line-height: 1.08; font-weight: 700; letter-spacing: -0.03em; margin: 0; text-wrap: balance; }
.h2 { font-size: var(--t-2xl); line-height: 1.15; font-weight: 700; letter-spacing: -0.025em; margin: 0; text-wrap: balance; }
.h3 { font-size: var(--t-lg); line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; margin: 0; }
.lede { font-size: var(--t-lg); line-height: 1.45; color: var(--ink-2); max-width: 38ch; margin: 0; }
.body { max-width: var(--measure-w); }
.small { font-size: var(--t-sm); color: var(--ink-3); line-height: 1.4; }
.muted { color: var(--ink-3); }
.rank { font: 700 var(--t-rank)/0.9 var(--font-round); letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.rank sup { font-size: 0.4em; vertical-align: 0.9em; letter-spacing: 0; margin-right: 0.04em; }
@media (max-width: 640px) { .display { font-size: var(--t-3xl); } .h1 { font-size: var(--t-2xl); } }

/* ---------- Layout ---------- */
.page { width: min(100% - 32px, var(--page-w)); margin-inline: auto; }
.stack { --stack: var(--s4); }
.stack > * + * { margin-top: var(--stack); }
.row { display: flex; gap: var(--s3); align-items: center; }
.row-wrap { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.split { display: grid; gap: var(--s10); grid-template-columns: 1.05fr 0.95fr; align-items: center; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; gap: var(--s8); } }
.section { padding-block: var(--s16); }
@media (max-width: 640px) { .section { padding-block: var(--s12); } }

/* ---------- Buttons: capsules, like the App Store's Get button ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; padding: 0 var(--s6); border-radius: var(--r-pill);
  font: 600 var(--t-body)/1 var(--font); letter-spacing: -0.01em; white-space: nowrap;
  background: var(--ink); color: var(--bg);
  transition: transform 0.12s var(--ease), background 0.12s var(--ease), opacity 0.12s;
}
.btn:active { transform: scale(0.97); }
.btn:hover { text-decoration: none; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-quiet { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--sep-strong); }
.btn-tint { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--sep); }
.btn-danger { background: var(--down); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 var(--s4); font-size: var(--t-md); }
.btn-get { min-height: 28px; padding: 0 var(--s4); font-size: var(--t-md); font-weight: 700; background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--sep); }
.btn-block { width: 100%; }
.btn .spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: gap-spin 0.7s linear infinite; }
@keyframes gap-spin { to { transform: rotate(360deg); } }

/* ---------- Fields ---------- */
.field { display: grid; gap: var(--s2); }
.field > label, .label { font-size: var(--t-md); font-weight: 600; color: var(--ink); }
.hint { font-size: var(--t-sm); color: var(--ink-3); }
.input, .textarea, .select {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: var(--r-field);
  background: var(--surface); color: var(--ink); border: 1px solid var(--sep-strong);
  font: 400 var(--t-body)/1.3 var(--font); letter-spacing: -0.01em;
}
.textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: var(--t-sm); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--measure); }
.input[aria-invalid="true"] { border-color: var(--down); }
.error { font-size: var(--t-sm); color: var(--down); }

/* The paste box: one field, one button, nothing else */
.paste { display: flex; gap: var(--s2); padding: 6px; border-radius: var(--r-pill); background: var(--surface); box-shadow: inset 0 0 0 1px var(--sep-strong), var(--shadow-float); }
.paste .input { border: 0; min-height: 48px; border-radius: var(--r-pill); background: transparent; box-shadow: none; padding-left: 18px; }
.paste .input:focus { box-shadow: none; }
.paste:focus-within { box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 4px var(--measure); }
@media (max-width: 520px) { .paste { flex-direction: column; border-radius: 20px; } .paste .input, .paste .btn { border-radius: 14px; } }

.check { display: grid; grid-template-columns: 22px 1fr; gap: var(--s3); align-items: start; font-size: var(--t-md); line-height: 1.45; color: var(--ink-2); }
.check input { appearance: none; width: 22px; height: 22px; margin: 1px 0 0; border-radius: 7px; border: 1.5px solid var(--sep-strong); background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.check input:checked { background: var(--ink); border-color: var(--ink); }
.check input:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--bg); border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }

/* ---------- Grouped lists (the main container, not cards) ---------- */
.group { background: var(--surface); border-radius: var(--r-group); overflow: hidden; box-shadow: 0 0 0 1px var(--sep); }
.group-title { font-size: var(--t-sm); color: var(--ink-3); margin: 0 0 var(--s2) var(--s4); }
.group-foot { font-size: var(--t-sm); color: var(--ink-3); margin: var(--s2) var(--s4) 0; line-height: 1.4; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s3); align-items: center; padding: 12px var(--s4); min-height: 52px; position: relative; text-decoration: none; }
.item + .item::before { content: ""; position: absolute; top: 0; right: 0; left: var(--inset, var(--s4)); border-top: 1px solid var(--sep); }
.item.has-icon { --inset: 76px; }
.item-title { font-weight: 600; font-size: var(--t-body); line-height: 1.25; letter-spacing: -0.015em; }
.item-sub { font-size: var(--t-sm); color: var(--ink-3); line-height: 1.35; }
.item-trail { display: flex; align-items: center; gap: var(--s2); color: var(--ink-3); font-size: var(--t-md); }
a.item:hover, button.item:hover { background: var(--surface-2); }
button.item { width: 100%; border: 0; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.chev { width: 8px; height: 13px; flex: none; opacity: 0.45; background: currentColor; -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'><path d='M1 1l5.5 5.5L1 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/contain no-repeat; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'><path d='M1 1l5.5 5.5L1 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/contain no-repeat; }

/* App icon */
.icon { width: 48px; height: 48px; border-radius: var(--r-icon); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--sep); object-fit: cover; flex: none; }
.icon-lg { width: 64px; height: 64px; }
.icon-sm { width: 32px; height: 32px; }

/* Search result row, App Store style */
.result { display: grid; grid-template-columns: 30px 48px 1fr auto; gap: var(--s3); align-items: center; padding: 10px var(--s4); position: relative; }
.result + .result::before { content: ""; position: absolute; top: 0; right: 0; left: 106px; border-top: 1px solid var(--sep); }
.result .pos { font: 700 var(--t-md)/1 var(--font-round); color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.result.you { background: var(--measure-soft); }
.result.you .pos { color: var(--measure-ink); }
.result.gap { padding-block: 8px; grid-template-columns: 30px 1fr; }
.result.gap .gap-label { justify-self: start; font: 700 var(--t-sm)/1 var(--font); color: #1c1c1e; background: var(--measure); padding: 6px 10px; border-radius: var(--r-pill); font-variant-numeric: tabular-nums; }
.stars { color: var(--ink-3); font-size: var(--t-xs); letter-spacing: 0.04em; }

/* ---------- The gap ruler: the one loud element ---------- */
/* Markup: <div class="measured"><div class="ruler" style="top:Apx;height:Bpx"></div> rows </div>.
   The ruler sits in the left gutter from the #1 row to the maker's row; the count lives in the .result.gap row it spans. */
.measured { position: relative; padding-left: 34px; }
.ruler { position: absolute; left: 6px; width: 16px; border-top: 4px solid var(--measure); border-bottom: 4px solid var(--measure); border-radius: 2px; }
.ruler::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 4px; background: var(--measure); border-radius: 2px; }
.ruler.draw::before { transform-origin: top; animation: gap-draw 1.1s var(--ease) 0.3s both; }
.ruler.draw { animation: gap-fade 0.3s var(--ease) both; }
@keyframes gap-draw { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes gap-fade { from { opacity: 0; } }

/* ---------- Rank deltas, badges ---------- */
.delta { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: var(--r-pill); font: 700 var(--t-sm)/1.4 var(--font); font-variant-numeric: tabular-nums; }
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
.delta.flat { background: var(--surface-2); color: var(--ink-3); }
.delta.up::before { content: "\25B2"; font-size: 0.65em; }
.delta.down::before { content: "\25BC"; font-size: 0.65em; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--t-sm); font-weight: 600; background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--sep); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.badge.ok::before { background: var(--up); }
.badge.warn::before { background: var(--measure); }
.badge.bad::before { background: var(--down); }
.badge.plain::before { display: none; }

/* ---------- Segmented control (iOS) ---------- */
.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: rgba(118, 118, 128, 0.12); gap: 2px; }
.segmented button { appearance: none; border: 0; background: transparent; color: var(--ink); font: 500 var(--t-md)/1 var(--font); padding: 7px 14px; border-radius: 7px; cursor: pointer; }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04); font-weight: 600; }

/* ---------- Notices, toasts, empty states ---------- */
.notice { display: grid; grid-template-columns: auto 1fr; gap: var(--s3); padding: var(--s4); border-radius: var(--r-group); background: var(--measure-soft); color: var(--ink); font-size: var(--t-md); line-height: 1.45; }
.notice::before { content: ""; width: 4px; border-radius: 2px; background: var(--measure); }
.notice.bad { background: var(--down-soft); }
.notice.bad::before { background: var(--down); }
.notice.ok { background: var(--up-soft); }
.notice.ok::before { background: var(--up); }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); font-weight: 600; font-size: var(--t-md); box-shadow: var(--shadow-float); animation: gap-toast 0.25s var(--ease); max-width: calc(100% - 32px); }
@keyframes gap-toast { from { opacity: 0; transform: translate(-50%, 10px); } }
.empty { text-align: center; padding: var(--s12) var(--s6); color: var(--ink-3); }
.empty .h3 { color: var(--ink); margin-bottom: var(--s2); }

/* ---------- Data ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
.table th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: var(--t-sm); padding: 10px var(--s4); border-bottom: 1px solid var(--sep); }
.table td { padding: 12px var(--s4); border-bottom: 1px solid var(--sep); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.n, .table th.n { text-align: right; font-variant-numeric: tabular-nums; }
.stat { display: grid; gap: 2px; }
.stat b { font: 700 var(--t-2xl)/1.1 var(--font-round); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat span { font-size: var(--t-sm); color: var(--ink-3); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--sep), var(--surface-2)); background-size: 200% 100%; animation: gap-shimmer 1.4s linear infinite; border-radius: 8px; min-height: 14px; }
@keyframes gap-shimmer { to { background-position: -200% 0; } }

/* ---------- Steps (onboarding is a real sequence, so numbers are earned) ---------- */
.steps { display: flex; gap: var(--s2); list-style: none; padding: 0; margin: 0; }
.steps li { flex: 1; height: 4px; border-radius: 2px; background: var(--sep-strong); }
.steps li[aria-current="step"], .steps li.done { background: var(--ink); }

/* ---------- Device frame for product shots ---------- */
.device { width: min(100%, 380px); border-radius: var(--r-device); padding: 12px; background: #1c1c1e; box-shadow: var(--shadow-float), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
.device-screen { border-radius: calc(var(--r-device) - 12px); overflow: hidden; background: var(--bg); }
.device-bar { height: 44px; display: flex; align-items: center; justify-content: center; font: 600 var(--t-sm)/1 var(--font); color: var(--ink); }
.search-bar { margin: 0 12px 10px; padding: 9px 12px; border-radius: 10px; background: rgba(118, 118, 128, 0.12); font-size: var(--t-md); color: var(--ink); display: flex; align-items: center; gap: 8px; }
.search-bar svg { width: 15px; height: 15px; opacity: 0.6; }

/* ---------- App shell (portal) ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100dvh; }
.side { padding: var(--s5) var(--s3); border-right: 1px solid var(--sep); background: var(--surface); position: sticky; top: 0; height: 100dvh; overflow-y: auto; }
.side a.nav { display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s3); border-radius: 10px; text-decoration: none; font-weight: 500; color: var(--ink-2); }
.side a.nav[aria-current="page"] { background: var(--bg); color: var(--ink); font-weight: 600; }
.side a.nav .count { margin-left: auto; font-size: var(--t-xs); font-weight: 700; background: var(--measure); color: #1c1c1e; border-radius: var(--r-pill); padding: 1px 7px; }
.main { padding: var(--s8) var(--s8) var(--s16); max-width: 980px; width: 100%; }
.tabbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: max(var(--s5), env(safe-area-inset-top)) var(--s4) calc(96px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 40; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--sep); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: 10.5px; font-weight: 600; color: var(--ink-3); text-decoration: none; position: relative; }
  .tabbar a[aria-current="page"] { color: var(--ink); }
  .tabbar a svg { width: 24px; height: 24px; }
  .tabbar a .dot { position: absolute; top: 4px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--measure); box-shadow: 0 0 0 2px var(--surface); }
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); }
.app-switch { display: flex; align-items: center; gap: var(--s3); }

/* ---------- Prose (legal pages, answer pages) ---------- */
.prose { max-width: 68ch; font-size: var(--t-body); line-height: 1.6; }
.prose h1 { font-size: var(--t-3xl); line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 var(--s4); }
.prose h2 { font-size: var(--t-xl); letter-spacing: -0.02em; margin: var(--s10) 0 var(--s3); line-height: 1.25; }
.prose h3 { font-size: var(--t-lg); margin: var(--s6) 0 var(--s2); }
.prose p, .prose ul, .prose ol { margin: 0 0 var(--s4); }
.prose li + li { margin-top: var(--s2); }
.prose .short-answer { font-size: var(--t-lg); line-height: 1.5; padding: var(--s4) var(--s5); border-radius: var(--r-group); background: var(--surface); box-shadow: inset 4px 0 0 var(--measure), 0 0 0 1px var(--sep); }
.prose aside.app-cta { margin: var(--s8) 0; padding: var(--s4) var(--s5); border-radius: var(--r-group); background: var(--measure-soft); }
