:root {
  --bg: #0c2a38;
  --bg-card: #134155;
  --bg-card-2: #1a5168;
  --bg-elevated: #1f5f78;
  --text: #eef8fb;
  --text-muted: #a8d4e6;
  --text-dim: #7eb8cf;
  --accent: #4eb8d4;
  --accent-soft: #2f9bb8;
  --accent-glow: rgba(78, 184, 212, 0.32);
  --sea: #6ed4ea;
  --sea-deep: #1a7a96;
  --foam: rgba(180, 235, 255, 0.12);
  --green: #5fd4a4;
  --blue-badge: #5eb0e8;
  --danger: #e88b8b;
  --border: rgba(140, 210, 230, 0.22);
  --radius: 18px;
  --radius-sm: 14px;
  --nav-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(ellipse 110% 55% at 50% -5%, rgba(110, 212, 234, 0.28), transparent 58%),
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(47, 155, 184, 0.18), transparent 52%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(26, 122, 150, 0.2), transparent 50%),
    linear-gradient(180deg, #0f3345 0%, #0c2a38 100%);
}

.hidden { display: none !important; }

.app {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 16px 12px;
  background: rgba(12, 42, 56, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--sea);
}

.content {
  padding: 14px 16px 24px;
  position: relative;
  min-height: 50vh;
  will-change: transform, opacity;
}

.content.tab-out-left {
  animation: tabOutLeft 0.18s ease forwards;
}

.content.tab-out-right {
  animation: tabOutRight 0.18s ease forwards;
}

