@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800&display=swap');

:root {
  --bg: #060810;
  --bg-soft: #0b0f1a;
  --panel: rgba(11, 15, 27, 0.88);
  --panel-strong: rgba(6, 9, 17, 0.97);
  --line: rgba(255, 255, 255, 0.06);
  --line-hi: rgba(255, 255, 255, 0.12);
  --text: #edf1fc;
  --text-soft: #c5cede;
  --muted: #7986a0;
  --primary: #ff5533;
  --primary-soft: rgba(255, 85, 51, 0.13);
  --primary-glow: rgba(255, 85, 51, 0.32);
  --accent: #00dfc8;
  --accent-soft: rgba(0, 223, 200, 0.11);
  --purple: #ae6ef5;
  --purple-soft: rgba(174, 110, 245, 0.11);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  --shadow-xl: 0 30px 80px rgba(0, 0, 0, 0.46);
  --topbar-h: 64px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Plus Jakarta Sans", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Ambient background ─── */
.noise-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 1;
  background-image:
    radial-gradient(ellipse 80% 60% at 10% 8%, rgba(255, 85, 51, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 70% 55% at 92% 12%, rgba(0, 223, 200, 0.09) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 50% 95%, rgba(174, 110, 245, 0.07) 0%, transparent 50%),
    linear-gradient(160deg, #07090f 0%, #0d1220 45%, #07090f 100%);
  animation: bgShift 28s ease-in-out infinite;
}

.ambient {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  animation: drift 20s ease-in-out infinite;
}

.ambient-a {
  width: 360px;
  height: 360px;
  left: -100px;
  top: 80px;
  background: radial-gradient(circle, rgba(255, 85, 51, 0.18) 0%, transparent 65%);
  filter: blur(50px);
  opacity: 0.7;
}

.ambient-b {
  width: 420px;
  height: 420px;
  right: -110px;
  top: 140px;
  background: radial-gradient(circle, rgba(0, 223, 200, 0.14) 0%, transparent 65%);
  filter: blur(60px);
  opacity: 0.65;
  animation-delay: -7s;
}

.ambient-c {
  width: 320px;
  height: 320px;
  left: 38%;
  bottom: -80px;
  background: radial-gradient(circle, rgba(174, 110, 245, 0.14) 0%, transparent 68%);
  filter: blur(55px);
  opacity: 0.6;
  animation-delay: -13s;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  color: inherit;
}

/* ─── App shell ─── */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(1680px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 32px;
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--topbar-h);
  margin-bottom: 16px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line-hi);
  background: rgba(8, 11, 20, 0.82);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(255, 85, 51, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--primary) 0%, #ff8c42 60%, #ffb23a 100%);
  box-shadow:
    0 4px 16px rgba(255, 85, 51, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  padding: 7px;
  transition: transform 240ms ease, box-shadow 240ms ease;
  flex-shrink: 0;
}

.brand-mark::before,
.brand-mark::after {
  content: '';
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.88);
}

.brand-mark:hover {
  transform: scale(1.06);
  box-shadow:
    0 6px 22px rgba(255, 85, 51, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.brand-kicker,
.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.9;
}

.brand h1,
.card-heading h2,
.hero-card h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ─── Buttons ─── */
.soft-button,
.primary-button,
.wide-button {
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.soft-button {
  border: 1px solid var(--line-hi);
  background: rgba(255, 255, 255, 0.04);
}

.soft-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.primary-button {
  border: 1px solid rgba(255, 85, 51, 0.4);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.22), rgba(0, 223, 200, 0.16));
  color: var(--text);
}

.primary-button:hover {
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.35), rgba(0, 223, 200, 0.26));
  border-color: rgba(255, 85, 51, 0.6);
  box-shadow: 0 0 20px var(--primary-glow), 0 8px 24px rgba(0, 0, 0, 0.28);
  transform: translateY(-1px);
}

.wide-button {
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(255, 85, 51, 0.3);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.18), rgba(0, 223, 200, 0.14));
  font-size: 0.9rem;
  font-weight: 700;
}

.wide-button:hover {
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.3), rgba(0, 223, 200, 0.22));
  border-color: rgba(255, 85, 51, 0.5);
  box-shadow: 0 0 24px var(--primary-glow), 0 10px 28px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

.wide-button.is-generating {
  position: relative;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.8;
}

.wide-button.is-generating::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.12) 40%,
    rgba(255, 255, 255, 0.22) 50%,
    rgba(255, 255, 255, 0.12) 60%,
    transparent 100%
  );
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ─── Layout ─── */
.studio-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.sidebar,
.main-panel {
  display: grid;
  gap: 14px;
  align-self: start;
}

