/* ───────────────────────────────────────────────────────────────────────────
   Tensil Fit design system · mobile-first
   Direction: measured, not guessed. Gym-chalk surfaces, graphite ink, black pill
   actions; ONE accent — measuring-tape yellow — reserved for the tape signature
   (sizes, fit zones, progress) and focus. Archivo (variable width) for kit-print
   display type, Martian Mono for numbers.
   ─────────────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Archivo Variable'; font-style: normal; font-display: swap;
  font-weight: 100 900; font-stretch: 62% 125%;
  src: url(/fonts/archivo-latin-wdth-normal.woff2) format('woff2-variations');
}
@font-face {
  font-family: 'Martian Mono Variable'; font-style: normal; font-display: swap;
  font-weight: 100 800; font-stretch: 75% 112.5%;
  src: url(/fonts/martian-mono-latin-standard-normal.woff2) format('woff2-variations');
}

:root {
  --t-chalk: #F3F4F1;
  --t-surface: #FFFFFF;
  --t-raised: #FAFAF8;
  --t-ink: #14161B;
  --t-ink-2: #4A505C;
  --t-ink-3: #6B707A;          /* 4.5:1 on chalk (was #7B818C, 3.5:1) */
  --t-line: #E2E4DF;
  --t-line-2: #CDD0C9;
  --t-tape: #FFC629;
  --t-tape-deep: #E9AE00;
  --t-tape-ink: #2B2200;
  --t-on: #0B7F58;              /* status text ≥4.5:1 on chalk in light; brighter originals in dark */
  --t-snug: #B4540C;
  --t-off: #CB3838;
  --t-off-fill: #CB3838;        /* danger button fill: white text 5:1 in both themes */
  --t-field-line: #8B8D89;      /* input borders: 3:1 on chalk and surface */
  --t-focus: #14161B;           /* focus ring: graphite on light grounds, tape yellow on dark */
  --t-accent: var(--t-ink);          /* brand hosts may override (widget) */
  --t-accent-ink: #FFFFFF;
  --t-shadow: 0 1px 2px rgba(20, 22, 27, .06), 0 8px 24px rgba(20, 22, 27, .06);
  --t-shadow-lg: 0 -8px 40px rgba(20, 22, 27, .18);
  --t-r-sm: 10px; --t-r: 16px; --t-r-lg: 24px; --t-pill: 999px;
  --t-font: 'Archivo Variable', 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --t-mono: 'Martian Mono Variable', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --t-gutter: 16px;
  --t-tap: 48px;
  --t-ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --t-chalk: #0E1014; --t-surface: #171A20; --t-raised: #1D2027;
    --t-ink: #F2F3EF; --t-ink-2: #A9AFB9; --t-ink-3: #7D838E;
    --t-line: #262A31; --t-line-2: #343943;
    --t-accent: #F2F3EF; --t-accent-ink: #14161B;
    --t-on: #0E9F6E; --t-snug: #D9650F; --t-off: #DC5656; --t-field-line: #63676E; --t-focus: #FFC629;
    --t-shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --t-shadow-lg: 0 -8px 40px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --t-chalk: #0E1014; --t-surface: #171A20; --t-raised: #1D2027;
  --t-ink: #F2F3EF; --t-ink-2: #A9AFB9; --t-ink-3: #7D838E;
  --t-line: #262A31; --t-line-2: #343943;
  --t-accent: #F2F3EF; --t-accent-ink: #14161B;
  --t-on: #0E9F6E; --t-snug: #D9650F; --t-off: #DC5656; --t-field-line: #63676E; --t-focus: #FFC629;
  color-scheme: dark;
}

