/* ============================================================================
   SORBET — Components
   Layer 2 of 2. Requires tokens.css.

   Every rule below reads from tokens only. No literal colour, radius or
   duration appears in this file — that is the contract that makes the
   system retonable and theme-able.
   ========================================================================== */

/* ── Reset the parts that matter ─────────────────────────────────────────── */
.sb *,
.sb *::before,
.sb *::after { box-sizing: border-box; }

.sb {
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--fg-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.sb :focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

@media (prefers-reduced-motion: reduce) {
  .sb *,
  .sb *::before,
  .sb *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Typography ──────────────────────────────────────────────────────────
   Heavy + tight for display, normal + open for body. The serif italic is
   an accent for exactly one word in a heading — never a whole line. */
.t-hero,
.t-display,
.t-title {
  font-family: var(--font-display);
  font-weight: var(--weight-heavy);
  text-wrap: balance;
  margin: 0;
}
.t-hero    { font-size: var(--text-hero);    line-height: var(--leading-hero);    letter-spacing: var(--track-hero); }
.t-display { font-size: var(--text-display); line-height: var(--leading-display); letter-spacing: var(--track-display); }
.t-title   { font-size: var(--text-title);   line-height: var(--leading-title);   letter-spacing: var(--track-title); }

.t-heading {
  font-family: var(--font-display);
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  letter-spacing: var(--track-heading);
  font-weight: var(--weight-bold);
  margin: 0;
}
.t-subhead {
  font-size: var(--text-subhead);
  line-height: var(--leading-subhead);
  letter-spacing: var(--track-subhead);
  font-weight: var(--weight-medium);
  margin: 0;
}
.t-body  { font-size: var(--text-body);  line-height: var(--leading-body);  margin: 0; }
.t-small { font-size: var(--text-small); line-height: var(--leading-small); margin: 0; }

.t-label {
  font-size: var(--text-label);
  line-height: var(--leading-label);
  letter-spacing: var(--track-label);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  margin: 0;
}

/* The one editorial move in the system. */
.t-accent {
  font-family: var(--font-accent);
  font-style: italic;
  font-weight: var(--weight-regular);
  letter-spacing: 0;
}

.t-muted     { color: var(--fg-secondary); }
.t-faint     { color: var(--fg-muted); }
.t-numeric   { font-variant-numeric: tabular-nums; }
.t-critical  { color: var(--critical); }
.t-positive  { color: var(--positive); }

/* ── Button ──────────────────────────────────────────────────────────────
   One shape: the pill. Variants differ only in ground. Height is locked to
   the touch target so buttons never fall below 44px. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--target-min);
  padding-inline: var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-bold);
  letter-spacing: -0.005em;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition:
    transform var(--duration-fast) var(--ease-standard),
    background-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
.btn:active { transform: scale(0.965); }
.btn[disabled],
.btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

.btn--solid  { background: var(--action-solid); color: var(--action-solid-fg); }
.btn--accent { background: var(--accent); color: var(--accent-fg); }
.btn--tone   { background: var(--tone-500); color: var(--fg-on-tone); }
.btn--quiet  { background: var(--bg-surface); color: var(--fg-primary); box-shadow: var(--shadow-1); }
.btn--ghost  { background: transparent; color: var(--fg-primary); box-shadow: inset 0 0 0 1.5px var(--border-strong); }

.btn--sm { min-height: 36px; padding-inline: var(--space-4); font-size: var(--text-small); }
.btn--lg { min-height: 54px; padding-inline: var(--space-6); font-size: var(--text-subhead); }
.btn--block { display: flex; width: 100%; }

/* Circular icon button — the satellite that orbits a primary pill. */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--target-min);
  height: var(--target-min);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--fg-primary);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-standard),
              background-color var(--duration-fast) var(--ease-standard);
}
.btn-icon:active { transform: scale(0.92); }
.btn-icon--tone  { background: var(--tone-300); }
.btn-icon--solid { background: var(--action-solid); color: var(--action-solid-fg); }

