:root {
  --bg: #05010f;
  --cherry: #ff2d6a;
  --cyan: #00e5ff;
  --purple: #b24dff;
  --text: #f5f0ff;
  --muted: rgba(245, 240, 255, 0.65);
  --glass: rgba(10, 4, 24, 0.82);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  touch-action: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.hidden { opacity: 0 !important; pointer-events: none !important; visibility: hidden; }
.nameplates { position: fixed; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; }
.nameplate {
  position: absolute; transform: translate(-50%, -100%);
  padding: 2px 8px; border-radius: 8px;
  background: rgba(0,0,0,0.55); border: 1px solid rgba(255,45,106,0.35);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  color: #fff; text-shadow: 0 0 8px rgba(0,0,0,0.8);
}
.canvas-wrap { position: fixed; inset: 0; z-index: 1; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }

.landing {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  padding: 20px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 70% 50% at 50% 20%, rgba(178,77,255,0.2), transparent 55%),
    radial-gradient(ellipse 50% 40% at 80% 80%, rgba(0,229,255,0.1), transparent 50%),
    var(--bg);
  transition: opacity 0.6s ease;
}
.landing__glow {
  position: absolute; width: min(90vw, 420px); height: min(90vw, 420px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,45,106,0.28), transparent 70%);
  filter: blur(40px); animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.12); opacity: 1; }
}
.landing__card {
  position: relative; width: min(94vw, 440px);
  padding: 1.7rem 1.35rem 1.25rem;
  background: var(--glass); border: 1px solid rgba(178,77,255,0.4);
  border-radius: 22px; backdrop-filter: blur(16px);
  box-shadow: 0 0 40px rgba(255,45,106,0.15);
  text-align: center;
}
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  background: linear-gradient(135deg, var(--cherry), var(--purple));
  margin-bottom: 0.6rem;
}
.landing__tag { font-size: 0.72rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--cyan); }
.landing__logo {
  font-family: Orbitron, sans-serif; font-weight: 900;
  font-size: clamp(2rem, 10vw, 2.8rem); letter-spacing: 0.12em;
  background: linear-gradient(120deg, #fff, var(--cherry), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin: 0.3rem 0;
}
.landing__sub {
  font-size: 1rem; color: var(--text); line-height: 1.4;
  margin-bottom: 0.9rem; opacity: 0.9;
}

.template-picker {
  text-align: left;
  margin-bottom: 0.95rem;
  padding: 0.7rem 0.75rem 0.75rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(178, 77, 255, 0.28);
}
.template-picker__head {
  margin-bottom: 0.55rem;
}
.template-picker__label {
  font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
}
.template-picker__grid {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tpl-btn {
  appearance: none; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-family: Inter, system-ui, sans-serif;
  font-size: 0.7rem; font-weight: 600;
  padding: 0.38rem 0.55rem; border-radius: 999px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  touch-action: manipulation;
}
.tpl-btn:hover {
  border-color: rgba(0, 229, 255, 0.45);
  color: var(--text);
}
.tpl-btn.is-active {
  border-color: rgba(255, 45, 106, 0.75);
  background: rgba(255, 45, 106, 0.18);
  color: #fff;
  box-shadow: 0 0 12px rgba(255, 45, 106, 0.25);
}
.tpl-btn:disabled,
.tpl-btn.is-off {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}
.engine-picker { margin-bottom: 0.7rem; }

.dropzone {
  border: 1.5px dashed rgba(0,229,255,0.4);
  border-radius: 16px; padding: 1.4rem 1rem;
  background: rgba(0,0,0,0.3); cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 0.9rem;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--cherry);
  background: rgba(255,45,106,0.08);
}
.dropzone__icon { font-size: 2rem; color: var(--cyan); margin-bottom: 0.3rem; }
.dropzone__title { font-weight: 600; margin-bottom: 0.25rem; }
.dropzone__hint { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.8rem; }

.field { display: block; text-align: left; margin: 0 0 0.7rem; }
.field span {
  display: block; font-size: 0.68rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 0.3rem;
}
.field input {
  width: 100%; padding: 0.65rem 0.8rem; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.4); color: #fff;
  font-size: 0.95rem; font-family: inherit; outline: none;
  touch-action: manipulation; user-select: text;
}
.field input:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(0,229,255,0.2); }

.mp-block { margin: 0.15rem 0 0.85rem; }
.mp-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 0.72rem; margin: 0.65rem 0 0.5rem;
}
.mp-divider::before, .mp-divider::after {
  content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.12);
}
.mp-status { margin-top: 0.55rem; font-size: 0.8rem; color: var(--cyan); line-height: 1.35; }
.mp-status.is-error { color: #ff6b8a; }
.btn--primary, .mp-block .btn--ghost { width: 100%; }
.mp-block .btn--ghost { margin-top: 0.35rem; }

.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: Orbitron, sans-serif; font-weight: 700;
  font-size: 0.78rem; letter-spacing: 0.08em;
  padding: 0.75rem 1.2rem; border-radius: 999px;
}
.btn--primary {
  color: #fff; width: 100%;
  background: linear-gradient(135deg, var(--cherry), #7a1a9e 55%, #0a8fa0);
  box-shadow: 0 0 22px rgba(255,45,106,0.4);
}
.btn--ghost {
  color: var(--cyan); background: transparent;
  border: 1px solid rgba(0,229,255,0.45);
}
.status {
  margin: 0.6rem 0; padding: 0.6rem 0.8rem; border-radius: 10px;
  font-size: 0.85rem; background: rgba(255,45,106,0.12);
  border: 1px solid rgba(255,45,106,0.35); color: #ffb0c4;
}
.quota-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-wrap: wrap; margin-top: 0.55rem;
}
.quota { font-size: 0.78rem; color: var(--muted); }
.btn-reset {
  appearance: none; border: 1px solid rgba(0,229,255,0.35);
  background: rgba(0,229,255,0.08); color: var(--cyan);
  font-size: 0.72rem; padding: 6px 10px; border-radius: 999px;
  cursor: pointer; font-family: inherit;
}
.btn-reset:hover { background: rgba(0,229,255,0.18); }

