:root {
  color-scheme: dark;
  --bg: #08111f;
  --surface: #0e1a2b;
  --surface-2: #132238;
  --text: #f4f7fb;
  --muted: #a8b8cc;
  --accent: #38d7f4;
  --accent-text: #04131a;
  --green: #41e6a7;
  --gold: #ffbd36;
  --line: rgba(137, 171, 209, .19);
  --safe-top: var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 280px;
  background:
    radial-gradient(circle at 100% 0, rgba(56, 215, 244, .11), transparent 36rem),
    var(--bg);
  color: var(--text);
}
button, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 14px calc(20px + var(--safe-bottom));
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  margin-bottom: 10px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand img { width: 42px; height: 42px; border-radius: 12px; }
.brand span { display: grid; line-height: 1; }
.brand strong { font-size: 15px; letter-spacing: .03em; }
.brand small { margin-top: 5px; color: var(--accent); font: 700 10px/1 ui-monospace, monospace; letter-spacing: .22em; }
.session-badge, .count-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  background: rgba(8, 17, 31, .45);
  font-size: 12px;
  font-weight: 700;
}
.session-badge.is-verified { color: var(--green); border-color: rgba(65, 230, 167, .35); }

.source-card, .data-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(19, 34, 56, .94), rgba(10, 20, 35, .98));
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
}
.source-card { padding: 18px; }
.eyebrow {
  color: var(--accent);
  font: 800 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .15em;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(23px, 7vw, 34px); letter-spacing: -.03em; }
h2 { margin: 5px 0 0; font-size: 19px; letter-spacing: -.02em; }
.source-card > div > p { margin-bottom: 15px; color: var(--muted); font-size: 13px; line-height: 1.5; }
#welcomeText { margin-bottom: 7px; }
.source-card > div > .connector-invite { margin-bottom: 15px; }
.connector-invite a { color: var(--accent); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.source-field { display: grid; gap: 6px; }
.source-field span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
select {
  width: 100%;
  border: 1px solid rgba(56, 215, 244, .35);
  border-radius: 12px;
  padding: 12px 38px 12px 12px;
  background: #091526;
  color: var(--text);
}
select:disabled { opacity: .65; }
.status-line { min-height: 18px; margin: 10px 0 0; color: var(--green); font-size: 12px; }
.status-line.is-error { color: #ff7189; }

.tabs {
  position: sticky;
  top: var(--safe-top);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 12px 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}
.tab {
  border: 0;
  border-radius: 10px;
  padding: 10px 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tab.is-active { background: var(--accent); color: var(--accent-text); }
.panel { display: none; }
.panel.is-active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}
.metric-grid article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 9px;
  background: var(--surface);
}
.metric-grid span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.metric-grid strong { display: block; overflow: hidden; color: var(--green); font: 800 14px/1.1 ui-monospace, monospace; text-overflow: ellipsis; }
#timerMetric {
  overflow: visible;
  font-size: clamp(11px, 3.15vw, 13px);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.045em;
  text-overflow: clip;
  white-space: nowrap;
}

.data-card { overflow: hidden; }
.data-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.live-dot { color: var(--muted); font-size: 11px; white-space: nowrap; }
.live-dot i { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
th:nth-child(2), td:nth-child(2) { text-align: left; }
td:first-child { color: var(--gold); font-weight: 800; }
td:nth-child(2) { max-width: 150px; overflow: hidden; font-weight: 800; text-overflow: ellipsis; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 28px 12px; color: var(--muted) !important; text-align: center !important; white-space: normal; }

.round-list { display: grid; }
.round-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.round-row:last-child { border-bottom: 0; }
.round-index {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(56, 215, 244, .3);
  border-radius: 13px;
  color: var(--accent);
  font: 800 12px/1 ui-monospace, monospace;
}
.round-copy { min-width: 0; }
.round-copy strong, .round-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-copy span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.round-multiplier { color: var(--gold); font: 800 13px/1 ui-monospace, monospace; }

.tools-card { padding-bottom: 14px; }
.tool-links { display: grid; gap: 8px; padding: 14px; }
.tool-links a {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: rgba(7, 16, 30, .64);
}
.tool-links a:active { border-color: var(--accent); transform: translateY(1px); }
.tool-links strong { font-size: 14px; }
.tool-links span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.write-access {
  width: calc(100% - 28px);
  margin: 0 14px;
  border: 0;
  border-radius: 13px;
  padding: 13px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 900;
}
.write-access:disabled { opacity: .55; }
.helper { margin: 9px 16px 0; color: var(--muted); font-size: 11px; line-height: 1.45; text-align: center; }
footer { display: flex; justify-content: space-between; gap: 12px; padding: 18px 4px 4px; color: var(--muted); font-size: 10px; }
footer a { color: var(--accent); }

@media (max-width: 380px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .round-row { grid-template-columns: 46px 1fr auto; padding-inline: 12px; }
}

@media (min-width: 620px) {
  .app-shell { padding-inline: 22px; }
  .source-card { display: grid; grid-template-columns: 1fr 240px; column-gap: 22px; align-items: end; }
  .source-card .status-line { grid-column: 1 / -1; }
}
