:root {
  --bg: #0c1014;
  --card: #121820;
  --ink: #e6edf5;
  --muted: #9ea9b7;
  --accent: #3d8bff;
  --accent-2: #b98458;
  --border: #253242;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -8%, rgba(61, 139, 255, 0.16) 0%, transparent 42%),
    radial-gradient(circle at 88% 8%, rgba(62, 170, 144, 0.1) 0%, transparent 42%),
    linear-gradient(180deg, #0b1016 0%, #0c1118 100%),
    var(--bg);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.8rem;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.controls,
.preview {
  margin-top: 18px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
}

.dropzone {
  display: block;
  width: 100%;
  border: 2px dashed #3a4b61;
  border-radius: 12px;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: 140ms ease;
}

.dropzone.dragover {
  border-color: var(--accent);
  color: var(--accent);
  background: #11271f;
}

.dropzone input {
  display: none;
}

.row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: start;
}

.actions-row {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.93rem;
}

.inline-check > span:last-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="number"],
input[type="range"],
select,
button {
  width: 100%;
}

input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 1rem;
  background: #0f141b;
  color: var(--ink);
}

select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  background: #0f141b;
  color: var(--ink);
}

button {
  border: 1px solid #33465d;
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 650;
  cursor: pointer;
  background: #1a2431;
  color: #d6e2f2;
  transition: 120ms ease;
  min-height: 38px;
}

button:hover:not(:disabled) {
  background: #212f40;
  border-color: #436081;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#generateBtn {
  background: var(--accent-2);
  border-color: #d2a074;
  color: #1a1210;
}

#generateBtn:hover:not(:disabled) {
  background: #ca9568;
  border-color: #e0b489;
}

#downloadSelectedBtn {
  background: #1a2431;
  border-color: #33465d;
}

#undoBtn,
#restoreBtn,
#toggleSelectBtn,
#downloadAllBtn,
#downloadSelectedBtn {
  background: #1a2431;
  border-color: #33465d;
}

.meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.preview h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #1d2f4c;
  color: #b7ceff;
  border: 1px solid #3b5582;
}

.mode-pill.reorder {
  background: #2b234b;
  color: #cfbeff;
  border-color: #57428f;
}

.preview h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.helper {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.ig-preview-wrap {
  display: grid;
  grid-template-columns: 42px minmax(300px, 360px) 42px;
  justify-content: start;
  gap: 10px;
  align-items: center;
}

.ig-nav {
  min-height: 34px;
  padding: 6px 0;
  font-size: 16px;
}

.phone-frame {
  border: 1px solid #3a4658;
  background: #0a0e13;
  border-radius: 26px;
  padding: 10px;
  position: relative;
  width: 360px;
}

.phone-notch {
  width: 120px;
  height: 16px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: #000;
  border: 1px solid #2b323b;
}

.ig-shell {
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #1d2631;
  background: #02070f;
}

.ig-topbar {
  font-size: 11px;
  color: #dce4f2;
  display: flex;
  justify-content: space-between;
  padding: 8px 10px 6px;
}

.ig-posthead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #0f1a27;
  border-bottom: 1px solid #0f1a27;
}

.ig-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: linear-gradient(145deg, #f7b941, #ee3664 45%, #7d4dff);
  position: relative;
}

.ig-avatar::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 999px;
  background: #172334;
}

.ig-postmeta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  flex: 1;
}

.ig-postmeta strong {
  font-size: 14px;
}

.ig-postmeta span {
  font-size: 12px;
  color: #aeb7c7;
}

.ig-menu {
  color: #c8d1df;
  font-size: 17px;
}

.ig-media-wrap {
  position: relative;
}

.ig-bubble {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 3;
  font-size: 12px;
  color: #fff;
  background: rgba(70, 70, 70, 0.72);
  border-radius: 999px;
  padding: 4px 9px;
}

.ig-viewport {
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  background: #000;
}

.ig-viewport::-webkit-scrollbar {
  display: none;
}

.ig-track {
  display: flex;
  height: 100%;
}

.ig-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: start;
  background: #000;
}

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

.ig-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 10px 8px;
  font-size: 13px;
  color: #dce4f2;
}

.ig-actions span:last-child {
  margin-left: auto;
}

.ig-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px 10px;
}

.ig-dots {
  display: flex;
  gap: 5px;
}

.ig-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #52637a;
  border: 0;
  padding: 0;
}

.ig-dot.active {
  background: #dbe8ff;
}

.ig-caption {
  border-top: 1px solid #0f1a27;
  padding: 10px;
}

.ig-caption strong {
  font-size: 14px;
}

.ig-caption p {
  margin: 6px 0 0;
  font-size: 13px;
  color: #d2dbe9;
  line-height: 1.32;
}

.slides-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.slide {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #090c10;
  position: relative;
  cursor: pointer;
}

.slide canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
}

.slide .idx {
  position: absolute;
  left: 8px;
  top: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 999px;
}

.slide.selected {
  outline: 3px solid #3d8bff;
  outline-offset: -3px;
}

.slide.dragging {
  opacity: 0.55;
}

.slide.edit-mode {
  cursor: crosshair;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.photo-pool,
.cell-grid {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f141b;
  min-height: 140px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.photo-thumb,
.cell-thumb {
  border: 1px solid #304055;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  cursor: grab;
  position: relative;
}

.photo-thumb img,
.cell-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  aspect-ratio: 1 / 1;
}

.photo-thumb span,
.cell-thumb span {
  position: absolute;
  left: 4px;
  top: 4px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  border-radius: 999px;
  padding: 2px 5px;
  font-size: 11px;
}

.photo-thumb small,
.cell-thumb small {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 10px;
}

.photo-thumb.used {
  opacity: 0.55;
}

.photo-thumb.used img {
  filter: grayscale(0.35);
}

.cell-thumb.drop-target,
.photo-thumb.drop-target,
.slide.drop-target {
  outline: 3px solid #2f5f4a;
  outline-offset: -3px;
}

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

  .actions-row {
    grid-template-columns: 1fr 1fr;
  }

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

  .ig-preview-wrap {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .ig-nav {
    display: none;
  }

}
