:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --border: #e5e5ea;
  --border-strong: #c0c0c8;
  --text: #0a0a0f;
  --muted: #6a6a78;
  --accent: #0066ff;
  --accent-2: #8b5cf6;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-strong: 0 4px 24px rgba(0,0,0,0.12);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0f;
    --bg-soft: #14141c;
    --surface: #14141c;
    --surface-2: #1c1c28;
    --border: #2a2a3a;
    --border-strong: #3a3a4f;
    --text: #f5f5fa;
    --muted: #8a8aa0;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.3);
    --shadow-strong: 0 4px 24px rgba(0,0,0,0.6);
  }
}

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

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.12);
}

/* === Topbar === */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand .version {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  background: var(--surface-2);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.tabs { display: flex; gap: 0.25rem; }

.tab {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.15s;
}

.tab:hover:not(:disabled) { color: var(--text); }
.tab.active { background: var(--surface-2); color: var(--text); }
.tab:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Layout / views === */
.layout {
  padding: 2rem 1.5rem 4rem;
  max-width: 1400px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.hero {
  margin-bottom: 2rem;
  max-width: 720px;
}

.hero h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--muted);
  font-size: 0.95rem;
}

/* === Filters === */
.filters {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filters #search {
  flex: 1;
  min-width: 240px;
}

.count {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: auto;
  font-family: var(--mono);
}

/* === Grid === */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.card-preview {
  position: relative;
  background: #0a0a0f;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.card-preview.format-vertical { aspect-ratio: 16 / 9; /* mantenemos 16:9 pero con letterbox */ }

.card-preview iframe {
  position: absolute;
  top: 0;
  left: 0;
  border: none;
  pointer-events: none;
  transform-origin: top left;
}

.card-preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.35);
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.card-body {
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}

.card-format {
  display: inline-flex;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--surface-2);
  color: var(--accent);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-family: var(--mono);
  align-self: flex-start;
}

.card-title { font-weight: 700; font-size: 0.98rem; letter-spacing: -0.01em; }
.card-name { color: var(--muted); font-size: 0.72rem; font-family: var(--mono); }
.card-desc { color: var(--muted); font-size: 0.82rem; line-height: 1.45; flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.tag-chip {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.66rem;
  padding: 0.18rem 0.42rem;
  border-radius: 3px;
  font-family: var(--mono);
}

/* === Detail view === */
.back-btn {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  padding: 0.4rem 0;
  font-weight: 500;
  transition: color 0.15s;
}

.back-btn:hover { color: var(--text); }

.detail-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-info h2 { font-size: 1.5rem; letter-spacing: -0.02em; margin-bottom: 0.4rem; }
.detail-info .muted { color: var(--muted); }
.detail-meta {
  margin: 1.25rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

button.primary, button.secondary {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.92rem;
  transition: all 0.15s;
}

button.primary {
  background: var(--accent);
  color: white;
}

button.primary:hover:not(:disabled) { background: #0052cc; }
button.primary:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover:not(:disabled) { background: var(--border); }

.hint { font-size: 0.78rem; line-height: 1.4; }

.preview-frame {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  position: relative;
  border: 1px solid var(--border);
}

.preview-frame.format-vertical { aspect-ratio: 9 / 16; max-width: 360px; margin: 0 auto; }
.preview-frame.format-square { aspect-ratio: 1 / 1; max-width: 540px; margin: 0 auto; }

.preview-frame iframe {
  position: absolute;
  top: 0;
  left: 0;
  border: none;
  display: block;
  transform-origin: top left;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-strong);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-header h3 span {
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.95rem;
}

.modal-close {
  font-size: 1.5rem;
  color: var(--muted);
  line-height: 1;
  padding: 0 0.5rem;
}

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

.modal-body { padding: 1.25rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.field > label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.segmented {
  display: flex;
  gap: 0.3rem;
  background: var(--surface-2);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.segmented .seg {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  border-radius: 5px;
  transition: all 0.15s;
}

.segmented .seg:hover { color: var(--text); }
.segmented .seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.duration-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.duration-row input { flex: 1; max-width: 120px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* === Progress === */
.progress-info { margin-bottom: 1rem; }
.progress-info p { font-size: 0.92rem; }
.progress-info p:first-child { font-weight: 600; margin-bottom: 0.25rem; }
.progress-info .muted { font-size: 0.8rem; font-family: var(--mono); }

.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.2s;
}

.done-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0.5rem auto 1rem;
}

#modal-done p { text-align: center; }
#modal-done p:nth-of-type(1) { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
#modal-done .muted { font-size: 0.85rem; font-family: var(--mono); margin-bottom: 1rem; }

/* === Empty state (galeria vacia) === */
.empty-state {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  margin: 2rem 0;
}

.empty-state h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.empty-state p {
  color: var(--muted);
  margin-bottom: 1rem;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

.code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text);
  margin: 0.75rem auto;
  max-width: 600px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

/* === Render cards === */
.render-card .card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.canal-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-family: var(--mono);
}

.canal-badge.canal-pau { background: rgba(0, 102, 255, 0.12); color: var(--accent); }
.canal-badge.canal-martin { background: rgba(139, 92, 246, 0.12); color: var(--accent-2); }
.canal-badge.canal-comun { background: var(--surface-2); color: var(--muted); }

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.4rem;
  gap: 0.5rem;
}

.muted.small { font-size: 0.72rem; }

/* === Prompt helper en detalle catalogo === */
.prompt-helper {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.prompt-helper .code-block {
  margin: 0.5rem 0;
  max-width: 100%;
}

/* === Video player en render detail === */
#render-video {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background: #000;
  border: none;
}

.preview-frame video {
  display: block;
}

.detail-actions a.primary {
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.link-btn {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover { opacity: 0.8; }
