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

:root {
  --bg: #0A0A0A;
  --bg-card: #111111;
  --bg-card-hover: #181818;
  --bg-input: #1A1A1A;
  --border: #222222;
  --border-focus: #444444;
  --text: #F0F0F0;
  --text-muted: rgba(240,240,240,0.5);
  --text-secondary: #888888;
  --accent: #C8C8C8;
  --accent-hover: #FFFFFF;
  --danger: #CC4444;
  --success: #44AA66;
  --radius: 8px;
  --radius-sm: 4px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.header-left { display: flex; align-items: baseline; gap: 16px; }
h1 { font-size: 1.2rem; font-weight: 600; letter-spacing: -0.02em; }

nav { display: flex; gap: 4px; }
.nav-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { color: var(--text); background: var(--bg-card); }
.nav-btn.active { color: var(--text); background: var(--bg-card); border-color: var(--border); }

/* Main */
main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 16px;
}

/* Template Selector */
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.template-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}
.template-card:hover { border-color: var(--border-focus); background: var(--bg-card-hover); }
.template-card.selected { border-color: var(--accent); }
.template-card h3 { font-size: 0.95rem; font-weight: 500; margin-bottom: 6px; }
.template-card p { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4; }

/* Form Fields */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input[type="text"],
.field textarea,
.field select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  transition: border-color 0.15s;
  resize: vertical;
  -webkit-appearance: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--border-focus);
}
.field textarea { min-height: 72px; }

/* Sections Editor */
.section-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}
.section-item .section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-type-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
}
.section-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.section-remove:hover { color: var(--danger); background: rgba(204,68,68,0.1); }

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(200,200,200,0.03);
}
.upload-icon { font-size: 2rem; color: var(--text-muted); margin-bottom: 8px; }
.upload-zone p { font-size: 0.85rem; color: var(--text-secondary); }
.upload-hint { font-size: 0.75rem !important; color: var(--text-muted) !important; margin-top: 4px; }

.file-list { margin-top: 12px; }
.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 0.85rem;
  gap: 8px;
}
.file-item span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.file-item .file-ext {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 3px;
  flex-shrink: 0;
}
.file-item .file-remove,
.file-item .script-file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-item .file-remove:hover,
.file-item .script-file-remove:hover { color: var(--danger); }

.project-name-row {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.project-name-row label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.project-name-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}
.project-name-row input:focus { outline: none; border-color: var(--border-focus); }

/* Preview */
.preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.preview-header h2 { margin-bottom: 0; }
.preview-controls { display: flex; align-items: center; gap: 8px; }
.preview-container {
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 9/16;
  max-height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.preview-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.preview-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-render, .btn-icon {
  font-family: var(--font);
  font-size: 0.85rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-primary:hover { color: var(--text); border-color: var(--border-focus); }
.btn-secondary {
  padding: 10px 16px;
  background: none;
  color: var(--text-muted);
  border: 1px dashed var(--border);
}
.btn-secondary:hover { color: var(--text); border-color: var(--border-focus); }
.btn-icon {
  padding: 8px 14px;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  min-width: 44px;
  min-height: 44px;
}
.btn-icon:hover { color: var(--text); }
.btn-render {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}
.btn-render:hover { background: var(--accent-hover); }
.btn-render:disabled { opacity: 0.4; cursor: not-allowed; }

/* Render Status */
.render-status { margin-top: 16px; }
.render-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.render-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
  animation: render-pulse 2s infinite;
}
@keyframes render-pulse {
  0%,100% { opacity: 0.6; }
  50% { opacity: 1; }
}
#render-status-text { font-size: 0.8rem; color: var(--text-muted); }

/* Archive */
.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.archive-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.archive-item:hover { border-color: var(--border-focus); }
.archive-thumb {
  aspect-ratio: 9/16;
  max-height: 300px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.archive-thumb video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.archive-info { padding: 14px; }
.archive-info h3 { font-size: 0.9rem; font-weight: 500; margin-bottom: 4px; }
.archive-info .archive-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}
.archive-actions {
  padding: 0 14px 14px;
  display: flex;
  gap: 8px;
}
.archive-actions a, .archive-actions button {
  flex: 1;
  text-align: center;
  padding: 10px;
  font-family: var(--font);
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.archive-actions a {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.archive-actions a:hover { color: var(--text); border-color: var(--border-focus); }

.archive-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* Layout — Desktop */
.create-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

/* Script Generator */
.script-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.script-left select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}
.script-left select:focus { outline: none; border-color: var(--border-focus); }

.script-output { min-height: 200px; }
.script-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 60px 20px;
}
.script-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.script-loading .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.script-result { font-size: 0.9rem; line-height: 1.6; }
.script-result .script-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.script-result .script-section:last-child { border-bottom: none; }
.script-result .script-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 6px;
}
.script-result .script-section-content { color: var(--text); }
.script-result .talking-point {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}
.talking-point .tp-point { font-weight: 500; margin-bottom: 4px; }
.talking-point .tp-details { font-size: 0.82rem; color: var(--text-secondary); }
.talking-point .tp-duration {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.script-result .script-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.script-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Duration indicator */
.duration-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 3px 8px;
  border-radius: 3px;
  margin-left: 8px;
}

/* ============================================
   MOBILE RESPONSIVE — max-width: 768px
   ============================================ */
@media (max-width: 768px) {
  html { font-size: 14px; }

  /* Header: stack logo top, nav bottom */
  header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
    align-items: stretch;
  }
  .header-left {
    justify-content: center;
  }
  h1 { font-size: 1.1rem; }

  nav {
    justify-content: center;
    gap: 2px;
    width: 100%;
  }
  .nav-btn {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    font-size: 0.8rem;
  }

  /* Main content */
  main {
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  /* Cards */
  .card { padding: 16px; margin-bottom: 12px; }

  /* Layouts go single column */
  .create-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .script-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Templates: stack vertically */
  .template-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .template-card {
    padding: 14px;
  }
  .template-card h3 { font-size: 0.9rem; }
  .template-card p { font-size: 0.78rem; }

  /* Upload zone smaller */
  .upload-zone { padding: 24px 16px; }
  .upload-icon { font-size: 1.5rem; }

  /* Project name row: stack */
  .project-name-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  /* Preview */
  .preview-container { max-height: 400px; }

  /* Archive grid */
  .archive-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .archive-thumb { max-height: 200px; }
  .archive-info { padding: 10px; }
  .archive-info h3 { font-size: 0.82rem; }
  .archive-actions { padding: 0 10px 10px; }

  .archive-empty { padding: 40px 16px; }

  /* Script output */
  .script-output { min-height: 150px; }
  .script-placeholder { padding: 40px 16px; }

  /* Buttons: bigger touch targets */
  .btn-render { padding: 16px; font-size: 1rem; }
  .btn-primary { padding: 14px; }
  .btn-secondary { padding: 12px 16px; }
}

/* ============================================
   SMALL MOBILE — max-width: 400px
   ============================================ */
@media (max-width: 400px) {
  main { padding: 12px; }
  .card { padding: 14px; }

  .archive-grid { grid-template-columns: 1fr; }

  .nav-btn { font-size: 0.75rem; padding: 8px 6px; }
}

/* ============================================
   TABLET — 769px to 1024px
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
  .create-layout {
    grid-template-columns: 1fr 320px;
  }
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