/* ── base ── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.t {
  margin: 0; background: var(--t-chalk); color: var(--t-ink);
  font: 420 16px/1.5 var(--t-font); font-stretch: 100%;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
/* zero-specificity base rules so component classes (.t-btn etc.) always win */
:where(.t) :where(button, input, select, textarea) { font: inherit; color: inherit; }
:where(.t) :where(a) { color: inherit; text-underline-offset: 3px; }
:where(.t) :where(img, svg) { max-width: 100%; }
:where(.t) :focus-visible { outline: 3px solid var(--t-focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; } /* components set display; keep the hidden attribute authoritative */
.t-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── type ── */
.t-display { font-weight: 830; font-stretch: 125%; letter-spacing: -.015em; line-height: .95; }
.t-h1 { font-size: clamp(26px, 7vw, 40px); font-weight: 780; font-stretch: 115%; letter-spacing: -.01em; line-height: 1.08; margin: 0; }
.t-h2 { font-size: 20px; font-weight: 740; font-stretch: 110%; line-height: 1.2; margin: 0; }
.t-h3 { font-size: 16px; font-weight: 700; font-stretch: 105%; margin: 0; }
.t-body { font-size: 16px; color: var(--t-ink); }
.t-muted { color: var(--t-ink-2); }
.t-small { font-size: 13.5px; line-height: 1.45; }
.t-label { font: 600 11px/1.2 var(--t-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--t-ink-2); }
.t-num { font-family: var(--t-mono); font-variant-numeric: tabular-nums; font-weight: 560; letter-spacing: -.01em; }

/* ── layout ── */
.t-wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 var(--t-gutter); }
.t-stack > * + * { margin-top: 12px; }
.t-stack-lg > * + * { margin-top: 20px; }
.t-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.t-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.t-spacer { flex: 1; }
.t-divider { height: 1px; background: var(--t-line); border: 0; margin: 16px 0; }

/* ── buttons ── */
.t-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--t-tap); padding: 0 22px; border-radius: var(--t-pill);
  border: 1.5px solid transparent; background: var(--t-accent); color: var(--t-accent-ink);
  font-weight: 680; font-stretch: 105%; font-size: 16px; letter-spacing: .005em;
  cursor: pointer; text-decoration: none; transition: transform .12s var(--t-ease), background .2s, opacity .2s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.t-btn:active { transform: scale(.98); }
.t-btn:disabled, .t-btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.t-btn--ghost { background: transparent; color: var(--t-ink); border-color: var(--t-line-2); }
.t-btn--quiet { background: transparent; color: var(--t-ink); border-color: transparent; padding: 0 12px; text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.t-btn--tape { background: var(--t-tape); color: var(--t-tape-ink); }
.t-btn--block { width: 100%; }
.t-btn--sm { min-height: 38px; padding: 0 14px; font-size: 14px; }
.t-btn--danger { background: var(--t-off-fill); color: #fff; }

/* ── cards & lists ── */
.t-card { background: var(--t-surface); border: 1px solid var(--t-line); border-radius: var(--t-r-lg); padding: 18px; }
.t-card--flat { background: var(--t-raised); border-color: transparent; }
.t-card--tape { border-color: var(--t-tape-deep); box-shadow: inset 4px 0 0 var(--t-tape); }
.t-list { list-style: none; margin: 0; padding: 0; }
.t-list > li { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--t-line); min-height: 56px; }
.t-list > li:last-child { border-bottom: 0; }

/* ── fields ── */
.t-field { display: block; }
.t-field > span { display: block; font-weight: 640; font-size: 14px; margin-bottom: 6px; }
.t-field small { display: block; color: var(--t-ink-2); font-size: 13px; margin-top: 4px; }
.t-input, .t-select {
  width: 100%; min-height: 52px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--t-field-line);
  background: var(--t-surface); font-size: 16px; /* ≥16px avoids iOS zoom */ transition: border-color .15s;
}
.t-input:focus, .t-select:focus { border-color: var(--t-ink); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-tape) 70%, transparent); }
.t-input--num { font-family: var(--t-mono); font-size: 18px; letter-spacing: -.01em; }
.t-input-unit { position: relative; }
.t-input-unit > em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font: 600 12px var(--t-mono); color: var(--t-ink-3); font-style: normal; pointer-events: none; }
.t-range { width: 100%; accent-color: var(--t-ink); height: 32px; }

/* ── segmented / choice cards ── */
.t-seg { display: inline-flex; padding: 4px; gap: 2px; border-radius: var(--t-pill); background: var(--t-raised); border: 1px solid var(--t-line); }
.t-seg button { border: 0; background: transparent; min-height: 40px; padding: 0 16px; border-radius: var(--t-pill); font-weight: 620; cursor: pointer; }
.t-seg button[aria-pressed="true"] { background: var(--t-ink); color: var(--t-chalk); }
.t-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.t-choice {
  text-align: left; border: 1.5px solid var(--t-line); background: var(--t-surface); border-radius: var(--t-r);
  padding: 14px; min-height: 92px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, box-shadow .15s;
}
.t-choice b { font-weight: 720; font-stretch: 108%; }
.t-choice small { color: var(--t-ink-2); font-size: 13px; line-height: 1.35; }
.t-choice[aria-pressed="true"] { border-color: var(--t-ink); box-shadow: inset 0 0 0 1px var(--t-ink); }
.t-choice svg { width: 28px; height: 36px; color: var(--t-ink-2); }

