:root {
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #0a0a0a;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: rgba(10, 10, 10, 0.08);
  --grid: rgba(10, 10, 10, 0.07);
  --track: #f4f4f5;
  --dim: #d4d4d8;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --accent-ink: #4338ca;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
}

.rev {
  position: relative;
  width: min(480px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(14px, 3.6vh, 22px) clamp(14px, 4.4vw, 22px) clamp(12px, 2.8vh, 18px);
  box-shadow:
    0 1px 2px rgba(10, 10, 10, 0.04),
    0 10px 28px -14px rgba(10, 10, 10, 0.14),
    0 34px 70px -40px rgba(10, 10, 10, 0.16);
}

.rev__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rev__title { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 520; color: var(--muted); }
.rev__icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }

.seg {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--track);
}
.seg__pill {
  position: absolute;
  top: 3px; left: 0;
  height: calc(100% - 6px);
  width: 40px;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(10, 10, 10, 0.08), 0 0 0 1px rgba(10, 10, 10, 0.04);
}
.seg__btn {
  position: relative;
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.2s ease;
}
.seg__btn[aria-selected="true"] { color: var(--ink); }
.seg__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.rev__fig { display: flex; align-items: center; gap: 10px; margin-top: clamp(10px, 2.6vh, 16px); }

.num {
  display: flex;
  font-size: clamp(28px, min(9vw, 7.4vh), 40px);
  font-weight: 620;
  font-variation-settings: 'wdth' 100;
  letter-spacing: -0.025em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.num__slot { position: relative; display: inline-block; height: 1.08em; overflow: hidden; }
.num__col { display: flex; flex-direction: column; will-change: transform; }
.num__col > span, .num__ch { display: block; height: 1.08em; line-height: 1.08em; }
.num__slot--d { -webkit-mask-image: linear-gradient(transparent 2%, #000 24%, #000 76%, transparent 98%); mask-image: linear-gradient(transparent 2%, #000 24%, #000 76%, transparent 98%); }
.num__ch { color: var(--ink); }
.num__ch--soft { color: var(--faint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  padding: 0 7px 0 5px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  background: var(--accent-soft);
  white-space: nowrap;
  transition: color 0.25s ease, background-color 0.25s ease;
}
.badge.is-neg { color: #52525b; background: var(--track); }
.badge__arrow { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.rev__subrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; margin-top: 5px; }
.rev__sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clear {
  display: inline-flex; align-items: center; gap: 4px;
  appearance: none; border: 1px solid var(--line); background: #fff;
  font: inherit; font-size: 11.5px; font-weight: 560; color: var(--muted);
  height: 22px; padding: 0 8px 0 6px; border-radius: 999px; cursor: pointer;
  opacity: 0; visibility: hidden; flex: none;
}
.clear svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (hover: hover) { .clear:hover { color: var(--ink); border-color: rgba(10, 10, 10, 0.16); } }

.plot {
  position: relative;
  height: clamp(104px, 30vh, 176px);
  margin-top: clamp(10px, 2.4vh, 16px);
  cursor: crosshair;
  touch-action: pan-y;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}
.plot:focus-visible { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); border-radius: 8px; }
.plot__svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.plot__grid { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 2 4; }
.plot__base { stroke: var(--line); stroke-width: 1; }
.plot__line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot__line--dim { stroke: var(--dim); }
.plot__area { fill: url(#rev-fill); }
.plot__area--dim { fill: url(#rev-fill-dim); }
.plot__band { fill: var(--accent-soft); opacity: 0; }

.handle { opacity: 0; }
.handle__bar { stroke: var(--accent); stroke-width: 1; }
.handle__grip { fill: #fff; stroke: var(--accent); stroke-width: 1.2; filter: drop-shadow(0 1px 1.5px rgba(10, 10, 10, 0.16)); }

.cursor { opacity: 0; pointer-events: none; }
.cursor__line { stroke: rgba(10, 10, 10, 0.18); stroke-width: 1; stroke-dasharray: 3 3; }
.cursor__halo { fill: var(--accent); opacity: 0.14; }
.cursor__dot { fill: #fff; stroke: var(--accent); stroke-width: 2; }

.tip {
  position: absolute;
  top: 0; left: 0;
  display: flex; gap: 6px; align-items: baseline;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 6px 16px -6px rgba(10, 10, 10, 0.4);
}
.tip__val { font-weight: 640; }

.axis { position: relative; height: 16px; margin-top: 8px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.axis span { position: absolute; top: 0; white-space: nowrap; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.fake {
  position: absolute;
  top: 0; left: 0;
  width: 18px; height: 22px;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 1.3;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(10, 10, 10, 0.25));
  transform-origin: 3px 2px;
}

@media (max-width: 380px) {
  .seg__btn { padding: 5px 8px; }
}
