:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --primary: #0d6efd;
  --primary-dark: #0b5ed7;
  --border: #e5e7eb;
  --danger: #dc3545;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 12px 0;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  white-space: nowrap;
}

.badge.online {
  background: #198754;
}

.badge.offline {
  background: var(--danger);
}

/* Main */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* Launch / redirect screen */
.app-main.launch {
  display: flex;
  align-items: center;
  justify-content: center;
}

.launch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.launch-status {
  font-size: 1rem;
  margin: 0 0 12px;
}

.launch-target {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
  margin: 0 0 20px;
}

.launch-target a {
  color: var(--primary);
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.9);
  color: var(--primary);
  padding: 8px 14px;
  font-size: 0.875rem;
}

/* Footer */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}

/* Offline page */
.offline-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.offline-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  text-align: center;
  max-width: 360px;
}

.offline-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.offline-card h1 {
  font-size: 1.25rem;
  margin: 8px 0 12px;
}

.offline-card p {
  color: var(--muted);
  margin: 6px 0;
}

.offline-card .btn {
  margin-top: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #1a2130;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2b3444;
  }
}
