/* IGWATCH Mini App — dark theme.
 *
 * One committed visual world instead of following the Telegram theme: a deep
 * violet-black ground with a violet-to-pink accent spent sparingly (figures,
 * the active tab, avatars). Colour lives in tokens only — no literal anywhere
 * below the token block.
 *
 * Layers, darkest to lightest: page -> card -> raised -> pressed. Nothing on a
 * dark ground needs a drop shadow to separate; a hairline and one step of
 * lightness do it better and never smear on an OLED panel.
 */

:root {
  color-scheme: dark;
  accent-color: var(--accent);

  /* -- tier 1: literals ------------------------------------------------- */
  --ink-page: #0d0b12;
  --ink-card: #16131d;
  --ink-raised: #1e1a28;
  --ink-pressed: #241f30;
  --ink-track: #221d2d;

  --violet: #9b6bf3;
  --violet-soft: #c4a6ff;
  --pink: #e9559c;
  --pink-soft: #ffa6cd;

  --white-96: #f4f1f8;
  --pure-white: #ffffff;
  --white-72: #b3aac4;
  --white-56: #8a82a0;

  --green: #4ade9a;
  --amber: #f5b942;
  --red: #ff6b6b;

  /* -- tier 2: semantic -------------------------------------------------- */
  --page: var(--ink-page);
  --card: var(--ink-card);
  --card-press: var(--ink-pressed);
  --raised: var(--ink-raised);

  --text: var(--white-96);
  --text-2: var(--white-72);
  --text-3: var(--white-56);

  --accent: var(--violet);
  --accent-text: var(--violet-soft);
  --accent-grad: linear-gradient(135deg, var(--violet) 0%, var(--pink) 100%);
  --accent-wash: rgba(155, 107, 243, 0.14);
  --accent-wash-strong: rgba(155, 107, 243, 0.22);
  --on-accent: var(--pure-white);

  --ok: var(--green);
  --warn: var(--amber);
  --danger: var(--red);

  /* Violet-tinted rules read as part of the world; neutral grey reads as dirt. */
  --hairline: rgba(196, 166, 255, 0.10);
  --separator: rgba(196, 166, 255, 0.14);
  --border-strong: rgba(196, 166, 255, 0.22);

  --skeleton: rgba(196, 166, 255, 0.09);
  --skeleton-hi: rgba(196, 166, 255, 0.04);

  /* -- tier 3: shape, space, motion -------------------------------------- */
  --radius-card: 18px;
  --radius-ctl: 12px;
  --radius-pill: 999px;
  --gap: 12px;
  --pad: 16px;

  /* Strong ease-out: the user watches the first frames, so move immediately. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --dur-press: 140ms;
  --dur-ctl: 200ms;
  --dur-view: 240ms;

  --hdr-h: 108px;
  /* Telegram Desktop opens the app in a wide panel; content that stretches to
     1500px reads as a broken page, not a phone app. */
  --content-max: 620px;

  font: 100%/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    system-ui, sans-serif;
}

/* Gradient interpolation space, only where the browser understands it. */
:root {
  --in-oklab: ;
}
@supports (background: linear-gradient(in oklab, red, blue)) {
  :root {
    --in-oklab: in oklab;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* Every container here sets its own display, which beats the UA rule for the
   `hidden` attribute — without this the skeleton never leaves the screen. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

h1,
h2,
h3,
p,
figure {
  margin: 0;
}

button,
input {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--card);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-ctl);
  z-index: 50;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* Figures are compared down a column, so they must not dance. */
/* Backstop for the class of bug above: an unsized inline SVG can never be
   taller than the text it sits in. */
svg {
  max-height: 1.6em;
}
.icon-btn svg,
.search-clear svg,
.avatar svg,
.avatar-lg svg {
  max-height: none;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ------------------------------------------------------------------ header */

/* A translucent layer with content scrolling under it, not an opaque strip. */
.hdr {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) 0;
  background: color-mix(in srgb, var(--page) 78%, transparent);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
}

/* A scroll edge fade rather than a 1px rule: the boundary appears only where
   floating chrome actually overlaps content. */
.hdr::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 20px;
  pointer-events: none;
  background: linear-gradient(
    to bottom var(--in-oklab),
    color-mix(in srgb, var(--page) 72%, transparent),
    transparent
  );
}

