:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-light: #eff4ff;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --error-border: #fecaca;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --card-bg: #1e2126;
    --text: #f0f1f3;
    --text-muted: #9aa0ab;
    --border: #2c3036;
    --primary: #5b8def;
    --primary-light: #1c2636;
    --error-bg: #2a1616;
    --error-text: #f87171;
    --error-border: #4c1f1f;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --card-bg: #1e2126;
  --text: #f0f1f3;
  --text-muted: #9aa0ab;
  --border: #2c3036;
  --primary: #5b8def;
  --primary-light: #1c2636;
  --error-bg: #2a1616;
  --error-text: #f87171;
  --error-border: #4c1f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 1.6rem;
  margin: 0 0 6px;
}

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

.intro {
  color: var(--text-muted);
  margin: 10px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ad-slot-top {
  margin-bottom: 20px;
}

.ad-slot-bottom {
  margin-top: 20px;
}

.hidden {
  display: none !important;
}

/* ---- Progression ---- */

.progress {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.step-count {
  margin: 8px 0 18px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- Formulaire ---- */

.step {
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.step legend {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 18px;
  padding: 0;
}

.field {
  margin-bottom: 16px;
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.field > label,
.field > .label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.req {
  color: var(--error-text);
}

.opt {
  font-weight: 400;
  font-size: 0.78rem;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

.field.invalid input,
.field.invalid .segmented {
  border-color: var(--error-text);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Boutons radio en segments */
.segmented {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border: 1px solid transparent;
  border-radius: 12px;
}

.segmented label {
  flex: 1 1 0;
  min-width: 0;
  cursor: pointer;
}

.segmented input,
.chips input,
.universe-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  height: 100%;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.segmented small {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.segmented input:checked + span,
.chips input:checked + span,
.universe-grid input:checked + span {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.segmented input:focus-visible + span,
.chips input:focus-visible + span,
.universe-grid input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Puces à choix multiples */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips label {
  cursor: pointer;
}

.chips span {
  display: inline-block;
  padding: 7px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.chips input:disabled + span {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Choix de l'univers */
.universe-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

@media (max-width: 520px) {
  .universe-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.universe-grid label {
  cursor: pointer;
}

.universe-grid label > span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  padding: 12px 8px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.universe-grid .u-emoji {
  font-size: 1.6rem;
}

.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.85rem;
  margin: 4px 0 16px;
  text-align: center;
}

/* ---- Boutons ---- */

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.controls-nav {
  justify-content: space-between;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 20px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.8rem;
}

/* ---- Histoire ---- */

.story {
  margin-top: 0;
}

.story-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
}

#story-content {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
  line-height: 1.75;
}

#story-content h2 {
  font-size: 1.6rem;
  line-height: 1.3;
  text-align: center;
  margin: 8px 0 4px;
}

#story-content .story-sub {
  text-align: center;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0 0 24px;
}

#story-content h3 {
  font-size: 1.15rem;
  margin: 28px 0 8px;
  color: var(--primary);
}

#story-content p {
  margin: 0 0 14px;
  text-align: justify;
  hyphens: auto;
}

#story-content .story-end {
  text-align: center;
  font-style: italic;
  margin-top: 24px;
  color: var(--text-muted);
}

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 20px;
}

.footer a {
  color: var(--text-muted);
}

@media print {
  body {
    background: #fff;
    color: #000;
  }
  .breadcrumb, .header, .ad-slot, .footer, #wizard-card,
  .story-toolbar, .story .controls {
    display: none !important;
  }
  .card {
    border: none;
    padding: 0;
  }
  #story-content h3 {
    color: #000;
  }
}
