/* /app/ — the family kit on your home screen (UX run-25, DESIGN.md § 8j). A v2 page on the css/toys.css
   tokens: putty surface, physical depth, springy keys, light and dark, Geist + Geist Mono like the other
   family pages. One cobalt accent, the colour of the app's icon: the stage where a drawn home screen holds
   the icon, its real count and its long-press menu, next to a paper card that says how to install it here.
   Cobalt is an object colour and stays the same in dark mode; text on it is white (5.4:1). The card is
   paper with ink text in both schemes, as on /together/. */
body.ap {
  --t-display: "Geist", ui-sans-serif, system-ui, sans-serif;
  --ap-gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  --ap-ink: #141414;
  --ap-ink-2: #5d5b55;          /* on the paper card: 6.3:1 */
  --ap-paper: #f7f6f2;
  --ap-line: rgba(20,20,20,.14);
  --ap-cobalt: #2f55ff;
  --ap-cobalt-deep: #1a33b8;
  --ap-badge: #e3173d;           /* white on it: 4.9:1 */
  padding-top: var(--header-h);
  font-family: var(--t-display);
  font-variation-settings: normal;
}
html:has(body.ap) { scroll-padding-top: calc(var(--header-h) + 18px); }
body.ap .t-wrap,
body.ap .container-wide { width: min(100% - 2 * var(--ap-gutter), 1240px); }

/* Until app.js has chosen the install card, the card's words are laid out but not painted. */
html.ap-wait .ap-card,
html.ap-wait .ap-bring-keys,
html.ap-wait #ap-ready,
html.ap-wait #ap-offline-key { visibility: hidden; animation: ap-show 0s 3s forwards; }
@keyframes ap-show { to { visibility: visible; } }
@media (scripting: none) { .ap-card, .ap-bring, .ap-offline { display: none; } }
.ap-noscript { margin: 0 0 32px; padding: 18px 20px; border-radius: var(--t-r-m); background: var(--t-card); box-shadow: inset 0 0 0 2px var(--t-line); }

/* ---------- Masthead ---------- */
.ap-main { padding-bottom: 48px; }
.ap-top { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 40px; padding-bottom: 36px; }
.ap-mast { padding: 32px 0 22px; }
@media (min-width: 1100px) { .ap-top { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); align-items: center; padding-top: 24px; } .ap-mast { padding: 0; } }
.ap-kicker { margin: 0 0 14px; color: var(--t-ink-2); }
.ap-mast h1 {
  margin: 0; max-width: 12ch;
  font-size: 2.5rem; line-height: .94; font-weight: 800; letter-spacing: -.02em; text-wrap: balance;
  animation: ap-rise .7s var(--t-spring) both;
}
.ap-mast h1:focus { outline: none; }
.ap-lede { margin: 18px 0 0; max-width: 46ch; font-size: 1.125rem; line-height: 1.4; color: var(--t-ink-2); text-wrap: pretty; }
.ap-lede strong { color: var(--t-ink); font-weight: 600; }
@keyframes ap-rise { from { transform: translateY(28px) scale(.97); } }
@media (min-width: 380px) { .ap-mast h1 { font-size: 2.75rem; } }
@media (min-width: 600px) { .ap-mast h1 { font-size: 4.25rem; } .ap-lede { font-size: 1.3125rem; } }
@media (min-width: 1100px) { .ap-mast h1 { font-size: 5rem; } }

/* ---------- The stage: a drawn home screen and the install card ---------- */
.ap-stage {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
  padding: 14px; border-radius: 34px;
  background: var(--ap-cobalt); color: #fff;
  box-shadow: inset 0 -10px 0 rgba(0,0,0,.18), 0 26px 48px -28px rgba(26,51,184,.95);
  animation: ap-slab .8s var(--t-spring) .08s both;
}
@keyframes ap-slab { from { transform: translateY(36px) scale(.97); } }
@media (min-width: 700px) { .ap-stage { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: stretch; padding: 20px; gap: 20px; } }

