:root {
  /* Golden Theme Colors */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --text-primary: #f0f0f5;
  --text-secondary: #c8c8d8;
  --text-muted: #8b949e;
  --primary: #D4AF37;
  --primary-light: #F4E4C1;
  --accent: #C9A227;
  --accent-gradient: linear-gradient(135deg, #D4AF37, #C9A227, #B8860B);
  --gold-glow: rgba(212, 175, 55, 0.3);
  --glass-bg: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(212, 175, 55, 0.15);
  --glass-hover: rgba(212, 175, 55, 0.12);
  --border: rgba(212, 175, 55, 0.15);
  --card: rgba(255, 255, 255, 0.06);
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 0 40px rgba(212, 175, 55, 0.25);
  --ink: #2a1c12;
  --paper: #fbf3e0;
  --paper2: #f7edd7;
  --wood1: #4a3728;
  --wood2: #1e1510;
  --metal1: #e5e7eb;
  --metal2: #9ca3af;
  --success: #10b981;
  --danger: #ef4444;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* ==================== GLOBAL RESETS ==================== */
* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text-primary);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(212, 175, 55, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(201, 162, 39, 0.08), transparent 45%),
    radial-gradient(ellipse at 50% 100%, rgba(184, 134, 11, 0.08), transparent 55%),
    radial-gradient(ellipse at 30% 60%, rgba(212, 175, 55, 0.05), transparent 40%),
    linear-gradient(180deg, #0d1117 0%, #161b22 30%, #1c2128 60%, #21262d 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Circuit pattern background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23D4AF37' stroke-width='0.5'%3E%3Cpath d='M10 10h20v20H10z'/%3E%3Cpath d='M40 10h20'/%3E%3Cpath d='M70 10h20v30H70'/%3E%3Cpath d='M10 40v20h30'/%3E%3Ccircle cx='50' cy='50' r='3'/%3E%3Cpath d='M50 53v17h40'/%3E%3Cpath d='M10 70h20v20'/%3E%3Cpath d='M40 80h20'/%3E%3Cpath d='M70 70v20h20'/%3E%3Ccircle cx='20' cy='20' r='2'/%3E%3Ccircle cx='80' cy='25' r='2'/%3E%3Ccircle cx='25' cy='80' r='2'/%3E%3Ccircle cx='80' cy='80' r='2'/%3E%3Cpath d='M30 10v10'/%3E%3Cpath d='M60 10v20h10'/%3E%3Cpath d='M10 30h10'/%3E%3Cpath d='M50 30h10v10'/%3E%3Cpath d='M30 60h10v10'/%3E%3Cpath d='M60 60v10'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 100px 100px;
  animation: circuit-pulse 15s ease-in-out infinite;
}

@keyframes circuit-pulse {

  0%,
  100% {
    opacity: 0.06;
  }

  50% {
    opacity: 0.10;
  }
}

/* Glowing orbs - golden theme */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(circle at 15% 25%, rgba(212, 175, 55, 0.18) 0%, transparent 35%),
    radial-gradient(circle at 85% 75%, rgba(184, 134, 11, 0.15) 0%, transparent 35%);
  filter: blur(80px);
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }
}

/* ==================== LOGIN SCREEN ==================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(99, 102, 241, 0.25), transparent 50%),
    radial-gradient(ellipse at 75% 70%, rgba(236, 72, 153, 0.18), transparent 50%),
    linear-gradient(180deg, #0a0a14 0%, #12121f 50%, #1a1a2e 100%);
}

.login-container {
  width: min(420px, 92vw);
  padding: 40px 32px;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  text-align: center;
}

.login-title {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 900;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  margin: 0 0 28px;
  color: var(--text-muted);
  font-size: 15px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input::placeholder {
  color: var(--text-muted);
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.auth-toggle {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-toggle a {
  color: var(--primary-light);
  font-weight: 700;
  text-decoration: none;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.auth-error {
  margin-top: 14px;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  color: #fca5a5;
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  line-height: 1.6;
}

.auth-error.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

/* ==================== BUTTONS ==================== */
.primary {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 800;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.4);
}