.hdr-inner {
  max-width: var(--content-max);
  margin-inline: auto;
}

/* A gradient hairline under the chrome instead of a grey rule: the accent
   appears once at the top of the screen and never repeats. */
.hdr::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(
    to right var(--in-oklab),
    transparent,
    var(--violet) 22%,
    var(--pink) 62%,
    transparent
  );
  opacity: 0.5;
  pointer-events: none;
}

.hdr-bar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
}

.hdr-id {
  min-width: 0;
  flex: 1;
}

/* Large text: tight leading, negative tracking. */
.hdr-title {
  font-size: 26px;
  transform-origin: left center;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.021em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hdr-sub .warn-dot {
  color: var(--warn);
}

.hdr-sub {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--raised);
  border: 1px solid var(--hairline);
  color: var(--text-2);
  transition:
    transform var(--dur-press) var(--ease-out),
    background-color var(--dur-press) var(--ease-out),
    color var(--dur-press) var(--ease-out);
}
.icon-btn svg {
  width: 19px;
  height: 19px;
}
.icon-btn:active {
  transform: scale(0.94);
  background: var(--card-press);
  color: var(--text);
}
/* aria-busy is what the refresh handler toggles. */
.icon-btn[aria-busy="true"] svg {
  animation: spin 900ms linear infinite;
}

/* A 38px control is under the 44px comfortable touch target; grow the hit area
   without growing the visual. */
.icon-btn {
  position: relative;
}
.icon-btn::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-pill);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* iOS large-title behaviour: the name shrinks into the bar as content scrolls
   under it. Scroll-driven animations run off the main thread; browsers without
   them simply keep the full-size title, which is a fine resting state. */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .hdr-title {
      animation: title-shrink linear both;
      animation-timeline: scroll();
      animation-range: 0 90px;
    }
    .hdr-sub {
      animation: sub-fade linear both;
      animation-timeline: scroll();
      animation-range: 0 70px;
    }
  }
}

@keyframes title-shrink {
  to {
    transform: scale(0.72);
  }
}

@keyframes sub-fade {
  to {
    opacity: 0.55;
  }
}

/* -------------------------------------------------------- segmented control */

.seg {
  position: relative;
  max-width: var(--content-max);
  margin-inline: auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  margin-bottom: 12px;
  background: var(--ink-track);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-ctl);
}

.seg-item {
  position: relative;
  z-index: 1;
  padding: 8px 6px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.006em;
  color: var(--text-3);
  border-radius: 9px;
  transition:
    color var(--dur-ctl) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}
.seg-item[aria-selected="true"] {
  color: var(--text);
}
.seg-item:active {
  transform: scale(0.97);
}

/* The one moving part of the chrome: the thumb slides, the labels do not. */
.seg-thumb {
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 0;
  height: calc(100% - 6px);
  border-radius: 9px;
  background: var(--accent-grad);
  box-shadow: 0 2px 10px rgba(155, 107, 243, 0.35);
  transition:
    transform var(--dur-ctl) var(--ease-out),
    width var(--dur-ctl) var(--ease-out);
  will-change: transform;
}

/* -------------------------------------------------------------------- views */

main {
  padding: 0 var(--pad);
  max-width: calc(var(--content-max) + var(--pad) * 2);
  margin-inline: auto;
}

/* Views enter from the side their tab sits on, matching the thumb's travel —
   the same path in reverse when going back (spatial consistency). */
.view {
  animation: view-in var(--dur-view) var(--ease-out) both;
}
body[data-dir="back"] .view {
  animation-name: view-in-back;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translate3d(14px, 0, 0);
  }
}

@keyframes view-in-back {
  from {
    opacity: 0;
    transform: translate3d(-14px, 0, 0);
  }
}

/* Rows arrive in a short cascade instead of all at once; the delay is set per
   row in JS and capped, so a long list is never held up by motion. */
.row,
.acct,
.kv,
.tl-item {
  animation: row-in 260ms var(--ease-out) both;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translate3d(0, 7px, 0);
  }
}

.stack {
  display: grid;
  gap: var(--gap);
}

/* -------------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: var(--pad);
}

/* Rows inside a flush card reach the card's edges. */
.card-flush {
  padding: var(--pad) 0 4px;
}
.card-flush .card-head,
.card-flush .card-title {
  padding-inline: var(--pad);
}
.card-flush .rows {
  border-radius: 0;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

/* Small uppercase labels want a touch of positive tracking. */
.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}
.card-head .card-title {
  margin-bottom: 0;
}

