:root {
  --bg: #0b0d12; --panel: #141821; --panel2: #1a1f2b; --line: #262d3a;
  --ink: #e7ecf4; --ink2: #b9c4d6; --muted: #8794a8; --faint: #5b6779;
  --accent: #7fb4ff;

  /* status ramp — mirrors engine/scale.py STATES, never used without a label */
  --calm: #35c69f;
  --drifting: #9ac93f;
  --approaching: #e8b12e;
  --at-the-line: #f5842b;
  --past-the-line: #f04b48;
  --breaking: #ff3d6e;
}

* { box-sizing: border-box; }
/* Mobile Safari counts any bleed — an SVG dot drawn on the edge, an absolutely
   positioned tooltip — into the document width and lets the page pan sideways.
   Nothing here is ever wider than the viewport, so clamp it at the root. */
html, body { margin: 0; padding: 0; width: 100%; max-width: 100%; overflow-x: hidden; }
img, svg, canvas, video { max-width: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 24px;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 480px; margin: 0 auto; padding: 16px 14px 24px; overflow-x: clip; }
@media (min-width: 900px) { .wrap { max-width: 940px; } }

.topBar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.langSeg { margin-bottom: 20px; }
.langSeg button { font-size: 13px; }

a.back {
  display: inline-flex; align-items: center; gap: 8px; color: var(--ink);
  text-decoration: none; font-size: 15px; font-weight: 600; margin-bottom: 20px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); transition: border-color .15s ease, transform .05s ease;
}
a.back:hover { border-color: var(--accent); transform: translateX(-2px); }

.appHeader h1 { margin: 0 0 4px; font-size: 27px; letter-spacing: -.02em; }
.appHeader p { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; max-width: 62ch; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; margin-bottom: 12px;
}
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- hero dial */
.hero { display: grid; gap: 18px; }
@media (min-width: 720px) { .hero { grid-template-columns: 260px 1fr; align-items: center; } }

.dialBox { display: flex; flex-direction: column; align-items: center; }
.dial { width: 100%; max-width: 260px; height: auto; display: block; }
.dialScore {
  margin-top: -34px; text-align: center; line-height: 1;
}
.dialScore .n { font-size: 46px; font-weight: 700; letter-spacing: -.03em; }
.dialScore .d { font-size: 14px; color: var(--muted); }
.dialState {
  margin-top: 10px; display: inline-flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; letter-spacing: .01em;
}
.dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }

.heroText h2 { margin: 0 0 8px; font-size: 15px; color: var(--ink2); font-weight: 600; }
.verdict { margin: 0 0 14px; font-size: 14px; color: var(--ink2); }
.stamp { font-size: 12px; color: var(--faint); }
.stamp a { color: var(--faint); }

/* ------------------------------------------------------------- tier meters */
.tiers { display: grid; gap: 10px; margin-top: 4px; }
.tierRow { display: grid; grid-template-columns: 1fr; gap: 4px; }
.tierHead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tierName { font-size: 13px; font-weight: 600; }
.tierName .w { color: var(--faint); font-weight: 400; font-size: 11.5px; margin-left: 6px; }
.tierVal { font-size: 13px; font-weight: 700; }
.meter { height: 8px; border-radius: 4px; background: var(--panel2); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; }
.tierBlurb { font-size: 12px; color: var(--faint); }

/* --------------------------------------------------------- signatures */
.sectionHead { margin-bottom: 12px; }
.sectionHead h2 { margin: 0; font-size: 15px; }
.sectionHead p { margin: 3px 0 0; font-size: 12.5px; color: var(--faint); max-width: 70ch; }