.secondary {
  background: var(--glass-bg);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.secondary:hover {
  background: var(--glass-hover);
  box-shadow: var(--shadow-md);
}

/* ==================== PAGE LAYOUT ==================== */
.page {
  min-height: 100vh;
  padding: 24px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand {
  grid-column: 2;
  text-align: center;
}

.hero h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.4px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero .subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
}

.controls {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.status {
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  min-width: 150px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  color: var(--text-secondary);
}

/* ==================== CATEGORY HINT SECTION ==================== */
.category-hint-section {
  text-align: center;
  margin: 0 auto 16px;
}

.category-hint {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.reference-upload-panel {
  width: min(900px, 94vw);
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(190px, 260px) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
}

.reference-upload-panel strong {
  display: block;
  color: var(--text-primary);
  font-size: 14px;
}

.reference-upload-panel span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.reference-upload-panel input {
  width: 100%;
  color: var(--text-secondary);
}

.reference-upload-status {
  grid-column: 1 / -1;
  min-height: 18px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ==================== TV SECTION ==================== */
.tv-section {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 24px;
  margin: 8px 0 20px;
  flex-wrap: wrap;
}

.tv-sidebar-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* remove align-self: center to allow stretch from parent */
}

.tv-shell {
  position: relative;
  width: min(580px, 92vw);
  padding: 28px 24px 24px;
  border-radius: 24px;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(0, 0, 0, 0.4);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 30%),
    linear-gradient(135deg, rgba(99, 102, 241, 0.08), transparent 60%),
    linear-gradient(135deg, var(--wood1), var(--wood2));
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.tv-shell::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), transparent 35%);
  pointer-events: none;
}

.tv-body {
  display: grid;
  grid-template-columns: 1fr 80px;
  gap: 14px;
  align-items: stretch;
}

/* .tv-controls-left removed */

/* ==================== MODE PANEL ==================== */
.mode-panel {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  width: 260px;
  /* Wider panel as requested */
  height: 100%;
  padding: 24px 20px;
  gap: 20px;
}

.mode-header {
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 16px;
  margin-bottom: 4px;
}

.mode-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.mode-subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.4;
}

.mode-toggle-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  text-align: left;
  width: 100%;
  position: relative;
  overflow: hidden;
  color: var(--text-secondary);
  flex: 1;
}

.mode-card:hover {
  background: rgba(212, 175, 55, 0.08);
  transform: translateY(-2px) scale(1.02);
  border-color: rgba(212, 175, 55, 0.4);
}

.mode-card.selected {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.15), rgba(184, 134, 11, 0.1));
  border: 1px solid rgba(212, 175, 55, 0.6);
  box-shadow: 0 4px 20px rgba(212, 175, 55, 0.25);
}

.mode-card.selected .mode-name {
  color: #F4E4C1;
  font-weight: 800;
}

.mode-card.selected .mode-desc {
  color: rgba(244, 228, 193, 0.9);
}

/* Aspect Box Visuals */
.aspect-box {
  border: 2px solid rgba(212, 175, 55, 0.4);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(212, 175, 55, 0.05);
}

.mode-card.selected .aspect-box {
  border-color: #D4AF37;
  background: rgba(212, 175, 55, 0.25);
  box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.aspect-box.landscape {
  width: 48px;
  height: 27px;
  /* 16:9 ratio */
}

.aspect-box.landscape::before {
  content: "🖥️";
  font-size: 14px;
}

.aspect-box.portrait {
  width: 27px;
  height: 48px;
  /* 9:16 ratio */
}

.aspect-box.portrait::before {
  content: "📱";
  font-size: 14px;
}

.mode-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.mode-desc {
  font-size: 11px;
  color: var(--text-muted);
}


.mode-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tv-bezel {
  border-radius: 18px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.05)),
    linear-gradient(135deg, #2a2f3a, #0b0f16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), inset 0 -14px 25px rgba(0, 0, 0, 0.45);
}

.tv-screen {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 14px;
  overflow: hidden;
  background: #070a10;
  box-shadow: inset 0 0 35px rgba(0, 0, 0, 0.75);
}

