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

:root {
  --bg: #0f0f13;
  --surface: #18181f;
  --surface2: #22222d;
  --border: #2e2e3a;
  --accent: #6c63ff;
  --accent2: #e040fb;
  --text: #e8e8f0;
  --text-muted: #7a7a99;
  --radius: 10px;
  --radius-sm: 6px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

header .tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Main Layout ── */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Controls Panel ── */
#controls {
  width: 300px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

#controls::-webkit-scrollbar {
  width: 5px;
}
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-group label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.optional {
  font-size: 0.7rem;
  opacity: 0.6;
}

.control-row {
  display: flex;
  gap: 10px;
}
.control-row .control-group {
  flex: 1;
}

input[type="text"],
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

select option {
  background: var(--surface2);
}

/* Range */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

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

.range-value {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  display: block;
  margin-top: -2px;
}

/* Position sliders */
.pos-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.pos-slider-row input[type="range"] { flex: 1; }
.pos-axis {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  width: 36px;
  flex-shrink: 0;
}
.pos-slider-row .range-value {
  min-width: 28px;
  margin-top: 0;
}

/* Color input */
.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.color-input-wrapper:hover { border-color: var(--accent); }

input[type="color"] {
  -webkit-appearance: none;
  border: none;
  background: none;
  width: 24px;
  height: 24px;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-input-wrapper span {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* Icon Grid */
/* Icon category tabs */
.icon-cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.icon-cat-tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.7rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.icon-cat-tab:hover { color: var(--text); border-color: #555; }
.icon-cat-tab.active {
  background: rgba(108,99,255,0.18);
  border-color: var(--accent);
  color: #b0aaff;
  font-weight: 600;
}

/* Scrollable icon grid wrapper */
.icon-grid-wrap {
  max-height: 176px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  background: var(--surface2);
}
.icon-grid-wrap::-webkit-scrollbar { width: 4px; }
.icon-grid-wrap::-webkit-scrollbar-track { background: transparent; }
.icon-grid-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 2px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1;
  text-align: center;
}

.icon-btn:hover {
  background: var(--border);
}

.icon-btn.active {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.18);
  color: #b0aaff;
}

/* Style Tabs */
.style-tabs, .bg-toggle {
  display: flex;
  gap: 5px;
}

.style-tab {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.style-tab:hover { color: var(--text); border-color: #555; }
.style-tab.active {
  background: rgba(108, 99, 255, 0.18);
  border-color: var(--accent);
  color: #b0aaff;
  font-weight: 600;
}

/* ── Preview Panel ── */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 28px 32px;
  gap: 20px;
  overflow: auto;
}

.preview-header {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.bg-toggle {
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.bg-opt {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.73rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.bg-opt:hover { color: var(--text); }
.bg-opt.active {
  border-color: var(--accent);
  color: #b0aaff;
  background: rgba(108, 99, 255, 0.18);
}

.canvas-wrapper {
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 48px rgba(0,0,0,0.5);
  transition: background 0.3s;
  flex-shrink: 0;
}

.canvas-wrapper.bg-dark  { background: #111; }
.canvas-wrapper.bg-light { background: #e8e8e8; }
.canvas-wrapper.bg-checker {
  background-image:
    linear-gradient(45deg, #555 25%, transparent 25%),
    linear-gradient(-45deg, #555 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #555 75%),
    linear-gradient(-45deg, transparent 75%, #555 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #333;
}

#logoCanvas {
  display: block;
  max-width: 100%;
  max-height: 520px;
  user-select: none;
  -webkit-user-select: none;
}

.drag-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.55;
  text-align: center;
  padding: 0 8px;
}

/* ── Download Row ── */
.download-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.undo-redo-group {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 2px 16px rgba(108,99,255,0.35);
}
.btn.primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 24px rgba(108,99,255,0.5);
}

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.secondary:hover { border-color: var(--accent); color: #b0aaff; }

.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn.ghost:hover { color: var(--text); border-color: #555; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Extra text lines ── */
.extra-text-group { padding: 0; }
.extra-text-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.section-sublabel {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-add-text {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-add-text:hover { opacity: 0.85; }

.extra-text-row {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 6px;
}
.et-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.et-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.et-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 0.85rem;
  box-sizing: border-box;
  margin-bottom: 6px;
}
.et-input:focus { outline: none; border-color: var(--accent); }
.et-row2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.et-row2 .color-input-wrapper { flex-shrink: 0; }
.et-row2 .et-size-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.et-row2 input[type="range"] { flex: 1; min-width: 0; }
.et-size-val {
  font-size: 0.72rem;
  color: var(--text-muted);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Advanced panel ── */
.adv-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: 6px;
  transition: all 0.15s;
}
.adv-toggle:hover { border-color: var(--accent); color: #b0aaff; }
.adv-arrow { font-size: 0.6rem; opacity: 0.7; }

.advanced-panel {
  display: none;
  flex-direction: column;
  gap: 6px;
}
.advanced-panel.open { display: flex; }

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
}
.check-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── File upload ── */
.file-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface2);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: border-color 0.2s, color 0.2s;
  width: 100%;
  text-align: center;
}
.file-upload-label:hover { border-color: var(--accent); color: #b0aaff; }
.file-upload-label input[type="file"] { display: none; }

.file-upload-label--sm { padding: 8px 10px; font-size: 0.78rem; margin-top: 6px; }
.custom-icon-row { margin-top: 4px; }
#customIconPreviewWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin-top: 4px;
}
#customIconPreview {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.06);
}
.custom-icon-name {
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.file-upload-label--sm { padding: 8px 10px; font-size: 0.78rem; margin-top: 6px; }

.custom-icon-row { margin-top: 4px; }
#customIconPreviewWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin-top: 4px;
}
#customIconPreview {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.06);
}
.custom-icon-name {
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

#bgImagePreviewWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin-top: 4px;
}
#bgImagePreview {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-remove-img {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  margin-left: auto;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}
.btn-remove-img:hover { color: #ff6b6b; }

/* ── Ad blocks ── */
.ad-leaderboard {
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
  padding: 6px 0;
  flex-shrink: 0;
}

.ad-inline {
  width: 100%;
  max-width: 600px;
  min-height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ── Footer ── */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.site-footer strong { color: var(--text); }
.footer-sep { opacity: 0.35; }

/* ── Sticky bottom ad (mobile only) ── */
.ad-sticky-bottom {
  display: none;
}

/* ── Responsive / Mobile ── */

/* Tablet & large phone (≤ 768px) */
@media (max-width: 768px) {
  html, body { height: auto; }

  body { overflow-x: hidden; }

  header {
    padding: 10px 16px;
    gap: 8px;
    flex-wrap: wrap;
  }
  header .tagline { display: none; }

  .ad-leaderboard { min-height: 60px; }

  main {
    flex-direction: column;
    overflow: visible;
    height: auto;
  }

  /* Canvas preview appears first and sticks to top on mobile */
  .preview-panel {
    order: -1;
    flex: none;
    width: 100%;
    padding: 12px 14px 10px;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  }

  .preview-header {
    max-width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .bg-toggle { flex-wrap: wrap; }

  .canvas-wrapper {
    width: min(55vw, 260px);
    height: min(55vw, 260px);
  }

  #logoCanvas {
    max-width: 100%;
    max-height: 100%;
  }

  /* Controls scrolls as part of page on mobile */
  #controls {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-top: none;
    max-height: none;
    overflow-y: visible;
    padding: 16px 14px 100px; /* extra bottom pad clears sticky ad */
  }

  /* Sticky bottom ad */
  .ad-sticky-bottom {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border-top: 1px solid var(--border);
    justify-content: center;
    align-items: center;
    min-height: 60px;
    padding: 4px 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
  }

  /* Hide drag hint in sticky bar to save space */
  .preview-panel .drag-hint { display: none; }

  /* Hide inline ad on mobile — sticky bottom ad serves instead */
  .ad-inline { display: none; }

  .download-row .btn {
    padding: 11px 16px;
  }
}

/* Small phones (≤ 480px) */
@media (max-width: 480px) {
  header { padding: 9px 12px; }

  .preview-panel { padding: 12px 10px 10px; }

  #controls { padding: 14px 12px 24px; }

  /* Stack two-column rows into single column */
  .control-row {
    flex-direction: column;
    gap: 10px;
  }

  /* Higher-contrast, easier-to-tap style tabs */
  .style-tab {
    font-size: 0.7rem;
    padding: 7px 3px;
  }

  /* Icon grid — bigger tap targets */
  .icon-btn {
    padding: 7px 2px;
    font-size: 0.9rem;
    min-height: 34px;
  }

  /* Download row: 2-col grid on small phones */
  .download-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    width: 100%;
  }
  /* Undo/redo side-by-side, spanning full width */
  .undo-redo-group {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
  }
  .undo-redo-group .btn {
    flex: 1;
    padding: 11px 8px;
    text-align: center;
    font-size: 0.85rem;
  }
  /* Download + randomize fill the grid cells */
  #downloadPng, #downloadSvg, #randomize {
    width: 100%;
    padding: 12px 8px;
    text-align: center;
    font-size: 0.88rem;
  }
  /* Randomize spans full width on its own row */
  #randomize {
    grid-column: 1 / -1;
  }

  /* Larger range thumb for touch */
  input[type="range"]::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
  }

  /* Inputs & selects easier to tap */
  input[type="text"],
  select {
    padding: 10px 10px;
    font-size: 0.9rem;
  }

  .adv-toggle { padding: 11px 12px; }
}

