:root {
  --bg: #f6f7fb;
  --bg-grad-1: #eef2ff;
  --bg-grad-2: #f6f7fb;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-fg: #ffffff;
  --primary-soft: color-mix(in srgb, var(--primary) 10%, white);
  --accent: #0f172a;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --success: #15803d;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.16);
  --ring: 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent);
  --ease: cubic-bezier(.32, .72, 0, 1);
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.55 var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -200px, var(--bg-grad-1), transparent 60%),
    var(--bg-grad-2);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

.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;
}

.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 24px;
}
.brand img {
  height: 32px;
  width: auto;
  display: block;
}
.trust {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.trust svg { width: 14px; height: 14px; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px;
}
.card-head { margin-bottom: 28px; }
.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
}
h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.025em;
}
.lede {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  max-width: 48ch;
}

/* Form */
fieldset { border: 0; padding: 0; margin: 0; }
.identity { display: grid; gap: 14px; }
.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 480px) {
  .row.two { grid-template-columns: 1fr; }
}
.field { display: block; }
.label {
  display: block;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
  -webkit-appearance: none;
}
.field input::placeholder { color: var(--text-subtle); }
.field input:hover { border-color: color-mix(in srgb, var(--text) 28%, transparent); }
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.channels legend {
  padding: 0;
  margin-bottom: 14px;
}
.legend-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.legend-sub {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Toggle rows */
.channels {
  display: grid;
  gap: 10px;
}
.toggle {
  display: block;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}
.toggle:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border-strong)); }
.toggle input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.toggle input:focus-visible ~ .toggle-row { box-shadow: var(--ring); border-radius: var(--radius); }
.toggle-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
}
.toggle-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 10px;
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.toggle-icon svg { width: 20px; height: 20px; }
.toggle-title {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.toggle-desc {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Switch UI */
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: #d4d4d8;
  transition: background 200ms var(--ease);
  flex-shrink: 0;
}
.switch-dot {
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 200ms var(--ease);
}
.toggle input:checked ~ .toggle-row .switch { background: var(--primary); }
.toggle input:checked ~ .toggle-row .switch .switch-dot { transform: translateX(18px); }
.toggle input:checked ~ .toggle-row { /* selected styles handled by parent border via :has */ }
.toggle:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 4%, white);
}

/* Actions */
.actions {
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  padding: 0 26px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 100ms var(--ease), background 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease), color 160ms var(--ease);
  -webkit-appearance: none;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.ghost:hover { background: var(--surface-hover); }
.btn.danger {
  background: var(--danger);
  color: #fff;
}
.btn.danger:hover { background: var(--danger-hover); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-spinner {
  width: 18px; height: 18px;
  color: currentColor;
  display: none;
  animation: spin 800ms linear infinite;
}
.btn.loading .btn-spinner { display: inline-block; }
.btn.loading .btn-label { opacity: 0.85; }
@keyframes spin { to { transform: rotate(360deg); } }

.saved {
  margin: 0;
  font-size: 14px;
  color: var(--success);
  font-weight: 500;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
.saved.show { opacity: 1; transform: none; }
.saved.error { color: var(--danger); }

/* Unsubscribe footer */
.unsub-foot {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.unsub-link {
  font-size: 13px;
  color: var(--text-subtle);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--text-subtle) 50%, transparent);
  text-underline-offset: 3px;
  font-weight: 400;
  letter-spacing: 0;
  transition: color 160ms var(--ease);
}
.unsub-link:hover { color: var(--text-muted); }
.unsub-link:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }

.legal {
  margin: 24px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-subtle);
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #0f172a 55%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  opacity: 0;
  transition: opacity 200ms var(--ease);
}
.overlay[hidden] { display: none; }
.overlay.show { opacity: 1; }
.overlay-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(0.98);
  transition: transform 240ms var(--ease);
}
.overlay.show .overlay-card { transform: none; }
.overlay-card h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.overlay-card p {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.55;
}
.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.overlay-actions .btn { height: 46px; padding: 0 18px; font-size: 14px; }

/* Done state */
.card.done {
  text-align: center;
}
.card.done .done-icon {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--success) 12%, white);
  color: var(--success);
  border-radius: 50%;
}
.card.done .done-icon svg { width: 30px; height: 30px; }

@media (max-width: 540px) {
  .card { padding: 28px 22px; }
  .topbar { padding-bottom: 18px; }
  .toggle-row { grid-template-columns: 36px 1fr auto; padding: 14px; gap: 12px; }
  .toggle-icon { width: 36px; height: 36px; }
  .toggle-icon svg { width: 18px; height: 18px; }
}