.tv-screen video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tv-screen .youtube-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.tv-screen .youtube-iframe.hidden {
  display: none;
}

/* CRT effects */
.tv-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 3px);
  opacity: 0.3;
  mix-blend-mode: overlay;
  pointer-events: none;
}

.tv-screen::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.15), transparent 40%);
  transform: rotate(8deg);
  pointer-events: none;
}

.video-overlay {
  position: absolute;
  inset: 0;
  border: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.70));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-weight: 800;
  cursor: pointer;
}

.video-overlay.hidden {
  display: none;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

/* ==================== TV SIDE PANEL WITH KNOBS ==================== */
.tv-strip {
  border-radius: 14px;
  padding: 12px 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.tv-knobs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: 100%;
}

/* Category Knob Buttons */
.knob.category-knob {
  width: 100%;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.knob.category-knob:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.3),
    0 8px 20px rgba(99, 102, 241, 0.25);
}

.knob.category-knob.selected {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.25));
  border-color: rgba(99, 102, 241, 0.7);
  box-shadow:
    0 0 20px rgba(99, 102, 241, 0.4),
    0 6px 20px rgba(99, 102, 241, 0.3);
}

.knob-label {
  font-size: 18px;
  line-height: 1;
}

.knob-text {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.85);
}

.tv-speaker-slit {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.22) 0 1.2px, transparent 1.7px) 0 0 / 8px 6px,
    linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(0, 0, 0, 0.25));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10);
}

/* ==================== FLOATING CHAT WIDGET ==================== */
.chat-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 1000;
}

.chat-widget-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: white;
  font-size: 26px;
  cursor: pointer;
  box-shadow:
    0 8px 32px rgba(212, 175, 55, 0.4),
    0 0 20px rgba(184, 134, 11, 0.3);
  position: relative;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget-btn:hover {
  transform: scale(1.1);
  box-shadow:
    0 12px 40px rgba(212, 175, 55, 0.5),
    0 0 30px rgba(184, 134, 11, 0.4);
}

.widget-icon {
  position: relative;
  z-index: 1;
}

.widget-pulse {
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: var(--accent-gradient);
  opacity: 0.4;
  animation: pulse-ring 2s ease-out infinite;
  z-index: 0;
}

@keyframes pulse-ring {
  0% {
    transform: scale(1);
    opacity: 0.4;
  }

  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

.chat-widget-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 360px;
  max-height: 480px;
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-widget-panel:not(.hidden) {
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--accent-gradient);
  color: white;
}

.widget-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 15px;
}

.widget-avatar {
  font-size: 20px;
}

.widget-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.widget-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Chat Messages - Reused styles */
.chat-messages {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 280px;
  min-height: 150px;
  overflow-y: auto;
  flex: 1;
}

.chat-message {
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.45;
}

.chat-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.25), rgba(184, 134, 11, 0.2));
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--text-primary);
}

.chat-message.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

.chat-upload-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 0;
  background: rgba(0, 0, 0, 0.15);
}

.chat-upload-chip {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(212, 175, 55, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.32);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}

.chat-upload-status {
  min-height: 14px;
  padding: 4px 16px 0;
  background: rgba(0, 0, 0, 0.15);
  color: var(--text-muted);
  font-size: 11px;
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.15);
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}

.chat-input-row input {
  flex: 1 1 auto;
  min-width: 0;
  width: 0; /* force flex shrink so Send stays fully visible */
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  box-sizing: border-box;
}

.chat-input-row input::placeholder {
  color: var(--text-muted);
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.chat-input-row button {
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease;
  white-space: nowrap;
}

.chat-input-row .chat-upload-btn {
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  height: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  flex: 0 0 40px;
}

.chat-input-row #chat-send {
  min-width: 64px;
  max-width: 30%;
}

.chat-input-row button:hover:not(:disabled) {
  transform: scale(1.02);
}

.chat-input-row button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ==================== SOCIAL CARDS ==================== */
.social-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 18px auto 20px;
  width: min(850px, 94vw);
}