.link-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-text);
  transition: opacity var(--dur-press) var(--ease-out);
}
.link-btn:active {
  opacity: 0.6;
}
.chev-inline {
  margin-left: 2px;
}

/* ------------------------------------------------------------------ metrics */

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding-block: 18px;
}

.metric {
  animation: row-in 320ms var(--ease-out) both;
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  min-width: 0;
}

/* The single loud moment in the design: the three figures carry the accent. */
.metric-value {
  font-size: clamp(26px, 8.5vw, 34px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.metric:nth-child(2) {
  animation-delay: 60ms;
}
.metric:nth-child(3) {
  animation-delay: 120ms;
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

/* ------------------------------------------------------------- key / value */

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 14px;
  border-top: 1px solid var(--hairline);
}
.kv:first-child {
  border-top: 0;
  padding-top: 0;
}
.kv-k {
  color: var(--text-3);
  flex: none;
}
.kv-v {
  color: var(--text);
  text-align: right;
  min-width: 0;
}
/* A second line under the value; inline it would run straight into the value. */
.kv-v .sub {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-3);
}

.state-ok {
  color: var(--ok);
}
.state-warn {
  color: var(--warn);
}
.state-bad {
  color: var(--danger);
}

.note {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
  background: rgba(245, 185, 66, 0.10);
  border: 1px solid rgba(245, 185, 66, 0.24);
  border-radius: var(--radius-ctl);
}
.note-mark {
  flex: none;
  color: var(--warn);
}

/* ------------------------------------------------------------------- meter */

.budget {
  margin-top: 4px;
}
.budget-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 6px;
}
.meter {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--ink-track);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent-grad);
  transition: width var(--dur-view) var(--ease-out);
}
.meter-fill.hot {
  background: var(--warn);
}
.meter-fill.over {
  background: var(--danger);
}

/* ------------------------------------------------------------------- chips */

.filters {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
}

.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-inline: calc(var(--pad) * -1);
  padding-inline: var(--pad);
  scroll-padding-inline: var(--pad);
}
.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.004em;
  color: var(--text-2);
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  transition:
    transform var(--dur-press) var(--ease-out),
    background-color var(--dur-ctl) var(--ease-out),
    color var(--dur-ctl) var(--ease-out),
    border-color var(--dur-ctl) var(--ease-out);
}
.chip:active {
  transform: scale(0.94);
}
/* A selected chip settles a hair larger — the state is felt, not only seen. */
.chip[aria-selected="true"],
.chip[aria-pressed="true"] {
  transform: scale(1.03);
}
.chip[aria-selected="true"],
.chip[aria-pressed="true"] {
  color: var(--white-96);
  background: var(--accent-wash-strong);
  border-color: var(--border-strong);
}

/* Period filters sit below the primary chips and must not compete with them. */
.chips-quiet {
  gap: 6px;
}
.chip-sm {
  padding: 5px 11px;
  font-size: 12px;
  background: transparent;
}

/* ------------------------------------------------------------------ search */

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 11px;
  width: 17px;
  height: 17px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 10px 38px 10px 35px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-ctl);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--dur-ctl) var(--ease-out);
}
.search-input::placeholder {
  color: var(--text-3);
}
.search-input:focus {
  outline: none;
  border-color: var(--border-strong);
}
.search-input::-webkit-search-cancel-button {
  display: none;
}
.search-clear {
  position: absolute;
  right: 8px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.search-clear svg {
  width: 19px;
  height: 19px;
}

.count-line {
  font-size: 12px;
  color: var(--text-3);
  min-height: 1em;
}

/* -------------------------------------------------------------------- rows */

.rows {
  display: grid;
}
/* An empty list must not leave its border and padding behind. */
.rows:empty {
  display: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 0;
  text-align: left;
  border-top: 1px solid var(--hairline);
  border-radius: 10px;
  transition:
    transform var(--dur-press) var(--ease-out),
    background-color var(--dur-press) var(--ease-out);
  /* Long lists: skip rendering offscreen rows, but reserve their height so the
     scrollbar never jumps. 44px avatar + 20px padding. */
  content-visibility: auto;
  contain-intrinsic-size: auto 64px;
}
.row:first-child {
  border-top: 0;
}
.row:active {
  transform: scale(0.985);
  background: var(--card-press);
}

.avatar,
.avatar-lg {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--accent-wash);
  border: 1px solid var(--border-strong);
  color: var(--accent-text);
  font-weight: 700;
  overflow: hidden;
  object-fit: cover;
}
.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  font-size: 15px;
  letter-spacing: 0.01em;
}
.avatar-lg {
  position: relative;
  width: 62px;
  height: 62px;
  font-size: 22px;
}

