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

:root {
  --bg-base: #0e0e12;
  --bg-panel: #16161d;
  --bg-elevated: #1e1e28;
  --bg-input: #12121a;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);
  --text: #f0f0f5;
  --text-muted: #8888a0;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --accent-glow: rgba(108, 140, 255, 0.25);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body.gallery-mode {
  overflow: auto;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
}

.studio {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.studio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-hover);
  background: #252530;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* Main layout */
.studio-main {
  display: grid;
  grid-template-columns: 280px 1fr 260px;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 20px 18px;
}

.panel-left {
  border-right: 1px solid var(--border);
}

.panel-right {
  border-left: 1px solid var(--border);
}

.panel-section + .panel-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.panel-section h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Upload zone */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-input);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.06);
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 10px;
}

.upload-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.upload-zone-sm {
  padding: 14px;
  margin-top: 12px;
}

.upload-zone-sm p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.file-name {
  font-size: 11px;
  color: var(--text-muted);
  margin: 10px 0;
  font-family: var(--mono);
  word-break: break-all;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header-row h2 {
  margin-bottom: 0;
}

.design-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: rgba(108, 140, 255, 0.1);
  padding: 3px 8px;
  border-radius: 999px;
}

.upload-zone-full {
  opacity: 0.55;
  cursor: not-allowed;
}

.design-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
  max-height: 180px;
  overflow-y: auto;
}

.design-list-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0;
}

.design-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.design-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(108, 140, 255, 0.25);
}

.design-item.is-locked {
  border-color: rgba(52, 211, 153, 0.35);
}

.design-item.is-locked.active {
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.25);
}

.design-item-select {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  min-width: 0;
}

.design-item-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.design-item-side {
  font-size: 10px;
  color: var(--text-muted);
}

.design-item-remove {
  width: 32px;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.design-item-lock {
  width: 32px;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.design-item-lock:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.design-item-lock.is-locked {
  color: #34d399;
  background: rgba(52, 211, 153, 0.08);
}

.design-item-lock.is-locked:hover {
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.14);
}

.design-item-remove:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.08);
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 0;
  line-height: 1.4;
}

.panel-section.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.panel-section.is-locked:not(.is-disabled) {
  opacity: 0.65;
}

/* Controls */
.control {
  margin-bottom: 16px;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.control-header label {
  font-size: 12px;
  color: var(--text-muted);
}

.control-header output {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}

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

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

/* Color picker */
.color-picker-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

input[type="color"] {
  width: 44px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.hex-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 10px;
  outline: none;
}

.hex-input:focus {
  border-color: var(--accent);
}

.color-presets,
.bg-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.color-swatch,
.bg-preset {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:hover,
.bg-preset:hover {
  transform: scale(1.12);
  border-color: white;
}

.field-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.side-btn {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.side-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.side-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.panel-section .field-label:not(:first-of-type) {
  margin-top: 16px;
}

/* Toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 12px;
  user-select: none;
}

.toggle input {
  display: none;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--bg-elevated);
  border-radius: 10px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: white;
}

/* Viewport */
.viewport {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  min-width: 0;
}

.viewport-frame {
  flex: 1;
  position: relative;
  min-height: 0;
}

.viewport-frame canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.viewport-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

.viewport-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.viewport-frame.viewport-error {
  display: grid;
  place-items: center;
  background: var(--bg-input);
}

.viewport-error-msg {
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.viewport-error-msg p {
  font-size: 13px;
}

.viewport-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

/* Scrollbar */
.panel::-webkit-scrollbar {
  width: 5px;
}

.panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Responsive */
@media (max-width: 960px) {
  .studio-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    overflow-y: auto;
  }

  .panel-left,
  .panel-right {
    border: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  .viewport {
    min-height: 420px;
  }

  body {
    overflow: auto;
  }

  .studio {
    height: auto;
    min-height: 100vh;
  }
}

@media (max-width: 600px) {
  .studio-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-actions .btn {
    flex: 1;
    justify-content: center;
    min-width: 120px;
  }
}

/* Gallery home */
.gallery {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.gallery-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.gallery-main {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.gallery-hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 40px;
  align-items: center;
  margin-bottom: 48px;
  padding: 36px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(108, 140, 255, 0.08), rgba(167, 139, 250, 0.06));
  border: 1px solid var(--border);
}

.gallery-hero-content h2 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.gallery-hero-content p {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 24px;
  max-width: 520px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 14px;
}

.gallery-hero-visual {
  position: relative;
  height: 200px;
}

.hero-card {
  position: absolute;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero-card-1 {
  width: 120px;
  height: 140px;
  background: linear-gradient(160deg, #f5f5f0, #e8e8e0);
  top: 20px;
  left: 20px;
  transform: rotate(-6deg);
}

.hero-card-2 {
  width: 120px;
  height: 140px;
  background: linear-gradient(160deg, #1a1a1a, #2a2a32);
  top: 10px;
  left: 90px;
  transform: rotate(4deg);
}

.hero-card-3 {
  width: 120px;
  height: 140px;
  background: linear-gradient(160deg, #2d4a3e, #1e3a2e);
  top: 30px;
  left: 160px;
  transform: rotate(-2deg);
}

.gallery-section {
  margin-bottom: 48px;
}

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

.section-heading h3 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.section-heading p {
  font-size: 13px;
  color: var(--text-muted);
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #34d399;
  background: rgba(52, 211, 153, 0.1);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.design-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.design-card {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.design-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.design-card-btn {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  padding: 0;
}

.design-card-preview {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.design-card-preview img {
  max-width: 70%;
  max-height: 70%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
}

.design-card-body {
  padding: 14px 16px 16px;
}

.design-card-body h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.design-card-body p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.design-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(108, 140, 255, 0.1);
  padding: 3px 8px;
  border-radius: 999px;
}

.design-card-author {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.author-name {
  font-size: 12px;
  font-weight: 500;
}

.author-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.design-card-saved .saved-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.design-card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(14, 14, 18, 0.75);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.design-card-saved:hover .design-card-delete {
  opacity: 1;
}

.design-card-delete:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

.gallery-empty {
  text-align: center;
  padding: 40px 20px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.gallery-empty p {
  font-size: 14px;
  color: var(--text-muted);
}

.gallery-empty-hint {
  font-size: 12px !important;
  margin-top: 6px;
}

.gallery-security-note {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

/* Editor overlay */
.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg-base);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.editor-overlay.is-open {
  opacity: 1;
}

.editor-overlay-inner {
  height: 100%;
}

.editor-overlay .studio {
  height: 100vh;
}

.editor-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .gallery-header {
    padding: 16px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .gallery-main {
    padding: 20px;
  }

  .gallery-hero {
    grid-template-columns: 1fr;
    padding: 24px;
  }

  .gallery-hero-visual {
    display: none;
  }

  .section-heading {
    flex-direction: column;
  }
}