/* ── Card ────────────────────────────────────────────────────────────────
   .card is white paper. .card--tone is a flat pastel field — no shadow,
   because a coloured field is already a layer. */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
}
.card--flat { box-shadow: none; border: 1px solid var(--border-subtle); }
.card--tone {
  background: var(--tone-100);
  color: var(--fg-primary);
  box-shadow: none;
}
.card--tone-solid {
  background: var(--tone-500);
  color: var(--fg-on-tone);
  box-shadow: none;
}
.card--lifted { box-shadow: var(--shadow-2); }

/* Squircle tile — the mood/status square. Aspect-locked so a row of them
   stays a grid no matter how long the labels get. */
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  aspect-ratio: 1 / 1;
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--tone-500);
  color: var(--fg-on-tone);
  text-align: center;
}
.tile__caption {
  font-size: var(--text-small);
  font-weight: var(--weight-medium);
  opacity: 0.75;
}
.tile__value {
  font-family: var(--font-accent);
  font-size: var(--text-heading);
  line-height: 1;
}
.tile__glyph { display: block; }

/* ── Assistant card ──────────────────────────────────────────────────────
   Reserved for machine-authored messages. The oversized glyph bleeding off
   the bottom-right corner is the tell — nothing else in the system does it,
   so users learn to read it as "this came from the assistant". */
.assistant {
  position: relative;
  overflow: hidden;
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--tone-300);
  color: var(--fg-primary);
}
.assistant__from {
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  opacity: 0.6;
}
.assistant__body {
  margin-block: var(--space-2) var(--space-4);
  font-size: var(--text-subhead);
  line-height: 1.35;
  font-weight: var(--weight-medium);
  max-width: 34ch;
  position: relative;
  z-index: 1;
}
.assistant__mark {
  position: absolute;
  right: calc(var(--space-4) * -1);
  bottom: calc(var(--space-6) * -1);
  width: 128px;
  height: 128px;
  color: var(--tone-500);
  pointer-events: none;
}
.assistant .btn { position: relative; z-index: 1; }

/* ── Score ring ──────────────────────────────────────────────────────────
   A segmented arc, one segment per tracked system. The number is the whole
   point, so it gets the hero step and everything else stays out of its way. */
.ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  margin-inline: auto;
}
.ring__svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ring__seg { fill: none; stroke-width: 17; stroke-linecap: round; }
.ring__center { display: grid; justify-items: center; gap: var(--space-1); text-align: center; }
.ring__value {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--track-hero);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ring__caption { font-size: var(--text-small); color: var(--fg-secondary); }

/* ── Meter ───────────────────────────────────────────────────────────────
   Track is a wash of the same tone as the fill, so a row of meters in
   different tones still reads as one family. */
.meter {
  height: 12px;
  border-radius: var(--radius-pill);
  background: var(--tone-100);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--tone-500);
  transition: width var(--duration-slow) var(--ease-standard);
}
.meter--thin { height: 6px; }

/* Data row: glyph · label · meter · value. The value is right-aligned and
   tabular so a stack of rows forms a readable column of numbers. */
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  padding-block: var(--space-3);
}
.row__glyph {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--tone-300);
}
.row__label { font-weight: var(--weight-medium); }
.row__meter { grid-column: 2; }
.row__value { font-variant-numeric: tabular-nums; font-weight: var(--weight-bold); text-align: right; }
.row__value small { font-weight: var(--weight-regular); color: var(--fg-muted); }
.row + .row { border-top: 1px solid var(--border-subtle); }

/* ── Tabs ────────────────────────────────────────────────────────────────
   Underline tabs for switching *view*; chips for filtering *content*.
   Using the wrong one is the most common misuse of this system. */
.tabs {
  display: flex;
  gap: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  border: 0;
  background: none;
  color: var(--fg-muted);
  font-family: var(--font-display);
  font-size: var(--text-heading);
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-heading);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
  transition: color var(--duration-fast) var(--ease-standard);
}
.tab[aria-selected="true"] { color: var(--fg-primary); border-bottom-color: var(--fg-primary); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 34px;
  padding-inline: var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--fg-secondary);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--action-solid); color: var(--action-solid-fg); }
