/* Thème sombre, accent rouge « Mulhouse » (#cc0000, couleur du thème de lavieamulhouse.com) */
:root {
  --ink: #f1f2f5;
  --ink-soft: #a4a9b6;
  --paper: #0e1014;
  --card: #1a1d24;
  --card-2: #262a34;
  --field: #11131a;
  --line: #333845;
  --edge: #3d4350;
  --accent: #cc0000;
  --accent-text: #ff6060;
  --accent-ink: #ffffff;
  --radius: 18px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, #222733 1.2px, transparent 0);
  background-size: 22px 22px;
  line-height: 1.5;
  min-height: 100vh;
}

.studio {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 48px) clamp(16px, 3vw, 32px) 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "intro intro" "tabs tabs" "controls preview";
  gap: 24px 32px;
  align-items: start;
}

.intro { grid-area: intro; }
.intro h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1;
}
.intro p { margin: 10px 0 0; color: var(--ink-soft); font-size: 1.1rem; max-width: 46ch; }

/* ---------- Panneau de réglages ---------- */
.panel {
  grid-area: controls;
  background: var(--card);
  border: 2px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 #000;
  padding: clamp(18px, 3vw, 28px);
  display: grid;
  gap: 22px;
}

.field-title, legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
  padding: 0;
  display: block;
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color .15s, background .15s;
}
textarea { resize: vertical; min-height: 96px; }
textarea:focus, select:focus { outline: none; border-color: var(--accent-text); background: #0b0d12; }
select:disabled { opacity: .5; }

.hint { margin: 6px 0 0; font-size: .85rem; color: var(--ink-soft); }
.hint.center { text-align: center; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- Choix de formes (pastilles) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label {
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: .92rem;
  cursor: pointer;
  background: var(--field);
  user-select: none;
  transition: border-color .12s, background .12s, color .12s;
}
.chips label:hover { border-color: var(--ink-soft); }
.chips input:checked + label { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips input:focus-visible + label { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Couleurs ---------- */
.colors { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: center; }
.color { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.color.off { opacity: .35; pointer-events: none; }
input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 42px; height: 42px; padding: 0;
  border: 2px solid #8b92a3; border-radius: 50%;
  background: none; cursor: pointer; overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
.switch { display: flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; margin-left: auto; }
.switch input { accent-color: var(--accent-text); width: 18px; height: 18px; }

/* ---------- Curseurs ---------- */
.slider { display: grid; gap: 8px; font-size: .92rem; font-weight: 600; }
.slider b { font-weight: 800; color: var(--accent-text); }
input[type="range"] { width: 100%; accent-color: var(--accent-text); }
.select { font-size: .92rem; font-weight: 600; display: grid; gap: 8px; }
.select select { font-weight: 400; }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-weight: 600;
  padding: 10px 18px;
  border: 2px solid #565d6e;
  border-radius: 12px;
  background: var(--card-2); color: var(--ink);
  cursor: pointer;
  box-shadow: 3px 3px 0 #000;
  transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #000; }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #000; }
.btn:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 3px; }
.btn.primary { background: var(--accent); border-color: #ff4040; color: var(--accent-ink); }
.btn.ghost { display: inline-block; box-shadow: none; padding: 8px 14px; font-size: .92rem; }
.btn.ghost:hover { box-shadow: none; transform: none; background: #323847; }
.btn.link { border: 0; box-shadow: none; background: none; text-decoration: underline; padding: 8px; }
.logo-row { display: flex; align-items: center; gap: 6px; }

/* ---------- Aperçu : le QR code est un « autocollant » ---------- */
.preview { grid-area: preview; position: sticky; top: 24px; display: grid; gap: 18px; }
.sticker {
  background: #fff;
  border: 2px solid #fff;
  border-radius: 26px;
  padding: 22px;
  box-shadow: 8px 8px 0 var(--accent);
  transform: rotate(-1.5deg);
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  position: relative;
}
#qr { transition: opacity .2s; line-height: 0; }
#qr svg, #qr canvas { max-width: 100%; height: auto; border-radius: 6px; }
.empty {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center; text-align: center;
  padding: 36px; color: #555; font-weight: 600;
}
.empty[hidden] { display: none; }

.downloads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.downloads .btn { padding: 10px 6px; font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  /* Ordre inversé sur mobile : le formulaire (controls) arrive avant l'aperçu (preview) */
  .studio { grid-template-columns: 1fr; grid-template-areas: "intro" "tabs" "controls" "preview"; }
  .preview { position: static; max-width: 380px; width: 100%; margin: 0 auto; }
}
@media (max-width: 520px) {
  .two { grid-template-columns: 1fr; }
  .switch { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Onglets ---------- */
[hidden] { display: none !important; }
.tabs { grid-area: tabs; display: flex; gap: 8px; }
.tab {
  font: inherit; font-weight: 600; font-size: 1rem;
  padding: 10px 24px;
  border: 2px solid var(--edge);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.tab:hover { color: var(--ink); border-color: #565d6e; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Décodeur ---------- */
.decode { grid-area: 3 / 1 / 4 / -1; }
.field-title.big { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.drop {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 22px;
  border: 2px dashed var(--edge);
  border-radius: 14px;
  background: var(--field);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent-text); background: #1d1416; }
.drop .btn { display: inline-block; }
.drop-name { color: var(--ink-soft); font-size: .95rem; overflow-wrap: anywhere; }
.decode-out { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }
.thumb {
  background: #fff; border: 2px solid #fff; border-radius: 14px; padding: 8px;
  display: grid; place-items: center; box-shadow: 5px 5px 0 var(--accent);
}
.thumb img { max-width: 100%; max-height: 220px; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.actions .btn { text-decoration: none; display: inline-block; font-size: .92rem; }
.error { margin: 0; padding: 12px 14px; border-radius: 12px; background: #2a1316; border: 2px solid var(--accent); color: #ffb3b3; font-weight: 600; }
@media (max-width: 620px) { .decode-out { grid-template-columns: 1fr; } .thumb { max-width: 240px; } }

/* ---------- Conseils et contrôle du contenu ---------- */
.advice {
  margin: 10px 0 0; padding: 10px 14px;
  color: #ffb454; background: rgba(255, 180, 84, .08);
  border-left: 4px solid #ffb454; border-radius: 8px;
  font-size: .9rem;
}
.advice strong { color: #ffc97d; }
.meter { height: 6px; margin-top: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: #3ecf8e; border-radius: 99px; transition: width .2s, background .2s; }
.meter span.warn { background: #ffb454; }
.meter span.err { background: var(--accent-text); }
.hint.warn { color: #ffb454; }
.hint.err { color: var(--accent-text); font-weight: 600; }
.alert { margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-size: .92rem; border: 2px solid; }
.alert p { margin: 0; }
.alert p + p { margin-top: 6px; }
.alert.is-error { background: #2a1316; border-color: var(--accent); color: #ffb3b3; }
.alert.is-warn { background: #2a2213; border-color: #ffb454; color: #ffd9a0; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: 3px 3px 0 #000; }
/* Bouton de téléchargement direct pour mobile */
.mobile-dl {
  width: 100%;
  text-align: center;
  font-size: 1rem;
  padding: 12px;
}
#game-info { font-size: 14px; font-weight: 700; color: #cbd5e1; }