.ap-phone {
  position: relative; min-width: 0;
  padding: 10px; border-radius: 30px;
  background: #141414;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.16), inset 0 -6px 0 rgba(255,255,255,.06);
}
.ap-screen {
  position: relative; overflow: hidden;
  min-height: 236px; height: 100%; padding: 12px 14px 16px; border-radius: 22px;
  background: radial-gradient(120% 90% at 30% 0%, #26304f 0%, #141414 70%);
}
.ap-clock { display: block; margin: 0 0 18px; font: 600 .8125rem/1 var(--t-mono); font-variant-numeric: tabular-nums; color: rgba(255,255,255,.86); text-align: center; }
.ap-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 12px; margin: 0; padding: 0; list-style: none; }
.ap-grid > li { aspect-ratio: 1; border-radius: 22%; background: rgba(255,255,255,.1); box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.ap-grid > li.ap-icon-cell { position: relative; z-index: 2; aspect-ratio: auto; background: none; box-shadow: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ap-icon { position: relative; display: block; width: 100%; aspect-ratio: 1; animation: ap-lift 1.1s var(--t-spring) .5s both; }
.ap-icon img { display: block; width: 100%; height: 100%; border-radius: 22%; box-shadow: 0 10px 20px -8px rgba(0,0,0,.7), 0 0 0 3px rgba(255,255,255,.9); }
@keyframes ap-lift { from { transform: scale(.86); } 60% { transform: scale(1.08); } to { transform: scale(1.04); } }
.ap-badge {
  position: absolute; top: -8px; right: -8px;
  display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px;
  background: var(--ap-badge); color: #fff; font: 700 .8125rem/1 var(--t-display); font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px #141414;
}
.ap-badge[hidden] { display: none; }
.ap-icon-name { font: 600 .75rem/1.1 var(--t-display); color: #fff; white-space: nowrap; }
/* The long-press menu the manifest's shortcuts make. Decoration: the real one is the system's. */
.ap-menu {
  position: absolute; z-index: 3; left: -10%; top: calc(100% + 8px); width: 200px; max-width: 290%;
  margin: 0; padding: 6px; list-style: none; border-radius: 16px;
  background: rgba(247,246,242,.97); color: var(--ap-ink);
  box-shadow: 0 18px 36px -10px rgba(0,0,0,.65);
  transform-origin: 20% 0;
  animation: ap-menu .6s var(--t-spring) 1.2s both;
}
.ap-menu li { padding: 7px 10px; font: 600 .8125rem/1.25 var(--t-display); white-space: nowrap; }
.ap-menu li + li { border-top: 1px solid var(--ap-line); }
@keyframes ap-menu { from { opacity: 0; transform: translateY(-10px) scale(.9); } }

.ap-card {
  display: flex; flex-direction: column; min-width: 0;
  padding: 20px 18px 18px; border-radius: 24px;
  background: var(--ap-paper); color: var(--ap-ink);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.08);
}
@media (min-width: 600px) { .ap-card { padding: 26px 26px 22px; } }
.ap-card-k { margin: 0 0 8px; font: 600 .75rem/1.3 var(--t-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ap-ink-2); }
.ap-card-title { margin: 0 0 10px; font-size: 1.875rem; line-height: 1; font-weight: 800; letter-spacing: -.015em; text-wrap: balance; }
.ap-card-title:focus { outline: none; }
@media (min-width: 600px) { .ap-card-title { font-size: 2.25rem; } }
.ap-how { margin: 0 0 12px; max-width: 46ch; color: var(--ap-ink-2); }
.ap-steps { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; counter-reset: ap; }
.ap-steps[hidden] { display: none; }
.ap-steps li { counter-increment: ap; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 1.5px var(--ap-line); font-weight: 600; line-height: 1.3; }
.ap-steps li::before { content: counter(ap); flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ap-ink); color: var(--ap-paper); font: 600 .8125rem/1 var(--t-mono); }
.ap-glyph { flex: none; color: var(--ap-cobalt-deep); }
.ap-keys { display: flex; flex-wrap: wrap; gap: 8px; }
.ap-badge-line { margin: 14px 0 0; padding-top: 12px; border-top: 1.5px solid var(--ap-line); font: 500 .875rem/1.45 var(--t-mono); color: var(--ap-ink-2); }
.ap-status { margin: 8px 0 0; font-weight: 600; }
.ap-status:empty { display: none; }

/* ---------- Keys ---------- */
body.ap .ap-key {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 18px; border: 0; border-radius: var(--t-r-btn, 10px); cursor: pointer;
  background: var(--t-card); color: var(--t-ink); text-decoration: none; text-align: center;
  font: 600 .9375rem/1.2 var(--t-display);
  box-shadow: inset 0 0 0 1.5px var(--t-line), inset 0 -4px 0 rgba(0,0,0,.08);
  transition: transform var(--t-base) var(--t-spring);
}
body.ap .ap-key:active { transform: translateY(2px) scale(.97); }
body.ap .ap-key:disabled { cursor: default; opacity: .6; }
body.ap .ap-key[hidden] { display: none; }
body.ap .ap-key-ink { background: var(--t-ink); color: var(--t-surface); box-shadow: inset 0 -4px 0 rgba(255,255,255,.14); font-weight: 700; }
body.ap .ap-key-ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--t-ink); }
body.ap .ap-card .ap-key-main { background: var(--ap-cobalt); color: #fff; box-shadow: inset 0 -5px 0 rgba(0,0,0,.2); font-weight: 800; }
body.ap .ap-card :focus-visible { outline: 3px solid var(--ap-ink); outline-offset: 2px; }
body.ap .ap-card a:not(.ap-key) { color: var(--ap-ink); }
@media (max-width: 599px) { .ap-keys > .ap-key, .ap-bring-keys > .ap-key { flex: 1 1 auto; } }

/* ---------- What changes ---------- */
.ap-h2 { margin: 0 0 16px; font-size: clamp(1.875rem, 4.6vw, 3rem); line-height: .98; font-weight: 800; letter-spacing: -.02em; text-wrap: balance; }
.ap-h2:focus { outline: none; }
.ap-gets { padding: 28px 0 8px; }
.ap-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin: 0; padding: 0; list-style: none; }
@media (min-width: 700px) { .ap-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .ap-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.ap-feat { min-width: 0; padding: 20px 20px 22px; border-radius: var(--t-r-l); background: var(--t-card); box-shadow: inset 0 0 0 1.5px var(--t-line), inset 0 -6px 0 rgba(0,0,0,.05); }
.ap-feat-k { margin: 0 0 10px; font: 600 .75rem/1.3 var(--t-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--t-ink-2); }
.ap-feat h3 { margin: 0 0 8px; font-size: 1.3125rem; line-height: 1.1; font-weight: 800; letter-spacing: -.01em; text-wrap: balance; }
.ap-feat p:last-child { margin: 0; color: var(--t-ink-2); line-height: 1.45; }

/* ---------- Bring your things in, and offline ---------- */
.ap-bring, .ap-offline, .ap-plain { margin-top: 36px; padding: 24px 20px; border-radius: var(--t-r-l); background: var(--t-surface-2); }
@media (min-width: 600px) { .ap-bring, .ap-offline, .ap-plain { padding: 32px 32px; } }
.ap-bring-k { margin: 0 0 12px; color: var(--t-ink-2); }
.ap-text { margin: 0 0 16px; max-width: 62ch; color: var(--t-ink-2); line-height: 1.45; }
.ap-bring-keys { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
body.ap .ap-key-light { background: var(--t-ink); color: var(--t-surface); font-weight: 700; box-shadow: inset 0 -4px 0 rgba(255,255,255,.14); }
.ap-hand { margin: 0 0 12px; max-width: 640px; }
.ap-hand summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.ap-hand-label { display: block; margin: 6px 0; font-size: .875rem; color: var(--t-ink-2); }
body.ap .ap-hand-text { display: block; box-sizing: border-box; width: 100%; min-height: 88px; padding: 10px 12px; border: 0; border-radius: var(--t-r-s); background: var(--t-card); color: var(--t-ink); font: 500 1rem/1.35 var(--t-mono); box-shadow: inset 0 0 0 1.5px var(--t-line); resize: vertical; }
.ap-preview { margin: 0 0 12px; padding: 18px; border-radius: var(--t-r-m); background: var(--t-card); box-shadow: inset 0 0 0 2px var(--t-ink); max-width: 640px; }
.ap-preview[hidden] { display: none; }
.ap-preview-title { margin: 0 0 6px; font-weight: 800; font-size: 1.125rem; }
.ap-preview-title:focus { outline: none; }
.ap-preview-text { margin: 0 0 14px; color: var(--t-ink-2); }
.ap-preview-keys { display: flex; flex-wrap: wrap; gap: 8px; }
.ap-bring-status { margin: 0; font-weight: 600; max-width: 62ch; }
.ap-ready { margin: 0 0 14px; font: 600 .9375rem/1.4 var(--t-mono); }
.ap-plain-list { margin: 0 0 18px; padding-left: 20px; max-width: 70ch; color: var(--t-ink-2); line-height: 1.5; }
.ap-plain-list li + li { margin-top: 6px; }
.ap-plain-list a { color: var(--t-ink); }

@media (prefers-reduced-motion: reduce) {
  .ap-mast h1, .ap-stage, .ap-icon, .ap-menu { animation: none; }
  body.ap .ap-key { transition: none; }
}