/* ─── Cards ─── */
.card {
  border: 1px solid var(--line-hi);
  border-radius: var(--radius-xl);
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  transition: border-color 240ms ease, box-shadow 240ms ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-xl), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.upload-card,
.control-card,
.stats-card,
.preview-card,
.palette-card,
.notes-card,
.hero-card {
  padding: 18px;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-heading.tight {
  margin-bottom: 12px;
}

.card-heading h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* ─── Remove legacy transform-style (no 3D tilt) ─── */
.card,
.dropzone,
.soft-button,
.primary-button,
.wide-button,
.canvas-scroll {
  transform-style: flat;
  will-change: auto;
}

/* Collapsible settings toggle */
.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: opacity 160ms ease;
}

.settings-toggle:hover {
  opacity: 0.85;
}

.settings-toggle h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}

.settings-toggle-icon {
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform 280ms ease, color 180ms ease;
}

.settings-toggle[aria-expanded="true"] .settings-toggle-icon {
  transform: rotate(180deg);
  color: var(--primary);
}

/* Collapsible body using grid animation trick */
.collapsible-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms ease;
  overflow: hidden;
}

.collapsible-body.is-open {
  grid-template-rows: 1fr;
}

.collapsible-inner {
  min-height: 0;
  overflow: hidden;
  padding-top: 2px;
}

/* ─── Tags / chips ─── */
.tag,
.hero-chip,
.value-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.74rem;
  font-weight: 500;
}

.hero-chip {
  color: var(--accent);
  border-color: rgba(0, 223, 200, 0.22);
  background: rgba(0, 223, 200, 0.06);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ─── Dropzone ─── */
.dropzone {
  display: block;
  position: relative;
  min-height: 160px;
  border: 1.5px dashed rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(255, 85, 51, 0.06), rgba(0, 223, 200, 0.06)),
    rgba(255, 255, 255, 0.015);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 200ms ease, background 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}

.dropzone-empty-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px;
  text-align: center;
  min-height: 160px;
}

.dropzone.has-image .dropzone-empty-content {
  display: none;
}

.dropzone.is-dragging {
  border-color: var(--primary);
  border-style: solid;
  background:
    linear-gradient(135deg, rgba(255, 85, 51, 0.12), rgba(0, 223, 200, 0.1)),
    rgba(255, 255, 255, 0.02);
  transform: scale(1.01);
  box-shadow: 0 0 0 3px var(--primary-soft), inset 0 0 30px rgba(255, 85, 51, 0.06);
}

.dropzone:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.dropzone strong {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
}

.dropzone em {
  font-style: normal;
  font-size: 0.77rem;
  color: var(--muted);
}

/* Upload thumbnail */
.upload-thumb {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: contain;
  padding: 10px;
  background: transparent;
}

.upload-thumb-overlay {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(6, 8, 16, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 200ms ease;
}

.dropzone.has-image:hover .upload-thumb-overlay {
  opacity: 1;
}

.upload-thumb-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 85, 51, 0.85);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.dropzone-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, #ffb23a 100%);
  box-shadow:
    0 8px 20px rgba(255, 85, 51, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-text,
.notes-list,
.field span,
.stat-item span {
  color: var(--muted);
}

.status-text {
  margin: 10px 2px 0;
  font-size: 0.8rem;
  line-height: 1.65;
}

/* ─── Control grid ─── */
.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-span-2 {
  grid-column: 1 / -1;
}

.field span {
  font-size: 0.79rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}

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

.field input[type="number"],
.field select {
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-hi);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 500;
  transition: border-color 160ms ease, background 160ms ease;
}

.field input[type="number"]:focus,
.field select:focus {
  outline: none;
  border-color: rgba(255, 85, 51, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

.field select option {
  background: #0d1119;
}

.field input[type="range"] {
  accent-color: var(--primary);
  height: 20px;
}

.inline-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 160ms ease, background 160ms ease;
}

.inline-field:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-hi);
}

.inline-field input {
  width: auto;
  accent-color: var(--primary);
}

.value-pill {
  justify-self: start;
  color: var(--text);
  font-weight: 600;
  font-size: 0.78rem;
}

/* ─── Style presets ─── */
.style-preset-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.style-preset {
  border: 1px solid var(--line-hi);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 160ms ease;
}

.style-preset:hover {
  color: var(--text-soft);
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.style-preset.is-active {
  color: var(--text);
  border-color: rgba(255, 85, 51, 0.45);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.18), rgba(0, 223, 200, 0.14));
  box-shadow: 0 0 14px rgba(255, 85, 51, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ─── Stats card ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-item {
  padding: 14px 14px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 160ms ease, background 160ms ease;
}

.stat-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-hi);
}

