:root {
  --bg: #07060d;
  --bg-2: #0e0a18;
  --panel: rgba(16, 10, 28, 0.72);
  --panel-solid: #120c1e;
  --line: rgba(168, 85, 247, 0.28);
  --line-strong: rgba(192, 132, 252, 0.55);
  --text: #f3eaff;
  --muted: #a48fc4;
  --purple: #c084fc;
  --violet: #8b5cf6;
  --fuchsia: #e879f9;
  --neon: #d946ef;
  --lime: #a3e635;
  --danger: #fb7185;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
  --font-display: "Syne", sans-serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1000px 600px at 12% -8%, rgba(139, 92, 246, 0.28), transparent 55%),
    radial-gradient(900px 500px at 92% 8%, rgba(217, 70, 239, 0.16), transparent 50%),
    linear-gradient(165deg, #05040a, #0b0714 48%, #06050c);
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.file-input-hidden {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

h1,
h2,
.brand-mark {
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}

a {
  color: var(--purple);
}

/* ===== Effects / atmosphere ===== */
.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.fx-grid {
  position: absolute;
  inset: -20% -10% -40%;
  background-image:
    linear-gradient(rgba(168, 85, 247, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(168, 85, 247, 0.1) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(800px) rotateX(62deg);
  transform-origin: center top;
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent 78%);
  animation: gridPulse 9s ease-in-out infinite;
}

.fx-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.55;
  animation: floatOrb 14s ease-in-out infinite;
}

.fx-a {
  width: 340px;
  height: 340px;
  top: 6%;
  left: 6%;
  background: radial-gradient(circle, rgba(192, 132, 252, 0.55), transparent 70%);
}

.fx-b {
  width: 440px;
  height: 440px;
  top: 30%;
  right: -8%;
  background: radial-gradient(circle, rgba(217, 70, 239, 0.32), transparent 70%);
  animation-delay: -5s;
}

.fx-noise {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.glass {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.glass:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow), 0 0 40px rgba(168, 85, 247, 0.1);
}

.brand-mark {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--fuchsia);
  letter-spacing: 0.2em;
  font-weight: 700;
}

/* ===== Login ===== */
.page-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(440px, calc(100% - 2rem));
  padding: 2rem 0;
}

.login-card {
  padding: 2.25rem 2rem 2rem;
  animation: riseIn 0.7s ease both;
  overflow: hidden;
}

.neon-ring {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    rgba(232, 121, 249, 0.45),
    transparent 40%,
    transparent 60%,
    rgba(139, 92, 246, 0.4)
  );
  opacity: 0.7;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  padding: 1px;
}

.login-card h1 {
  margin: 0.85rem 0 0.4rem;
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  font-weight: 800;
}

.login-sub {
  margin: 0 0 1.6rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.login-form label,
.field-label,
.deck-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-mono);
}

.password-field {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.password-field input {
  flex: 1;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(6, 4, 12, 0.9);
  color: var(--text);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.18);
}

