/* Plans & payments screen (public/plans.js). Uses the app's CSS variables from index.html. */

/* Entry points */
#plans-btn {
  width: 100%;
  margin-top: 2px;
  font-weight: 700;
  font-size: 11.5px;
  color: #fde68a;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.2), rgba(236, 72, 153, 0.18));
  border-color: rgba(251, 191, 36, 0.45);
}
#plans-btn:hover:not(:disabled) { background: linear-gradient(90deg, rgba(245, 158, 11, 0.32), rgba(236, 72, 153, 0.28)); border-color: rgba(251, 191, 36, 0.7); }
#plans-btn.is-paid { color: #e2e8f0; background: var(--bg-surface); border-color: var(--border-glass); font-weight: 600; }
#paint-more {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(16, 185, 129, 0.22));
  border-color: rgba(56, 189, 248, 0.5);
}
#paint-more[hidden] { display: none; }
.px-icon, .px-svg { display: inline-grid; place-items: center; flex: none; line-height: 0; image-rendering: pixelated; }
#plans-btn .px-svg, #project-calc .px-svg { width: 13px; height: 13px; }
#paint-more .px-svg { width: 14px; height: 14px; }
.plans-x .px-svg { width: 12px; height: 12px; }
#plan { cursor: pointer; }
#plan[data-plan="premium"] { color: #bae6fd; background: rgba(56, 189, 248, 0.22); }
#plan[data-plan="patron"] { color: #1c1404; background: linear-gradient(90deg, #fcd34d, #f59e0b); box-shadow: 0 0 8px rgba(251, 191, 36, 0.55); }

/* Dialog */
#plans {
  position: fixed;
  width: min(980px, 96vw);
  max-height: 94vh;
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--text-main, #f8fafc);
  background: radial-gradient(120% 80% at 50% -10%, #1e3a8a 0%, #0f172a 52%, #020617 100%);
  box-shadow: 0 30px 80px -10px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(148, 163, 184, 0.2);
  overflow: hidden auto;
  overscroll-behavior: contain;
}
#plans[open] { animation: plans-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
#plans::backdrop { background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(3px); }
@keyframes plans-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } }

