:root {
  --bg: #101642;
  --bg-elev: #16205c;
  --fg: #f4f6fb;
  --muted: #9aa3c7;
  --line: rgba(255, 255, 255, 0.1);
  --ok: #3dd68c;
  --ok-bg: #143d2c;
  --warn: #f5c14a;
  --warn-bg: #3d3210;
  --bad: #ff6b6b;
  --bad-bg: #4a1520;
  --accent: #00bcd4;
  --accent-ink: #06263a;
  --brand: #f4f6fb;
  --header-h: 3.5rem;
  --radius: 16px;
  --tabbar-bg: #101642;
  --input-bg: color-mix(in srgb, var(--bg-elev) 80%, #101642);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #070b28;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body {
  display: flex;
  justify-content: center;
  height: 100dvh;
  height: var(--app-h, 100dvh);
  overflow: hidden;
}
button, input, select { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
.app-frame {
  width: 100%;
  max-width: 32rem;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.top {
  flex: none;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 0.85rem 0;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.05rem; letter-spacing: -0.03em; font-weight: 700; color: var(--brand); }
.brand em { color: var(--accent); font-style: normal; }
.grow { flex: 1; }
.pill {
  height: 36px;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.86rem;
  font-weight: 700;
}
.pill[aria-pressed="true"] { background: var(--bad); color: #fff; }
.pill:disabled { opacity: 0.45; }
.chip-status {
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
}
.chip-status.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.chip-status.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
#tool {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#tool[hidden] { display: none; }
#blocked:not([hidden]) { flex: 1 1 auto; }
#tool > .panel:not([hidden]) { flex: none; }
.page {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.85rem 0.9rem 1rem;
}
.panel[hidden] { display: none; }
#test-panel, #cmd-panel {
  overflow: visible;
  padding-bottom: 0.2rem;
}
.stack { flex: none; }
.meters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
}
.meters b { color: var(--fg); font-weight: 700; }
.meters [data-q="good"],
.meters [data-q="good"] b { color: var(--ok); }
.meters [data-q="fair"],
.meters [data-q="fair"] b { color: var(--warn); }
.meters [data-q="poor"],
.meters [data-q="poor"] b { color: var(--bad); }
.fix {
  margin: -0.2rem 0 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.fix:empty { display: none; }
.row { display: flex; gap: 0.45rem; margin: 0 0 0.5rem; }
.row > * { flex: 1; }
.btn {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.4rem 0.7rem;
}
.btn.ghost {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--line);
}
.btn[aria-pressed="true"] { background: var(--ok); color: #06263a; }
.btn:disabled, .modes button:disabled { opacity: 0.4; }
h2 {
  margin: 0.05rem 0 0.28rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.subtabs { display: flex; gap: 0.35rem; margin: 0 0 0.4rem; }
.subtabs button {
  flex: 1;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.subtabs button.on { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.grid { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; }
.grid[hidden], .sf[hidden] { display: none; }
.grid button {
  min-height: 44px;
  padding: 0.3rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg);
  font-size: 0.86rem;
  font-weight: 650;
}
.sf { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.3rem; margin: 0; }
.sf button {
  min-height: 40px;
  padding: 0.15rem 0.1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 700;
}
.field { display: flex; flex-direction: column; gap: 0.4rem; }
select, .field input {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--fg);
  padding: 0 0.8rem;
}
.modes { display: flex; gap: 0.4rem; margin: 0.55rem 0; }
.modes[hidden] { display: none; }
.modes button {
  flex: 1;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-weight: 700;
}
.modes button.on { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.log-dock {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.15rem 0.9rem 0.35rem;
}
.log-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.log-bar h2 { margin: 0; flex: 1; }
.log-bar .btn { min-height: 32px; padding: 0.1rem 0.7rem; border-radius: 10px; font-size: 0.78rem; }
#log {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  overflow: auto;
  background: #0b1036;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.55rem 0.7rem;
  font-family: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
}
#log div { white-space: pre-wrap; overflow-wrap: anywhere; }
#log .sent { color: var(--accent); }
#log .desc { color: var(--warn); }
#log .recv { color: var(--ok); }
.composer { display: flex; gap: 0.4rem; margin: 0 0 0.55rem; }
.composer .btn { min-height: 40px; }
.composer input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--fg);
  padding: 0 0.75rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.tabbar {
  flex: none;
  display: flex;
  gap: 0.2rem;
  padding: 0.2rem 0.45rem max(0.35rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--tabbar-bg) 96%, transparent);
}
.tabbar button {
  flex: 1;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  font-size: 0.68rem;
  font-weight: 700;
}
.tabbar button.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tab-mark { position: relative; display: inline-flex; }
.dot {
  position: absolute;
  top: -2px;
  right: -6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.callout {
  margin: 0.4rem 0 0;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 0.95rem;
}
.banner {
  margin: 0 0 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.82rem;
  font-weight: 650;
}
