:root {
  color-scheme: dark;
  --bg: #07111d;
  --panel: #0d1b2b;
  --panel-2: #12243a;
  --text: #f5f9ff;
  --muted: #8fa5bb;
  --accent: #28d7ff;
  --accent-2: #5bffa8;
  --danger: #ff6b76;
  --border: rgba(255,255,255,.10);
  --shadow: 0 20px 50px rgba(0,0,0,.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--bg); min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -15%, rgba(40,215,255,.18), transparent 34rem),
    linear-gradient(180deg, #07111d 0%, #050a11 100%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
body.light {
  color-scheme: light;
  --bg: #edf5fb;
  --panel: #ffffff;
  --panel-2: #e9f2f8;
  --text: #0c1a26;
  --muted: #597086;
  --border: rgba(12,26,38,.12);
  --shadow: 0 18px 40px rgba(22,62,90,.14);
  background: linear-gradient(180deg, #f7fbff 0%, #e8f1f7 100%);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
.app-shell { width: min(980px, 100%); margin: 0 auto; padding: 18px 16px calc(30px + var(--safe-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.eyebrow { margin: 0 0 3px; font-size: .72rem; font-weight: 800; letter-spacing: .18em; color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(1.25rem, 4vw, 1.65rem); }
h2 { font-size: 1.15rem; }
.top-actions { display: flex; gap: 8px; }
.icon-button {
  width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel); color: var(--text); font-size: 1.3rem; cursor: pointer;
}
.hidden { display: none !important; }
.speed-card {
  position: relative; overflow: hidden; text-align: center; padding: 16px 16px 22px;
  border: 1px solid var(--border); border-radius: 28px; background: linear-gradient(180deg, rgba(18,36,58,.96), rgba(8,19,31,.96));
  box-shadow: var(--shadow);
}
body.light .speed-card { background: linear-gradient(180deg, #fff, #eaf4fa); }
.speed-card::after {
  content: ""; position: absolute; inset: auto 12% 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: .65;
}
.status-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; }
.status-spacer { flex: 1; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #6f7d8c; box-shadow: 0 0 0 4px rgba(111,125,140,.12); }
.status-dot.live { background: var(--accent-2); box-shadow: 0 0 0 4px rgba(91,255,168,.13); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,107,118,.12); }
.badge { padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,.04); font-size: .72rem; font-weight: 800; letter-spacing: .04em; }
.speed-value { margin-top: 4px; font-size: clamp(8rem, 34vw, 16rem); font-weight: 900; line-height: .87; letter-spacing: -.075em; font-variant-numeric: tabular-nums; text-shadow: 0 0 38px rgba(40,215,255,.12); }
.unit-button { border: 0; background: transparent; color: var(--accent); font-size: clamp(1.35rem, 5vw, 1.85rem); font-weight: 900; letter-spacing: .16em; cursor: pointer; }
.accuracy-line { margin-top: 9px; color: var(--muted); }
.heading-line { margin-top: 8px; font-size: 1.15rem; }
.heading-arrow { display: inline-block; color: var(--accent-2); font-size: 1.5rem; transform-origin: 50% 52%; transition: transform .3s ease; }
.primary-controls { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin: 12px 0; }
.primary-button, .secondary-button {
  min-height: 54px; border-radius: 16px; font-weight: 900; letter-spacing: .055em; cursor: pointer;
}
.primary-button { border: 0; background: linear-gradient(135deg, var(--accent), #2c8dff); color: #02131b; box-shadow: 0 10px 24px rgba(40,215,255,.18); }
.primary-button.stop { background: linear-gradient(135deg, #ff7d85, #ff4f5f); color: #210408; }
.secondary-button { border: 1px solid var(--border); background: var(--panel); color: var(--text); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.stat-card { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: 0 10px 28px rgba(0,0,0,.08); }
.stat-card span { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 6px; }
.stat-card strong { display: block; font-size: clamp(1rem, 3.2vw, 1.35rem); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-card { margin-top: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 22px; background: var(--panel); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tool-button { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--panel-2); color: var(--text); text-align: left; cursor: pointer; }
.tool-button > span:first-child { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: rgba(40,215,255,.10); color: var(--accent); font-size: 1.25rem; flex: 0 0 auto; }
.tool-button strong, .tool-button small { display: block; }
.tool-button small { margin-top: 3px; color: var(--muted); }
.helper-text { margin: 0 0 14px; color: var(--muted); line-height: 1.45; }
.compare-heading { margin-bottom: 8px; }
.compare-entry label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .85rem; }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; }
.input-row input { width: 100%; min-height: 52px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2); color: var(--text); padding: 0 14px; font-size: 1.25rem; font-weight: 800; }
.input-row > span { color: var(--muted); font-weight: 800; }
.compact { min-height: 52px; padding: 0 16px; }
.table-wrap { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: .78rem; }
.delete-sample { border: 0; border-radius: 10px; background: rgba(255,107,118,.12); color: var(--danger); width: 32px; height: 32px; cursor: pointer; }
.empty-row td { text-align: center; color: var(--muted); }
.calibration-summary { margin: 14px 0; padding: 12px; border-radius: 14px; background: var(--panel-2); color: var(--muted); line-height: 1.45; }
.wide { width: 100%; }
.notice-card { margin-top: 12px; padding: 12px 14px; border: 1px solid rgba(255,202,87,.18); border-radius: 16px; background: rgba(255,202,87,.07); color: #ffd979; line-height: 1.45; font-size: .88rem; }
footer { display: flex; justify-content: space-between; gap: 18px; margin-top: 16px; color: var(--muted); font-size: .75rem; }
dialog { width: min(92vw, 420px); border: 1px solid var(--border); border-radius: 22px; padding: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.65); }
.dialog-card { padding: 20px; }
.dialog-card p { color: var(--muted); line-height: 1.5; }
.dialog-card .primary-button { width: 100%; margin-top: 8px; }

@media (max-width: 720px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .speed-card { border-radius: 24px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .tool-grid { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 4px; }
}
@media (max-width: 390px) {
  .primary-controls { grid-template-columns: 1fr; }
  .speed-value { font-size: 7.6rem; }
  .input-row { grid-template-columns: 1fr auto; }
  .input-row .compact { grid-column: 1 / -1; }
}
@media (display-mode: standalone) {
  #installBtn, #installToolBtn { display: none !important; }
}
