:root {
  --bg: #0a0a0a;
  --bg-2: #111114;
  --surface: #16161a;
  --surface-2: #1d1d22;
  --border: #26262d;
  --text: #f4f4f5;
  --text-dim: #a1a1aa;
  --text-mute: #71717a;
  --green: #22c55e;
  --green-2: #16a34a;
  --amber: #f59e0b;
  --amber-2: #d97706;
  --red: #ef4444;
  --red-2: #dc2626;
  --emerald-from: #10b981;
  --emerald-to: #059669;
  --warn-from: #f59e0b;
  --warn-to: #d97706;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  min-height: 100dvh;
}

body {
  background:
    radial-gradient(60% 40% at 50% 0%, rgba(16,185,129,0.06), transparent 60%),
    radial-gradient(50% 30% at 50% 100%, rgba(245,158,11,0.04), transparent 60%),
    var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  padding-top: calc(24px + env(safe-area-inset-top));
  max-width: 520px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}
.brand .title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.brand .role {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}
.brand .role.primary { color: var(--green); border-color: rgba(34,197,94,0.4); }
.brand .role.backup { color: var(--amber); border-color: rgba(245,158,11,0.4); }

.pills {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 28px;
}
.pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-dim);
  transition: border-color 160ms ease, color 160ms ease;
}
.pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--text-mute);
  box-shadow: 0 0 0 0 rgba(255,255,255,0);
  transition: background-color 160ms ease, box-shadow 160ms ease;
}
.pill .label { flex: 1; font-weight: 500; }
.pill .meta {
  font-size: 11px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.pill[data-state="ok"] { color: var(--text); border-color: rgba(34,197,94,0.35); }
.pill[data-state="ok"] .dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(34,197,94,0.15);
  animation: pulse-ok 2.4s ease-in-out infinite;
}
.pill[data-state="warn"] { color: var(--text); border-color: rgba(245,158,11,0.35); }
.pill[data-state="warn"] .dot {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(245,158,11,0.15);
}
.pill[data-state="error"] { color: var(--text); border-color: rgba(239,68,68,0.4); }
.pill[data-state="error"] .dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(239,68,68,0.18);
}

.pill--hero {
  padding: 22px 22px;
  font-size: 18px;
  border-radius: 16px;
  letter-spacing: 0.02em;
}
.pill--hero .dot { width: 12px; height: 12px; }
.pill--hero .label { font-weight: 600; }
.pill--hero .meta { font-size: 16px; color: var(--text-dim); }
.pill--hero[data-state="ok"] .meta { color: var(--green); font-weight: 700; }

body.minimal {
  justify-content: flex-start;
}
body.minimal .pills { margin-bottom: 36px; margin-top: 12px; }
body.minimal .actions { gap: 18px; }

@keyframes pulse-ok {
  0%, 100% { box-shadow: 0 0 0 4px rgba(34,197,94,0.15); }
  50%      { box-shadow: 0 0 0 7px rgba(34,197,94,0.05); }
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 88px;
  border: 0;
  border-radius: 18px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: white;
  cursor: pointer;
  transition: transform 80ms ease, opacity 200ms ease, filter 200ms ease;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.3); }
.btn.start {
  background: linear-gradient(180deg, var(--emerald-from), var(--emerald-to));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 6px 20px rgba(16,185,129,0.18);
}
.btn.fade {
  background: linear-gradient(180deg, var(--warn-from), var(--warn-to));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 6px 20px rgba(245,158,11,0.16);
}
.btn .spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn[data-pending="true"] .spinner { display: inline-block; }
.btn .progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(0,0,0,0.25);
  overflow: hidden;
}
.btn .progress .fill {
  height: 100%;
  width: 0;
  background: rgba(255,255,255,0.85);
  transition: width 6s linear;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn.arm {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 6px 20px rgba(59,130,246,0.22);
}

.console {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--text-mute);
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 30vh;
  overflow: hidden;
}
.console .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.console .line .ts { color: var(--text-mute); margin-right: 8px; }
.console .line.evt-error { color: var(--red); }
.console .line.evt-warn { color: var(--amber); }
.console .line.evt-info { color: var(--text-dim); }

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 50;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  animation: toast-in 200ms ease-out;
}
.toast.error { border-color: rgba(239,68,68,0.45); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.test-toggle {
  margin-top: 20px;
  text-align: center;
}
.test-toggle button {
  background: transparent;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
}
.test-toggle button:hover { color: var(--text); border-color: var(--text-mute); }
.test-toggle button[disabled] { opacity: 0.35; cursor: not-allowed; }
.test-toggle .back-link {
  display: inline-block;
  margin-left: 12px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}
.test-toggle .back-link:hover { color: var(--text); border-color: var(--text-mute); }

.player-arm-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.player-status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.stat .k {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 4px;
}
.stat .v {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald-from), var(--emerald-to));
  width: 0;
  transition: width 200ms ease;
}
