:root {
  --bg: #0a0a0c;
  --surface: #16161c;
  --card: #1c1c26;
  --border: #2a2a36;
  --text: #f0f0f5;
  --muted: #8b8b9a;
  --accent: #e8c840;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --ring: rgba(59, 130, 246, 0.28);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 12px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 12px calc(72px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 6px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(180deg, rgba(10, 10, 12, 0.98), rgba(10, 10, 12, 0.75));
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.app-version {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.brand-icon {
  font-size: 1.4rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
}

.view {
  display: none;
  padding: 16px 0;
  animation: fade 0.2s ease;
}

.view.active {
  display: block;
}

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

.section-title {
  font-size: 0.95rem;
  margin: 8px 0 12px;
  font-weight: 600;
}

.view-head {
  margin-bottom: 8px;
}

.section-title.accent {
  color: var(--accent);
  margin-bottom: 4px;
}

.section-subtitle {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.card {
  background: linear-gradient(180deg, rgba(28, 28, 38, 0.92), rgba(21, 21, 30, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.card-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.card-title.accent {
  color: var(--accent);
}

.badge {
  display: inline-block;
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.badge-premium {
  color: var(--accent);
  background: rgba(232, 200, 64, 0.12);
}

.progress-wrap {
  margin-top: 8px;
}

.usage-card {
  padding-top: 12px;
}

.usage-layout {
  display: flex;
  align-items: center;
  gap: 14px;
}

.usage-ring {
  --deg: 0deg;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: conic-gradient(#4f8dff var(--deg), rgba(255, 255, 255, 0.1) 0deg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.usage-ring-inner {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.usage-legend {
  flex: 1;
  min-width: 0;
}

.usage-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  padding: 6px 0;
}

.usage-row b {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.usage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.usage-dot.used {
  background: #4f8dff;
}

.usage-dot.remaining {
  background: #22c55e;
}

.progress-bar {
  height: 10px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4f8dff, #7cb2ff);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.overview-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
}

.overview-k {
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 4px;
}

.overview-v {
  font-weight: 700;
  font-size: 0.94rem;
}

.metric-tile {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
}

.metric-k {
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 4px;
}

.metric-v {
  font-weight: 700;
  font-size: 0.95rem;
}

.sub-row {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.sub-row:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.sub-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.sub-meta {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.sub-valid {
  font-size: 0.78rem;
  color: var(--muted);
}

.sub-stats {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0;
  flex-wrap: wrap;
}

.sub-stats b {
  color: var(--text);
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  width: 100%;
}

.btn.primary {
  background: linear-gradient(180deg, #4e86ff, #2f6fee);
  color: #fff;
  margin-bottom: 10px;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.35);
}

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

.btn.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.btn.full {
  width: 100%;
}

a.btn {
  text-decoration: none;
  box-sizing: border-box;
}

.server-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: linear-gradient(180deg, rgba(28, 28, 38, 0.92), rgba(21, 21, 30, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  margin-bottom: 10px;
}

.server-region-card {
  background: linear-gradient(180deg, rgba(28, 28, 38, 0.92), rgba(21, 21, 30, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
}

.server-region-head {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  cursor: pointer;
}

.server-region-head::-webkit-details-marker {
  display: none;
}

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

.server-region-name {
  font-size: 1rem;
  font-weight: 600;
}

.server-region-count {
  color: var(--muted);
  font-size: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 2px 8px;
}

.server-region-body {
  padding: 0 12px 10px;
}

.region-server-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 11px 2px;
}

.server-crown {
  margin-left: 4px;
}

.server-ping {
  color: #22c55e;
  font-size: 0.85rem;
  white-space: nowrap;
}

.server-ping-muted {
  color: var(--muted);
}

.server-flag {
  font-size: 1.6rem;
  line-height: 1;
}

.server-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.server-name {
  font-weight: 500;
}

.server-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.server-pill {
  border: 1px solid rgba(232, 200, 64, 0.32);
  color: var(--accent);
  background: rgba(232, 200, 64, 0.08);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
}

.server-pill.muted {
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.package-card {
  background: linear-gradient(180deg, rgba(28, 28, 38, 0.95), rgba(21, 21, 30, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}

.package-price {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
}

.package-desc {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
}

.package-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.package-features {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--text);
}

.package-features li {
  padding: 4px 0;
  padding-left: 22px;
  position: relative;
}

.package-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: #4ade80;
}

.package-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.package-actions .btn {
  margin-bottom: 0;
}

.banner {
  background: linear-gradient(135deg, #1e3a5f, #162238);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.banner.hidden {
  display: none;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: min(100%, 760px);
  margin: 0 auto;
  display: flex;
  background: linear-gradient(180deg, rgba(22, 22, 28, 0.98), rgba(18, 18, 24, 0.98));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px 11px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.68rem;
  cursor: pointer;
}

.tab.active {
  color: #77a7ff;
}

.tab-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 28, 38, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  max-width: 90%;
  z-index: 30;
}

.toast.hidden {
  display: none;
}

.onboarding-strip {
  padding: 0 0 6px;
}

.onboarding-strip .onboard-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.onboarding-strip .onboard-card p {
  margin: 0 0 6px;
}

.onboarding-strip .onboard-card p:last-child {
  margin-bottom: 0;
}

.redeem-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.redeem-row .btn {
  margin-bottom: 0;
  width: auto;
  min-width: 120px;
}

.input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
}

.input:focus {
  border-color: rgba(109, 99, 255, 0.85);
  box-shadow: 0 0 0 3px rgba(109, 99, 255, 0.18);
}

.input::placeholder {
  color: var(--muted);
}

.empty-card {
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  #app {
    width: 100%;
    padding: 0 10px calc(72px + var(--safe-bottom));
  }

  .tabbar {
    width: 100%;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .overview-grid {
    grid-template-columns: 1fr;
  }

  .redeem-row {
    flex-direction: column;
    align-items: stretch;
  }

  .redeem-row .btn {
    width: 100%;
    min-width: 0;
  }

  .package-actions {
    grid-template-columns: 1fr;
  }

  .usage-layout {
    flex-direction: column;
    align-items: flex-start;
  }
}