textarea {
  resize: vertical;
  min-height: 96px;
  margin-bottom: 0.75rem;
  font-family: var(--font-body);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.quick-grid button,
.topup-btn,
.upload-btn {
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary-btn,
.danger-btn {
  padding: 0.8rem 1.1rem;
}

.primary-btn {
  background: linear-gradient(135deg, #c026d3, #7c3aed);
  color: #fff;
  font-weight: 700;
  width: 100%;
  box-shadow: 0 0 28px rgba(192, 38, 211, 0.25);
}

.primary-btn.full {
  width: 100%;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 0 36px rgba(217, 70, 239, 0.35);
}

.danger-btn {
  background: rgba(80, 12, 32, 0.45);
  border-color: rgba(251, 113, 133, 0.4);
  color: #fecdd3;
  width: 100%;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0 0.9rem;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.form-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.form-ok {
  margin: 0.85rem 0 0;
  color: var(--lime);
  font-size: 0.9rem;
}

/* ===== Studio ===== */
.page-studio {
  min-height: 100vh;
}

.studio-top,
.studio-layout,
.setup-error,
.toast {
  position: relative;
  z-index: 1;
}

.studio-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.5rem 0.45rem;
  animation: riseIn 0.55s ease both;
}

.brand-block h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.25rem, 2.5vw, 1.65rem);
}

.top-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.chip,
.status-pill {
  font-size: 0.76rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(10, 6, 18, 0.85);
  font-family: var(--font-mono);
}

.chip-dim {
  color: var(--muted);
}

.chip-balance {
  color: var(--lime);
  border-color: rgba(163, 230, 53, 0.4);
}

.chip-used {
  color: var(--fuchsia);
  border-color: rgba(232, 121, 249, 0.4);
}

.status-pill {
  min-width: 7rem;
  text-align: center;
  color: var(--muted);
}

.status-pill.connected {
  color: var(--lime);
  border-color: rgba(163, 230, 53, 0.45);
  box-shadow: 0 0 18px rgba(163, 230, 53, 0.12);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.45);
}

.topup-btn {
  background: rgba(139, 92, 246, 0.2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
}

.topup-btn:hover {
  background: rgba(192, 132, 252, 0.28);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.2);
}

.logout-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 999px;
}

.logout-link:hover {
  color: var(--text);
  border-color: var(--line);
}

.setup-error {
  margin: 0.75rem 1.5rem 0;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(80, 10, 24, 0.55);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fecdd3;
  animation: riseIn 0.35s ease both;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  background: rgba(20, 10, 40, 0.92);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 24px rgba(168, 85, 247, 0.2);
  animation: riseIn 0.3s ease both;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(280px, 0.78fr);
  gap: 1rem;
  padding: 1rem 1.5rem 1.75rem;
  max-width: 1520px;
  margin: 0 auto;
  animation: riseIn 0.7s ease both;
}

.stage-panel,
.control-deck {
  padding: 1rem 1.1rem 1.15rem;
}

.stage-head,
.control-deck h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.stage-head h2,
.control-deck h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.meter {
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

.meter-accent {
  color: var(--purple);
}

.stage-meters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.stage-grid {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.feed-in,
.feed-out {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.feed-label {
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-family: var(--font-mono);
}

.feed-label-accent {
  color: var(--fuchsia);
}

.video-frame {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, rgba(18, 10, 32, 0.98), rgba(6, 4, 12, 0.98));
  border: 1px solid rgba(168, 85, 247, 0.2);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}

.video-frame-source {
  flex: 1;
  width: 100%;
  min-height: 280px;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
}

.video-frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  background: #000;
  z-index: 1;
}

.video-frame .placeholder {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.tablet-shell {
  width: 100%;
  flex: 1;
}

.tablet-bezel {
  width: 100%;
  height: 100%;
  padding: 12px;
  border-radius: 22px;
  background: linear-gradient(160deg, #1e1430 0%, #0c0814 55%, #161022 100%);
  border: 1px solid rgba(168, 85, 247, 0.25);
  box-shadow:
    0 24px 50px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 40px rgba(168, 85, 247, 0.1);
}

.tablet-screen {
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: 420px;
  border-radius: 14px;
  border-color: rgba(217, 70, 239, 0.3);
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.5),
    0 0 28px rgba(192, 38, 211, 0.08);
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
}

.placeholder-ready .ready-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232, 121, 249, 0.45);
}

.cam-glyph {
  color: rgba(192, 132, 252, 0.55);
  display: grid;
  place-items: center;
}

.cam-glyph-faint {
  color: rgba(192, 132, 252, 0.28);
  animation: glyphPulse 3.2s ease-in-out infinite;
}

.burn-badge {
  position: absolute;
  z-index: 2;
  left: 0.55rem;
  bottom: 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: rgba(8, 4, 16, 0.82);
  border: 1px solid rgba(232, 121, 249, 0.4);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--fuchsia);
  backdrop-filter: blur(8px);
}

