/* X CDN Testbed — instrument-panel aesthetic, light + dark.
   No external fonts on purpose: every request must belong to the CDN test.
   Themes are driven by [data-theme] on <html>, resolved before first paint. */

:root {
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;

  /* ---- light theme (default) ---- */
  --bg: #ECEFF3;
  --surface: #FFFFFF;
  --surface-2: #F2F5F8;
  --text: #18232F;
  --text-dim: #556575;
  --text-faint: #8996A5;
  --border: #E4E9EF;
  --border-strong: #D3DBE3;

  --accent: #E39A2E;
  --accent-strong: #D08820;
  --accent-ink: #3A2909;
  --accent-soft: #FBEFD8;

  --green: #2E8B6E;
  --red: #C4453B;

  --chip-amber-bg: #FBEFD8; --chip-amber-text: #8A5E17;
  --chip-green-bg: #E1F0EA; --chip-green-text: #1F6B54;
  --chip-red-bg: #F8E3E1; --chip-red-text: #A33A31;

  --term-bg: #131C26; --term-text: #D7E1EB;

  --header-bg: #131B24;
  --header-text: #EEF2F6;
  --header-dim: #93A3B4;
  --header-line: rgba(255,255,255,0.11);
  --header-fill: rgba(255,255,255,0.06);
  --header-fill-hi: rgba(255,255,255,0.12);

  --bar-track: #EAEFF4;
  --bar-dl: #33475C;

  --shadow-sm: 0 1px 2px rgba(19,27,38,0.06);
  --shadow-md: 0 2px 10px rgba(19,27,38,0.06), 0 14px 30px rgba(19,27,38,0.05);
  --ring: rgba(227,154,46,0.55);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0D141C;
  --surface: #151E28;
  --surface-2: #1B2634;
  --text: #E7EDF3;
  --text-dim: #97A6B6;
  --text-faint: #6B7B8B;
  --border: #253241;
  --border-strong: #32414F;

  --accent: #F0AE4E;
  --accent-strong: #F6BB63;
  --accent-ink: #231903;
  --accent-soft: rgba(240,174,78,0.14);

  --green: #46B892;
  --red: #E06A60;

  --chip-amber-bg: rgba(240,174,78,0.16); --chip-amber-text: #F1C57F;
  --chip-green-bg: rgba(70,184,146,0.16); --chip-green-text: #74D6B4;
  --chip-red-bg: rgba(224,106,96,0.16); --chip-red-text: #EFA098;

  --term-bg: #0A1017; --term-text: #C8D4DF;

  --header-bg: #0A1017;
  --header-text: #EEF2F6;
  --header-dim: #8A9BAC;
  --header-line: rgba(255,255,255,0.09);
  --header-fill: rgba(255,255,255,0.05);
  --header-fill-hi: rgba(255,255,255,0.10);

  --bar-track: #212E3D;
  --bar-dl: #A6BACE;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-md: 0 2px 12px rgba(0,0,0,0.42), 0 18px 40px rgba(0,0,0,0.34);
  --ring: rgba(240,174,78,0.6);

  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body, .masthead, .panel, .btn, .select, .input, .asset, .tag, .mono-out,
.edge-status, .icon-btn, .seg, .wf-track, .tp-bar, code {
  transition: background-color 0.25s ease, border-color 0.25s ease,
              color 0.25s ease, box-shadow 0.25s ease;
}

/* ============ masthead ============ */
.masthead {
  background: var(--header-bg);
  border-bottom: 2px solid var(--accent);
}
.masthead-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--header-fill);
  border: 1px solid var(--header-line);
  border-radius: 11px;
}
.brand-text h1 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--header-text);
  line-height: 1.1;
}
.brand-text .sub {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 0.71rem;
  color: var(--header-dim);
}

.masthead-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctrl-cluster { display: flex; align-items: center; gap: 8px; }

.edge-status {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--header-text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--header-fill);
  border: 1px solid var(--header-line);
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
}
.edge-status:hover { background: var(--header-fill-hi); }
.edge-status:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--header-dim);
  flex: none;
}
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent); }

