:root {
  --bg-1: #08161f;
  --bg-2: #0d3135;
  --card: rgba(7, 17, 23, 0.78);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f3fbff;
  --muted: #a6c2cc;
  --accent: #ffc64d;
  --accent-2: #55d8c7;
  --danger: #ff8168;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 12% 15%, #1f5448 0%, transparent 45%),
    radial-gradient(circle at 82% 80%, #6f3e14 0%, transparent 42%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
  padding: 18px;
  overflow-x: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(4, 10, 14, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-gate.active {
  display: flex;
}

.auth-card {
  width: min(560px, 96vw);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.auth-grid {
  display: grid;
  gap: 8px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-message {
  color: var(--muted);
  min-height: 20px;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(10px);
  opacity: 0.3;
  animation: float 9s ease-in-out infinite;
}

.bg-shape-a {
  width: 260px;
  height: 260px;
  top: -70px;
  right: -50px;
  background: #ffba4a;
}

.bg-shape-b {
  width: 300px;
  height: 300px;
  left: -95px;
  bottom: -90px;
  background: #5ac6ff;
  animation-delay: 1.3s;
}

header,
.page {
  max-width: 1250px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  backdrop-filter: blur(10px);
}

header {
  padding: 16px;
  margin-bottom: 14px;
}

header h1 {
  font-size: clamp(1.3rem, 2.4vw, 2.1rem);
}

header p {
  color: var(--muted);
  margin-top: 4px;
}

.session-bar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

nav {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.backend-bar {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

button,
select,
input,
textarea,
pre,
.download-link {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.26);
  color: var(--text);
  padding: 10px;
  font: inherit;
}

button {
  cursor: pointer;
  font-weight: 700;
  background: #1f3f46;
}

button:hover {
  background: #2c5963;
}

.nav-btn.active {
  background: linear-gradient(130deg, var(--accent), #f9a54b);
  color: #221401;
  border-color: rgba(255, 198, 77, 0.5);
}

.page {
  display: none;
  padding: 15px;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

h2 {
  margin-bottom: 10px;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 10px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 10px;
}

.chat-sidebar {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  gap: 10px;
  align-content: start;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-sidebar h3 {
  font-size: 0.95rem;
}

.chat-list {
  display: grid;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.chat-item {
  width: 100%;
  text-align: left;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.chat-item.active {
  border-color: rgba(255, 198, 77, 0.7);
  background: rgba(255, 198, 77, 0.2);
}

.chat-main {
  min-width: 0;
}

.danger-btn {
  background: #5b2a2a;
  border-color: rgba(255, 129, 104, 0.5);
}

.danger-btn:hover {
  background: #773333;
}

.grid-3 {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
}

pre {
  margin-top: 10px;
  min-height: 110px;
  white-space: pre-wrap;
}

#chatWindow {
  min-height: 260px;
  max-height: 48vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  padding: 10px;
}

.message {
  width: fit-content;
  max-width: min(760px, 95%);
  margin-bottom: 8px;
  padding: 9px;
  border-radius: 10px;
}

.message.user {
  margin-left: auto;
  background: rgba(255, 198, 77, 0.18);
  border: 1px solid rgba(255, 198, 77, 0.45);
}

.message.ai {
  background: rgba(82, 224, 196, 0.16);
  border: 1px solid rgba(82, 224, 196, 0.4);
}

.media-stage {
  margin-top: 10px;
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
}

.empty-text {
  color: var(--muted);
}

.generated-image,
.animated-photo {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.video-player,
.video-canvas {
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
}

.download-link {
  display: inline-block;
  margin-top: 10px;
  text-decoration: none;
  font-weight: 700;
  width: fit-content;
}

.history-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.06);
}

.history-item b {
  color: var(--accent);
}

.status-line {
  max-width: 1250px;
  margin: 10px auto 0;
  color: var(--muted);
}

.divider {
  margin-top: 12px;
  border: none;
  border-top: 1px solid var(--line);
}

.scene-track {
  width: 100%;
  display: grid;
  gap: 10px;
}

.scene-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  padding: 10px;
  animation: rise 0.35s ease;
}

.scene-card.active-scene {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(82, 224, 196, 0.4);
}

.photo-pan {
  animation: photoPan 10s ease-in-out infinite alternate;
}

.photo-zoom {
  animation: photoZoom 10s ease-in-out infinite;
}

.photo-pulse {
  animation: photoPulse 3.5s ease-in-out infinite;
}

.photo-spin {
  animation: photoSpin 12s linear infinite;
}

@keyframes photoPan {
  from { transform: scale(1.08) translateX(-5%); }
  to { transform: scale(1.08) translateX(5%); }
}

@keyframes photoZoom {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.17); }
}

@keyframes photoPulse {
  0%, 100% { transform: scale(1); filter: contrast(1); }
  50% { transform: scale(1.05); filter: contrast(1.2); }
}

@keyframes photoSpin {
  from { transform: rotate(0deg) scale(1.02); }
  to { transform: rotate(360deg) scale(1.02); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(12px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .row,
  .grid-3,
  .backend-bar {
    grid-template-columns: 1fr;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  header,
  .page {
    padding: 12px;
  }

  .media-stage {
    min-height: 220px;
  }
}