.loading {
  position: fixed; inset: 0; z-index: 1100;
  display: grid; place-items: center;
  background: rgba(5,1,15,0.82); backdrop-filter: blur(10px);
  transition: opacity 0.4s; padding: 16px;
}
.loading__card {
  text-align: left; width: min(88vw, 340px);
  background: var(--glass); border: 1px solid rgba(178,77,255,0.35);
  border-radius: 18px; padding: 1.25rem 1.15rem 1.15rem;
  box-shadow: 0 0 40px rgba(178,77,255,0.15);
}
.loading__head { display: flex; gap: 12px; align-items: center; margin-bottom: 0.95rem; }
.loading__spin {
  width: 40px; height: 40px; flex-shrink: 0;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--cyan); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading__brand {
  font-family: Orbitron, sans-serif; font-size: 0.65rem;
  letter-spacing: 0.14em; color: var(--purple); margin-bottom: 0.2rem;
}
.loading__text {
  font-family: Orbitron, sans-serif; font-size: 0.88rem;
  letter-spacing: 0.04em; color: var(--text);
}
.loading__bar { height: 4px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow: hidden; }
.loading__bar-fill { height: 100%; width: 10%; background: linear-gradient(90deg, var(--cherry), var(--purple), var(--cyan)); transition: width 0.35s; }

.paywall {
  position: fixed; inset: 0; z-index: 1200;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.7); padding: 20px;
}
.paywall__card {
  max-width: 380px; padding: 1.6rem; border-radius: 18px;
  background: var(--glass); border: 1px solid rgba(255,45,106,0.4); text-align: center;
}
.paywall__card h2 { font-family: Orbitron, sans-serif; font-size: 1.1rem; margin-bottom: 0.6rem; }
.paywall__card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; line-height: 1.45; }

.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  pointer-events: none;
}
.hud__logo {
  font-family: Orbitron, sans-serif; font-weight: 900; font-size: 1rem;
  letter-spacing: 0.1em; color: transparent; -webkit-text-stroke: 1px var(--cherry);
}
.hud__sub { display: block; font-size: 0.62rem; color: var(--cyan); letter-spacing: 0.12em; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud__mid { text-align: center; pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.hud__code {
  appearance: none; border: 1px solid rgba(178,77,255,0.45);
  background: rgba(0,0,0,0.45); color: #fff; border-radius: 12px;
  padding: 5px 12px; cursor: pointer; font-family: Orbitron, sans-serif;
  font-size: 0.74rem; letter-spacing: 0.08em;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.hud__code small { font-size: 0.52rem; opacity: 0.65; letter-spacing: 0.12em; font-family: Inter, sans-serif; }
.hud__code:hover { border-color: var(--cyan); }
.hud__count { font-size: 0.68rem; color: var(--muted); }
.hud__bpm-label { font-family: Orbitron, sans-serif; font-size: 0.85rem; }
.hud__source { font-size: 0.65rem; color: var(--muted); }
.hud__right { display: flex; gap: 6px; pointer-events: auto; }
.hud__btn {
  min-width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2); background: var(--glass);
  color: #fff; cursor: pointer; font-size: 1rem;
}
.hud__btn--text { font-family: Orbitron, sans-serif; font-size: 0.62rem; letter-spacing: 0.04em; padding: 0 10px; width: auto; }

.hints {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%); z-index: 90;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,45,106,0.3);
  font-size: 0.78rem; color: var(--muted); pointer-events: none;
}
.hints kbd { border: 1px solid rgba(0,229,255,0.4); color: var(--cyan); padding: 1px 6px; border-radius: 5px; font-size: 0.72rem; }
.hints__mobile { display: none; }

.touch { position: fixed; inset: 0; z-index: 120; pointer-events: none; }
.joystick { position: absolute; left: calc(18px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); pointer-events: auto; }
.joystick__base {
  width: 114px; height: 114px; border-radius: 50%;
  background: rgba(0,0,0,0.35); border: 2px solid rgba(255,45,106,0.45); position: relative;
}
.joystick__knob {
  position: absolute; top: 50%; left: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--cherry) 55%, #7a1238);
}
.dance-btn {
  position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(34px + var(--safe-b));
  pointer-events: auto; width: 82px; height: 82px; border-radius: 50%;
  border: 2px solid var(--cyan); background: radial-gradient(circle at 40% 30%, rgba(0,229,255,0.4), rgba(5,1,15,0.85));
  color: #fff; font-family: Orbitron, sans-serif; font-weight: 700; font-size: 0.65rem; cursor: pointer;
}
.dance-btn.active { border-color: var(--cherry); transform: scale(0.94); }

@media (hover: none), (pointer: coarse) {
  .hints__desktop { display: none; }
  .hints__mobile { display: inline; }
  .hints { bottom: calc(150px + var(--safe-b)); }
}
body.touch-device .hints__desktop { display: none; }
body.touch-device .hints__mobile { display: inline; }
body.touch-device .hints { bottom: calc(150px + var(--safe-b)); }
