:root {
  color-scheme: light dark;
  --ink: #2b2320;
  --paper: #fdfaf6;
  --panel: #ffffff;
  --line: #e8e0d6;
  --accent-warm: #c96b4f;
  --muted: #8a8078;
  --input-bg: #ffffff;
  --drop-highlight: #fbf1ec;
  --btn-primary-bg: #2b2320;
  --btn-primary-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1ece5;
    --paper: #1b1714;
    --panel: #241f1a;
    --line: #3c342c;
    --accent-warm: #e2916d;
    --muted: #a89a8d;
    --input-bg: #2a241e;
    --drop-highlight: #3a2c22;
    --btn-primary-bg: #f1ece5;
    --btn-primary-fg: #201a15;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f1ece5;
  --paper: #1b1714;
  --panel: #241f1a;
  --line: #3c342c;
  --accent-warm: #e2916d;
  --muted: #a89a8d;
  --input-bg: #2a241e;
  --drop-highlight: #3a2c22;
  --btn-primary-bg: #f1ece5;
  --btn-primary-fg: #201a15;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Browsers don't reliably apply the default [hidden]{display:none} rule to
   inline SVG elements — enforce it explicitly so el.hidden always works. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Poppins', system-ui, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-mark { display: flex; align-items: center; gap: 10px; }
.brand-mark .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-warm);
  display: inline-block;
}
.brand-mark h1 { font-size: 16px; margin: 0; font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 14px; }

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  flex: none;
}
.theme-toggle:hover { background: var(--input-bg); }
.status-msg { font-size: 12.5px; color: var(--muted); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s ease, transform .1s ease;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); }
.btn-primary:not(:disabled):hover { opacity: .85; }
.btn-primary:not(:disabled):active { transform: scale(0.98); }
.btn-generate { width: 100%; margin-top: 18px; padding: 13px; font-size: 14px; }

.link-btn {
  background: none; border: none; color: var(--muted);
  font-size: 11px; text-decoration: underline; cursor: pointer;
  font-family: inherit; padding: 0;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 57px);
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel {
    max-height: none;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .gallery-wrap {
    max-height: none;
    overflow-y: visible;
    padding: 20px 16px;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
}

.field-group {
  margin-bottom: 26px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.field-group:last-of-type { border-bottom: none; }

.field-group h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.collapsible-group > summary {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
  list-style: none;
}
.collapsible-group[open] > summary { margin-bottom: 14px; }
.collapsible-group > summary::-webkit-details-marker { display: none; }
.collapsible-group > summary .hint { margin-left: 8px; }
.collapsible-group > summary::after {
  content: '';
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .15s ease;
  flex-shrink: 0;
}
.collapsible-group[open] > summary::after { transform: rotate(-135deg); }
.collapsible-group:not([open]) { padding-bottom: 0; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--ink);
}

.hint { font-weight: 400; color: var(--muted); font-size: 11.5px; }

input[type="text"],
input[type="file"],
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--input-bg);
  color: var(--ink);
}
textarea { resize: vertical; }

input[type="color"] {
  margin-top: 6px;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
  background: var(--input-bg);
}

.color-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.color-field input[type="color"] {
  margin-top: 0;
  width: 44px;
  min-width: 44px;
  height: 36px;
  padding: 3px;
  flex: none;
}
.color-field input.hex-input {
  margin-top: 0;
  flex: 1;
  font-family: 'SFMono-Regular', Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.color-field input.hex-input:invalid {
  border-color: #d9534f;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.badge-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  margin: 0;
  cursor: pointer;
}
.chip input { margin: 0; }

.chip-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.chip-toggle input { margin: 0; }

input[type="range"] {
  width: 100%;
  margin-top: 8px;
}

#watermarkOptions { margin-top: 14px; }

.profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.color-scheme-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  margin-bottom: 16px;
}
.color-scheme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: none;
  cursor: pointer;
  font-family: inherit;
}
.color-scheme-option:hover { border-color: var(--muted); }
.color-scheme-option.selected { border-color: var(--accent-warm); }
.color-scheme-swatch {
  display: flex;
  width: 60px;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
}
.color-scheme-swatch span { flex: 1; }
.color-scheme-label { font-size: 11.5px; font-weight: 600; color: var(--ink); }

.type-status-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  margin: -8px 0 16px;
}
.profile-row select {
  flex: 1;
  margin-top: 0;
  padding: 8px 9px;
}
.profile-row .link-btn { white-space: nowrap; }

.mockup-slot {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--line);
}
.mockup-slot:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.pin-canvas-wrap { margin-top: 10px; }
.pin-canvas-wrap canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: grab;
  background: var(--input-bg);
  touch-action: none;
}
.pin-canvas-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.logo-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -6px 0 12px;
}
.logo-preview img {
  height: 40px;
  max-width: 100px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  background: var(--input-bg);
}


.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 22px 12px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  transition: border-color .15s ease, background .15s ease;
}
.drop-zone.dragover {
  border-color: var(--accent-warm);
  background: var(--drop-highlight);
}

.image-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.image-thumbs .thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  cursor: grab;
}
.image-thumbs .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.image-thumbs .thumb.first::after {
  content: "hero";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 9px;
  text-align: center;
  padding: 2px 0;
}
.image-thumbs .thumb .remove-btn {
  position: absolute;
  top: 2px; right: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,.65);
  color: #fff;
  border: none;
  font-size: 10px;
  line-height: 16px;
  padding: 0;
  cursor: pointer;
}

.gallery-wrap {
  padding: 28px;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

.empty-state {
  max-width: 420px;
  margin: 80px auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.seo-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 24px;
}
.seo-panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}
.seo-titles { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.seo-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.seo-title-row .title-text { flex: 1; font-size: 13.5px; line-height: 1.4; }
.seo-title-row .char-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.seo-title-row button {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.seo-title-row button:hover { background: var(--input-bg); }

.seo-tags-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 8px;
}
.seo-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.seo-tag {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  background: var(--input-bg);
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 12.5px;
}
.card-footer .name { font-weight: 600; }
.card-footer button {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
}
.card-footer button:hover { background: var(--paper); }