/* ── chips ── */
.t-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 10px; border-radius: var(--t-pill); background: var(--t-raised); border: 1px solid var(--t-line); font-size: 12.5px; font-weight: 640; white-space: nowrap; }
.t-chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--t-ink-3); }
.t-chip--on::before { background: var(--t-on); } .t-chip--snug::before { background: var(--t-snug); } .t-chip--off::before { background: var(--t-off); }
.t-chip--tape { background: var(--t-tape); border-color: var(--t-tape-deep); color: var(--t-tape-ink); }
.t-chip--tape::before { background: var(--t-tape-ink); }
.t-chip--plain::before { display: none; }

/* ── THE TAPE (signature) ── */
.t-tape {
  --tick: color-mix(in srgb, var(--t-tape-ink) 55%, transparent);
  position: relative; display: flex; border-radius: 6px; overflow: visible;
  background:
    repeating-linear-gradient(90deg, var(--tick) 0 1px, transparent 1px 6px) bottom left / 100% 7px no-repeat,
    repeating-linear-gradient(90deg, var(--t-tape-ink) 0 1.5px, transparent 1.5px 30px) bottom left / 100% 14px no-repeat,
    var(--t-tape);
  color: var(--t-tape-ink); box-shadow: inset 0 -1px 0 rgba(0,0,0,.12), 0 1px 0 rgba(0,0,0,.05);
}
.t-tape__seg {
  flex: 1; position: relative; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit;
  border-left: 1px solid color-mix(in srgb, var(--t-tape-ink) 30%, transparent);
}
.t-tape__seg:first-child { border-left: 0; }
.t-tape__seg b { font: 760 15px/1 var(--t-font); font-stretch: 115%; }
.t-tape__seg i { font: 600 9px/1 var(--t-mono); font-style: normal; margin-top: 4px; letter-spacing: .04em; opacity: .75; text-transform: uppercase; }
.t-tape__seg.is-poor { opacity: .38; }
.t-tape__seg.is-alt::after { content: ''; position: absolute; inset: 3px; border: 1.5px dashed var(--t-tape-ink); border-radius: 4px; }
.t-tape__seg.is-you { background: #14161B; /* always dark on the yellow tape, in both themes */ color: var(--t-tape); border-radius: 6px; z-index: 1; margin: -6px 0; padding-top: 14px; box-shadow: 0 0 0 2px var(--t-tape), 0 6px 16px rgba(0,0,0,.25); }
.t-tape__seg.is-you i { opacity: 1; color: var(--t-tape); }
.t-tape__seg[aria-pressed="true"]:not(.is-you) { box-shadow: inset 0 0 0 2px var(--t-tape-ink); border-radius: 6px; }

/* zone strip: where you sit in this garment's intended fit */
.t-zone { display: grid; grid-template-columns: 84px 1fr; gap: 6px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--t-line); }
.t-zone:last-child { border-bottom: 0; }
.t-zone__name { font-weight: 680; font-stretch: 105%; }
.t-zone__strip {
  position: relative; height: 14px; border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--t-ink) 22%, transparent) 0 1px, transparent 1px 8px) bottom / 100% 6px no-repeat,
    var(--t-raised);
  border: 1px solid var(--t-line);
}
.t-zone__band { position: absolute; top: 0; bottom: 0; left: 38%; width: 34%; background: var(--t-tape); opacity: .85; border-radius: 2px; }
.t-zone__mark { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1.5px; background: var(--t-ink); border-radius: 2px; transition: left .5s var(--t-ease); }
.t-zone__mark::after { content: ''; position: absolute; top: -5px; left: -4px; border: 5.5px solid transparent; border-top-color: var(--t-ink); }
.t-zone__note { grid-column: 2; font-size: 13px; color: var(--t-ink-2); display: flex; gap: 8px; flex-wrap: wrap; }
.t-zone__note b { color: var(--t-ink); font-weight: 650; }
.t-zone__note .is-on { color: var(--t-on); } .t-zone__note .is-snug { color: var(--t-snug); } .t-zone__note .is-off { color: var(--t-off); }