.sigs { display: grid; gap: 10px; }
@media (min-width: 860px) { .sigs { grid-template-columns: repeat(3, 1fr); } }
.sig { border: 1px solid var(--line); border-radius: 11px; padding: 12px; background: var(--panel2); }
.sig.armed { border-color: var(--past-the-line); background: #1e1418; }
.sigTop { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sigName { font-size: 13.5px; font-weight: 700; }
.sigQuestion {
  font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint); font-weight: 700; margin-top: 2px;
}
.sigCount {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--faint); white-space: nowrap;
}
.sig.armed .sigCount { color: var(--past-the-line); }
.sigMeaning { margin: 6px 0 9px; font-size: 12.5px; color: var(--muted); }
.sigCond { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; padding: 2px 0; }
.sigCond .mark { font-size: 11px; font-weight: 700; width: 13px; flex: none; color: var(--faint); }
.sigCond.met .mark { color: var(--past-the-line); }
.sigCond .txt { color: var(--muted); }
.sigCond.met .txt { color: var(--ink2); }
.sigCond .det { margin-left: auto; color: var(--ink2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------- crisis distance */
.dists { display: grid; gap: 10px; }
@media (min-width: 720px) { .dists { grid-template-columns: repeat(3, 1fr); } }
.dist { border: 1px solid var(--line); border-radius: 11px; padding: 12px; background: var(--panel2); }
.dist .era { font-size: 12.5px; font-weight: 700; }
.dist .gap { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; }
.dist .sub { font-size: 11.5px; color: var(--faint); }
.dist .worse { margin-top: 8px; font-size: 11.5px; color: var(--ink2); }
.dist .worse b { color: var(--past-the-line); font-weight: 600; display: block; margin-bottom: 2px; }

/* ------------------------------------------------------------------ legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; }

/* ------------------------------------------------------------------ toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 22px 0 12px;
}
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; padding: 5px 13px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--panel2); color: var(--ink); font-weight: 600; }
.toolbar .spacer { flex: 1; }
.ghost {
  appearance: none; background: transparent; border: 1px solid var(--line);
  color: var(--muted); font: inherit; font-size: 13px; padding: 6px 13px;
  border-radius: 999px; cursor: pointer;
}
.ghost:hover { border-color: var(--accent); color: var(--ink); }

/* ------------------------------------------------------------- indicators */
.groupHead { margin: 22px 0 10px; }
.groupHead h2 { margin: 0; font-size: 15px; letter-spacing: .01em; }
.groupHead p { margin: 3px 0 0; font-size: 12.5px; color: var(--faint); max-width: 66ch; }

.grid { display: grid; gap: 12px; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; } }

.ind { display: flex; flex-direction: column; gap: 11px; }
.indTop { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.indName { font-size: 14px; font-weight: 600; line-height: 1.3; }
.indSub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.derivedTag {
  display: inline-block; margin-top: 5px; font-size: 10.5px; letter-spacing: .03em;
  color: var(--accent); border: 1px solid #2b3a52; background: #111826;
  border-radius: 5px; padding: 1px 6px; font-variant-numeric: tabular-nums;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 11.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap;
}
.pill .lbl { color: var(--ink); }

.indValue { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.indValue .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.indValue .u { font-size: 15px; color: var(--muted); font-weight: 600; }
.indValue .t { font-size: 12px; color: var(--muted); }

/* threshold bar: where this reading sits between calm and crisis */
.track { position: relative; height: 34px; }
.track svg { display: block; width: 100%; height: 34px; }
.trackLabels { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 2px; }
.trackLabels .danger { color: var(--ink2); font-weight: 600; }

.sparkBox { position: relative; }
.sparkBox svg { display: block; width: 100%; height: 46px; }
.sparkCap { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); }
.tip {
  position: absolute; pointer-events: none; opacity: 0; transform: translate(-50%, -100%);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 8px; font-size: 11.5px; white-space: nowrap; color: var(--ink);
  max-width: 100%;
  transition: opacity .1s ease; z-index: 5;
}
.tip.on { opacity: 1; }

.crash { border-top: 1px solid var(--line); padding-top: 9px; }
.crashRow { display: flex; gap: 6px; }
.crashCell { flex: 1; min-width: 0; }
.crashCell .k { font-size: 10.5px; color: var(--faint); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crashCell .v { font-size: 13px; font-weight: 600; color: var(--ink2); }
.crashCell .v.na { color: var(--faint); font-weight: 400; }
.crashNote { font-size: 11px; color: var(--faint); margin-top: 6px; }

details.why { border-top: 1px solid var(--line); padding-top: 8px; }
details.why summary {
  cursor: pointer; font-size: 12.5px; color: var(--muted); list-style: none;
  display: flex; align-items: center; gap: 6px;
}
details.why summary::-webkit-details-marker { display: none; }
details.why summary::after { content: "+"; color: var(--faint); }
details.why[open] summary::after { content: "–"; }
details.why p { margin: 8px 0 0; font-size: 13px; color: var(--ink2); }
details.why .src { margin-top: 8px; font-size: 11.5px; }
details.why .src a { color: var(--accent); }

/* ----------------------------------------------------------------- sectors */
.sectorGrid { display: grid; gap: 10px; }
@media (min-width: 620px) { .sectorGrid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .sectorGrid { grid-template-columns: 1fr 1fr 1fr 1fr; } }
.sector { border: 1px solid var(--line); border-radius: 11px; padding: 12px; background: var(--panel2); }
.sectorName {
  font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); font-weight: 700;
}
.sector .metric { font-size: 12.5px; color: var(--ink2); margin-top: 3px; line-height: 1.3; }
.sectorVal { display: flex; align-items: baseline; gap: 6px; margin: 8px 0 2px; }
.sectorVal .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.sectorVal .u { font-size: 12px; color: var(--muted); font-weight: 600; }
.sector .track, .sector .track svg { height: 22px; }
.sectorFoot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--faint); }
.sectorState { font-weight: 700; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.sectorState i { width: 8px; height: 8px; border-radius: 2px; }
.sector details.why { margin-top: 8px; }

/* ------------------------------------------------------------------- table */
.tableWrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 620px; }
th, td { text-align: right; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--panel2); }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }

/* -------------------------------------------------------------------- misc */
.notice { font-size: 12.5px; color: var(--faint); margin-top: 16px; }
.notice a { color: var(--accent); }
.disclaimer {
  margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; max-width: 72ch;
}
.disclaimer strong { color: var(--ink2); }
footer { color: var(--muted); font-size: 12.5px; text-align: center; margin-top: 30px; }
footer a { color: var(--muted); }

.skeleton { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }

/* Very narrow phones: let the three-up rows stack rather than squeeze. */
@media (max-width: 400px) {
  .trackLabels { flex-wrap: wrap; gap: 2px 10px; }
  .trackLabels .danger { order: -1; width: 100%; }
  .crashRow { flex-wrap: wrap; }
  .crashCell { flex: 1 1 45%; }
  .indValue .v { font-size: 25px; }
}
