:root {
  --ink: #2b241d;
  --paper: #faf6f0;
  --panel: #ffffff;
  --border: #e7ddcf;
  --accent: #b8622c;
  --accent-dark: #8f4a1f;
  --radius: 14px;
  font-family: 'Poppins', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

.app-header {
  text-align: center;
  padding: 32px 16px 12px;
}

.app-header h1 {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: clamp(28px, 5vw, 42px);
  margin: 0 0 6px;
  color: var(--accent-dark);
}

.app-header p {
  margin: 0;
  color: #6b6058;
}

.app {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  max-width: 1180px;
  margin: 24px auto 60px;
  padding: 0 20px;
  align-items: start;
}

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

.panel, .preview-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 0;
}

.preview-wrap {
  position: sticky;
  top: 20px;
  text-align: center;
}

.step { margin-bottom: 28px; }
.step:last-child { margin-bottom: 0; }

h2 {
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
}

h2 span {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.background-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.bg-swatch {
  flex: 0 0 auto;
  width: 72px;
  aspect-ratio: 9 / 16;
  border-radius: 8px;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
  outline-offset: 2px;
  scroll-snap-align: start;
}

.bg-swatch.selected {
  border-color: var(--accent);
}

.mode-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.mode-btn, .bgtype-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}

.mode-btn.active, .bgtype-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mode-panel { display: none; }
.mode-panel.active { display: block; }

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: #55493f;
}

.field span {
  display: block;
  margin-bottom: 6px;
}

.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field { flex: 1; }

select, input[type="text"], input[type="date"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  /* 16px minimum : sous ce seuil, Safari iOS zoome automatiquement au focus. */
  font-size: 16px;
  resize: vertical;
}

select:focus, input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #55493f;
  cursor: pointer;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

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

.color-swatches {
  display: flex;
  gap: 10px;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}

.color-dot.selected {
  border-color: var(--accent);
}

.shape-swatches {
  display: flex;
  gap: 10px;
}

.shape-dot {
  width: 48px;
  height: 28px;
  background: #8a7c6c;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.shape-dot.selected {
  border-color: var(--accent);
  border-width: 3px;
}

.canvas-shell {
  max-width: 300px;
  margin: 0 auto 18px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.15);
}

#story-canvas {
  width: 100%;
  height: auto;
  display: block;
}

.download-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 28px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

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

/* ---- Verrou par mot de passe ------------------------------------ */

.password-gate {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.password-gate[hidden] {
  display: none;
}

.password-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.password-box h1 {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  color: var(--accent-dark);
  margin: 0 0 10px;
}

.password-box p {
  font-size: 13px;
  color: #6b6058;
  margin: 0 0 18px;
}

.password-box input {
  margin-bottom: 12px;
  text-align: center;
  /* 16px minimum : sous ce seuil, Safari iOS zoome automatiquement au focus. */
  font-size: 16px;
}

.password-box button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.password-box button:hover {
  background: var(--accent-dark);
}

.password-error {
  color: #b3261e !important;
  margin-top: 12px !important;
  margin-bottom: 0 !important;
}