/* progress as tape ticks */
.t-steps { display: flex; gap: 4px; }
.t-steps > i { flex: 1; height: 5px; border-radius: 3px; background: var(--t-line); }
.t-steps > i.is-done { background: var(--t-ink); }
.t-steps > i.is-now { background: var(--t-tape); }

/* ── bottom sheet ── */
.t-sheet-backdrop { position: fixed; inset: 0; background: rgba(12, 14, 18, .5); opacity: 0; transition: opacity .25s var(--t-ease); }
.t-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 94dvh; display: flex; flex-direction: column;
  background: var(--t-surface); border-radius: 22px 22px 0 0; box-shadow: var(--t-shadow-lg);
  transform: translateY(100%); transition: transform .32s var(--t-ease);
  padding-bottom: env(safe-area-inset-bottom);
}
.is-open > .t-sheet-backdrop { opacity: 1; }
.is-open > .t-sheet { transform: none; }
.t-sheet__handle { width: 40px; height: 5px; border-radius: 3px; background: var(--t-line-2); margin: 8px auto 0; }
.t-sheet__head { display: flex; align-items: center; gap: 10px; padding: 10px 16px 12px; }
.t-sheet__body { overflow: auto; padding: 4px 16px 20px; flex: 1; overscroll-behavior: contain; }
.t-sheet__foot { padding: 12px 16px 14px; border-top: 1px solid var(--t-line); display: flex; gap: 10px; background: var(--t-surface); }
.t-sheet__foot .t-btn { flex: 1; }
@media (min-width: 760px) {
  .t-sheet { left: auto; top: 0; width: 460px; max-height: none; border-radius: 0; transform: translateX(100%); }
  .t-sheet__handle { display: none; }
}

/* ── icon button ── */
.t-icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 50%; border: 0; background: var(--t-raised); color: var(--t-ink); cursor: pointer; font-size: 20px; line-height: 1; }

/* ── bottom tab bar (app shells) ── */
.t-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--t-surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--t-line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.t-tabbar a, .t-tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 50px; justify-content: center; background: none; border: 0; text-decoration: none; color: var(--t-ink-3); font-size: 11.5px; font-weight: 640; cursor: pointer; border-radius: 12px; }
.t-tabbar svg { width: 22px; height: 22px; }
.t-tabbar [aria-current="page"] { color: var(--t-ink); }
.t-tabbar [aria-current="page"] svg { color: var(--t-ink); }
.t-tabbar [aria-current="page"]::after { content: ''; width: 18px; height: 3px; border-radius: 2px; background: var(--t-tape); }
@media (min-width: 900px) { .t-tabbar { position: sticky; top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--t-line); grid-auto-columns: max-content; justify-content: center; gap: 8px; } .t-tabbar a, .t-tabbar button { flex-direction: row; padding: 0 14px; font-size: 14px; } .t-tabbar [aria-current="page"]::after { display: none; } .t-tabbar [aria-current="page"] { background: var(--t-raised); } }

/* ── toast ── */
.t-toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; max-width: calc(100vw - 24px); background: var(--t-ink); color: var(--t-chalk); padding: 12px 14px; border-radius: 16px; box-shadow: var(--t-shadow); animation: t-rise .25s var(--t-ease); }
.t-toast .t-btn { min-height: 36px; padding: 0 14px; font-size: 14px; background: var(--t-chalk); color: var(--t-ink); }
@keyframes t-rise { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ── tables (console) ── */
.t-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.t-table th { text-align: left; font: 600 11px var(--t-mono); text-transform: uppercase; letter-spacing: .05em; color: var(--t-ink-2); padding: 10px 8px; border-bottom: 1px solid var(--t-line-2); white-space: nowrap; }
.t-table td { padding: 12px 8px; border-bottom: 1px solid var(--t-line); vertical-align: top; }
.t-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--t-gutter)); padding: 0 var(--t-gutter); }

/* ── states ── */
.t-empty { text-align: center; padding: 32px 16px; color: var(--t-ink-2); }
.t-error { color: var(--t-off); font-size: 14px; font-weight: 560; }
.t-skel { background: linear-gradient(90deg, var(--t-raised), var(--t-line), var(--t-raised)); background-size: 200% 100%; animation: t-shimmer 1.2s infinite; border-radius: 8px; min-height: 16px; }
@keyframes t-shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .t *, .t *::before, .t *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
