:root {
  --bg: #13100d;
  --bg-soft: #1d1915;
  --panel: rgba(255, 248, 238, 0.08);
  --panel-strong: rgba(255, 248, 238, 0.11);
  --stroke: rgba(255, 244, 232, 0.12);
  --ink: #f6eedf;
  --muted: rgba(246, 238, 223, 0.68);
  --accent: #efd39d;
  --accent-strong: #f6be55;
  --danger: #ffb0a0;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --font-sans: "Avenir Next", "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-serif: "Iowan Old Style", "Georgia", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(246, 190, 85, 0.16), transparent 26%),
    radial-gradient(circle at bottom right, rgba(232, 214, 180, 0.12), transparent 28%),
    linear-gradient(180deg, #17120f 0%, #0f0d0b 100%);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

.shell {
  display: grid;
  gap: 24px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.controls-panel,
.preview-panel {
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  overflow: hidden;
}

.controls-panel {
  padding: 24px 20px 20px;
}

.preview-panel {
  padding: 18px;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  margin-top: 8px;
  font-family: var(--font-serif);
  font-size: clamp(36px, 5vw, 58px);
  font-weight: 700;
}

h2 {
  font-size: 22px;
}

.intro,
.preview-help,
.status-message,
.hint {
  color: var(--muted);
}

.intro {
  max-width: 62ch;
  margin: 12px 0 0;
  font-size: 15px;
  line-height: 1.6;
}

.panel-grid {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.card {
  padding: 18px;
  background: rgba(255, 250, 242, 0.03);
  border: 1px solid rgba(255, 247, 234, 0.08);
  border-radius: var(--radius-md);
}

.card.wide {
  grid-column: 1 / -1;
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.hint {
  font-size: 13px;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.field:first-of-type {
  margin-top: 0;
}

.field.compact {
  margin-top: 0;
}

.field > span,
.field-row {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

input[type="text"],
textarea,
select,
input[type="file"] {
  width: 100%;
  border: 1px solid rgba(255, 244, 232, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(12, 10, 8, 0.42);
  color: var(--ink);
  padding: 12px 14px;
}

textarea {
  resize: vertical;
  min-height: 110px;
  line-height: 1.5;
}

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

input[type="color"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 244, 232, 0.12);
  border-radius: 12px;
  background: rgba(12, 10, 8, 0.42);
  padding: 6px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-strong);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
  margin-top: 16px;
}

.section-stack {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.subcard {
  border: 1px solid rgba(255, 247, 234, 0.08);
  border-radius: 16px;
  background: rgba(255, 251, 246, 0.03);
  overflow: hidden;
}

.subcard summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subcard summary::-webkit-details-marker {
  display: none;
}

.subcard[open] summary {
  border-bottom: 1px solid rgba(255, 247, 234, 0.08);
}

.subcard .control-grid {
  margin-top: 0;
  padding: 16px;
}

.template-save-row {
  display: grid;
  gap: 12px;
}

.subcard-hint {
  margin: 0;
  padding: 0 16px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.template-name-field {
  margin-top: 0;
}

.templates-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.template-empty {
  margin: 0;
  padding: 14px 16px;
  border: 1px dashed rgba(255, 247, 234, 0.12);
  border-radius: 14px;
  color: var(--muted);
  font-size: 14px;
}

.template-item {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 247, 234, 0.08);
  border-radius: 16px;
  background: rgba(255, 251, 246, 0.03);
}

.template-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.template-name {
  font-size: 15px;
  font-weight: 700;
}

.template-meta {
  font-size: 12px;
  color: var(--muted);
}

.preset-meta {
  margin: 14px 0 0;
  padding: 0 2px;
  line-height: 1.45;
}

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

.template-actions button {
  min-height: 38px;
  padding: 10px 14px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f3d9a7 0%, #f0be67 100%);
  color: #18130f;
  font-weight: 700;
  text-decoration: none;
}

.button-link.ghost {
  color: var(--ink);
  background: rgba(255, 248, 238, 0.07);
  border: 1px solid rgba(255, 247, 234, 0.12);
}

.color-field {
  align-content: end;
}

.checkbox-field {
  align-content: center;
}

.checkbox-field input {
  justify-self: start;
}

code {
  font-size: 0.9em;
}

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

.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(246, 190, 85, 0.12);
  border: 1px solid rgba(246, 190, 85, 0.2);
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
}

.badge.danger {
  background: rgba(255, 110, 92, 0.12);
  border-color: rgba(255, 110, 92, 0.2);
  color: var(--danger);
}

.preview-frame {
  background:
    linear-gradient(180deg, rgba(255, 251, 246, 0.04), rgba(255, 251, 246, 0.01)),
    #0f0c09;
  border-radius: 26px;
  border: 1px solid rgba(255, 247, 234, 0.08);
  padding: 12px;
}

#previewCanvas {
  display: block;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  border-radius: 22px;
  touch-action: none;
  background: #0a0807;
}

.preview-help {
  margin: 12px 4px 0;
  font-size: 13px;
}

.action-row {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.export-result {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid rgba(255, 247, 234, 0.1);
  border-radius: 18px;
  background: rgba(255, 251, 246, 0.04);
}

.export-result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.export-result-header h3 {
  margin: 4px 0 0;
  font-size: 18px;
}

.export-result-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.export-preview-frame {
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(255, 247, 234, 0.08);
  background: rgba(0, 0, 0, 0.2);
}

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

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 14px 16px;
  color: #18130f;
  background: linear-gradient(180deg, #f3d9a7 0%, #f0be67 100%);
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(240, 190, 103, 0.22);
}

button.ghost {
  color: var(--ink);
  background: rgba(255, 248, 238, 0.07);
  border: 1px solid rgba(255, 247, 234, 0.12);
  box-shadow: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.status-message {
  min-height: 24px;
  margin: 14px 4px 0;
  font-size: 14px;
  line-height: 1.5;
}

.status-message.error {
  color: var(--danger);
}

@media (max-width: 560px) {
  .control-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .export-result-header {
    flex-direction: column;
  }
}

@media (min-width: 980px) {
  .shell {
    grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
    align-items: start;
    padding: 28px 20px 36px;
  }

  .preview-panel {
    position: sticky;
    top: 20px;
  }

  .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .template-save-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
}