.chip--tone { background: var(--tone-300); color: var(--fg-primary); }

/* Count badge. Uses --critical only — never a pastel; a pastel badge reads
   as decoration and stops being noticed. */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  border-radius: var(--radius-pill);
  background: var(--critical);
  color: var(--paper);
  font-size: var(--text-label);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

/* ── Chat ────────────────────────────────────────────────────────────────── */
.bubble {
  max-width: 76%;
  width: fit-content;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-small);
  line-height: 1.45;
}
.bubble--them {
  background: var(--tone-100);
  border-end-start-radius: var(--radius-xs);
}
.bubble--me {
  margin-inline-start: auto;
  background: var(--bg-surface);
  box-shadow: var(--shadow-1);
  border-end-end-radius: var(--radius-xs);
}
.bubble--typing { color: var(--fg-muted); }

/* ── Field ───────────────────────────────────────────────────────────────
   Input and its action share one pill. The action never sits outside the
   field — that separation is what makes forms feel like paperwork. */
.field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  box-shadow: var(--shadow-1);
}
.field__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--fg-primary);
  font: inherit;
  font-size: var(--text-body);
}
.field__input::placeholder { color: var(--fg-muted); }
.field__input:focus { outline: none; }
.field:focus-within { box-shadow: var(--shadow-1), 0 0 0 2px var(--focus-ring); }

/* ── Tab bar + FAB ───────────────────────────────────────────────────────
   The bar floats clear of the screen edge; the FAB is the only element in
   the system allowed to break a container's bounds. */
.tabbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--bg-inverse);
  color: var(--fg-on-inverse);
  box-shadow: var(--shadow-2);
}
.tabbar__item {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--target-min);
  height: var(--target-min);
  border: 0;
  background: none;
  color: currentColor;
  opacity: 0.55;
  cursor: pointer;
  border-radius: var(--radius-pill);
  transition: opacity var(--duration-fast) var(--ease-standard);
}
.tabbar__item[aria-current="page"] { opacity: 1; }
.tabbar__item[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  translate: -50% 0;
  width: 16px;
  height: 2px;
  border-radius: var(--radius-pill);
  background: currentColor;
}
.fab {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform var(--duration-base) var(--ease-spring);
}
.fab:active { transform: scale(0.9); }

/* ── Deck ────────────────────────────────────────────────────────────────
   Stacked topic cards. Peeked headers give the pile a legible index; the
   top card is the only one that shows its body. */
.deck { display: flex; flex-direction: column; }
.deck__card {
  position: relative;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--tone-500);
  color: var(--fg-on-tone);
  box-shadow: 0 -2px 7px rgb(35 27 15 / 0.09);
}
/* Later cards paint over earlier ones, so source order is stack order. */
.deck__card + .deck__card { margin-top: -14px; }
.deck__title {
  font-family: var(--font-accent);
  font-size: var(--text-subhead);
  font-style: italic;
}

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--tone-300);
  color: var(--fg-primary);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  overflow: hidden;
  flex: none;
}
.avatar--lg { width: 48px; height: 48px; font-size: var(--text-subhead); }

/* ── Stat ─────────────────────────────────────────────────────────────────
   Number-first block for a single figure. Label sits under the value, never
   over it — the eye should land on the digit. */
.stat { display: grid; gap: var(--space-1); }
.stat__value {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--track-title);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat__label {
  font-size: var(--text-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  color: var(--fg-secondary);
}

/* ── Screen scaffold ─────────────────────────────────────────────────────── */
.screen {
  display: flex;
  flex-direction: column;
  background: var(--bg-canvas);
  color: var(--fg-primary);
}
.screen__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-inline: var(--gutter);
}
.screen__foot {
  padding: var(--space-3) var(--gutter) var(--space-4);
}
.stack   { display: grid; gap: var(--space-4); }
.stack-2 { display: grid; gap: var(--space-2); }
.stack-6 { display: grid; gap: var(--space-6); }
.cluster { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.spread  { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
