:root {
  color-scheme: light;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #d0d7de;
  --accent: #2563eb;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button,
input,
textarea {
  font: inherit;
}

.app-header {
  padding: 24px clamp(16px, 4vw, 48px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.brand-icon {
  width: 40px;
  height: 40px;
  fill: var(--accent);
}

.tagline {
  margin: 0;
  max-width: 720px;
  font-size: 1.05rem;
  color: var(--muted);
}

.status-message {
  margin: 0 clamp(16px, 4vw, 48px);
  margin-bottom: -12px;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: #e0f2fe;
  color: #0c4a6e;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}

.status-message.status-message--error {
  background: #fee2e2;
  color: #7f1d1d;
  border-color: #fecaca;
}

.status-message.status-message--success {
  background: #dcfce7;
  color: #14532d;
  border-color: #bbf7d0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 48px) 48px;
  flex: 1;
}

.controls,
.editor,
.preview,
.gallery {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.controls fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.controls legend {
  padding: 0 8px;
  font-weight: 600;
  color: var(--muted);
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.controls input,
.controls textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.controls input.is-invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.controls input:focus,
.controls textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.mode-button {
  padding: 8px 16px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

.mode-button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.toolbar {
  gap: 12px;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.theme-pickers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.theme-pickers label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.theme-pickers input[type="color"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  background: transparent;
}

.theme-presets {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-presets-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.theme-presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.theme-preset {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #f1f5f9;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.theme-preset::before {
  content: "";
  display: block;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--preset-accent) 0%, var(--preset-text) 45%, var(--preset-muted) 100%);
}

.theme-preset::after {
  content: "";
  display: block;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--preset-background), var(--preset-surface));
  border: 1px solid rgba(15, 23, 42, 0.05);
}

.theme-preset span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.theme-preset:hover,
.theme-preset:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
  transform: translateY(-1px);
}

.theme-preset.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
}

.theme-preset.is-active span {
  color: var(--accent);
}

.tool-button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f1f5f9;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s ease, border 0.2s ease;
}

.tool-button:hover {
  background: rgba(37, 99, 235, 0.12);
  border-color: var(--accent);
}

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

.actions button {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.actions button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.share-output {
  display: grid;
  gap: 8px;
}

#shareLink {
  width: 100%;
  resize: vertical;
}

#copyShareButton {
  justify-self: start;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
}

.editor {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
  display: grid;
}

.design-editor,
.html-editor {
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: #fff;
  font-size: 1rem;
  line-height: 1.6;
  overflow: auto;
}

.design-editor {
  outline: none;
}

.html-editor {
  font-family: "JetBrains Mono", "Fira Code", Consolas, Monaco, monospace;
  display: none;
}

.preview {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
}

.preview-header label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

.preview-frame-wrapper {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 420px;
  background: #0f172a;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.preview-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.gallery {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.gallery-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #f8fafc;
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
  transform: translateY(-2px);
}

.gallery-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.gallery-card h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.gallery-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.app-footer {
  padding: 20px clamp(16px, 4vw, 48px) 32px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
  }

  .editor,
  .preview,
  .gallery {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