/* An active story gets Instagram's own signal: a ring around the avatar. It is
   deliberately static — this sits on screen through every scroll, and a rotating
   gradient there would be noise (and battery) rather than life. */
.avatar.has-story {
  border-color: transparent;
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    var(--accent-grad) border-box;
  border: 2px solid transparent;
}
.avatar.has-story::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  background: var(--accent-grad);
  opacity: 0.18;
  filter: blur(5px);
  z-index: -1;
}

/* The real picture covers the initials once it loads. */
.avatar img,
.avatar-lg img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.row-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}
.row-name > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.006em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Both are <span>s built in JS; an inline box ignores overflow/text-overflow,
   so a long full name would paint straight over the date. */
.row-sub,
.row-meta {
  display: block;
  font-size: 12.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-meta {
  flex: none;
}
.row-chev {
  flex: none;
  color: var(--text-3);
  opacity: 0.7;
}

/* These are inline <svg> elements. An SVG with a viewBox but no width/height
   fills its container and then takes the viewBox aspect ratio for its height —
   a 501px-wide row name became 503px tall. Always size an inline SVG. */
.badge {
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: 5px;
  vertical-align: -2px;
}
.badge-verified {
  color: var(--accent-text);
}
.badge-private {
  color: var(--text-3);
}

/* Event direction is colour plus a glyph, never colour alone. */
/* Appended inside .row-sub ahead of the label text, and also used as a flex
   child on the overview rows — inline-block is the one display that works in
   both places; grid would break the label onto its own line. */
.ev-mark {
  display: inline-block;
  flex: none;
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  vertical-align: -9px;
  margin-right: 7px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 700;
}
.ev-up {
  color: var(--ok);
  background: rgba(74, 222, 154, 0.13);
}
.ev-down {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.13);
}
.ev-info {
  color: var(--accent-text);
  background: var(--accent-wash);
}

.timeline {
  display: grid;
  gap: 2px;
}
.tl-item:first-child {
  border-top: 0;
}
.tl-item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 14px;
  padding: 5px 0;
}
.tl-when {
  flex: none;
  color: var(--text-3);
  font-size: 12.5px;
}

/* ------------------------------------------------------------------ states */

.empty,
.error-box,
.gate {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
  padding: 34px 20px;
}
.view:focus {
  outline: none;
}

/* Separate account blocks inside one card. */
.acct + .acct {
  border-top: 1px solid var(--hairline);
  margin-top: 12px;
  padding-top: 12px;
}

.error-title,
.empty-title,
.gate-title {
  font-size: 16px;
  font-weight: 600;
}
.error-text,
.empty-text,
.gate-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-3);
  max-width: 34ch;
}
.gate {
  min-height: 70vh;
  align-content: center;
}
.gate .btn,
.error-box .btn {
  margin-top: 18px;
}

.gate-card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 26px 20px;
  display: grid;
  gap: 8px;
  justify-items: center;
}

.btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  transition:
    transform var(--dur-press) var(--ease-out),
    opacity var(--dur-press) var(--ease-out);
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  color: var(--on-accent);
  background: var(--accent-grad);
  box-shadow: 0 2px 12px rgba(155, 107, 243, 0.3);
}
.btn-quiet {
  color: var(--text-2);
  background: var(--raised);
  border: 1px solid var(--hairline);
}

.list-end,
.loading-more,
.recent-empty {
  padding: 16px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent-text);
  border-radius: var(--radius-pill);
  animation: spin 700ms linear infinite;
  vertical-align: -2px;
}

.sentinel {
  height: 1px;
}

/* --------------------------------------------------------------- skeletons */