.stat-item span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.stat-item strong {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ─── Main panel ─── */
.main-panel {
  grid-template-rows: auto auto auto;
}


/* ─── Pattern + palette row ─── */
.pattern-palette-row {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

.pattern-palette-row .pattern-main-card {
  flex: 1 1 0;
  min-width: 0;
}

.palette-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.palette-sidebar .palette-list {
  flex: 1;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.tag-hint {
  color: var(--accent);
  border-color: rgba(0, 223, 200, 0.2);
  background: rgba(0, 223, 200, 0.06);
  font-size: 0.72rem;
  cursor: default;
}

/* ─── Fullscreen editor modal ─── */
.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #060810;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-hi);
  background: rgba(8, 11, 20, 0.97);
  flex-shrink: 0;
}

.editor-header-left {
  flex-shrink: 0;
}

.editor-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.editor-close-btn {
  flex-shrink: 0;
  font-weight: 700;
}

.editor-toolbar .soft-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.editor-canvas-wrap {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  background: #07090f;
  user-select: none;
}

.editor-canvas-wrap canvas {
  display: block;
  border-radius: 10px;
  cursor: crosshair;
  image-rendering: pixelated;
}

.editor-canvas-wrap.is-grab {
  cursor: grab;
}

.editor-canvas-wrap.is-grab canvas {
  cursor: grab;
}

.editor-canvas-wrap.is-grabbing,
.editor-canvas-wrap.is-grabbing canvas {
  cursor: grabbing;
}

.editor-palette-panel {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 18px 16px;
  border-left: 1px solid var(--line-hi);
  background: rgba(8, 11, 20, 0.92);
  display: flex;
  flex-direction: column;
}

.editor-palette-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-palette-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 140ms ease;
}

.editor-palette-item:hover,
.editor-palette-item.is-selected {
  border-color: rgba(255, 85, 51, 0.38);
  background: linear-gradient(90deg, rgba(255, 85, 51, 0.1), rgba(0, 223, 200, 0.07));
}

.editor-palette-item.is-eraser {
  justify-content: center;
  grid-template-columns: 1fr;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.editor-palette-item.is-eraser:hover {
  color: var(--text);
  border-color: rgba(174, 110, 245, 0.4);
  background: rgba(174, 110, 245, 0.08);
}

.editor-swatch {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.editor-color-meta strong {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-color-meta span {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ─── Pattern main card ─── */
.pattern-main-card {
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(255, 85, 51, 0.08) 0%, transparent 45%),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(0, 223, 200, 0.07) 0%, transparent 40%),
    var(--panel);
  border-color: rgba(255, 85, 51, 0.12);
}

/* legacy alias */
.emphasis-card {
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(255, 85, 51, 0.08) 0%, transparent 45%),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(0, 223, 200, 0.07) 0%, transparent 40%),
    var(--panel);
  border-color: rgba(255, 85, 51, 0.12);
}

/* ─── Toolbar ─── */
.pattern-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.toolbar-button {
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 600;
}

.toolbar-button.is-active {
  color: var(--text);
  border-color: rgba(255, 85, 51, 0.4);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.18), rgba(0, 223, 200, 0.14));
  box-shadow: 0 0 12px rgba(255, 85, 51, 0.18);
}

/* ─── Canvas frames ─── */
.canvas-frame,
.canvas-scroll {
  border-radius: 18px;
  border: 1px solid var(--line-hi);
  background: #09101a;
  position: relative;
  transition: border-color 220ms ease, box-shadow 220ms ease;
}

.canvas-frame:hover,
.canvas-scroll:hover {
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 20px 48px rgba(0, 0, 0, 0.3);
}

.canvas-frame {
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: hidden;
}

.source-frame {
  min-height: 160px;
  max-height: 220px;
}

.canvas-scroll {
  min-height: 420px;
  max-height: 640px;
  overflow: auto;
  padding: 14px;
  scroll-behavior: auto;
}

/* Custom scrollbar for canvas */
.canvas-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.canvas-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 3px;
}

.canvas-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.canvas-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
}

.pattern-scroll {
  min-height: 680px;
  max-height: calc(100vh - 180px);
}

.canvas-scroll.is-zooming {
  cursor: zoom-in;
}

.source-frame canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 8px;
}

.canvas-scroll canvas {
  display: block;
  border-radius: 10px;
}

#pattern-preview.is-editing {
  cursor: crosshair;
}

/* ─── Generating overlay ─── */
.generating-overlay {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(6, 8, 16, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.generating-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.gen-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 85, 51, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.gen-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

/* ─── Palette list ─── */
.palette-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  overflow-y: auto;
  padding-right: 2px;
}

.palette-list::-webkit-scrollbar {
  width: 4px;
}

.palette-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.palette-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  transition: all 150ms ease;
}