.card {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 16px;
  text-align: left;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.card:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.card:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: rgba(212, 175, 55, 0.3);
}

.card-title {
  font-weight: 900;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.card-title::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: inline-block;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  background-color: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 82% 82%;
}

.linkedin .card-title::before {
  background-image: url("assets/linkedin.svg");
}

.facebook .card-title::before {
  background-image: url("assets/facebook.svg");
}

.x .card-title::before {
  background-image: url("assets/x.svg");
}

.download .card-title::before {
  content: "⬇";
  background-image: none;
  background-color: rgba(212, 175, 55, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.card.download {
  border-color: rgba(212, 175, 55, 0.25);
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.08), rgba(184, 134, 11, 0.05));
}

.card.download:hover:not(:disabled) {
  border-color: rgba(212, 175, 55, 0.5);
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.15), rgba(184, 134, 11, 0.1));
  box-shadow: 0 8px 24px rgba(212, 175, 55, 0.2);
}

.card.download .card-title {
  color: #F4E4C1;
}

.card-body {
  color: var(--text-muted);
  font-size: 13px;
}

/* ==================== BOOK SECTION ==================== */
.book-section {
  margin-top: 14px;
  text-align: center;
}

.book-heading {
  margin: 18px auto 14px;
  width: min(700px, 94vw);
  font-size: clamp(18px, 2vw, 26px);
  font-weight: 900;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.book {
  width: min(720px, 94vw);
  margin: 0 auto 30px;
  position: relative;
}

.book-spread {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px 20px 24px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.08)),
    linear-gradient(135deg, rgba(99, 102, 241, 0.06), transparent 60%),
    linear-gradient(135deg, #2d1f16, #140e0a);
  box-shadow: var(--shadow-lg);
  perspective: 1200px;
  overflow: hidden;
  min-height: clamp(380px, 45vh, 520px);
}

.book-spread::before {
  content: "";
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 50%;
  width: 70px;
  transform: translateX(-50%);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.08), transparent 55%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.65), rgba(255, 255, 255, 0.15) 36%, rgba(0, 0, 0, 0.70));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.10),
    0 8px 18px rgba(0, 0, 0, 0.18);
  z-index: 1;
  pointer-events: none;
}

.book-spread::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 35%);
  z-index: 0;
  pointer-events: none;
}

.page-paper {
  position: relative;
  border-radius: 14px;
  padding: 16px 16px 12px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.50), transparent 45%),
    linear-gradient(180deg, var(--paper), var(--paper2));
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.10),
    inset 0 -16px 24px rgba(0, 0, 0, 0.08);
  transform-style: preserve-3d;
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 2;
}

.page-left {
  padding-right: 35px;
}

.page-right {
  padding-left: 35px;
}

.page-paper h3 {
  margin: 0;
  font-family: ui-serif, Georgia, Cambria, serif;
  letter-spacing: -0.2px;
  color: var(--ink);
  font-size: 16px;
}

.page-text {
  margin-top: 10px;
  flex: 1;
  overflow-y: auto;
  text-align: left;
  line-height: 1.45;
  color: var(--ink);
  mix-blend-mode: multiply;
  text-shadow: 0 0.3px 0 rgba(0, 0, 0, 0.06);
  scrollbar-width: none;
  font-size: 13px;
}

.page-text::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.page-text p {
  margin: 0 0 10px;
}

/* Spiral coil */
.book-coil {
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 50%;
  width: 48px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  z-index: 7;
  pointer-events: none;
  filter: drop-shadow(0 14px 16px rgba(0, 0, 0, 0.32));
}

.book-coil::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 50%;
  width: 28px;
  transform: translateX(-50%);
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.12), transparent 62%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.88), rgba(255, 255, 255, 0.10) 48%, rgba(0, 0, 0, 0.92));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 -14px 22px rgba(0, 0, 0, 0.50);
}

