:root {
  --bg: #04060c;
  --bg-2: #0a1220;
  --panel: rgba(10, 18, 32, 0.72);
  --panel-solid: #0c1526;
  --line: rgba(56, 189, 248, 0.22);
  --line-strong: rgba(34, 211, 238, 0.45);
  --text: #e8f4ff;
  --muted: #8aa0b8;
  --cyan: #22d3ee;
  --teal: #14b8a6;
  --lime: #a3e635;
  --danger: #fb7185;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  --font-display: "Orbitron", sans-serif;
  --font-body: "Space Grotesk", sans-serif;
}

*,
*::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(1200px 700px at 15% -10%, #123055 0%, transparent 55%),
    radial-gradient(900px 600px at 90% 10%, #0b3a3a 0%, transparent 50%),
    linear-gradient(160deg, #02040a, #071018 45%, #050810);
  overflow-x: hidden;
}

h1,
h2,
.brand-mark {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}

a {
  color: var(--cyan);
}

.scene {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.scene-dim {
  opacity: 0.55;
}

.grid-floor {
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: -35%;
  height: 75%;
  background-image:
    linear-gradient(rgba(34, 211, 238, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.12) 1px, transparent 1px);
  background-size: 56px 56px;
  transform: perspective(700px) rotateX(68deg);
  transform-origin: center top;
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent 78%);
  animation: floorPulse 8s ease-in-out infinite;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.55;
  animation: floatOrb 12s ease-in-out infinite;
}

.orb-a {
  width: 320px;
  height: 320px;
  top: 8%;
  left: 8%;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.55), transparent 70%);
}

.orb-b {
  width: 420px;
  height: 420px;
  top: 35%;
  right: -5%;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.4), transparent 70%);
  animation-delay: -4s;
}

.orb-c {
  width: 260px;
  height: 260px;
  bottom: 10%;
  left: 40%;
  background: radial-gradient(circle, rgba(163, 230, 53, 0.22), transparent 70%);
  animation-delay: -7s;
}

.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 3px
  );
  opacity: 0.35;
}

.perspective-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  transform: perspective(1200px) rotateX(2deg);
  transition: transform 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

.perspective-card:hover {
  transform: perspective(1200px) rotateX(0deg) translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 35px 90px rgba(0, 0, 0, 0.6), 0 0 40px rgba(34, 211, 238, 0.08);
}

.card-glow {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.25), transparent 35%, transparent 65%, rgba(20, 184, 166, 0.2));
  opacity: 0.55;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  padding: 1px;
}

.brand-mark {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--cyan);
  letter-spacing: 0.18em;
}

/* ===== 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;
  text-align: left;
  animation: riseIn 0.7s ease both;
}

.login-card h1 {
  margin: 0.85rem 0 0.4rem;
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 800;
}

.login-sub {
  margin: 0 0 1.6rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.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(2, 8, 18, 0.85);
  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(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

textarea {
  resize: vertical;
  min-height: 96px;
  margin-bottom: 0.75rem;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.quick-grid button {
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.primary-btn,
.secondary-btn,
.danger-btn {
  padding: 0.8rem 1.1rem;
}

.primary-btn {
  background: linear-gradient(135deg, #14b8a6, #0891b2);
  color: #041018;
  font-weight: 700;
  width: 100%;
}

.primary-btn.full {
  width: 100%;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.secondary-btn {
  background: rgba(8, 20, 36, 0.9);
  border-color: var(--line);
  color: var(--text);
}

.secondary-btn:hover:not(:disabled) {
  border-color: var(--cyan);
}

.danger-btn {
  background: rgba(127, 29, 29, 0.35);
  border-color: rgba(251, 113, 133, 0.4);
  color: #fecdd3;
}

.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;
}

/* ===== Studio ===== */
.page-studio {
  min-height: 100vh;
}

.studio-top,
.studio-layout,
.setup-error {
  position: relative;
  z-index: 1;
}

.studio-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 0.5rem;
  animation: riseIn 0.55s ease both;
}

.brand-block h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
}

.top-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.chip,
.status-pill {
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(6, 14, 26, 0.8);
}

.chip-dim {
  color: var(--muted);
}

