/* xTrain as an app: the shell (top bar under the status bar, the tab bar over the
   home indicator, the screens between them) and what each screen changes when the
   site becomes a phone app. Loaded after the site's stylesheets: the tokens, type,
   controls and drawings are the site's own, untouched. */

:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar: 52px;                              /* the top bar, under the status bar */
  --bar-h: calc(var(--bar) + var(--safe-t));
  --tabs: 60px;                             /* the tab bar, over the home indicator */
  --tabs-h: calc(var(--tabs) + var(--safe-b));
}

/* ---------- an app, not a page ---------- */
html, body { background: var(--ground); }
html { -webkit-tap-highlight-color: transparent; }
.app { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.app input, .app textarea { -webkit-user-select: text; user-select: text; }
.app a, .app button, .app summary, .app [role='button'] { touch-action: manipulation; }
.app [hidden] { display: none !important; }
html.is-locked, html.is-locked body { overflow: hidden; }
@view-transition { navigation: none; }

/* ---------- the top bar ---------- */
.app .top { height: var(--bar-h); padding: var(--safe-t) var(--gut) 0; }
.app .top .mark { font-size: 21px; height: 44px; align-items: center; }
.app .top-end { gap: var(--s2); }
.app .top .dk-saved { height: 38px; background: color-mix(in oklch, var(--paper) 60%, transparent); }
.app .top.on-cone .dk-saved { background: var(--paper); border-color: transparent; }
.app .top .btn-sm { --h: 38px; padding: 0 16px 0 14px; gap: 8px; }
/* the site hides top-bar buttons on phones behind its Menu; the app's one action stays */
.app .top-end .btn.bar-act { display: inline-flex; }
.app .top .btn-sm .ic { width: 15px; height: 15px; }

/* ---------- the tab bar ---------- */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 31;
  height: var(--tabs-h); padding: 6px 6px var(--safe-b);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: start;
  border-top: 1px solid var(--joint);
  transition: border-color 0.3s var(--out);
}
.tabs::before { content: ''; position: absolute; inset: 0; z-index: -1; background: var(--ground); transition: background-color 0.3s var(--out); }
.tabs.on-cone::before { background: var(--cone); }
.tabs.on-cone { border-top-color: color-mix(in oklch, var(--ink) 14%, transparent); }
.tab {
  position: relative; z-index: 1; height: calc(var(--tabs) - 12px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink-2); white-space: nowrap;
  font-size: 12px; font-weight: 640; font-stretch: 100%; letter-spacing: -0.005em; line-height: 1;
  transition: color 0.2s var(--out);
}
.tab-glyph { width: 27px; height: 27px; opacity: 0.55; transition: opacity 0.2s var(--out), transform 0.16s var(--out); }
.tab.is-on { color: var(--ink); }
.tab.is-on .tab-glyph { opacity: 1; }
.tab:active .tab-glyph { transform: scale(0.9); }
.tab:focus-visible { outline-offset: -2px; border-radius: var(--r-ctl); }
/* the site's nav pill, now under the tab you're on */
.tab-pill { position: absolute; left: 0; top: 6px; z-index: 0; height: calc(var(--tabs) - 12px); width: 0; border-radius: var(--r-ctl); background: var(--paper); opacity: 0; pointer-events: none; }
.tab-glyph .f-path { stroke-width: 5; }
.tab-glyph .tab-run { stroke-width: 4.2; stroke-dasharray: 0.5 8.5; }
.tab-glyph .tab-line { stroke: var(--ink); stroke-width: 3.5; }
.tab-glyph .tab-hole { fill: var(--ground); }
.tab.is-on .tab-hole { fill: var(--paper); }
.tab-glyph .tab-nose { fill: none; stroke: var(--paper); stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.tab-glyph .tab-head { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
/* over the flood the kit keeps an ink edge, so a cone on cone still reads */
.tabs.on-cone .tab:not(.is-on) .f-cone-brim { stroke: var(--ink); stroke-width: 2.4; }
.tabs.on-cone .tab:not(.is-on) .tab-hole { fill: var(--cone); }
.tabs.on-cone .tab:not(.is-on) { color: var(--ink); }
.tabs.on-cone .tab:not(.is-on) .tab-glyph { opacity: 0.7; }

/* ---------- screens ---------- */
.screens { position: relative; min-height: 100dvh; }
.scr { min-height: 100dvh; }
/* the flood at the end of a screen runs on under the tab bar, so the screen ends in orange */
.scr > .join:last-child { padding-bottom: calc(72px + var(--tabs-h)); }
.app .join-btn { margin-top: var(--s6); }
.app .join .join-btn { --h: 56px; padding: 0 26px; font-size: 16px; }

/* ---------- sheets (the plan's details, the deck's filters) ---------- */
.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 45; max-height: min(70svh, 640px); display: flex;
  transform: translateY(102%); visibility: hidden; transition: transform 0.5s var(--out), visibility 0s linear 0.5s;
}
.sheet.is-open { transform: none; visibility: visible; transition: transform 0.5s var(--out); }
.sheet-in {
  width: 100%; overflow-y: auto; overscroll-behavior: contain; background: var(--paper);
  border-radius: var(--r-obj) var(--r-obj) 0 0; border-top: 1.5px solid var(--ink);
  padding: 0 var(--gut) calc(var(--s5) + var(--safe-b));
}
.sheet-head { display: flex; position: sticky; top: 0; z-index: 2; align-items: center; justify-content: space-between; padding: var(--s3) 0; margin-bottom: var(--s3); background: var(--paper); border-bottom: 1px solid var(--joint); }
.sheet-head p { font-weight: 700; font-size: 15px; line-height: 1.3; padding: 4px 8px; margin-left: -8px; border-radius: 8px; min-width: 0; font-variant-numeric: tabular-nums; }

/* ====================================================================== */
/* Phones. The site already stacks to one column here; the app goes further:
   one row where the site wraps, one caption where it listed three, and both
   days of the adapt board side by side, so a screen holds one idea at a time. */
@media (max-width: 760px) {

  /* ---------- Home ---------- */
  .app .hero { padding: calc(var(--bar-h) + 20px) var(--gut) var(--s7); gap: var(--s4); }
  .app .hero-title { font-size: clamp(38px, 11.4vw, 54px); }
  .app .hero .field-wrap { margin: var(--s2) calc(var(--gut) * -1) 0; }
  .app .hero .field { border-radius: 0; }
  .app .hero .field-cap { padding: 0 var(--gut); }
  .app .kit { margin-top: var(--s2); }
  .app .hero .lane { border-top: 1px solid var(--joint); padding-top: var(--s4); margin-top: var(--s2); }
  .hero-go { order: 5; width: 100%; --h: 56px; margin-top: var(--s2); }
  .hero-go .ic { width: 15px; height: 15px; }

  /* the run: pinned like the site, sized to the space between the bars, one step at a time */
  .app .run-pin {
    min-height: 0; height: 100svh; display: flex; flex-direction: column; gap: var(--s4);
    padding: calc(var(--bar-h) + var(--s4)) 0 calc(var(--tabs-h) + var(--s3));
  }
  .app .run-copy { order: 1; padding: 0 var(--gut); }
  .app .run h2 { font-size: clamp(30px, 8.6vw, 40px); max-width: 11em; }
  .app .run-steps { display: grid; margin-top: var(--s4); max-width: 34ch; }
  .app .run-steps li { grid-area: 1 / 1; opacity: 0; transform: translateY(6px); transition: opacity 0.35s var(--out), transform 0.45s var(--out); font-size: 16px; line-height: 1.4; color: var(--ink); }
  .app .run-steps li.is-on { opacity: 1; transform: none; }
  .app .run-steps li b { font-size: 18px; }
  .app .run-stage { order: 2; flex: 1; min-height: 0; height: auto; margin: 0; }
  .app .field-run { height: 100%; aspect-ratio: auto; }
  .app .phone { right: 6%; height: min(88%, 330px); width: auto; aspect-ratio: 9 / 18.5; }

  /* too easy: today and tomorrow side by side, the change under them, the question last */
  .app .adapt { padding: var(--s8) var(--gut) var(--s8); }
  .app .adapt-board { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: 'today tomorrow' 'change change' 'ask ask'; gap: var(--s3); margin-top: var(--s6); }
  .app .adapt-day { order: 0 !important; }
  .app .adapt-day:first-child { grid-area: today; }
  .app .adapt-day:nth-child(3) { grid-area: tomorrow; }
  .app .adapt-day figcaption { font-size: 14px; margin-bottom: var(--s2); }
  .app .adapt-change { grid-area: change; margin-top: 0; font-size: 16px; }
  .app .adapt-ask { grid-area: ask; order: 0; margin-top: var(--s3); padding-top: var(--s4); border-top: 1px solid var(--joint); }
  .app .adapt-q { max-width: none; }
  .app .adapt-btns { flex-wrap: nowrap; gap: 6px; }
  .app .adapt-btns .chip { padding: 0 14px; }

  .app .lib { padding: var(--s8) 0; }

  .app .scr-home .join { padding-bottom: var(--s8); }
  .app .foot { padding: var(--s8) var(--gut) calc(var(--s6) + var(--tabs-h)); }
  .app .foot-row { flex-wrap: wrap; }
  .foot-forget { padding: 10px 0 4px; font-size: 14px; }

  /* ---------- Basics ---------- */
  .app .bx { padding-top: calc(var(--bar-h) + 16px); }
  .app .bx-techs { position: relative; flex-wrap: nowrap; overflow-x: auto; margin: var(--s4) calc(var(--gut) * -1) 0; padding: 0 var(--gut); scrollbar-width: none; scroll-padding: 0 var(--gut); }
  .app .bx-techs::-webkit-scrollbar { display: none; }
  .app .bx-techs .chip { flex: none; }
  .app .bx-side { margin-top: var(--s5); }
  .app .bx-name { font-size: 30px; }
  .app .bx-steps { margin: var(--s3) calc(var(--gut) * -1) 0; padding: 0 var(--gut); scroll-padding: 0 var(--gut); }
  .app .bx-steps::-webkit-scrollbar { display: none; }
  .app .bx-path, .app .bx-drills { padding-top: var(--s8); padding-bottom: var(--s8); }
  /* the three drills for this technique: one row you swipe, not three cards you scroll past */
  .app .bx-drill-row { display: flex; gap: var(--s3); overflow-x: auto; scroll-snap-type: x mandatory; margin: var(--s5) calc(var(--gut) * -1) 0; padding: 0 var(--gut); scroll-padding: 0 var(--gut); scrollbar-width: none; }
  .app .bx-drill-row::-webkit-scrollbar { display: none; }
  .app .bx-drill-row > li { flex: 0 0 84%; scroll-snap-align: start; }
  .app .bx-drill-row > li:only-child { flex-basis: 100%; }

  /* ---------- Drills ---------- */
  /* the deck fills exactly the space between the bars, controls just above the tab bar;
     the flood starts under the fold, so the tab bar turns cone only when you scroll to it */
  .app .dk { display: flex; flex-direction: column; height: max(100svh, 600px); min-height: 0; padding: calc(var(--bar-h) + 8px) var(--gut) calc(var(--tabs-h) + var(--s3)); }
  .app .dk-side { flex: none; }
  .app .dk-table { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .app .scr-drills.dk-spread .dk { height: auto; }
  .app .dk-title { font-size: clamp(46px, 13.6vw, 64px); }
  .app .dk-table { margin-top: var(--s3); }
  .app .dk-bar { gap: var(--s3); }
  .app .dk-stage { flex: 1; min-height: 300px; height: auto; }
  .app .dk-stage.is-spread { flex: none; }
  .app .dk-controls { margin-top: calc(var(--s3) + 30px); }
  .app .dk-filters { margin-top: 0; gap: var(--s5); }
  .app .dk-sheet .dk-group .kit, .app .dk-sheet .dk-group .chips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
  .app .dk-search { max-width: none; min-width: 0; flex: 1 1 160px; }
  .app .dk-search input { font-size: 16px; }
  .app .dd-window { height: min(76vw, 460px); }
  .app .dd-top { height: calc(64px + var(--safe-t)); padding-top: var(--safe-t); }
  .app .dd-in { padding-bottom: calc(var(--s6) + var(--safe-b)); }
  .app .tray { width: 100vw; }
  .app .tray-in { padding-top: calc(var(--s3) + var(--safe-t)); padding-bottom: calc(var(--s5) + var(--safe-b)); }

  /* ---------- Plan ---------- */
  .app .pl { padding: calc(var(--bar-h) + 12px) var(--gut) 0; }
  .app .pl-drawer { z-index: 45; max-height: min(74svh, 660px); }
  .app .pl-drawer-in { padding-bottom: calc(var(--s5) + var(--safe-b)); }
  .app .pl-changed { bottom: calc(var(--tabs-h) + var(--s3)); }
  .app .pl-save { margin: var(--s8) calc(var(--gut) * -1) 0; padding: var(--s8) var(--gut) calc(var(--s8) + var(--tabs-h)); }

  /* ---------- How it works ---------- */
  .app .hw-hero { padding-top: calc(var(--bar-h) + 24px); }
  .app .hw-eng { scroll-margin-top: calc(var(--bar-h) - 8px); }

  /* ---------- Out of bounds ---------- */
  .app .nf { padding-top: calc(var(--bar-h) + 32px); padding-bottom: calc(var(--s8) + var(--tabs-h)); min-height: 100dvh; }

  /* ---------- the runner, under the status bar and over the home indicator ---------- */
  .app .rx-in { padding: var(--safe-t) var(--gut) calc(var(--s4) + var(--safe-b)); }
  .app .rx-top { height: 60px; }
  .app .rx-body { gap: var(--s4); }
  .app .rx-name { font-size: clamp(28px, 8vw, 36px); }
  .app .rx-time { font-size: clamp(72px, 22vw, 96px); margin-top: var(--s2); }
  .app .rx-cue { font-size: 21px; margin-top: var(--s4); }
  .app .rx-ctl { margin-top: var(--s5); }
  .app .rx-ctl .btn { flex: 1; --h: 60px; }
  .app .rx-end { padding-bottom: var(--s5); }
}

/* the welcome opens on itself, not on its first chip */
.more-in:focus { outline: none; }

/* the deck's filter button sits in the deck bar */
.dk-filter {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 12px; border-radius: var(--r-ctl);
  border: 1.5px solid color-mix(in oklch, var(--ink) 18%, transparent); background: transparent; cursor: pointer; font-weight: 620; font-size: 14px;
  transition: border-color 0.2s var(--out), transform 0.16s var(--out);
}
.dk-filter:active { transform: scale(0.97); }
.dk-filter .ic { width: 16px; height: 16px; }
.dk-filter b { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--ink); color: var(--paper); font-size: 12px; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.dk-filter[aria-expanded='true'] { border-color: var(--ink); }

/* reminders on the plan's flood */
.pl-keep { margin-top: var(--s5); display: grid; gap: var(--s4); justify-items: start; }
.pl-remind { display: grid; gap: var(--s3); justify-items: start; }
.pl-remind .seg { background: color-mix(in oklch, var(--ink) 10%, transparent); }
.pl-remind .seg button[aria-checked='false'] { color: var(--ink); }
.pl-remind .btn.is-on { background: var(--paper); color: var(--ink); }
.pl-keep-note { font-size: 15px; font-weight: 600; }

/* bigger screens get the same app, centred on the ground */
@media (min-width: 761px) {
  .tabs { max-width: 560px; margin: 0 auto; border: 1px solid var(--joint); border-bottom: 0; border-radius: 22px 22px 0 0; overflow: hidden; }
}

/* focus a script moves (a dialog's title, a sheet, the rating box) shows no ring; focus the
   keyboard moves still does */
.app [tabindex='-1']:focus { outline: none; }

/* the runner: the version the plan picked for this drill, and a test week's Done */
.rx-version { margin-top: var(--s3); font-size: 15px; line-height: 1.45; font-weight: 560; color: var(--ink-2); max-width: 52ch; }
.rx-version b { color: var(--ink); font-weight: 700; }
.rx-test-done { margin-top: var(--s2); }

/* the deck's cards stack among themselves, under the top bar and the sheets */
.app .dk-stage { z-index: 1; }
@media (max-width: 760px) {
  /* the deck is as wide as the screen allows, not as wide as its first card */
  .app .dk { align-items: stretch; }
}
@media (min-width: 761px) {
  /* the deck and its buttons end above the tab bar */
  .app .dk { padding-bottom: calc(var(--s6) + var(--tabs-h)); }
  .app .dk-stage:not(.is-spread) { height: clamp(280px, calc(100svh - 290px - var(--tabs-h)), 660px); }
  /* the buttons clear the two fanned cards under the top one, as on a phone */
  .app .dk-controls { margin-top: calc(var(--s4) + 30px); }
}

/* a phone on its side: the drill beside the clock, and nothing under the notch */
@media (orientation: landscape) and (max-height: 520px) {
  .app .rx-in { padding: 0 max(var(--gut), env(safe-area-inset-right)) max(var(--s3), env(safe-area-inset-bottom)) max(var(--gut), env(safe-area-inset-left)); }
  .app .rx-top { height: 52px; }
  .app .rx-body { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); grid-template-rows: minmax(0, 1fr); gap: var(--s5); }
  .app .rx-text { overflow-y: auto; justify-content: flex-start; padding-bottom: var(--s2); }
  .app .rx-name { font-size: 26px; }
  .app .rx-time { font-size: 64px; margin-top: var(--s2); }
  .app .rx-cue { font-size: 18px; margin-top: var(--s3); }
  .app .rx-ctl { margin-top: var(--s3); }
  .app .rx-ctl .btn { --h: 52px; }
  /* Basics: the stage fits between the bars, so the feet and the ball show together */
  .app .bx-stage { height: max(220px, calc(100svh - var(--bar-h) - var(--tabs-h) - 16px)); }
}

/* Plan: Age and Weeks each get the drawer's full width, so every choice shows */
.app .pl-two { grid-template-columns: minmax(0, 1fr); }
.app .pl-two .seg { flex-wrap: wrap; }
/* the note after a rating stays above the tab bar at every width */
@media (min-width: 761px) { .app .pl-changed { bottom: calc(var(--tabs-h) + var(--s3)); } }
/* today, in the week */
.pw-day .tag-today { color: var(--ink); font-weight: 720; }
.pw-day.is-today:not(.is-sel) { border-color: color-mix(in oklch, var(--ink) 45%, transparent); }

/* Home */
@media (max-width: 760px) {
  /* the run's words start at the gutter like every other heading */
  .app .run-pin { align-items: stretch; }
  /* reduced motion: nothing is pinned, so the run takes the height its three steps need and the
     drawing keeps room for the whole phone */
  html.is-still .app .run-pin { height: auto; min-height: 100svh; }
  html.is-still .app .run-stage { flex: none; height: clamp(280px, 56svh, 420px); }
}
/* a short phone (Safari's toolbars showing): the run's phone drops its cue so the other lines fit */
@media (max-width: 760px) and (max-height: 600px) {
  .app .run .ph-cue { display: none; }
}
/* the shortest phones on end (an old SE with Safari's bars showing): just the drill and its clock */
@media (max-width: 760px) and (max-height: 500px) and (orientation: portrait) {
  .app .run .ph-count, .app .run .ph-next { display: none; }
  .app .run .phone-screen { padding: 10px 9px; }
  .app .run .ph-name { font-size: 13px; }
  .app .run .ph-time { font-size: 28px; }
}
/* a phone on its side: the run's words beside the drawing, so the phone in it gets the screen's height */
@media (max-width: 760px) and (orientation: landscape) and (max-height: 520px) {
  .app .run-pin { flex-direction: row; align-items: center; gap: var(--s5); }
  .app .run-copy { flex: 1 1 0; min-width: 0; }
  .app .run-stage, html.is-still .app .run-stage { flex: 1 1 0; min-width: 0; align-self: stretch; height: auto; }
  .app .run h2 { font-size: clamp(24px, 4.4vw, 32px); }
}
/* reduced motion: the run's three steps all show, one under the other */
html.is-still .app .run-steps li { grid-area: auto; opacity: 1; transform: none; }
html.is-still .app .run-steps { gap: var(--s2); }
/* the strip moves by itself and by hand, never by the browser scrolling it to a focused card */
.app .lib { overflow: clip; }
@media (min-width: 761px) {
  /* on a laptop the tab bar sits over the bottom of the screen: the hero and the footer clear it */
  .app .hero { padding-bottom: calc(var(--s5) + var(--tabs-h)); }
  .app .foot { padding-bottom: calc(var(--s6) + var(--tabs-h)); }
}

/* the shell, for the keyboard and every screen size */
/* focus moved by Tab stays clear of the two bars */
html { scroll-padding-top: calc(var(--bar-h) + 8px); scroll-padding-bottom: calc(var(--tabs-h) + 8px); }
.app .skip:focus { top: calc(var(--safe-t) + 8px); }
/* a phone on its side: everything stays inside the notch's insets */
.app { --gut: max(clamp(20px, 3.4vw, 56px), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)); }
.tabs { padding-left: max(6px, env(safe-area-inset-left, 0px)); padding-right: max(6px, env(safe-area-inset-right, 0px)); }
/* the narrowest phones: "How it works" fits its tab */
@media (max-width: 370px) { .tab { font-size: 10px; letter-spacing: -0.02em; } }

/* Plan on a laptop: the details are a column beside the plan, always showing, so the top bar
   doesn't need a button for them */
@media (min-width: 1101px) { .app .bar-act[data-act='plan'] { display: none !important; } }
/* the season's weeks are buttons: the keyboard's focus shows as an outline on the band */
.ps-hit:focus { outline: none; }
.ps-hit:focus-visible { stroke: var(--ink); stroke-width: 3px; }

/* the runner on a short phone: while rating, the cue and the next line make room for the drawing */
@media (max-height: 740px) and (orientation: portrait) {
  .run-x.is-rating .rx-cue, .run-x.is-rating .rx-version, .run-x.is-rating .rx-next { display: none; }
}
/* on its side: a water break, the test or the cool-down has no drawing, so its words take the width */
@media (orientation: landscape) and (max-height: 520px) {
  .app .run-x.no-drawing .rx-body { grid-template-columns: minmax(0, 1fr); }
}
