:root {
  --bg: #0b0e13;
  --bg-elev: #12171f;
  --bg-panel: #161c27;
  --border: #243044;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #5b8cff;
  --accent-dim: #3d5fad;
  --good: #3dd68c;
  --warn: #f5a524;
  --danger: #f04444;
  --overlay: rgba(0, 0, 0, 0.55);
  --safe: rgba(91, 140, 255, 0.18);
  --safe-border: rgba(91, 140, 255, 0.55);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand img { width: 28px; height: 28px; }
.brand span { font-size: 1.1rem; }
.brand .tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--bg-panel);
}
.badge.unlocked {
  color: var(--good);
  border-color: rgba(61, 214, 140, 0.4);
  background: rgba(61, 214, 140, 0.08);
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr 260px;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 64px);
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.panel + .panel { margin-top: 0.75rem; }
.sidebar .panel { margin-bottom: 0.75rem; }
.sidebar .panel:last-child { margin-bottom: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #1c2433; border-color: #35507a; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e13;
}
.btn-primary:hover { background: #7aa3ff; border-color: #7aa3ff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; display: block; text-align: center; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.06);
  color: var(--text);
}
.upload-zone input { display: none; }
.upload-zone strong { display: block; color: var(--text); margin-bottom: 0.25rem; }
.file-name {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.device-list { display: flex; flex-direction: column; gap: 0.35rem; max-height: 320px; overflow-y: auto; }
.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-elev);
  cursor: pointer;
  font-size: 0.88rem;
}
.device-item:hover { border-color: var(--border); }
.device-item.active {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.1);
}
.device-item.locked { opacity: 0.7; }
.device-item .lock-icon { font-size: 0.75rem; color: var(--warn); }

.controls { display: flex; flex-direction: column; gap: 0.75rem; }
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.control-row label { flex: 1; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.toggle input { accent-color: var(--accent); }

.preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.preview-stage {
  position: relative;
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.phone-frame {
  position: relative;
  border-radius: 36px;
  border: 3px solid #2a3548;
  box-shadow: 0 0 0 2px #1a2230, 0 20px 50px rgba(0,0,0,0.55);
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
}
.wallpaper-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}
.wallpaper-layer.dragging { cursor: grabbing; }
.wallpaper-layer img {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  max-width: none;
  pointer-events: none;
  user-select: none;
}
.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.overlay-svg { width: 100%; height: 100%; display: block; }
.safe-guide {
  position: absolute;
  border: 1.5px dashed var(--safe-border);
  background: var(--safe);
  border-radius: 8px;
  pointer-events: none;
  z-index: 4;
}
.placeholder-hint {
  color: var(--muted);
  text-align: center;
  padding: 2rem;
  max-width: 260px;
  font-size: 0.95rem;
}
.hint-bar {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.ad-slot {
  border: 1px dashed #3a4a66;
  background: rgba(36, 48, 68, 0.4);
  border-radius: 8px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}
.ad-slot[hidden], .ads-hidden .ad-slot { display: none !important; }

.export-opts { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }

footer.app-footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(420px, 100%);
  padding: 1.35rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal h3 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.modal p { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; }
.modal input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  margin-bottom: 0.75rem;
}
.modal input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.modal-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.modal-msg {
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
  min-height: 1.2em;
}
.modal-msg.error { color: var(--danger); }
.modal-msg.ok { color: var(--good); }
.checkout-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2433;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast[hidden] { display: none; }

.cross-promo {
  margin: .55rem 0 0;
  padding: .55rem .5rem .1rem;
  border-top: 1px solid color-mix(in srgb, var(--muted) 35%, transparent);
  font-size: .78rem;
  color: var(--muted);
}
.cross-promo-intro { margin: 0 0 .35rem; }
.cross-promo-hub { margin: 0 0 .35rem; }
.cross-promo-hub a, .cross-promo-list a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.cross-promo-hub a:hover, .cross-promo-list a:hover { color: var(--text); }
.cross-promo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.cross-promo-list .cross-buy { font-weight: 600; color: var(--accent, var(--text)); }

/* Louder Unlock / Buy CTAs (conversion) */
.btn.unlock-cta {
  font-weight: 800;
  font-size: 0.98rem;
  min-height: 44px;
  padding: 0.7rem 1.15rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.12) inset;
  letter-spacing: 0.01em;
  text-decoration: none;
}
.header-actions .btn.unlock-cta {
  white-space: nowrap;
}
.free-note {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(91, 140, 255, 0.08);
  font-size: 0.85rem;
  color: var(--muted);
}
.free-note strong { color: var(--text); }
.free-note-cta {
  display: flex;
  margin-top: 0.65rem;
}
.free-note-cta .btn.unlock-cta {
  width: 100%;
}
.unlock-inline {
  margin-bottom: 0.55rem;
}
.unlock-inline[hidden] { display: none !important; }
.soft-path {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.checkout-hint {
  font-size: 0.85rem;
  color: var(--warn);
  margin: 0 0 0.75rem;
}
.checkout-hint.soft { color: var(--muted); }
.footer-unlock-btn,
.footer-buy-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.app-footer .btn.unlock-cta {
  min-height: 44px;
}
.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem 1rem;
}
.tiny {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Unlock modal mobile */
.modal-backdrop {
  align-items: end;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
@media (min-width: 520px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  max-height: min(92vh, 720px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  width: min(420px, 100%);
  margin-bottom: 0;
}
.modal #checkoutLink,
.modal #btnRedeem {
  min-height: 48px;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}
.modal input[type="text"] {
  min-height: 44px;
  font-size: 16px; /* avoid iOS zoom */
  width: 100%;
  box-sizing: border-box;
}

/* Slim sticky Unlock bar (free tier only) */
.sticky-unlock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.55rem 0.85rem;
  padding-bottom: max(0.55rem, env(safe-area-inset-bottom));
  background: rgba(12,14,20,.94);
  border-top: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  box-shadow: 0 -8px 28px rgba(0,0,0,.35);
}
.sticky-unlock[hidden] { display: none !important; }
.sticky-unlock-copy {
  font-size: 0.82rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.sticky-unlock .btn.unlock-cta {
  flex-shrink: 0;
  min-height: 44px;
}
body.has-sticky-unlock {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
body.has-sticky-unlock .toast {
  bottom: calc(4.5rem + env(safe-area-inset-bottom));
}
@media (max-width: 420px) {
  .brand .tag { display: none; }
  .sticky-unlock-copy { font-size: 0.75rem; }
}
