:root {
  --brand: #4F46E5;
  --brand-light: #6D5DFB;
  --accent: #F97316;
  --ok: #16A34A;
  --warn: #D97706;
  --bad: #DC2626;
  --ink: #1E1B3A;
  --muted: #5B5875;
  --line: #E7E5F4;
  --bg: #F6F5FF;
  --card: #FFFFFF;
  --code-bg: #EEEDFF;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #9D93FF;
    --brand-light: #B7B0FF;
    --ok: #4ADE80;
    --warn: #FBBF24;
    --bad: #F87171;
    --ink: #EDECF7;
    --muted: #A6A3BF;
    --line: #2C2A45;
    --bg: #12111F;
    --card: #1C1B33;
    --code-bg: #262447;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; max-width: 760px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand img { height: 24px; width: auto; display: block; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button { background: none; border: 0; padding: 5px 11px; font-size: 13px; cursor: pointer; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--brand); color: #fff; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.label { font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(28px, 8vw, 40px); font-weight: 700; letter-spacing: .18em;
  background: var(--code-bg); color: var(--brand); border-radius: 10px; padding: 2px 12px; display: inline-block;
}
.room-actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 16px; font-weight: 600; text-decoration: none; cursor: pointer; font-size: 15px;
}
.btn.primary { background: linear-gradient(90deg, var(--brand-light), var(--brand)); color: #fff; border-color: transparent; }
.btn.ghost { color: var(--muted); }
.btn:active { transform: translateY(1px); }

.status { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 15px; background: var(--code-bg); }
.status::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; background: var(--muted); vertical-align: middle; }
.status[data-state="waiting"]::before { background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="connecting"]::before { background: var(--brand); animation: pulse .8s infinite; }
.status[data-state="connected"]::before { background: var(--ok); }
.status[data-state="error"]::before, .status[data-state="left"]::before { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

.join { margin-top: 14px; }
.join label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; min-width: 0; font: inherit; font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font-size: 16px;
}
.join-row input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }

.peers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 480px) { .peers { grid-template-columns: 1fr; } }
.peer h2 { margin: 0 0 8px; font-size: 15px; color: var(--brand); }
.peer dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13.5px; }
.peer dt { color: var(--muted); white-space: nowrap; }
.peer dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.peer.dim { opacity: .55; }

.path { font-size: 13.5px; color: var(--muted); margin-bottom: 10px; }
.path b { color: var(--ink); }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .hero-stats { grid-template-columns: 1fr; } }
.stat.big { background: var(--bg); border-radius: 12px; padding: 12px 14px; }
.stat .value { font-size: clamp(40px, 10vw, 56px); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.stat .value small { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .sub b { color: var(--ink); font-variant-numeric: tabular-nums; }
.value.good { color: var(--ok); } .value.meh { color: var(--warn); } .value.bad { color: var(--bad); }

canvas#chart { width: 100%; height: 120px; display: block; margin-top: 14px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.legend .dot.rtt { background: var(--brand); } .legend .dot.loss { background: var(--bad); }
.legend .window { margin-left: auto; }
.totals { margin: 12px 0 0; display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 4px 10px; font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
@media (max-width: 480px) { .totals { grid-template-columns: auto 1fr; } }
.totals dt { color: var(--muted); } .totals dd { margin: 0; font-variant-numeric: tabular-nums; }

.howto h3 { margin: 0 0 8px; font-size: 15px; }
.howto ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.howto li + li { margin-top: 4px; }

.fail { margin-top: 12px; padding: 12px; border: 1px solid var(--bad); border-radius: 12px; }
.fail p { margin: 0 0 10px; font-size: 14px; }
.fail b { color: var(--bad); }
.note { font-size: 12.5px; color: var(--warn); margin: 0 0 8px; }