/* A drifting field of pixels behind the header: the planet being painted. */
.plans-sky {
  position: absolute;
  inset: 0 0 auto 0;
  height: 260px;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    radial-gradient(4px 4px at 12% 30%, #f472b6 99%, transparent),
    radial-gradient(4px 4px at 22% 62%, #38bdf8 99%, transparent),
    radial-gradient(4px 4px at 35% 18%, #fde047 99%, transparent),
    radial-gradient(4px 4px at 64% 40%, #34d399 99%, transparent),
    radial-gradient(4px 4px at 78% 22%, #a78bfa 99%, transparent),
    radial-gradient(4px 4px at 88% 58%, #fb923c 99%, transparent),
    radial-gradient(4px 4px at 50% 70%, #f87171 99%, transparent);
  background-size: 16px 16px, 16px 16px, auto, auto, auto, auto, auto, auto, auto;
  -webkit-mask-image: linear-gradient(#000, transparent);
  mask-image: linear-gradient(#000, transparent);
  animation: plans-drift 24s linear infinite;
}
@keyframes plans-drift { to { background-position: 0 160px, 160px 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; } }
@media (prefers-reduced-motion: reduce) { .plans-sky, #plans[open] { animation: none; } }

.plans-x {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  outline: none;
}
.plans-x:focus-visible { box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.45); }
.plans-head { position: relative; text-align: center; padding: 28px 24px 8px; }
.plans-kicker { font-size: 11px; font-weight: 800; letter-spacing: 0.22em; color: #7dd3fc; }
#plans-test { margin-left: 6px; padding: 1px 6px; border-radius: 999px; letter-spacing: 0.08em; color: #1c1404; background: #fbbf24; }
.plans-head h2 {
  margin: 8px 0 6px;
  font-size: clamp(22px, 4vw, 32px);
  line-height: 1.15;
  background: linear-gradient(90deg, #f8fafc, #bae6fd 45%, #fde68a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.plans-head p { margin: 0 auto; max-width: 520px; color: #cbd5e1; font-size: 14px; line-height: 1.45; }

.plans-toggle {
  display: inline-flex;
  gap: 2px;
  margin-top: 16px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.25);
}
.plans-toggle button { border: 0; border-radius: 999px; padding: 6px 14px; background: transparent; font-weight: 600; font-size: 13px; color: #cbd5e1; }
.plans-toggle button[aria-checked="true"] { background: #f8fafc; color: #0f172a; }
.plans-save { font-style: normal; font-size: 10.5px; font-weight: 800; padding: 1px 6px; border-radius: 999px; color: #064e3b; background: #6ee7b7; }

.plans-status { position: relative; margin: 10px 24px 0; padding: 10px 14px; border-radius: 12px; text-align: center; font-weight: 600; background: rgba(56, 189, 248, 0.14); border: 1px solid rgba(56, 189, 248, 0.35); }
.plans-status.is-success { background: rgba(16, 185, 129, 0.16); border-color: rgba(52, 211, 153, 0.5); color: #d1fae5; }
.plans-status.is-warn { background: rgba(245, 158, 11, 0.14); border-color: rgba(251, 191, 36, 0.45); color: #fef3c7; }
.plans-status strong { display: block; font-size: 18px; margin-bottom: 2px; }

/* Cards */
.plans-grid { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 20px 24px 6px; align-items: stretch; }
.plan-card {
  --tint: 148, 163, 184;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 18px 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(var(--tint), 0.1), rgba(15, 23, 42, 0.85) 45%);
  border: 1px solid rgba(var(--tint), 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.plan-card:hover { transform: translateY(-3px); box-shadow: 0 18px 40px -18px rgba(var(--tint), 0.6); }
.plan-card[data-plan="premium"] { --tint: 56, 189, 248; border-width: 2px; box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25), 0 20px 50px -20px rgba(56, 189, 248, 0.7); }
.plan-card[data-plan="patron"] { --tint: 251, 191, 36; }
.plan-card[data-plan="patron"]::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, #fde68a, #f59e0b, #ec4899, #fde68a);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.plan-card.is-current { outline: 2px solid rgba(52, 211, 153, 0.7); outline-offset: 2px; }
.plan-ribbon { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: 0.04em; color: #082f49; background: linear-gradient(90deg, #7dd3fc, #38bdf8); }
.plan-card.is-current .plan-ribbon { color: #022c22; background: linear-gradient(90deg, #6ee7b7, #34d399); }

.plan-top { display: flex; align-items: center; gap: 11px; }
.plan-icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 10px; background: rgba(var(--tint), 0.16); border: 1px solid rgba(var(--tint), 0.35); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.plan-icon .px-svg { width: 32px; height: 32px; filter: drop-shadow(0 2px 0 rgba(2, 6, 23, 0.55)); }
.plan-name { margin: 0; font-size: 18px; font-weight: 800; }
.plan-tag { margin: 0; font-size: 12px; color: #94a3b8; }
.plan-price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; min-height: 54px; }
.plan-amount { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.plan-per { color: #94a3b8; font-size: 13px; }
.plan-sub { flex-basis: 100%; font-size: 12px; color: #6ee7b7; font-weight: 600; }

.plan-perks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; line-height: 1.35; flex: 1; }
.plan-perks li { display: flex; gap: 8px; align-items: flex-start; }
.plan-check { flex: none; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 4px; color: #0f172a; background: rgb(var(--tint)); margin-top: 1px; }
.plan-check .px-svg { width: 11px; height: 11px; }
.plan-x { margin-left: auto; flex: none; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 800; color: rgb(var(--tint)); background: rgba(var(--tint), 0.15); }

.plan-cta { width: 100%; padding: 10px 12px; border-radius: 12px; font-size: 14px; font-weight: 800; }
.plan-card[data-plan="premium"] .plan-cta:not(:disabled) { color: #082f49; border-color: transparent; background: linear-gradient(90deg, #7dd3fc, #38bdf8); }
.plan-card[data-plan="premium"] .plan-cta:hover:not(:disabled) { background: linear-gradient(90deg, #bae6fd, #7dd3fc); }
.plan-card[data-plan="patron"] .plan-cta:not(:disabled) { color: #1c1404; border-color: transparent; background: linear-gradient(90deg, #fde68a, #f59e0b); }
.plan-card[data-plan="patron"] .plan-cta:hover:not(:disabled) { background: linear-gradient(90deg, #fef3c7, #fbbf24); }
.plan-cta.is-manage:not(:disabled) { color: var(--text-main, #f8fafc) !important; background: var(--bg-surface, #1e293b) !important; border-color: rgba(148, 163, 184, 0.45) !important; }
.plan-note { margin: -4px 0 0; font-size: 11.5px; text-align: center; color: #94a3b8; min-height: 1em; }
.plan-note.is-warn { color: #fca5a5; }

.plans-msg { margin: 8px 24px 0; min-height: 1.2em; text-align: center; font-size: 13px; color: #fca5a5; }
.plans-foot { display: grid; gap: 4px; padding: 10px 24px 22px; text-align: center; font-size: 11.5px; color: #64748b; }
#plans-test-card { color: #fcd34d; }

/* Pixel confetti after a successful checkout */
.plans-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.plans-confetti i { position: absolute; top: -10px; width: 8px; height: 8px; animation: plans-fall 2.4s cubic-bezier(0.3, 0.6, 0.6, 1) forwards; }
@keyframes plans-fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); opacity: 0.2; } }

@media (max-width: 760px) {
  #plans { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .plans-grid { grid-template-columns: 1fr; padding: 18px 14px 4px; gap: 18px; }
  .plans-head { padding: 22px 16px 4px; }
  .plan-card[data-plan="premium"] { order: -1; }
}