.coil-loop {
  position: relative;
  width: 72px;
  height: 10px;
  border-radius: 9999px;
  background:
    linear-gradient(180deg,
      #07080b 0%,
      #26272d 18%,
      #cfd3da 48%,
      #2a2b31 78%,
      #06070a 100%);
  box-shadow:
    0 8px 10px rgba(0, 0, 0, 0.50),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 2px 1px rgba(255, 255, 255, 0.15),
    inset 0 -3px 4px rgba(0, 0, 0, 0.60);
  transform: rotate(-0.8deg);
}

.coil-loop::before {
  content: "";
  position: absolute;
  inset: 3px 9px;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.88), rgba(255, 255, 255, 0.08) 48%, rgba(0, 0, 0, 0.92));
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.60),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.coil-loop::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 8px;
  right: 8px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  opacity: 0.50;
}

.coil-loop:nth-child(even) {
  transform: rotate(0.9deg);
}

/* Page turn overlay */
.page-turn {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.page-turn::before,
.page-turn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  backface-visibility: hidden;
}

.page-turn::before {
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.50), transparent 45%),
    linear-gradient(180deg, var(--paper), var(--paper2));
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.10),
    inset 0 -16px 24px rgba(0, 0, 0, 0.08);
}

.page-turn::after {
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.35), transparent 55%),
    linear-gradient(180deg, #f4ead3, #f0e3c6);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    inset 0 -16px 24px rgba(0, 0, 0, 0.10);
}

.page-turn.active {
  opacity: 1;
}

.page-turn.dir-next {
  transform-origin: left center;
  animation: page-flip-next 560ms cubic-bezier(0.25, 0.85, 0.2, 1) forwards;
}

.page-turn.dir-prev {
  transform-origin: right center;
  animation: page-flip-prev 560ms cubic-bezier(0.25, 0.85, 0.2, 1) forwards;
}

@keyframes page-flip-next {
  0% {
    transform: translate3d(0, 0, 0) rotateY(0deg) rotateZ(0deg);
    filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.24));
  }

  38% {
    transform: translate3d(-10px, 0, 0) rotateY(-74deg) rotateZ(-1.2deg);
    filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.28));
  }

  70% {
    transform: translate3d(-12px, 0, 0) rotateY(-132deg) rotateZ(-1.8deg);
    filter: drop-shadow(-12px 8px 16px rgba(0, 0, 0, 0.24));
  }

  100% {
    transform: translate3d(-2px, 0, 0) rotateY(-180deg) rotateZ(0deg);
    filter: drop-shadow(-20px 5px 12px rgba(0, 0, 0, 0.16));
  }
}

@keyframes page-flip-prev {
  0% {
    transform: translate3d(0, 0, 0) rotateY(0deg) rotateZ(0deg);
    filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.24));
  }

  38% {
    transform: translate3d(10px, 0, 0) rotateY(74deg) rotateZ(1.2deg);
    filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.28));
  }

  70% {
    transform: translate3d(12px, 0, 0) rotateY(132deg) rotateZ(1.8deg);
    filter: drop-shadow(12px 8px 16px rgba(0, 0, 0, 0.24));
  }

  100% {
    transform: translate3d(2px, 0, 0) rotateY(180deg) rotateZ(0deg);
    filter: drop-shadow(20px 5px 12px rgba(0, 0, 0, 0.16));
  }
}

.page-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
}

.page-controls button {
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s ease;
}

.page-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.page-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#page-indicator {
  color: var(--text-muted);
  font-weight: 800;
  min-width: 70px;
  display: inline-block;
}

/* ==================== SCRIPT EDITOR ==================== */
/* Script editor pages use the same page-paper styling but shown/hidden via editor-mode */

.script-editor-page {
  display: none;
  /* Hidden by default, shown when editor-mode is active */
}

.script-editor-textarea {
  width: 100%;
  height: 100%;
  min-height: 280px;
  border: none;
  background: transparent;
  resize: none;
  font-family: ui-serif, Georgia, Cambria, serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  padding: 8px 0;
  outline: none;
  background-image: repeating-linear-gradient(to bottom,
      transparent,
      transparent 23px,
      rgba(200, 180, 150, 0.3) 23px,
      rgba(200, 180, 150, 0.3) 24px);
  background-size: 100% 24px;
}

