:root {
  --bg-primary: #09090b;
  --bg-surface: #18181b;
  --bg-surface-hover: #27272a;
  --border-color: rgba(255, 255, 255, 0.08);
  --accent-primary: #6366f1;
  --accent-hover: #4f46e5;
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-primary);
  color: var(--text-main);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), #818cf8);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

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

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent-primary);
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(380px, 420px) 1fr;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

.glass {
  background: rgba(24, 24, 27, 0.72);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.control-panel {
  max-height: calc(100vh - 6rem);
  overflow: auto;
  padding: 1rem;
}

.panel-section + .panel-section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.panel-section h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.field.inline {
  flex: 1;
}

.field input[type="text"],
.field input[type="email"],
.field select {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.5rem 0.65rem;
  font-size: 0.875rem;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent-primary);
}

.field em {
  font-style: normal;
  color: var(--text-main);
}

.field-color {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.color-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.color-hex-input {
  width: 5.5rem;
  min-width: 5.5rem;
  padding: 0.35rem 0.45rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: rgba(9, 9, 11, 0.6);
  color: var(--text-main);
}

.color-hex-input.invalid {
  border-color: #f87171;
}

.color-hex-input::placeholder {
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: normal;
}

.color-circle {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}

.color-circle::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 50%;
}

.color-circle::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-circle::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.hint {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.letter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.letter-chip {
  min-width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 600;
  transition: box-shadow 0.2s, background 0.2s;
}

.letter-chip:hover {
  background: var(--bg-surface-hover);
}

.letter-chip.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.letter-chip.customized {
  box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.55);
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.section-heading-row h2 {
  margin: 0;
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.per-letter-editor {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(9, 9, 11, 0.5);
  border: 1px solid var(--border-color);
}

.hidden {
  display: none !important;
}

.preview-area {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-stage {
  width: 100%;
}

.preview-card {
  max-width: 700px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  padding: 1rem;
  background: #f4f4f5;
  border: 1px solid rgba(0, 0, 0, 0.08);
  min-height: 280px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.preview-canvas-wrap {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 260px;
  display: grid;
  place-items: center;
}

.preview-img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 9, 11, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  background: rgba(24, 24, 27, 0.92);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  color: var(--accent-primary);
  animation: spin 0.85s linear infinite;
}

.loading-spinner circle {
  stroke-dasharray: 48;
  stroke-dashoffset: 16;
  stroke-linecap: round;
}

.preview-stage.is-loading .loading-overlay {
  opacity: 1;
}

.preview-stage.is-loading .loading-overlay .loading-indicator {
  animation: loading-pop 0.25s ease;
}

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

@keyframes loading-pop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.checkout-card {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkout-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.badge {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
}

.price {
  font-size: 1.25rem;
  font-weight: 700;
  color: #c7d2fe;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: white;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.trust {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.modal {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  color: var(--text-main);
  background: var(--bg-surface);
  max-width: 420px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.error {
  color: #fca5a5;
  font-size: 0.8rem;
}

.field-inline {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.field-grow {
  flex: 1;
  min-width: 0;
}

.btn-compact {
  white-space: nowrap;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
}

.hint-tight {
  margin: -0.35rem 0 0.75rem;
  font-size: 0.72rem;
}

.pattern-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.65);
}

.pattern-modal.hidden {
  display: none;
}

.pattern-modal-panel {
  width: min(640px, 100%);
  max-height: min(90vh, 820px);
  overflow: auto;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
}

.pattern-modal-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.pattern-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.pattern-tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.pattern-tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.pattern-tab-content {
  display: none;
}

.pattern-tab-content.active {
  display: block;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.pattern-swatch {
  aspect-ratio: 1;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: #fff;
}

.pattern-swatch.selected {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.35);
}

.pattern-swatch .pattern-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 0.62rem;
  padding: 0.2rem 0.25rem;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
}

.pattern-empty {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pattern-preview-section {
  margin-bottom: 1rem;
}

.pattern-preview-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.pattern-picker-preview {
  width: 300px;
  height: 300px;
  max-width: 100%;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
  background: #fff;
}

.pattern-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

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

  .preview-area {
    position: static;
  }
}
