/* Modern Dark-Themed Multi-Iframe Embed Studio */
:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #101623;
  --bg-card: #151c2d;
  --bg-card-hover: #1b2439;
  --bg-header: rgba(16, 22, 35, 0.85);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;
  --border-glow: rgba(99, 102, 241, 0.25);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --accent-pink: #ec4899;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-header: 0 4px 20px rgba(0, 0, 0, 0.4);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #253046;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #374663;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  box-shadow: var(--shadow-header);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px var(--primary-glow);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #ffffff 40%, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Desktop indicator badge */
.desktop-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  padding: 5px 12px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.desktop-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 2s infinite ease-in-out;
}

.stats-counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.count-label {
  color: var(--text-muted);
  font-weight: 500;
}

.count-value {
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
}

/* Header Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.styled-select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.82rem;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.styled-select:hover, .styled-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 8px var(--border-glow);
}

.styled-select.sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  outline: none;
  font-family: var(--font-sans);
}

.btn:active {
  transform: scale(0.97);
}

.btn.sm {
  padding: 5px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.btn-accent {
  background: linear-gradient(135deg, #ec4899, #d946ef);
  color: #fff;
  box-shadow: 0 2px 10px rgba(236, 72, 153, 0.3);
}

.btn-accent:hover {
  background: linear-gradient(135deg, #db2777, #c026d3);
  box-shadow: 0 4px 15px rgba(236, 72, 153, 0.5);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.btn-danger-ghost {
  background: transparent;
  color: #f87171;
}

.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

/* Sub-bar Utility */
.sub-bar {
  background: rgba(16, 22, 35, 0.5);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.quick-add-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 640px;
}

.quick-add-form input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  outline: none;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
}

.quick-add-form input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 10px var(--border-glow);
  background: var(--bg-card);
}

.quick-add-form input::placeholder {
  color: var(--text-faint);
}

.sub-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Grid Container */
.grid-container {
  display: grid;
  gap: 20px;
  padding: 24px;
  flex: 1;
  align-items: start;
}

/* Grid Columns Modifier Classes - Strictly maintains Desktop Grid across all screens */
.grid-cols-auto {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.grid-cols-1 {
  grid-template-columns: 1fr;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-cols-5 {
  grid-template-columns: repeat(5, 1fr);
}

.grid-cols-6 {
  grid-template-columns: repeat(6, 1fr);
}

/* Iframe Card Component */
.iframe-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.iframe-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 12px 30px -5px rgba(0, 0, 0, 0.7), 0 0 15px rgba(99, 102, 241, 0.15);
}

.iframe-card.is-active {
  border-color: var(--primary);
}

/* Card Header */
.card-header {
  background: #141b2a;
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
}

.card-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.card-badge-num {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.platform-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.platform-badge.youtube {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.platform-badge.shorts {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(236, 72, 153, 0.25));
  color: #f43f5e;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

.platform-badge.twitch {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.platform-badge.web {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.card-url-title {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  text-decoration: none;
  transition: color 0.2s;
}

.card-url-title:hover {
  color: #fff;
  text-decoration: underline;
}

/* Card Action Buttons */
.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.icon-btn.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Frame Body */
.frame-wrapper {
  position: relative;
  width: 100%;
  background: #0c1017;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Aspect Ratio Modifiers */
.aspect-shorts .frame-wrapper {
  aspect-ratio: 9 / 16;
  max-height: 800px;
}

.aspect-widescreen .frame-wrapper {
  aspect-ratio: 16 / 9;
}

.aspect-desktop .frame-wrapper {
  aspect-ratio: 4 / 3;
}

.aspect-square .frame-wrapper {
  aspect-ratio: 1 / 1;
}

.aspect-full .frame-wrapper {
  height: 680px;
}

.aspect-screen .frame-wrapper {
  height: 80vh;
}

.embed-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
  transition: transform 0.15s ease-out;
}

/* Desktop View for Embeds: iframe scaled to simulate full 1280px desktop resolution */
.iframe-card.is-desktop-mode .frame-wrapper {
  position: relative;
  overflow: hidden;
}

.iframe-card.is-desktop-mode .embed-iframe {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: #fff;
}

.btn.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--primary);
  color: #c7d2fe;
}

.icon-btn.active {
  color: #818cf8;
  background: rgba(99, 102, 241, 0.2);
}

/* Iframe Loading Skeleton */
.frame-loader {
  position: absolute;
  inset: 0;
  background: #0c1017;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 2;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(99, 102, 241, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.frame-loader.loaded {
  opacity: 0;
  visibility: hidden;
}

/* Fallback Notice for blocked iframes (e.g. strict X-Frame-Options) */
.iframe-fallback {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  z-index: 5;
}

.iframe-fallback a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.iframe-fallback a:hover {
  text-decoration: underline;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
  flex: 1;
}

.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 1.25rem;
  color: var(--text-main);
  margin-bottom: 8px;
}

.empty-state p {
  max-width: 480px;
  font-size: 0.9rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

.empty-state code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  color: #a5b4fc;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 90vh;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #131927;
}

.modal-title-group h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}

.modal-title-group p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* File Drop Zone */
.file-drop-zone {
  border: 2px dashed rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.05);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-drop-zone:hover, .file-drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.file-drop-zone svg {
  color: var(--primary);
  flex-shrink: 0;
}

.drop-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.drop-text strong {
  font-size: 0.88rem;
  color: var(--text-main);
}

.drop-text span {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editor-header strong {
  font-size: 0.84rem;
  color: var(--text-main);
}

.editor-badge {
  font-size: 0.74rem;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.15);
  padding: 2px 8px;
  border-radius: 9999px;
  font-family: var(--font-mono);
}

#urlTextarea {
  width: 100%;
  height: 200px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s ease;
}

#urlTextarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 10px var(--border-glow);
}

.conversion-guide {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--text-faint);
}

.guide-tag {
  color: #fbbf24;
  font-weight: 600;
}

.conversion-guide span:not(.guide-tag) {
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-muted);
}

.modal-footer {
  padding: 16px 24px;
  background: #131927;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.footer-left, .footer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mobile & Tablet Responsive Media Queries */
@media (max-width: 900px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px;
    gap: 12px;
  }

  .header-left {
    justify-content: space-between;
    width: 100%;
  }

  .header-actions {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 6px;
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .sub-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 16px;
    gap: 10px;
  }

  .quick-add-form {
    max-width: 100%;
    width: 100%;
  }

  .sub-bar-right {
    justify-content: flex-end;
    width: 100%;
  }

  .grid-container {
    padding: 12px;
    gap: 16px;
  }
}

@media (max-width: 640px) {
  .brand-title {
    font-size: 1rem;
  }

  .brand-sub {
    font-size: 0.68rem;
  }

  /* Automatically adapt grid to 1 column on phone screens */
  .grid-cols-2, .grid-cols-3, .grid-cols-4, .grid-cols-5, .grid-cols-6 {
    grid-template-columns: 1fr;
  }

  .aspect-shorts .frame-wrapper {
    aspect-ratio: auto;
    height: 580px;
    max-height: 82vh;
  }

  .card-header {
    padding: 8px 10px;
  }

  .card-actions .icon-btn {
    padding: 6px;
  }

  .modal-card {
    max-height: 94vh;
  }

  .modal-header, .modal-body, .modal-footer {
    padding: 14px 16px;
  }
}
