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

:root {
  --bg:        #0d0d0f;
  --surface:   #15151a;
  --surface2:  #1e1e26;
  --border:    #2a2a36;
  --accent:    #ffab3f;
  --accent2:   #7b6ef6;
  --text:      #e8e8f0;
  --muted:     #6b6b80;
  --danger:    #ff4f64;
  --radius:    12px;
  --font-main: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  border-bottom: 1px solid var(--border);
  padding: 20px 40px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}

.logo-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
  filter: saturate(1.2);
}

.logo-mark svg {
  width: 30px; height: 30px;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.header-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 100px;
  margin-left: 4px;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  max-width: 1100px;
  width: 100%;
  margin: 32px auto;
  padding: 0 24px;
  align-items: start;
  flex: 1;
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ── Dropzone ── */
#dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 20px;
}

#dropzone:hover, #dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(255, 171, 63, 0.04);
}

#dropzone .drop-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  display: block;
}

#dropzone p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

#dropzone strong { color: var(--accent); }

/* ── Frame Count Bar ── */
.frames-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 100px;
}

/* ── Grid frames ── */
#framesGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  min-height: 100px;
}

#emptyState {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100px;
  color: var(--muted);
  font-size: 0.82rem;
}

.frame-card {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: grab;
  transition: border-color 0.2s, transform 0.15s;
  aspect-ratio: 1;
  background: var(--surface2);
}

.frame-card:hover       { border-color: var(--accent2); }
.frame-card.dragging    { opacity: 0.4; transform: scale(0.95); }
.frame-card.drag-target { border-color: var(--accent); }

.frame-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.frame-number {
  position: absolute;
  top: 5px; left: 5px;
  background: rgba(0,0,0,0.7);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
}

.remove-btn {
  position: absolute;
  top: 5px; right: 5px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 20px; height: 20px;
  font-size: 0.6rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.frame-card:hover .remove-btn { display: flex; }

/* ── Sidebar Controls ── */
.control-group { margin-bottom: 18px; }

.control-group label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  min-width: 0;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
}

.range-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  white-space: nowrap;
  min-width: 52px;
  text-align: right;
}

select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-label { font-size: 0.88rem; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px; height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent2); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ── Generate Button ── */
#generateBtn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #1a1000;
  border: none;
  border-radius: 10px;
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  letter-spacing: 0.02em;
}

#generateBtn:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
#generateBtn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Progress ── */
#progressSection {
  margin-top: 20px;
  display: none;
}

.progress-track {
  background: var(--border);
  border-radius: 100px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

#progressBar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 100px;
  transition: width 0.3s;
  width: 0%;
}

#progressText {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}

/* ── Result ── */
#resultSection {
  margin-top: 20px;
  display: none;
}

#resultImg {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 10px;
}

.file-size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.78rem;
}

.file-size-label { color: var(--muted); }

.file-size-value {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 500;
}

#downloadBtn {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 10px;
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s;
}

#downloadBtn:hover { background: rgba(255, 171, 63, 0.08); }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: auto;
}

.footer-left {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.footer-right-group {
  display: flex;
  align-items: center;
  gap: 20px;
}

.footer-link {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-mono);
  transition: color 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-link:hover { color: var(--accent); }

.footer-link svg {
  width: 15px; height: 15px;
  fill: currentColor;
  flex-shrink: 0;
}

.footer-link--arrow::after {
  content: '↗';
  font-size: 0.7rem;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 0.83rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 999;
}

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

/* ── Responsive ── */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  header  { padding: 16px 20px; }
  footer  { padding: 16px 20px; flex-direction: column; align-items: flex-start; gap: 12px; }
}
