/* ==========================================================================
   MemeCraft - Clean & Functional UI
   ========================================================================== */

:root {
  --bg-page: #0d1117;
  --bg-surface: #161b22;
  --bg-surface-hover: #1c2129;
  --bg-input: #0d1117;
  --border-color: #30363d;
  --border-focus: #58a6ff;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --btn-primary: #1f6feb;
  --btn-primary-hover: #388bfd;
  --btn-secondary: #21262d;
  --btn-secondary-hover: #30363d;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 20px 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header & Brand */
.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

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

.brand-logo {
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.privacy-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: #7ee787;
  background: rgba(46, 160, 67, 0.15);
  border: 1px solid rgba(46, 160, 67, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  user-select: none;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

kbd {
  background: #21262d;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-size: 0.75rem;
  color: var(--text-primary);
  font-family: inherit;
}

/* Template selection strip */
.template-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  overflow: hidden;
}

.upload-tile {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 70px;
  height: 70px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-page);
  transition: all 0.15s ease;
}

.upload-tile:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.upload-tile.active {
  border-color: var(--btn-primary);
  color: var(--btn-primary);
  background: var(--bg-surface-hover);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.template-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.template-list::-webkit-scrollbar {
  height: 6px;
}

.template-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 9999px;
}

.template-item {
  flex-shrink: 0;
  width: 70px;
  height: 70px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  position: relative;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.template-item:hover {
  transform: translateY(-1px);
  border-color: var(--text-muted);
}

.template-item.active {
  border-color: var(--btn-primary);
}

.template-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Workspace Grid */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 880px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

/* Canvas Panel */
.canvas-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 460px;
  position: relative;
}

.canvas-frame {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
}

canvas {
  max-width: 100%;
  max-height: 540px;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  background: #000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  outline: none;
  cursor: default;
  touch-action: none;
}

canvas.cursor-move {
  cursor: grab;
}

canvas.cursor-moving {
  cursor: grabbing;
}

canvas.cursor-draw {
  cursor: crosshair;
}

.canvas-hints {
  font-size: 0.775rem;
  color: var(--text-muted);
  text-align: center;
}

.drop-hint {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.canvas-frame.drag-over .drop-hint {
  opacity: 1;
}

/* Controls Panel */
.controls-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tool Tabs */
.tool-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

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

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

.tool-tabs.five-tabs .tool-tab {
  font-size: 0.75rem;
  padding: 6px 2px;
}

.tool-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.tool-tab:hover {
  color: var(--text-primary);
}

.tool-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.tab-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tab-pane.hidden {
  display: none;
}

/* Segmented Layout Toggle */
.layout-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.toggle-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

/* Text Layers List */
.layer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-layers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.text-layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 8px;
  transition: border-color 0.15s ease;
}

.text-layer-item.active {
  border-color: var(--border-focus);
}

.layer-handle {
  color: var(--text-muted);
  font-size: 0.75rem;
  user-select: none;
  cursor: grab;
}

.layer-input {
  flex: 1;
  background: transparent !important;
  border: none !important;
  padding: 4px 0 !important;
  color: var(--text-primary);
  font-size: 0.85rem !important;
  outline: none !important;
}

.btn-layer-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.btn-layer-del:hover {
  color: #f85149;
}

/* Image Overlays List */
.overlay-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.overlay-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.overlay-item.active {
  border-color: var(--border-focus);
}

.overlay-thumb {
  width: 36px;
  height: 36px;
  object-fit: contain;
  background: #000;
  border-radius: var(--radius-sm);
}

.overlay-info {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-overlay-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
}

.selected-overlay-controls.hidden {
  display: none;
}

/* Control Groups */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.flex-1 {
  flex: 1;
}

.control-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

input[type="text"], textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus, textarea:focus {
  border-color: var(--border-focus);
}

input[type="text"]::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

.select-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.select-input:focus {
  border-color: var(--border-focus);
}

/* Text Color Presets */
.text-color-presets {
  display: flex;
  gap: 6px;
  align-items: center;
  height: 36px;
}

.btn-text-color {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.btn-text-color:hover {
  transform: scale(1.08);
}

.btn-text-color.active {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--btn-primary);
}

/* Aspect Ratio Selector */
.ratio-toggle {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.btn-ratio {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

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

.btn-ratio.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

/* Range Slider */
input[type="range"] {
  width: 100%;
  accent-color: var(--btn-primary);
  cursor: pointer;
}

/* Checkbox */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  padding: 6px 0;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--btn-primary);
  cursor: pointer;
}

/* Pen Tool Controls */
.pen-sizes {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.btn-size {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.btn-size.active {
  background: var(--bg-surface);
  border-color: var(--border-focus);
  color: var(--text-primary);
}

.color-palette {
  display: flex;
  gap: 8px;
}

.btn-color {
  width: 28px;
  height: 28px;
  border-radius: 9999px;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.btn-color:hover {
  transform: scale(1.1);
}

.btn-color.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--btn-primary);
}

/* Export Panel */
.file-stat-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Actions */
.actions {
  display: flex;
  gap: 8px;
}

.main-actions {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-sm {
  font-size: 0.775rem;
  padding: 4px 8px;
}

.btn-primary {
  flex: 1;
  background: var(--btn-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
}

.btn-secondary {
  flex: 1;
  background: var(--btn-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: var(--btn-secondary);
  color: var(--text-primary);
}

/* Footer */
.footer {
  text-align: center;
  padding: 14px 0 6px 0;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.footer a {
  color: var(--border-focus);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: #21262d;
  color: #f0f6fc;
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 50;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Meme Video Studio & Animation Presets
   ========================================================================== */
.video-style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.btn-video-style {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.btn-video-style:hover {
  background: var(--bg-surface-hover);
  border-color: var(--text-secondary);
}

.btn-video-style.active {
  background: rgba(31, 111, 235, 0.15);
  border-color: var(--btn-primary);
  box-shadow: 0 0 0 1px var(--btn-primary);
}

.btn-video-style .style-icon {
  font-size: 1.2rem;
  margin-bottom: 2px;
}

.btn-video-style .style-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-video-style .style-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* Progress bar */
.video-progress-box {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.video-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.video-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1f6feb, #58a6ff);
  border-radius: 4px;
  transition: width 0.1s ease;
}

.video-progress-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ==========================================================================
   Video Preview Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  display: none;
  opacity: 0;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopIn {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

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

.modal-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-badge {
  font-size: 0.7rem;
  color: #58a6ff;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s ease;
}

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

.modal-body {
  padding: 16px 18px;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-preview-wrapper {
  width: 100%;
  max-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-video {
  max-width: 100%;
  max-height: 440px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  background: #000;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-footer .btn {
  flex: 1;
  justify-content: center;
}