:root {
  --bg: #1c1a19;
  --panel: #2a2624;
  --copper: #d89b7c;
  --copper-dark: #b97a5c;
  --text: #f4efec;
  --muted: #a99d96;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at top, #3a2e27 0%, var(--bg) 60%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* Toute l'appli tient dans la hauteur de l'écran : l'affiche prend la place
   qui reste entre l'en-tête et les boutons. */
.app {
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hero { text-align: center; flex: none; }
.hero h1 {
  font-family: 'Great Vibes', cursive;
  font-weight: 400;
  font-size: 40px;
  margin: 0;
  line-height: 1.05;
}
.hero p { margin: 2px 0 0; color: var(--muted); font-size: 13px; line-height: 1.3; }
.hero strong { color: var(--copper); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}
.frame {
  position: relative;
  width: min(100cqw, 80cqh);
  aspect-ratio: 4 / 5;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 32px rgba(0, 0, 0, .55);
  background: #111;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
}
/* On ne bloque le défilement que lorsqu'on manipule la photo */
#canvas.editable { touch-action: none; cursor: grab; }
#canvas.editable:active { cursor: grabbing; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
  background: rgba(0, 0, 0, .65);
  border-radius: 999px;
  pointer-events: none;
  transition: opacity .6s;
}
.hint[hidden] { display: none; }
.hint.fade { opacity: 0; }

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, .55);
  font-size: 15px;
}
.busy[hidden] { display: none; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: var(--copper);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.controls { flex: none; display: flex; flex-direction: column; gap: 8px; }
.controls[hidden] { display: none; }
.row { display: flex; gap: 8px; }
.grow { flex: 1; }
.tools .btn { flex: 1; }
.tools #changeBtn { flex: none; width: 48px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 50px;
  padding: 10px 16px;
  border: 1px solid #4a423d;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: 600 16px Inter, system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  border: none;
  background: linear-gradient(135deg, var(--copper), var(--copper-dark));
  color: #1c1a19;
}
.btn.small { min-height: 42px; padding: 8px 6px; font-size: 13px; }
.btn.on { border-color: var(--copper); color: var(--copper); }

.zoom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 18px;
}
.zoom input { flex: 1; accent-color: var(--copper); }

.note {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.note .ico { width: 14px; height: 14px; }

.ico {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn.small .ico { width: 17px; height: 17px; }
.zoom .ico { width: 18px; height: 18px; display: block; }

/* Petits écrans en hauteur : on resserre */
@media (max-height: 700px) {
  .hero h1 { font-size: 32px; }
  .hero p { display: none; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
}

.save-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  background: rgba(0, 0, 0, .92);
  text-align: center;
}
.save-overlay img { max-width: 100%; max-height: 70vh; border-radius: 10px; }