.skel-card {
  display: grid;
  gap: 10px;
}
.skel-line,
.skel-row {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(
    90deg var(--in-oklab),
    var(--skeleton-hi),
    var(--skeleton),
    var(--skeleton-hi)
  );
  background-size: 220% 100%;
  animation: shimmer 1.4s var(--ease-in-out) infinite;
}
/* A skeleton row mirrors the real row: circle, then two lines. */
.skel-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  background: none;
  animation: none;
  height: auto;
}
.skel-row:first-child {
  border-top: 0;
}
.skel-row .avatar {
  background: var(--skeleton);
  border-color: transparent;
}
.skel-row .skel-body,
.skel-body {
  flex: 1;
  display: grid;
  gap: 7px;
  min-width: 0;
}
.skel-line-sm {
  height: 9px;
}
.w40 {
  width: 40%;
}
.w50 {
  width: 50%;
}
.w60 {
  width: 60%;
}
.w70 {
  width: 70%;
}
.w80 {
  width: 80%;
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

/* ------------------------------------------------------------------- sheet */

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 4, 10, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--dur-ctl) var(--ease-out) both;
}

.sheet {
  position: fixed;
  z-index: 31;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px var(--pad) calc(22px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border-strong);
  border-radius: 22px 22px 0 0;
  /* Enters and exits along the same path, so a downward swipe reads as dismissal. */
  animation: sheet-in 300ms var(--ease-out) both;
}

.sheet-grip {
  width: 38px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
.sheet-head {
  display: grid;
  gap: 3px;
  justify-items: center;
  text-align: center;
  margin-bottom: 16px;
}
.sheet-title > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.014em;
}
.sheet-sub {
  font-size: 13px;
  color: var(--text-3);
}
.sheet-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 16px 0 8px;
}
.sheet-body {
  display: grid;
  gap: 2px;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

@keyframes sheet-out {
  to {
    transform: translateY(100%);
  }
}

/* The sheet leaves the way it arrived, so a downward swipe reads as dismissal. */
.sheet.closing {
  animation: sheet-out 200ms var(--ease-out) both;
}
.sheet-scrim.closing {
  animation: fade-out 180ms var(--ease-out) both;
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}

/* ------------------------------------------------------- user preferences */

/* Reduced motion: keep the comprehension-carrying fades, drop the travel. */
@media (prefers-reduced-motion: reduce) {
  .view,
  .sheet,
  .sheet-scrim,
  .row,
  .acct,
  .kv,
  .tl-item,
  .metric {
    animation: fade-in 160ms var(--ease-out) both;
    animation-delay: 0ms !important;
  }
  .chip[aria-selected="true"],
  .chip[aria-pressed="true"] {
    transform: none;
  }
  .seg-thumb,
  .meter-fill {
    transition-duration: 1ms;
  }
  .skel-line,
  .skel-row,
  .spinner,
  .icon-btn[aria-busy="true"] svg {
    animation: none;
  }
  .row:active,
  .btn:active,
  .chip:active,
  .icon-btn:active,
  .seg-item:active {
    transform: none;
  }
}

/* Translucency is a preference, not a requirement: make the chrome solid. */
@media (prefers-reduced-transparency: reduce) {
  .hdr {
    background: var(--page);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .sheet-scrim {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(6, 4, 10, 0.86);
  }
}

@media (prefers-contrast: more) {
  :root {
    --text-2: #cfc8dc;
    --text-3: #a79fbb;
    --hairline: rgba(196, 166, 255, 0.26);
    --separator: rgba(196, 166, 255, 0.32);
  }
  .hdr {
    background: var(--page);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* Forced colours strip backgrounds and shadows; keep meaning on borders. */
@media (forced-colors: active) {
  .card,
  .chip,
  .search-input,
  .icon-btn,
  .gate .btn,
.error-box .btn {
  margin-top: 18px;
}

.gate-card {
    border: 1px solid CanvasText;
  }
  .metric-value {
    background: none;
    color: CanvasText;
    -webkit-text-fill-color: CanvasText;
  }
  .seg-thumb {
    background: Highlight;
  }
  .btn-primary {
    background: Highlight;
    color: HighlightText;
  }
}

/* Hover belongs to real pointers; on touch it fires on tap and lies. */
@media (hover: hover) and (pointer: fine) {
  .row:hover {
    background: var(--raised);
  }
  .chip:hover:not([aria-selected="true"]),
  .icon-btn:hover {
    border-color: var(--border-strong);
    color: var(--text);
  }
  .link-btn:hover {
    opacity: 0.8;
  }
}
