/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #09090b;
  --surface: #111115;
  --surface2: #18181e;
  --surface3: #1e1e26;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --gold: #c8922a;
  --gold-light: #e8b84b;
  --gold-dim: rgba(200,146,42,0.15);
  --text: #ebebeb;
  --text-muted: #777;
  --text-dim: #444;
  --radius: 10px;
  --panel-width: 290px;
  --header-h: 50px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  gap: 12px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.logo-icon {
  font-size: 18px;
  color: var(--gold);
  line-height: 1;
}
.logo-text {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  padding-left: 2px;
  border-left: 1px solid var(--border-hover);
  margin-left: 2px;
  padding-left: 8px;
}

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

.header-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

#main { display: flex; flex: 1; overflow: hidden; }

/* ── Control Panel ────────────────────────────────────────────── */
#controls {
  width: var(--panel-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#controls::-webkit-scrollbar { width: 3px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.control-section {
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.control-section:last-child { border-bottom: none; }

.section-title {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 12px;
}

/* ── Upload zone ──────────────────────────────────────────────── */
.upload-zone {
  border: 1.5px dashed rgba(200,146,42,0.3);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}
.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--gold);
  background: var(--gold-dim);
  outline: none;
}
.upload-zone.drag-over {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.upload-prompt {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  color: var(--text-muted);
}
.upload-icon-svg {
  width: 28px;
  height: 28px;
  color: var(--gold);
  margin-bottom: 4px;
  opacity: 0.8;
}
.upload-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}
.upload-hint {
  font-size: 10px;
  color: var(--text-dim);
}

.upload-loaded {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-check {
  width: 16px;
  height: 16px;
  color: #4ade80;
  flex-shrink: 0;
}
.upload-filename {
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: left;
}

.video-info {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.info-chip {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
}

/* ── Control rows ─────────────────────────────────────────────── */
.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.control-row:last-child { margin-bottom: 0; }
.control-row label {
  width: 52px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
}
.control-row input[type=range] {
  flex: 1;
  accent-color: var(--gold);
  cursor: pointer;
  height: 3px;
}
.ctrl-value {
  width: 34px;
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Layer blocks ─────────────────────────────────────────────── */
.layer-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.layer-block:last-of-type { margin-bottom: 0; }
.layer-block:has(input[type=checkbox]:checked) {
  border-color: rgba(200,146,42,0.2);
}

.layer-header { padding: 8px 10px; }
.layer-fields {
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.layer-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

/* Toggle switch */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle-label input[type=checkbox] { display: none; }
.toggle-track {
  width: 30px;
  height: 17px;
  border-radius: 9px;
  background: var(--surface3);
  border: 1px solid var(--border-hover);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle-label input:checked + .toggle-track {
  background: var(--gold);
  border-color: var(--gold);
}
.toggle-label input:checked + .toggle-track::after {
  transform: translateX(13px);
  background: #fff;
}

/* Text inputs */
.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.text-input:focus { border-color: rgba(200,146,42,0.5); }
.textarea {
  min-height: 52px;
  resize: vertical;
  line-height: 1.5;
}

.layer-meta {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
}

.select-sm {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  padding: 3px 5px;
  outline: none;
  cursor: pointer;
  font-family: inherit;
}
.select-sm:focus { border-color: rgba(200,146,42,0.5); }

.color-pick {
  width: 26px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px;
  cursor: pointer;
  background: none;
}

/* Count row */
.count-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.num-input { width: 70px; }
.count-arrow { color: var(--text-muted); font-size: 14px; }

/* Alignment row */
.align-row { margin-top: 10px; }
.align-btns { display: flex; gap: 4px; flex: 1; }
.align-btn {
  flex: 1;
  padding: 5px 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.align-btn svg {
  width: 14px;
  height: 14px;
}
.align-btn.active {
  background: var(--gold-dim);
  border-color: rgba(200,146,42,0.5);
  color: var(--gold);
}
.align-btn:hover:not(.active) {
  border-color: var(--border-hover);
  color: var(--text);
}

/* Progress bar */
.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 5px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  width: 0%;
  transition: width 0.15s;
  border-radius: 4px;
}
.progress-label {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.progress-note {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 5px;
  line-height: 1.4;
}

/* Panel footer */
.panel-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}
.panel-credit {
  font-size: 10px;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}
.panel-credit:hover { color: var(--gold); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gold);
  color: #000;
  font-weight: 700;
  font-size: 12.5px;
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.btn-primary:hover:not(:disabled) { opacity: 0.85; transform: translateY(-1px); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-secondary {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--gold);
  font-weight: 700;
  font-size: 12.5px;
  border: 1.5px solid var(--gold);
  border-radius: 7px;
  padding: 6px 13px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-secondary:hover:not(:disabled) { background: rgba(212,175,55,0.12); transform: translateY(-1px); }
.btn-secondary:active:not(:disabled) { transform: translateY(0); }
.btn-secondary:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 11px;
  transition: border-color 0.15s, color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text); }
.btn-sm { padding: 3px 8px; font-size: 11px; }

/* ── Preview area ─────────────────────────────────────────────── */
#preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #050507;
  position: relative;
  overflow: hidden;
}

#canvas-wrap {
  position: relative;
  display: inline-block;
  box-shadow: 0 12px 60px rgba(0,0,0,0.7);
}

#preview-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - var(--header-h));
}

.preview-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 13px;
  position: absolute;
  pointer-events: none;
  user-select: none;
}
.hint-icon {
  width: 40px;
  height: 40px;
  opacity: 0.4;
}

/* ── Card drag handle (DOM overlay) ──────────────────────────── */
#card-handle {
  position: absolute;
  cursor: move;
  border: 1.5px solid rgba(200,146,42,0.6);
  border-radius: 16px;
  pointer-events: auto;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.04);
  display: none;
  transition: border-color 0.15s;
}
#card-handle:hover { border-color: var(--gold); }
#card-handle.dragging { border-color: var(--gold-light); cursor: grabbing; }

/* ── Resize handles ───────────────────────────────────────────── */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--gold);
  border: 2px solid #000;
  border-radius: 50%;
  display: none;
  z-index: 10;
  transition: transform 0.1s;
}
.resize-handle:hover { transform: scale(1.3); }
#rh-se { cursor: se-resize; bottom: -6px; right: -6px; }
#rh-sw { cursor: sw-resize; bottom: -6px; left: -6px; }
#rh-ne { cursor: ne-resize; top: -6px; right: -6px; }
#rh-nw { cursor: nw-resize; top: -6px; left: -6px; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --panel-width: 100%; }
  #main { flex-direction: column; }
  #controls {
    width: 100%;
    height: 44vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
  }
  #preview-area { height: 56vh; }
  .logo-sub { display: none; }
}

@media (max-width: 400px) {
  #header { padding: 0 12px; }
  .logo-text { font-size: 13px; }
  .btn-primary { padding: 6px 10px; font-size: 12px; }
}