.palette-item:hover,
.palette-item.is-selected {
  transform: translateX(2px);
  border-color: rgba(255, 85, 51, 0.3);
  background: linear-gradient(90deg, rgba(255, 85, 51, 0.09), rgba(0, 223, 200, 0.07));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.palette-swatch {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 8px rgba(0, 0, 0, 0.28);
  flex-shrink: 0;
}

.palette-meta strong,
.palette-meta span {
  display: block;
}

.palette-meta strong {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.palette-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.palette-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

.palette-count {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
  text-align: right;
}


/* ─── Manual color panel ─── */
.manual-modal-dialog {
  width: min(92vw, 780px);
}

.manual-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.manual-panel-head strong {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.manual-tab-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.manual-prefix-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.manual-tab {
  border: 1px solid var(--line-hi);
  border-radius: 999px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 600;
  transition: all 160ms ease;
}

.manual-tab:hover,
.manual-tab.is-active {
  color: var(--text);
  border-color: rgba(255, 85, 51, 0.4);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.16), rgba(0, 223, 200, 0.12));
  box-shadow: 0 0 14px rgba(255, 85, 51, 0.16);
}

.manual-prefix-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-width: 40px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 160ms ease;
}

.manual-prefix-chip:hover,
.manual-prefix-chip.is-active {
  color: var(--text);
  border-color: rgba(255, 85, 51, 0.35);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.14), rgba(0, 223, 200, 0.1));
}

.manual-color-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: 8px;
  max-height: min(56vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.manual-color-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 160ms ease;
}

.manual-color-chip:hover,
.manual-color-chip.is-selected {
  transform: translateY(-1px);
  border-color: rgba(255, 85, 51, 0.3);
  background: linear-gradient(135deg, rgba(255, 85, 51, 0.1), rgba(0, 223, 200, 0.07));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.manual-color-chip.is-eraser {
  justify-content: center;
  font-weight: 700;
}

.manual-color-dot {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 1px 4px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.manual-color-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.manual-color-text strong {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manual-color-text span {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ─── Preview modal ─── */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 12, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.preview-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(92vw, 940px);
  max-height: min(92vh, 980px);
  display: grid;
  gap: 12px;
  padding: 20px;
  border-radius: 28px;
  border: 1px solid var(--line-hi);
  background:
    radial-gradient(ellipse at top right, rgba(255, 85, 51, 0.1) 0%, transparent 35%),
    radial-gradient(ellipse at bottom left, rgba(0, 223, 200, 0.08) 0%, transparent 35%),
    rgba(10, 14, 24, 0.97);
  box-shadow: var(--shadow-xl);
}

.preview-close {
  justify-self: end;
}

.preview-caption {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.preview-stage {
  min-height: 360px;
  max-height: calc(92vh - 160px);
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #080d14;
  cursor: grab;
}

.preview-stage img {
  display: block;
  transform-origin: center center;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  border-radius: 6px;
}

.preview-stage.is-panning {
  cursor: grabbing;
}

.preview-tip {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

/* ─── Animations ─── */
@keyframes bgShift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  33% { transform: translate3d(6px, -8px, 0) scale(1.01); }
  66% { transform: translate3d(-4px, 5px, 0) scale(0.99); }
}

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(28px, -22px, 0) scale(1.1); }
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─── */
@media (max-width: 1300px) {
  .studio-grid {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

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

  .sidebar {
    order: 2;
  }

  .main-panel {
    order: 1;
  }

  .control-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .pattern-palette-row {
    flex-direction: column;
  }

  .palette-sidebar {
    width: 100%;
  }

  .palette-sidebar .palette-list {
    max-height: 220px;
  }
}

@media (max-width: 900px) {
  .topbar {
    border-radius: 24px;
    height: auto;
    padding: 14px 16px;
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 7px;
  }

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

  .source-compare-grid {
    grid-template-columns: 1fr;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-frame,
  .canvas-scroll {
    min-height: 260px;
  }

  .pattern-scroll {
    min-height: 500px;
    max-height: 75vh;
  }

  .editor-palette-panel {
    width: 220px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: calc(100% - 20px);
    padding-top: 10px;
  }

  .upload-card,
  .control-card,
  .stats-card,
  .preview-card,
  .palette-card,
  .notes-card,
  .hero-card {
    padding: 14px;
  }

  .dropzone {
    min-height: 130px;
  }

  .canvas-frame,
  .canvas-scroll {
    min-height: 200px;
  }

  .pattern-scroll {
    min-height: 380px;
    max-height: 70vh;
  }

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

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

  .source-compare-grid {
    grid-template-columns: 1fr;
  }

  .manual-color-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