/* icon button (theme toggle) */
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--header-fill);
  border: 1px solid var(--header-line);
  border-radius: 10px;
  color: var(--header-text);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: var(--header-fill-hi); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn .ico { width: 18px; height: 18px; display: none; }
:root[data-theme="light"] .icon-btn .ico-moon { display: block; }
:root[data-theme="dark"] .icon-btn .ico-sun { display: block; }

/* segmented language switch with sliding thumb */
.seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--header-fill);
  border: 1px solid var(--header-line);
  border-radius: 999px;
  padding: 4px;
}
.seg-thumb {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease;
}
.seg[data-active="zh"] .seg-thumb { transform: translateX(100%); }
.seg-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: none;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1;
  padding: 6px 15px;
  color: var(--header-dim);
  cursor: pointer;
  border-radius: 999px;
  text-align: center;
  transition: color 0.2s ease;
}
.seg-btn:hover { color: var(--header-text); }
.seg[data-active="en"] .seg-btn[data-lang="en"],
.seg[data-active="zh"] .seg-btn[data-lang="zh"] { color: var(--accent-ink); font-weight: 700; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ============ layout ============ */
main {
  max-width: 1120px;
  margin: 28px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.span-2 { grid-column: 1 / -1; }
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

/* ============ panels ============ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 34px;
}
.panel h2 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--text);
}
.panel h2::before {
  content: "";
  width: 3px; height: 15px;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}
.panel-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.hint { color: var(--text-dim); font-size: 0.85rem; line-height: 1.6; margin: 10px 0 14px; }
.hint em { font-style: italic; color: var(--text); }
code {
  font-family: var(--mono);
  font-size: 0.8em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--text);
}
.tag {
  font-family: var(--mono);
  font-size: 0.71rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
}
.empty { color: var(--text-faint); font-size: 0.85rem; }

/* ============ controls ============ */
.btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 16px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
/* in-flight transfer: the Measure button turns into Cancel */
.btn.primary.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary.danger:hover { background: var(--red); filter: brightness(1.1); }
.btn[disabled] { opacity: 0.55; cursor: wait; transform: none; }
.btn:focus-visible, .input:focus-visible, .select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toggle {
  font-size: 0.82rem;
  color: var(--text-dim);
  display: inline-flex;
  gap: 7px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); }
.select, .input {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.82rem;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 8px 11px;
  background: var(--surface-2);
  color: var(--text);
}
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; min-width: 0; }

