.portal {
  max-width: 1120px;
  padding-top: clamp(26px, 5vw, 56px);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.portal-intro { margin-bottom: 24px; }
.portal h1 { font-size: clamp(2.1rem, 5.5vw, 3.8rem); }
.portal h2 { font-size: clamp(1.38rem, 3.2vw, 1.85rem); }
.portal .lede { margin-top: 10px; }

.portal-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.portal-status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--dim);
}
.portal-status-pill[data-connected="true"] {
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(16, 185, 129, 0.12);
  color: var(--good);
}
.portal-status-pill[data-connected="true"] .dot {
  background: var(--good);
  box-shadow: 0 0 10px var(--good);
}

.pairing-layout, .dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.stack { display: grid; gap: 12px; min-width: 0; }
.stack > p, .stack > div > p, .pair-guide p { margin: 0; }

.pair-card {
  background: linear-gradient(155deg, rgba(139, 92, 246, 0.12), rgba(21, 19, 34, 0.96) 55%);
  border-color: rgba(196, 181, 253, 0.24);
}
.pair-guide {
  background: linear-gradient(160deg, rgba(229, 9, 20, 0.08), var(--surface) 60%);
}
.pair-preview {
  margin-top: 16px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 16 / 9;
  background: #08070d;
}
.pair-preview img { width: 100%; height: 100%; object-fit: cover; }
.pair-tips {
  margin-top: 16px;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.portal label { color: var(--text); font-weight: 650; font-size: 0.88rem; }
.portal input:not([type="radio"]), .portal select {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  background: #0a0912;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.portal input:not([type="radio"]):focus, .portal select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
  outline: none;
}
.portal label + input, .portal label + select, .portal label + .input-with-action { margin-top: -5px; }
.portal input::placeholder { color: #71758f; }

#code-input {
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  text-align: center;
  min-height: 58px;
}

.portal fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }

/* Summary Telemetry Bar */
.overview-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.overview-stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
  display: grid;
  gap: 4px;
}
.overview-stat-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}
.overview-stat-val {
  font-size: 1rem;
  font-weight: 750;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* Sticky Section Jump Pills */
.jump-links {
  position: sticky;
  top: 74px;
  z-index: 20;
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 0;
  background: linear-gradient(180deg, rgba(9, 8, 15, 0.94) 65%, rgba(9, 8, 15, 0));
  overflow-x: auto;
  scrollbar-width: none;
}
.jump-links::-webkit-scrollbar { display: none; }
.jump-links a {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--muted);
  transition: border-color 0.16s var(--ease), color 0.16s var(--ease), background 0.16s var(--ease);
}
.jump-links a:hover { color: var(--text); border-color: rgba(196, 181, 253, 0.45); background: var(--surface-hover); }

.portal section, #plans-title, #membership-title { scroll-margin-top: 132px; }
.heading-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.status {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  color: #e4e6f5;
  padding: 5px 11px;
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.03em;
}
.status[data-tone="good"] { background: var(--good-bg); border-color: rgba(52, 211, 153, 0.35); color: var(--good); }
.status[data-tone="warn"] { background: var(--warn-bg); border-color: rgba(251, 191, 36, 0.35); color: var(--warn); }

.membership {
  background: linear-gradient(150deg, rgba(139, 92, 246, 0.14), var(--surface) 65%);
  border-color: rgba(196, 181, 253, 0.25);
}

.progress-wrap {
  display: grid;
  gap: 6px;
}
.progress-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--violet), var(--crimson-bright));
  width: 0%;
  transition: width 0.4s var(--ease);
}

/* Playlist Card & Summary */
.playlist-card-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(9, 8, 15, 0.55);
  display: grid;
  gap: 8px;
}
.playlist-meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

#playlist-current, #device-id { overflow-wrap: anywhere; }
.source-actions { margin: 0; gap: 8px; }
.source-actions .button { min-height: 42px; padding: 8px 14px; font-size: 0.88rem; }
.source-form { border-top: 1px solid var(--line); padding-top: 16px; }
.source-form .actions { margin-top: 4px; }