.status-pill {
  min-width: 7.5rem;
  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);
}

.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;
}

.setup-error[hidden] {
  display: none !important;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.75fr);
  gap: 1rem;
  padding: 1rem 1.5rem 1.75rem;
  max-width: 1500px;
  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.8rem;
}

.stage-grid {
  display: block;
}

.feed-out {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.feed-label {
  margin-bottom: 0.55rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.feed-out > .feed-label {
  text-align: center;
}

.feed-label-accent {
  color: var(--cyan);
}

.video-frame {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(8, 20, 36, 0.95), rgba(3, 8, 16, 0.98));
  border: 1px solid rgba(56, 189, 248, 0.16);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}

.video-frame-source {
  aspect-ratio: 4 / 3;
  width: 100%;
  border-radius: 10px;
}

.video-frame video,
.phone-screen video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

/* Large phone mockup — main AI output */
.phone-shell {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  min-height: min(82vh, 860px);
  padding: 0.25rem 0 0.5rem;
}

.phone-bezel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(420px, 92%);
  height: min(82vh, 860px);
  max-height: 860px;
  padding: 14px 14px 12px;
  border-radius: 42px;
  background: linear-gradient(165deg, #243044 0%, #0b1220 42%, #151d2c 100%);
  border: 2px solid rgba(148, 163, 184, 0.4);
  box-shadow:
    0 40px 80px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 0 60px rgba(34, 211, 238, 0.14);
}

.phone-ear {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 28px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.phone-speaker {
  width: 72px;
  height: 7px;
  border-radius: 999px;
  background: #05080f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.phone-cam {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #67e8f9, #0e7490 70%);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.45);
}

.phone-screen {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border-radius: 30px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(34, 211, 238, 0.35);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.55);
}

.phone-home {
  width: 110px;
  height: 5px;
  margin: 12px auto 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.5);
  flex-shrink: 0;
}

/* Small floating source preview */
.source-pip {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 2;
  width: 132px;
  padding: 0.45rem;
  border-radius: 14px;
  background: rgba(6, 12, 22, 0.88);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.source-pip .feed-label {
  margin-bottom: 0.3rem;
  font-size: 0.65rem;
}

.source-pip .placeholder {
  font-size: 0.7rem;
  padding: 0.45rem;
}

.source-pip .placeholder-icon {
  font-size: 1rem;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 1rem;
}

.placeholder-icon {
  font-size: 1.5rem;
  color: var(--cyan);
  opacity: 0.7;
}

.deck-section {
  margin-bottom: 1.15rem;
}

.deck-label {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.deck-hint {
  margin: -0.25rem 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 {
  cursor: pointer;
  width: 100%;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.25), rgba(8, 145, 178, 0.35));
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.12);
  transition: transform 0.15s ease, border-color 0.2s ease, filter 0.2s ease;
}

.upload-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--cyan);
  filter: brightness(1.08);
}

.upload-btn:active:not(:disabled) {
  transform: translateY(0);
}

.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(4, 12, 22, 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;
  white-space: nowrap;
}

.source-actions {
  display: grid;
  gap: 0.5rem;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.quick-grid button {
  background: rgba(6, 16, 28, 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(--cyan);
  color: var(--cyan);
}

.deck-note {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes floatOrb {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-24px) scale(1.05);
  }
}

@keyframes floorPulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 0.85;
  }
}

@media (max-width: 980px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }

  .phone-bezel {
    width: min(380px, 88%);
    height: min(72vh, 760px);
  }

  .phone-shell {
    min-height: min(72vh, 760px);
  }

  .perspective-card {
    transform: none;
  }

  .perspective-card:hover {
    transform: translateY(-2px);
  }
}

@media (max-width: 560px) {
  .studio-top,
  .studio-layout {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .login-card {
    padding: 1.6rem 1.2rem;
  }

  .phone-bezel {
    width: min(360px, 94%);
    height: min(70vh, 720px);
    border-radius: 36px;
  }

  .phone-shell {
    min-height: min(70vh, 720px);
  }

  .source-pip {
    width: 108px;
    left: 8px;
    top: 8px;
  }

  .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;
  }
}