.burn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fuchsia);
  box-shadow: 0 0 10px var(--neon);
  animation: blink 1s step-end infinite;
}

.deck-section {
  margin-bottom: 1.15rem;
}

.deck-hint {
  margin: -0.15rem 0 0.65rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

.ref-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.upload-btn {
  width: 100%;
  padding: 0.85rem 1.1rem;
  border: 1px solid rgba(192, 132, 252, 0.5);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.28), rgba(192, 38, 211, 0.28));
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.14);
}

.upload-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.upload-preview {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.75rem;
  padding: 0.45rem 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 4, 16, 0.75);
}

.upload-preview img {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000;
}

.ref-name {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.clear-ref {
  flex-shrink: 0;
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
}

.source-actions {
  display: grid;
  gap: 0.5rem;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.quick-grid button {
  background: rgba(10, 6, 20, 0.9);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.65rem 0.55rem;
  font-size: 0.82rem;
}

.quick-grid button:hover:not(:disabled) {
  border-color: var(--purple);
  color: var(--fuchsia);
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.15);
}

.credit-strip .bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  border: 1px solid var(--line);
}

.credit-strip .bar-track i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #e879f9);
  border-radius: inherit;
  transition: width 0.25s ease;
  box-shadow: 0 0 12px rgba(232, 121, 249, 0.4);
}

.credit-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.deck-note {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

/* ===== Modal / top-up ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 2, 10, 0.72);
  backdrop-filter: blur(6px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(90vh, 760px);
  overflow: auto;
  padding: 1.5rem 1.35rem 1.4rem;
  animation: riseIn 0.35s ease both;
}

.modal-x {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.modal-panel h2 {
  margin: 0.5rem 0 0.35rem;
  font-size: 1.4rem;
}

.modal-sub {
  margin: 0 0 1.15rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.package-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1.1rem;
}

.package-card {
  position: relative;
  text-align: left;
  padding: 0.9rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 4, 16, 0.85);
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 0.2rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.package-card:hover,
.package-card.selected {
  border-color: var(--line-strong);
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.2);
  transform: translateY(-1px);
}

.package-card.selected {
  background: rgba(88, 28, 135, 0.25);
}

.package-card.popular {
  border-color: rgba(232, 121, 249, 0.45);
}

.pkg-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
}

.pkg-credits {
  font-family: var(--font-mono);
  color: var(--fuchsia);
  font-size: 0.85rem;
}

.pkg-price {
  font-weight: 700;
}

.pkg-tag {
  font-size: 0.75rem;
  color: var(--muted);
}

.pkg-badge {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(217, 70, 239, 0.25);
  color: var(--fuchsia);
  border: 1px solid rgba(232, 121, 249, 0.35);
}

.pay-step .deck-label {
  margin-top: 0.75rem;
}

.chain-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.chain-btn {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 4, 16, 0.9);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
}

.chain-btn.active,
.chain-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
  box-shadow: 0 0 14px rgba(168, 85, 247, 0.2);
}

.address-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(4, 2, 10, 0.9);
}

.address-box code {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--purple);
}

/* ===== Motion ===== */
@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes floatOrb {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-22px) scale(1.05);
  }
}

@keyframes gridPulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.85;
  }
}

@keyframes glyphPulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
  }
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

@media (max-width: 980px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }

  .stage-grid {
    grid-template-columns: 160px minmax(0, 1fr);
  }

  .video-frame-source {
    min-height: 220px;
  }

  .tablet-screen {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .studio-top,
  .studio-layout {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .stage-grid {
    grid-template-columns: 1fr;
  }

  .feed-in {
    max-width: 240px;
  }

  .tablet-screen {
    min-height: 240px;
  }

  .package-grid {
    grid-template-columns: 1fr;
  }

  .quick-grid {
    grid-template-columns: 1fr;
  }

  .ref-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