.content.tab-in-left {
  animation: tabInLeft 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.content.tab-in-right {
  animation: tabInRight 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-section {
  position: relative;
}

.anim-item {
  opacity: 0;
  transform: translateY(14px);
  animation: itemIn 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(0.04s + var(--i, 0) * 0.05s);
}

.topbar-title.title-shift {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.topbar-title.title-pop {
  animation: titlePop 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes tabOutLeft {
  to { opacity: 0; transform: translateX(-24px) scale(0.98); }
}

@keyframes tabOutRight {
  to { opacity: 0; transform: translateX(24px) scale(0.98); }
}

@keyframes tabInLeft {
  from { opacity: 0; transform: translateX(-28px) scale(0.98); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes tabInRight {
  from { opacity: 0; transform: translateX(28px) scale(0.98); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes itemIn {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes titlePop {
  0% { opacity: 0; transform: translateY(8px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Per-tab accent themes */
body[data-tab="profile"],
.app[data-tab="profile"] {
  --tab-accent: #6ed4ea;
  --tab-glow: rgba(110, 212, 234, 0.2);
}

body[data-tab="subscriptions"],
.app[data-tab="subscriptions"] {
  --tab-accent: #5fd4a4;
  --tab-glow: rgba(95, 212, 164, 0.22);
}

body[data-tab="devices"],
.app[data-tab="devices"] {
  --tab-accent: #8eb8ff;
  --tab-glow: rgba(142, 184, 255, 0.22);
}

body[data-tab="referrals"],
.app[data-tab="referrals"] {
  --tab-accent: #f5c87a;
  --tab-glow: rgba(245, 200, 122, 0.22);
}

body[data-tab="profile"] {
  background:
    radial-gradient(ellipse 110% 55% at 50% -5%, rgba(110, 212, 234, 0.3), transparent 58%),
    linear-gradient(180deg, #0f3345 0%, #0c2a38 100%);
}

body[data-tab="subscriptions"] {
  background:
    radial-gradient(ellipse 90% 50% at 80% 0%, rgba(95, 212, 164, 0.22), transparent 55%),
    linear-gradient(180deg, #0f3a42 0%, #0c2a38 100%);
}

body[data-tab="devices"] {
  background:
    radial-gradient(ellipse 80% 45% at 10% 10%, rgba(142, 184, 255, 0.2), transparent 52%),
    linear-gradient(180deg, #122a45 0%, #0c2a38 100%);
}

body[data-tab="referrals"] {
  background:
    radial-gradient(ellipse 85% 48% at 50% 0%, rgba(245, 200, 122, 0.18), transparent 55%),
    linear-gradient(180deg, #2a3040 0%, #0c2a38 100%);
}

.app[data-tab] .topbar-title {
  color: var(--tab-accent);
  transition: color 0.35s ease;
}

.app[data-tab] .topbar {
  box-shadow: inset 0 -1px 0 var(--border), 0 8px 24px var(--tab-glow);
  transition: box-shadow 0.35s ease;
}

.app[data-tab] .nav-item.active {
  color: var(--tab-accent);
}

.app[data-tab] .nav-item.active .nav-icon {
  background: var(--tab-glow);
  color: var(--tab-accent);
  transform: scale(1.06);
  transition: transform 0.2s ease, background 0.3s ease, color 0.3s ease;
}

.app[data-tab="subscriptions"] .btn-primary {
  background: linear-gradient(180deg, #5fd4a4 0%, #3db88a 100%);
  box-shadow: 0 10px 28px rgba(95, 212, 164, 0.28);
}

.app[data-tab="devices"] .device-dot {
  background: rgba(142, 184, 255, 0.2);
}

.app[data-tab="referrals"] .ref-balance-value {
  color: var(--tab-accent);
}

.section-title {
  margin: 18px 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.card {
  background: linear-gradient(155deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 20, 35, 0.18);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--foam), transparent 50%);
  pointer-events: none;
}

.stat-card .badge {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 10px;
  font-weight: 800;
  padding: 4px 9px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.badge-no {
  background: rgba(94, 176, 232, 0.2);
  color: #9ed0ff;
}

.badge-yes {
  background: rgba(95, 212, 164, 0.22);
  color: #b8f5d8;
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 17px;
}

.stat-icon.red { background: rgba(232, 139, 139, 0.18); }
.stat-icon.green { background: rgba(95, 212, 164, 0.18); }
.stat-icon.sea { background: rgba(78, 184, 212, 0.22); }

.stat-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 4px;
}

.stat-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: #fff;
  box-shadow: 0 10px 28px var(--accent-glow);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger-text {
  background: rgba(232, 139, 139, 0.1);
  color: #ffc7c7;
  border: 1px solid rgba(232, 139, 139, 0.28);
}

.btn-sm {
  width: auto;
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 10px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.info-row:last-child { border-bottom: none; }

.info-row span:last-child {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.plan-card {
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.plan-card:active {
  transform: scale(0.99);
}

.plan-card.selected {
  border-color: var(--sea);
  box-shadow: 0 0 0 1px rgba(110, 212, 234, 0.45), 0 12px 30px rgba(47, 155, 184, 0.22);
}

.plan-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.plan-title {
  font-size: 16px;
  font-weight: 700;
}

.plan-badge {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(95, 212, 164, 0.18);
  color: var(--green);
  white-space: nowrap;
}

.plan-price {
  font-size: 24px;
  font-weight: 800;
  color: var(--sea);
  margin: 10px 0 0;
}

.device-pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
}

.device-pill {
  min-width: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}

.device-pill.active {
  border-color: var(--sea);
  color: #fff;
  background: rgba(110, 212, 234, 0.24);
  box-shadow: 0 6px 18px rgba(47, 155, 184, 0.2);
}

.device-item {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.device-item:last-child { border-bottom: none; }

.device-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.device-dot {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(110, 212, 234, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.device-meta {
  min-width: 0;
}

.device-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.ref-balance-card {
  text-align: center;
  padding: 22px 16px;
}

.ref-balance-value {
  font-size: 36px;
  font-weight: 800;
  color: var(--green);
  margin: 6px 0;
}

.ref-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ref-link-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed var(--border);
  font-size: 12px;
  word-break: break-all;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-state p { margin: 8px 0 0; font-size: 14px; line-height: 1.5; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 42, 56, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 30;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  cursor: pointer;
}

.nav-item.active { color: var(--sea); }

.nav-item.active .nav-icon {
  background: rgba(110, 212, 234, 0.18);
  color: var(--sea);
}

.nav-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
}

.loader-screen, .denied-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(110, 212, 234, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

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

.denied-card {
  max-width: 320px;
  padding: 28px 22px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.denied-card .crab { font-size: 42px; margin-bottom: 8px; }

.denied-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.denied-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; }

body.sheet-open {
  overflow: hidden;
}

.pay-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 16, 24, 0.62);
  backdrop-filter: blur(4px);
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

.pay-sheet-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 201;
  padding: 12px 16px calc(20px + var(--safe-bottom));
  background: linear-gradient(180deg, #1a5168 0%, #134155 100%);
  border-top: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 40px rgba(0, 20, 35, 0.35);
  animation: sheetUp 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.pay-sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 0 auto 14px;
}

.pay-sheet-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--sea);
}

.pay-sheet-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.pay-method-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin-bottom: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.pay-method-btn:active {
  transform: scale(0.99);
  border-color: var(--sea);
  background: rgba(110, 212, 234, 0.12);
}

.pay-method-btn span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pay-method-btn small {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.pay-method-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(110, 212, 234, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