/* ============ waterfall ============ */
.waterfall { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.wf-row {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.75rem;
}
@media (max-width: 640px) {
  .wf-row { grid-template-columns: 1fr; gap: 3px; }
}
.wf-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.wf-name .badge {
  display: inline-block;
  font-size: 0.62rem;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 7px;
  background: var(--chip-amber-bg);
  color: var(--chip-amber-text);
}
.wf-name .badge.mem { background: var(--chip-green-bg); color: var(--chip-green-text); }
.wf-track {
  position: relative;
  height: 16px;
  background: var(--bar-track);
  border-radius: 5px;
  overflow: hidden;
}
.wf-ttfb, .wf-dl {
  position: absolute;
  top: 0; bottom: 0;
  min-width: 1px;
  transition: width 0.4s ease, left 0.4s ease;
}
.wf-ttfb { background: var(--accent); }
.wf-dl { background: var(--bar-dl); }
.wf-figs { text-align: right; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.wf-figs strong { color: var(--text); }

/* ============ throughput ============ */
.tp-readout { margin: 12px 0 4px; }
.tp-figure { font-family: var(--mono); display: flex; align-items: baseline; gap: 8px; }
#tp-value {
  font-size: 2.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.tp-unit { color: var(--text-dim); font-size: 0.85rem; }
.tp-meta { font-family: var(--mono); font-size: 0.75rem; color: var(--text-dim); margin: 4px 0 10px; min-height: 1em; }
.tp-bar { height: 8px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.tp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.15s linear;
}

/* ============ cache checks ============ */
.checks {
  list-style: none;
  padding: 0;
  margin: 4px 0 10px;
  font-family: var(--mono);
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.checks li { padding: 6px 0 6px 24px; position: relative; color: var(--text); line-height: 1.5; }
.checks li::before {
  content: "";
  position: absolute;
  left: 0; top: 0.72em;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
}
.checks li.pass::before { background: var(--green); }
.checks li.fail::before { background: var(--red); }
.checks li.pass { color: var(--green); }
.checks li.fail { color: var(--red); }
.checks li.pending { color: var(--text-dim); }

/* ============ mono output (terminal) ============ */
.mono-out {
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.6;
  background: var(--term-bg);
  color: var(--term-text);
  border-radius: 10px;
  padding: 13px 15px;
  margin: 10px 0 0;
  min-height: 20px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.mono-out:empty { display: none; }
.mono-out .hl { color: var(--accent); }

/* ============ stress test ============ */
.stress-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 4px 0 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 0.76rem; color: var(--text-dim); }
.field .input { width: 100%; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.stat-v {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-k { font-size: 0.68rem; color: var(--text-dim); }

.status-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--mono);
  font-size: 0.73rem;
}
.status-list li {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.status-list .code { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-list .track { height: 12px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.status-list .fill { display: block; height: 100%; background: var(--text-dim); transition: width 0.2s ease; }
.status-list .n { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.status-list li.ok .fill { background: var(--green); }
.status-list li.ok .code { color: var(--green); }
.status-list li.limited .fill { background: var(--accent); }
.status-list li.limited .code { color: var(--accent); font-weight: 700; }
.status-list li.error .fill,
.status-list li.other .fill { background: var(--red); }
.status-list li.error .code,
.status-list li.other .code { color: var(--red); }

.asset-note.err { color: var(--red); }
/* #stress-out is a plain block, so the chip needs to hug its text explicitly */
#stress-out .verdict { display: inline-block; margin-top: 12px; }
#stress-out .asset-note { margin-top: 8px; }

/* ============ asset gallery (interactive cache probe) ============ */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(238px, 1fr));
  gap: 16px;
  margin-top: 6px;
}
.asset {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease;
}
.asset:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.asset-media {
  height: 92px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.asset-media img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.asset:hover .asset-media img { transform: scale(1.04); }
.asset-body {
  flex: 1;
  padding: 12px 13px 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.asset-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.asset-name { font-family: var(--mono); font-size: 0.76rem; font-weight: 600; color: var(--text); }
.tier {
  font-family: var(--mono);
  font-size: 0.61rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tier.immutable { background: var(--chip-green-bg); color: var(--chip-green-text); }
.tier.short { background: var(--chip-amber-bg); color: var(--chip-amber-text); }
.tier.nocache { background: var(--surface); color: var(--text-dim); border-color: var(--border); }

.verdict {
  align-self: flex-start;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.verdict.hit { background: var(--chip-green-bg); color: var(--chip-green-text); }
.verdict.revalidated,
.verdict.limited,
.verdict.miss { background: var(--chip-amber-bg); color: var(--chip-amber-text); }
.verdict.err { background: var(--chip-red-bg); color: var(--chip-red-text); }
.verdict.unknown { background: var(--surface); color: var(--text-faint); border-color: var(--border); }

.asset-note { font-family: var(--mono); font-size: 0.68rem; color: var(--text-faint); }
.asset-meta { font-family: var(--mono); font-size: 0.68rem; color: var(--text-dim); }

.hdr-list {
  list-style: none;
  margin: 0;
  padding: 9px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.45;
}
.hdr-list li { display: flex; gap: 8px; align-items: baseline; }
.hdr-list .k { flex: none; color: var(--text-faint); }
.hdr-list li.hi .k { color: var(--accent); font-weight: 700; }
.hdr-list .v { min-width: 0; color: var(--text); word-break: break-word; }

.asset-actions { margin-top: auto; padding-top: 2px; }
.btn.sm { padding: 5px 12px; font-size: 0.75rem; border-radius: 7px; font-weight: 600; }

/* ============ footer ============ */
footer {
  max-width: 1120px;
  margin: 8px auto 44px;
  padding: 16px 24px 0;
}
footer p {
  margin: 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.71rem;
  line-height: 1.6;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
