:root {
  color-scheme: dark;
  --background: #111114;
  --surface: #1a1a1f;
  --surface-light: #2a2a2e;
  --primary: #d7263d;
  --primary-hover: #e63c52;
  --primary-border: #c51f37;
  --white: #fff;
  --gray-100: #cfcfd2;
  --gray-300: #9b9b9f;
  --gray-500: #6d6d73;
  --border: rgba(255, 255, 255, 0.05);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

img,
video {
  max-width: 100%;
}

html {
  min-height: 100%;
  background: var(--background);
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--white);
  background: var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
a,
select {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  border: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 2px solid #ff5268;
  outline-offset: 3px;
}

button:active,
a:active {
  transform: scale(0.985);
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 390px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

.home-shell {
  display: grid;
  gap: 16px;
}

.topbar {
  min-height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.top-control,
.close-button {
  width: max-content;
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #2a2a2f;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 180ms ease, transform 140ms ease;
}

.top-control:hover,
.close-button:hover {
  background: #333338;
}

.control-icon {
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.brand {
  min-width: 154px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px 0 10px;
  border-radius: 22px;
  color: #ff3654;
  background: #5e1823;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  object-fit: cover;
}

.support-link-wrap {
  position: relative;
  justify-self: end;
  width: 44px;
  height: 44px;
  isolation: isolate;
}

.support-video-button {
  position: relative;
  z-index: 1;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(215, 38, 61, 0.52);
  border-radius: 50%;
  background: #241b1f;
  transition: border-color 180ms ease, transform 140ms ease;
}

.support-video-button:hover {
  border-color: var(--primary-hover);
}

.support-video-button video {
  width: 58px;
  height: 58px;
  display: block;
  object-fit: contain;
  mix-blend-mode: screen;
}

.support-dot {
  position: absolute;
  right: 1px;
  bottom: 3px;
  z-index: 3;
  width: 10px;
  height: 10px;
  border: 2px solid var(--background);
  border-radius: 50%;
  background: #67d991;
}

.profile-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.profile-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar,
.profile-brand-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar {
  display: grid;
  place-items: center;
  color: #1b1518;
  background: linear-gradient(145deg, #a5f05c, #42cf72);
  font-size: 20px;
  font-weight: 700;
}

.profile-brand-avatar {
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.profile-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.profile-copy strong {
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy span {
  color: var(--gray-300);
  font-size: 13px;
}

.app-card {
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.days-card {
  min-height: 190px;
  padding: 24px 20px 20px;
}

.days-label {
  display: block;
  color: #a4a4aa;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
}

.days-value-row {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.subscription-sticker {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  overflow: visible;
}

.subscription-sticker video {
  width: 80px;
  height: 80px;
  object-fit: contain;
  mix-blend-mode: screen;
}

.days-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.days-line strong {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.days-line span {
  font-size: 28px;
  font-weight: 750;
}

.days-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.large-action,
.primary-action,
.action-button {
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 22px;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease, transform 140ms ease;
}

.outline-action {
  color: #ff3654;
  border: 2px solid var(--primary-border);
  background: transparent;
}

.outline-action:hover {
  color: var(--white);
  border-color: var(--primary-hover);
  background: rgba(215, 38, 61, 0.1);
}

.filled-action {
  color: var(--white);
  background: var(--surface-light);
}

.filled-action:hover {
  background: #343439;
}

.key-card {
  min-height: 110px;
  padding: 18px 20px;
}

.card-toggle {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.key-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 650;
}

.key-heading small {
  color: var(--gray-300);
  font-size: 13px;
  font-weight: 400;
}

.key-sticker-video {
  width: 28px;
  height: 28px;
  object-fit: contain;
  mix-blend-mode: screen;
}

.chevron {
  color: var(--gray-300);
  font-size: 24px;
  transition: transform 180ms ease;
}

.card-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.key-line {
  min-height: 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
}

.key-line strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-days {
  color: var(--gray-300);
  font-size: 13px;
}

.status {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 15px;
  border-radius: 18px;
  color: var(--gray-100);
  background: #4a4a4f;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.status::before {
  margin-right: 6px;
  color: #b8b8bd;
  content: "•";
}

.status.inactive {
  color: var(--gray-300);
}

.collapsible {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 220ms ease, opacity 180ms ease;
}

.collapsible.open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.key-details-inner {
  min-height: 0;
  overflow: hidden;
}

.copy-row {
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 0 5px 0 14px;
  border-radius: 16px;
  background: var(--surface-light);
}

.copy-row code {
  overflow: hidden;
  color: var(--gray-100);
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-copy {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  color: #ff5268;
  background: rgba(215, 38, 61, 0.12);
  cursor: pointer;
}

.add-device-action {
  width: 100%;
  margin-top: 10px;
}

.primary-action {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--primary-border);
  border-radius: 24px;
  color: var(--white);
  background: var(--primary);
  font-size: 20px;
  font-weight: 750;
  box-shadow: 0 8px 24px rgba(215, 38, 61, 0.16);
}

.primary-action:hover {
  background: var(--primary-hover);
}

.primary-action:disabled {
  color: #bdbdc0;
  background: #5a2930;
  cursor: wait;
}

.primary-key {
  position: relative;
  color: #ff5268;
  font-size: 17px;
}

.primary-action .primary-key {
  color: var(--white);
}

.referral-card {
  min-height: 220px;
  padding: 12px 20px 20px;
  text-align: center;
}

.referral-sticker {
  height: 122px;
  display: grid;
  place-items: center;
  overflow: visible;
}

.referral-sticker video {
  width: 118px;
  height: 118px;
  object-fit: contain;
  mix-blend-mode: screen;
}

.referral-card > p {
  margin: 0 0 16px;
  color: var(--gray-100);
  font-size: 16px;
  line-height: 1.4;
}

.ref-stats {
  height: 72px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  margin-bottom: 16px;
  border-radius: 20px;
  background: #2b2b31;
}

.ref-stats > div {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 0 8px;
}

.ref-stats > div + div {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.ref-stats b {
  font-size: 30px;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ref-stats span {
  color: var(--gray-300);
  font-size: 12px;
}

.referral-copy {
  width: 100%;
}

.hidden-copy {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Device selection */
.flow-shell,
.instruction-shell,
.history-shell,
.payment-shell {
  padding-top: max(18px, env(safe-area-inset-top));
}

.flow-topbar {
  position: relative;
  margin-bottom: 52px;
}

.back-control {
  justify-self: start;
}

.back-control > span:first-child {
  font-size: 29px;
  font-weight: 300;
  line-height: 1;
}

.menu-control {
  justify-self: end;
  letter-spacing: 2px;
}

.header-sticker {
  width: 126px;
  height: 126px;
  display: grid;
  place-items: center;
  justify-self: center;
  margin-top: 48px;
  overflow: visible;
}

.header-sticker video {
  width: 154px;
  height: 154px;
  object-fit: contain;
  mix-blend-mode: screen;
}

.device-picker h1 {
  max-width: 310px;
  margin: 0 auto 56px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-align: center;
  text-wrap: balance;
}

.device-option-list {
  display: grid;
  gap: 12px;
}

.device-option {
  width: 100%;
  height: 76px;
  display: grid;
  grid-template-columns: 28px 1fr 24px;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 24px;
  color: var(--white);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.device-option.active {
  border: 2px solid var(--primary);
  color: #ff5268;
  background: rgba(215, 38, 61, 0.08);
}

.device-option b {
  font-size: 18px;
  font-weight: 600;
}

.device-option i {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
}

.device-option.active i {
  border: 6px solid rgba(215, 38, 61, 0.24);
  background: var(--primary);
}

.device-icon {
  font-size: 22px;
  text-align: center;
}

.flow-next {
  margin-top: 18px;
}

/* Instruction */
.simple-topbar {
  margin-bottom: 24px;
}

.flow-caption {
  color: var(--gray-300);
  font-size: 14px;
  text-align: center;
}

.page-title {
  margin: 0 0 18px;
  font-size: 32px;
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-align: center;
}

.setup-link-card {
  padding: 22px 20px;
  text-align: center;
}

.setup-link-card p {
  margin: 0 0 16px;
  color: var(--gray-300);
  font-size: 14px;
}

.setup-link-card code {
  width: 100%;
  height: 54px;
  display: flex;
  align-items: center;
  overflow: hidden;
  margin-bottom: 18px;
  padding: 0 16px;
  border-radius: 18px;
  color: var(--white);
  background: var(--surface-light);
  font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setup-link-card .large-action {
  width: 100%;
}

.instructions-card {
  margin-top: 16px;
  padding: 20px;
}

.instruction-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.instruction-title-row h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.instruction-title-row select {
  height: 44px;
  max-width: 132px;
  padding: 0 32px 0 14px;
  border: 0;
  border-radius: 18px;
  color: var(--white);
  background: var(--surface-light);
  font-size: 14px;
  font-weight: 600;
}

.client-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.client-button {
  min-width: 0;
  height: 56px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  color: var(--gray-100);
  background: #202026;
  cursor: pointer;
}

.client-button.active {
  color: #ff5268;
  border: 2px solid var(--primary);
  background: rgba(215, 38, 61, 0.08);
}

.client-check,
.client-copy small {
  display: none;
}

.client-copy b {
  overflow: hidden;
  display: block;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.steps {
  display: grid;
  gap: 12px;
}

.step {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  padding: 18px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: #1e1e23;
}

.step-number {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--primary);
  border-radius: 50%;
  color: #ff5268;
  font-size: 14px;
}

.step-body h3 {
  margin: 5px 0 8px;
  font-size: 16px;
  font-weight: 650;
}

.step-body p {
  margin: 0;
  color: var(--gray-300);
  font-size: 14px;
  line-height: 1.45;
}

.step-action {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  padding: 0 12px;
  border: 1px solid var(--primary);
  border-radius: 18px;
  color: #ff5268;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}

/* Payment and device purchase */
.payment-shell .topbar {
  margin-bottom: 24px;
}

.payment-shell .topbar .brand {
  grid-column: 2;
}

.payment-step {
  text-align: center;
}

.payment-sticker {
  height: 136px;
  display: grid;
  place-items: center;
}

.payment-sticker video {
  width: 154px;
  height: 154px;
  object-fit: contain;
  mix-blend-mode: screen;
}

.payment-step h1 {
  max-width: 310px;
  margin: 6px auto 30px;
  font-size: 30px;
  line-height: 1.08;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.plan-list {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.plan-option {
  width: 100%;
  height: 72px;
  display: grid;
  grid-template-columns: 26px 1fr auto 22px;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 24px;
  color: var(--white);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.plan-option.active {
  border: 2px solid var(--primary);
  color: #ff5268;
  background: rgba(215, 38, 61, 0.08);
}

.plan-option b,
.plan-option strong {
  font-size: 16px;
  font-weight: 600;
}

.plan-option strong {
  color: var(--white);
  font-variant-numeric: tabular-nums;
}

.plan-option i {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
}

.plan-option.active i {
  border: 6px solid rgba(215, 38, 61, 0.24);
  background: var(--primary);
}

.payment-submit {
  margin-top: 4px;
}

.payment-check {
  width: 100%;
  margin-top: 10px;
  color: var(--gray-100);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--surface-light);
}

.payment-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--gray-300);
  font-size: 13px;
}

.payment-status[data-tone="success"] {
  color: #72d49b;
}

.payment-status[data-tone="error"] {
  color: #ff7788;
}

.device-purchase-card {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 18px;
  padding: 0 20px;
  border: 2px solid var(--primary-border);
  border-radius: 24px;
  background: var(--surface);
}

.device-purchase-card span {
  color: var(--gray-100);
  font-weight: 600;
}

.device-purchase-card strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

/* History */
.compact-brand {
  min-width: 142px;
  font-size: 16px;
}

.topbar-spacer {
  width: 44px;
  justify-self: end;
}

.history-heading {
  margin: 18px 0 24px;
}

.history-heading span {
  color: #ff5268;
  font-size: 14px;
  font-weight: 600;
}

.history-heading h1 {
  margin: 6px 0 0;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-state {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  text-align: center;
}

.history-state b {
  font-size: 18px;
}

.history-state p {
  max-width: 250px;
  margin: 8px 0 0;
  color: var(--gray-300);
  font-size: 14px;
  line-height: 1.4;
}

.history-state button {
  min-height: 44px;
  margin-top: 16px;
  padding: 0 20px;
  border-radius: 18px;
  color: var(--white);
  background: var(--primary);
}

.history-loader {
  width: 30px;
  height: 30px;
  margin-bottom: 14px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.history-entry {
  min-height: 96px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
}

.history-entry-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.history-entry-main b {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entry-main span {
  color: var(--gray-300);
  font-size: 13px;
}

.history-entry-side {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.history-entry-side strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.history-badge {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 15px;
  color: var(--gray-100);
  background: var(--surface-light);
  font-size: 12px;
  font-weight: 600;
}

.history-badge[data-tone="success"] {
  color: #8ae3ae;
  background: rgba(82, 168, 116, 0.15);
}

.history-badge[data-tone="error"] {
  color: #ff8d9b;
  background: rgba(215, 38, 61, 0.13);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 20;
  padding: 12px 18px;
  border-radius: 18px;
  color: var(--white);
  background: #323238;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 370px) {
  .app-shell { padding-right: 14px; padding-left: 14px; }
  .brand { min-width: 138px; font-size: 16px; }
  .close-button { padding: 0 11px; }
  .days-card { padding-right: 14px; padding-left: 14px; }
  .days-line strong { font-size: 50px; }
  .large-action { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
