:root {
  --bg: var(--tg-theme-secondary-bg-color, #eef1f5);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-soft: color-mix(in srgb, var(--surface) 90%, #6f7a89 10%);
  --text: var(--tg-theme-text-color, #152033);
  --muted: var(--tg-theme-hint-color, #758094);
  --accent: var(--tg-theme-button-color, #1f7aec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d9485f;
  --success: #24a06b;
  --warning: #df8f1d;
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --safe-top: var(--tg-safe-area-inset-top, 0px);
  --safe-bottom: var(--tg-safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

body { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.app-shell {
  width: min(100%, 560px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
}

.topbar {
  padding: calc(14px + var(--safe-top)) 18px 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
}

.eyebrow, .label {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .09em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.05; }
h2 { margin: 2px 0 0; font-size: 20px; }

.connection {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 17%, transparent);
}

.connection-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 17%, transparent);
}

.connection-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 17%, transparent);
}

.content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 24px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hero-card, .metric-card, .control-card, .list-card, .latency-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 7px 22px rgba(18, 31, 53, .045);
}

.hero-card { padding: 17px; }
.hero-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero-value { display: block; margin-top: 4px; font-size: 20px; }
.divider { height: 1px; margin: 15px 0; background: var(--line); }
.match-title { display: block; margin-top: 6px; font-size: 17px; line-height: 1.35; }
.muted { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.compact { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.35; }

.pill, .state-badge, .counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
}

.pill { min-height: 28px; padding: 0 10px; }
.pill.neutral { color: var(--muted); background: var(--surface-soft); }
.pill.safe { color: var(--success); background: color-mix(in srgb, var(--success) 13%, transparent); }
.pill.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }

.metric-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card { padding: 14px; }
.metric-card strong { display: block; margin-top: 8px; font-size: 25px; line-height: 1; }
.metric-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.control-card {
  margin-top: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-buttons { display: flex; gap: 7px; }
.button {
  min-height: 38px;
  padding: 0 13px;
  border: 0;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.button:disabled { opacity: .45; cursor: wait; }
.button.primary { color: var(--accent-text); background: var(--accent); }
.button.secondary { color: var(--text); background: var(--surface-soft); }

.section-heading {
  margin: 2px 2px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.counter { min-width: 30px; height: 30px; padding: 0 9px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.stack { display: grid; gap: 9px; }
.empty-state { color: var(--muted); font-size: 13px; }

.list-card { padding: 14px; }
.card-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { margin: 8px 0 0; font-size: 15px; line-height: 1.35; }
.card-meta { margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.state-badge { min-height: 24px; padding: 0 8px; color: var(--muted); background: var(--surface-soft); }
.state-badge.active { color: var(--success); background: color-mix(in srgb, var(--success) 13%, transparent); }
.state-badge.warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 13%, transparent); }
.state-badge.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }

.profile-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.balance { font-size: 17px; font-weight: 750; text-align: right; }
.detail { grid-column: 1 / -1; margin: 0; color: var(--danger); font-size: 11px; line-height: 1.4; }

.latency-card { padding: 14px; }
.latency-values { margin-top: 11px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.latency-value { padding: 9px; border-radius: 11px; background: var(--surface-soft); }
.latency-value strong { display: block; margin-top: 4px; font-size: 15px; }
.bar-track { height: 5px; margin-top: 11px; overflow: hidden; border-radius: 99px; background: var(--surface-soft); }
.bar-value { height: 100%; border-radius: inherit; background: var(--accent); }

.timeline { display: grid; gap: 0; }
.event { position: relative; padding: 0 0 16px 22px; }
.event::before { content: ""; position: absolute; top: 6px; left: 4px; bottom: -6px; width: 1px; background: var(--line); }
.event:last-child::before { display: none; }
.event::after { content: ""; position: absolute; top: 5px; left: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg); }
.event-time { color: var(--muted); font-size: 10px; }
.event-title { margin: 3px 0 0; font-size: 13px; line-height: 1.35; }
.event-context { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.notice { margin-bottom: 12px; padding: 12px; border-radius: 12px; font-size: 12px; line-height: 1.45; }
.notice.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.hidden { display: none !important; }

.bottom-nav {
  padding: 7px 6px calc(7px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top: 1px solid var(--line);
}

.nav-button {
  min-width: 0;
  padding: 5px 1px;
  display: grid;
  justify-items: center;
  gap: 3px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 9px;
  cursor: pointer;
}
.nav-button > span:first-child { font-size: 17px; line-height: 1; }
.nav-button.active { color: var(--accent); font-weight: 750; }

@media (min-width: 561px) {
  body { background: #182131; }
  .app-shell { box-shadow: 0 0 50px rgba(0, 0, 0, .25); }
}

@media (max-width: 360px) {
  .control-card { align-items: stretch; flex-direction: column; }
  .control-buttons .button { flex: 1; }
}
