:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #0a84ff);
  --button: var(--tg-theme-button-color, #0a84ff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #ff453a);
  --radius: 14px;
  --gap: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  /* H5: safe-area-inset for notched devices (iPhone X+, Dynamic Island) */
  padding:
    max(var(--gap), env(safe-area-inset-top))
    max(var(--gap), env(safe-area-inset-right))
    max(var(--gap), env(safe-area-inset-bottom))
    max(var(--gap), env(safe-area-inset-left));
  gap: var(--gap);
}

.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 440px;
  gap: var(--gap);
}
.screen.active {
  display: flex;
}

/* ── Card ── */
.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hint);
}

.card-value {
  font-size: 16px;
  font-weight: 500;
}

/* ── Heading ── */
h1 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

p.subtitle {
  color: var(--hint);
  text-align: center;
  font-size: 14px;
}

/* ── Buttons ── */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: center;
}
.btn:active { opacity: 0.75; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--button);
  color: var(--button-text);
}
.btn-danger {
  background: var(--destructive);
  color: #fff;
}
.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

/* ── Zone select ── */
select {
  appearance: none;
  width: 100%;
  padding: 14px var(--gap);
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  font-size: 16px;
}
select:focus {
  outline: 2px solid var(--button);
  outline-offset: 2px;
}

/* ── Status badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.badge-online { background: rgba(48, 209, 88, 0.2); color: #30d158; }
.badge-offline { background: rgba(255, 69, 58, 0.2); color: var(--destructive); }

/* ── Countdown timer ── */
#countdown-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
#countdown-label {
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
#countdown-ring {
  transition: stroke-dashoffset 1s linear;
  transform-origin: center;
  transform: rotate(-90deg);
}

/* ── Heartbeat warning banner ── */
#heartbeat-banner {
  width: 100%;
  max-width: 440px;
  background: rgba(255, 69, 58, 0.15);
  border: 1px solid rgba(255, 69, 58, 0.4);
  border-radius: var(--radius);
  color: var(--destructive);
  font-size: 13px;
  font-weight: 600;
  padding: 10px var(--gap);
  text-align: center;
}

/* ── Map deep-link row ── */
.map-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
}
.map-link:active { opacity: 0.7; }

/* ── Spinner ── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error message ── */
.error-msg {
  color: var(--destructive);
  font-size: 14px;
  text-align: center;
}