.script-editor-textarea::placeholder {
  color: rgba(42, 28, 18, 0.4);
  font-style: italic;
}

.make-video-controls {
  margin-top: 16px;
  text-align: center;
}

.make-video-btn {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  padding: 14px 32px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(212, 175, 55, 0.3);
  transition: all 0.2s ease;
}

.make-video-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(212, 175, 55, 0.4);
}

.make-video-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Script mode toggle - hides summary pages when editor is active */
.book-spread.editor-mode .page-left:not(.script-editor-page),
.book-spread.editor-mode .page-right:not(.script-editor-page) {
  display: none;
}

.book-spread.editor-mode .script-editor-page {
  display: flex;
  flex-direction: column;
}

.book-spread:not(.editor-mode) .script-editor-page {
  display: none;
}

/* ==================== MODALS ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: min(620px, 92vw);
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-primary);
}

.modal-header h3 {
  margin: 0;
  font-weight: 800;
}

.modal-body {
  background: rgba(0, 0, 0, 0.2);
  padding: 14px;
  border-radius: 14px;
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text-secondary);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

#copy-btn,
#download-link {
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
  text-decoration: none;
}

#copy-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

#download-link {
  background: var(--accent-gradient);
  color: white;
}

#modal-close {
  cursor: pointer;
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

#modal-close:hover {
  color: var(--text-primary);
}

/* Settings Modal specific */
.settings-modal-content {
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: transparent;
  padding: 0 8px 0 0;
  min-height: auto;
  max-height: 60vh;
  overflow-y: auto;
  white-space: normal;
}

/* Visible scrollbar for settings */
.settings-body::-webkit-scrollbar {
  width: 8px;
}

.settings-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.settings-body::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.5);
  border-radius: 4px;
}

.settings-body::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.7);
}

.settings-body h4 {
  margin: 8px 0 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 8px;
}

.settings-body h4:first-child {
  margin-top: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.form-group input {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-primary);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.settings-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--success);
  min-height: 20px;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 880px) {
  .tv-body {
    grid-template-columns: 1fr 70px;
    gap: 12px;
  }

  .tv-shell {
    padding: 24px 18px 18px;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 16px;
  }

  .reference-upload-panel {
    grid-template-columns: 1fr;
  }

  .hero {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
  }

  .brand {
    grid-column: 1;
  }

  .controls {
    grid-column: 1;
    justify-self: center;
  }

  .social-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-body {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }


  .tv-body {
    grid-template-columns: 1fr 60px;
    gap: 10px;
  }

  .tv-shell {
    padding: 20px 14px 14px;
    width: min(420px, 94vw);
  }

  .tv-bezel {
    padding: 10px;
  }

  .tv-strip {
    padding: 8px 6px;
  }

  .knob.category-knob {
    padding: 6px 3px;
  }

  .knob-label {
    font-size: 16px;
  }

  .knob-text {
    font-size: 9px;
  }

  .chat-widget {
    bottom: 20px;
    right: 20px;
  }

  .chat-widget-btn {
    width: 56px;
    height: 56px;
    font-size: 22px;
  }

  .chat-widget-panel {
    width: calc(100vw - 40px);
    right: 0;
    max-height: 420px;
  }

  .book-spread {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .page-paper {
    height: auto;
  }

  .page-right {
    display: none;
  }

  .page-left {
    padding-right: 16px;
    padding-left: 45px;
  }

  .book-spread::before {
    left: 30px;
    transform: none;
    width: 60px;
  }

  .book-coil {
    left: 36px;
    transform: none;
    width: 40px;
    filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
  }

  .coil-loop {
    width: 56px;
    height: 9px;
  }

  .coil-loop::before {
    inset: 3px 8px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 22px;
  }

  .controls {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .controls>* {
    width: 100%;
    text-align: center;
  }

  .status {
    min-width: auto;
  }

  .tv-shell {
    width: 100%;
  }
}

/* Video Controls */
.video-controls-bar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 0;
}

.control-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.control-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