/* Smart Paste Helper */
.smart-paste {
  border: 1px dashed rgba(196, 181, 253, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(139, 92, 246, 0.07);
  display: grid;
  gap: 8px;
}
.smart-paste-title {
  font-size: 0.84rem;
  font-weight: 750;
  color: var(--accent);
}
.smart-paste-desc {
  font-size: 0.8rem;
  color: var(--muted);
}
.input-with-action {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.input-with-action input { flex: 1 1 auto; min-width: 0; }
.input-with-action .button { flex: none; min-height: 48px; padding: 0 14px; font-size: 0.85rem; }

/* Visual Segmented Source Switch */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: #0a0912;
  border: 1px solid var(--line);
}
.seg-btn {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}
.seg-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(229, 9, 20, 0.25), rgba(139, 92, 246, 0.28));
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(196, 181, 253, 0.35);
}

.advanced-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2px 14px;
  background: rgba(255, 255, 255, 0.02);
}
.advanced-details summary {
  min-height: 46px;
  font-size: 0.88rem;
  padding: 10px 0;
}
.advanced-inner {
  display: grid;
  gap: 12px;
  padding-bottom: 14px;
}

/* Diagnostics Card */
.diag-card {
  border: 1px solid rgba(52, 211, 153, 0.28);
  border-radius: 14px;
  padding: 14px;
  background: rgba(16, 185, 129, 0.06);
  display: grid;
  gap: 10px;
}
.diag-card[data-error="true"] {
  border-color: rgba(255, 123, 137, 0.38);
  background: rgba(229, 9, 20, 0.08);
}
.diag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 750;
  font-size: 0.92rem;
}
.diag-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  font-size: 0.84rem;
}
.diag-item { display: grid; gap: 2px; }
.diag-item span { color: var(--dim); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; }
.diag-item strong { color: var(--text); font-weight: 650; overflow-wrap: anywhere; }

.button.danger {
  border-color: rgba(255, 123, 137, 0.28);
  color: var(--danger);
  background: rgba(229, 9, 20, 0.06);
}
.button.danger:hover { background: rgba(229, 9, 20, 0.16); border-color: rgba(255, 123, 137, 0.45); }

.plans, .device { grid-column: 1 / -1; }
.plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.plan-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  min-height: 76px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #0c0b14;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease);
}
.plan-option:has(input:checked) {
  border-color: var(--accent);
  background: linear-gradient(145deg, rgba(139, 92, 246, 0.18), rgba(229, 9, 20, 0.09));
}
.plan-option input { accent-color: var(--violet); flex: none; width: 18px; height: 18px; margin: 0; }
.plan-option span { font-weight: 700; }
.plan-option span span { display: block; color: var(--muted); font-weight: 500; font-size: 0.9rem; margin-top: 2px; }

.payment-methods-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.payment-methods-label {
  font-size: 0.78rem;
  color: var(--dim);
  margin-right: 4px;
}
.pm-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(196, 181, 253, 0.22);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.pm-badge.active {
  border-color: rgba(139, 92, 246, 0.42);
  background: rgba(139, 92, 246, 0.12);
  color: var(--text);
}

.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px 20px;
  flex-wrap: wrap;
  width: 100%;
}
.device-mac-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.notice, .feedback:not(:empty) {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(52, 211, 153, 0.28);
  background: var(--good-bg);
  color: var(--good);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}
#payment-notice { margin-bottom: 16px; }
.feedback:empty { position: absolute; width: 1px; height: 1px; overflow: hidden; pointer-events: none; }
.tile { position: relative; }
.notice[data-info], .feedback[data-info] {
  border-color: rgba(196, 181, 253, 0.25);
  background: rgba(139, 92, 246, 0.1);
  color: var(--muted);
}
.notice[data-error], .feedback[data-error] {
  border-color: rgba(255, 123, 137, 0.35);
  background: var(--danger-bg);
  color: var(--danger);
}

.sr-only, .portal .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  border: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.portal-nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}
.portal-nav-links a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.portal-nav-links a:hover { color: var(--text); }

@media (max-width: 820px) {
  .pairing-layout, .dashboard-grid, .plan-grid, .overview-strip { grid-template-columns: 1fr; }
  .plan-option { min-height: 62px; }
  .plan-option span span { display: inline-block; margin-left: 8px; margin-top: 0; }
  .diag-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .input-with-action { flex-direction: column; }
  .source-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .source-actions .button { width: 100%; }
  .portal-nav-links a[href="/#faq"] { display: none; }
  .portal-nav-links { gap: 10px; }
  .portal-status-pill { font-size: 0.74rem; padding: 4px 10px; }
}
