:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --bg-soft: rgba(255, 255, 255, 0.68);
  --bg-strong: rgba(255, 255, 255, 0.86);
  --text: #16202e;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.1);
  --primary: #0f8b8d;
  --primary-2: #2563eb;
  --accent: #f59e0b;
  --danger: #e11d48;
  --success: #0f9f6e;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  --glass: blur(22px) saturate(145%);
}

.dark {
  color-scheme: dark;
  --bg: #0a0f19;
  --bg-soft: rgba(15, 23, 42, 0.58);
  --bg-strong: rgba(15, 23, 42, 0.8);
  --text: #edf3ff;
  --muted: #a4b1c4;
  --line: rgba(226, 232, 240, 0.13);
  --primary: #2dd4bf;
  --primary-2: #60a5fa;
  --accent: #fbbf24;
  --danger: #fb7185;
  --success: #34d399;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--bg) 93%, var(--primary)), var(--bg) 42%, color-mix(in srgb, var(--bg) 95%, var(--accent)));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.glass {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}

.glass-strong {
  background: var(--bg-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.55rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  padding: 0.68rem 0.9rem;
  color: var(--text);
  background: color-mix(in srgb, var(--bg-strong) 82%, transparent);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary) 48%, var(--line));
}

.btn-primary {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.btn-danger {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--danger), #f97316);
}

.icon-btn {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0;
}

.field {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-strong) 76%, transparent);
  color: var(--text);
  padding: 0.78rem 0.85rem;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}

.label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 0.2rem;
  padding: 0.25rem;
  border-radius: 0.62rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-strong) 75%, transparent);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.15rem;
  border: 0;
  border-radius: 0.42rem;
  padding: 0.45rem 0.7rem;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.theme-switch button {
  width: 2.2rem;
  padding: 0;
}

.theme-switch span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.card {
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-strong) 80%, transparent);
}

.speed-card {
  min-height: 8.2rem;
  padding: 1rem;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.speed-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.45rem;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  font-weight: 800;
}

.status-dot {
  width: 0.56rem;
  height: 0.56rem;
  border-radius: 999px;
  background: var(--muted);
}

.tone-fast .status-dot,
.tone-normal .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--success) 18%, transparent);
}

.tone-slow .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 18%, transparent);
}

.tone-down .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 18%, transparent);
}

.metric {
  font-variant-numeric: tabular-nums;
}

.toast-stack {
  position: fixed;
  right: 1rem;
  top: 1rem;
  z-index: 80;
  display: grid;
  gap: 0.65rem;
  width: min(23rem, calc(100vw - 2rem));
}

.toast-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: var(--bg-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0.85rem 0.95rem;
  backdrop-filter: var(--glass);
  animation: toastIn 0.22s ease-out;
}

.toast-item i {
  color: var(--success);
}

.toast-item.error i {
  color: var(--danger);
}

.toast-item.leaving {
  animation: toastOut 0.22s ease-in forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-0.6rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(-0.6rem);
  }
}

.mobile-shell {
  width: min(100%, 30rem);
  margin-inline: auto;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 0.9rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(2, 6, 23, 0.54);
  padding: 1rem;
}

.modal-mask.active {
  display: flex;
}

.modal-panel {
  width: min(100%, 34rem);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border-radius: 0.75rem;
}

@media (min-width: 768px) {
  .modal-mask {
    align-items: center;
  }

  .mobile-shell {
    width: min(100%, 76rem);
  }
}
