* { box-sizing: border-box; }

:root {
  --neon: #00f0ff;
  --bg: #05060a;
  --gap: clamp(8px, 1.5vw, 14px);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: #eaf6ff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body.cursor-idle { cursor: none; }

#webcam {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.55;
  filter: saturate(0.8) brightness(0.85);
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* --- masquage complet de l'interface (touche H) --- */

body.ui-hidden #webcam,
body.ui-hidden #hud,
body.ui-hidden #help-panel,
body.ui-hidden #toolbar {
  opacity: 0;
  pointer-events: none;
}

/* --- start overlay --- */

#start-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(0, 240, 255, 0.08), rgba(5, 6, 10, 0.96) 70%);
  z-index: 30;
  transition: opacity 0.5s ease;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

#start-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-card {
  max-width: 420px;
  text-align: center;
  padding: clamp(20px, 4vw, 32px);
  border-radius: 18px;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.25);
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.12);
}

.start-card h1 {
  margin: 0 0 12px;
  font-size: clamp(1.3rem, 4vw, 1.6rem);
  text-shadow: 0 0 18px rgba(0, 240, 255, 0.6);
}

.start-card p {
  margin: 0 0 20px;
  line-height: 1.5;
  color: #b9d6e0;
  font-size: 0.95rem;
}

.start-note {
  font-size: 0.75rem !important;
  color: #6d8a96 !important;
  margin-top: 16px !important;
}

#start-btn {
  appearance: none;
  border: none;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 999px;
  color: #05262b;
  background: linear-gradient(135deg, #00f0ff, #7dffb3);
  box-shadow: 0 0 25px rgba(0, 240, 255, 0.5);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#start-btn:hover { transform: translateY(-1px); box-shadow: 0 0 35px rgba(0, 240, 255, 0.7); }
#start-btn:active { transform: translateY(0); }

/* --- HUD --- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) 0 calc(var(--safe-left) + 16px);
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.3s ease;
}

#status-text {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.55);
  border: 1px solid rgba(0, 240, 255, 0.25);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
  backdrop-filter: blur(6px);
  transition: color 0.2s ease, border-color 0.2s ease;
}

#help-btn {
  pointer-events: auto;
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(0, 240, 255, 0.25);
  background: rgba(8, 12, 18, 0.55);
  color: #9fc4d0;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, color 0.15s ease;
}

#help-btn:hover, #help-btn[aria-expanded="true"] {
  background: rgba(0, 240, 255, 0.18);
  color: #00f0ff;
}

/* --- help panel --- */

#help-panel {
  position: fixed;
  top: calc(var(--safe-top) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(340px, calc(100vw - 32px));
  background: rgba(8, 12, 18, 0.85);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 14px;
  padding: 14px 18px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s ease;
}

#help-panel[hidden] { display: none; }

#help-panel h2 {
  margin: 10px 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6fd8e8;
}

#help-panel h2:first-child { margin-top: 0; }

#help-panel p {
  margin: 4px 0;
  font-size: 0.82rem;
  color: #cfe8ef;
  display: flex;
  align-items: center;
  gap: 8px;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  background: rgba(0, 240, 255, 0.18);
  color: #00f0ff;
  font-size: 0.65rem;
  font-weight: 700;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-family: inherit;
  font-size: 0.75rem;
  color: #eaf6ff;
}

/* --- toast --- */

#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 96px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 25;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.85);
  border: 1px solid rgba(0, 240, 255, 0.3);
  font-size: 0.82rem;
  color: #eaf6ff;
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-action {
  appearance: none;
  border: none;
  background: none;
  color: var(--neon);
  font-size: inherit;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-left: 10px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.toast-action:hover { opacity: 0.75; }

/* --- toolbar --- */

#toolbar {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  max-width: calc(100vw - 24px);
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s ease;
}

#palette {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  appearance: none;
  border: 2px solid transparent;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background-color: var(--swatch-color);
  box-shadow: 0 0 8px var(--swatch-color);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.swatch:hover { transform: scale(1.12); }

.swatch.active {
  border-color: #fff;
  transform: scale(1.18);
  box-shadow: 0 0 16px var(--swatch-color);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.15);
}

#width-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

#actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: #b9d6e0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn svg { width: 19px; height: 19px; }

.icon-btn:hover {
  background: rgba(0, 240, 255, 0.15);
  color: #00f0ff;
}

.icon-btn.on {
  background: rgba(255, 47, 214, 0.18);
  color: #ff8fd0;
}

#save-btn:hover { color: #7dffb3; background: rgba(125, 255, 179, 0.15); }
#save-svg-btn:hover { color: #b98bff; background: rgba(185, 139, 255, 0.15); }
#clear-btn:hover { color: #ff8fd0; background: rgba(255, 90, 160, 0.15); }

/* --- touch targets on coarse pointers (mobile/tablet) --- */

@media (pointer: coarse) {
  .icon-btn { width: 46px; height: 46px; }
  .swatch { width: 30px; height: 30px; }
  #help-btn { width: 38px; height: 38px; }
  #help-kbd { display: none; }
}

/* --- breakpoints --- */

@media (max-width: 900px) {
  #help-panel { top: calc(var(--safe-top) + 54px); }
}

@media (max-width: 600px) {
  #toolbar { gap: 6px; padding: 6px 10px; bottom: calc(var(--safe-bottom) + 12px); }
  .toolbar-divider { display: none; }
  #palette { order: 3; flex-basis: 100%; justify-content: center; }
  #width-controls { order: 2; justify-content: center; }
  #actions { order: 1; flex-basis: 100%; justify-content: center; }
  .start-card { max-width: 90vw; padding: 24px; }
}

@media (max-height: 420px) and (orientation: landscape) {
  #toolbar { bottom: calc(var(--safe-bottom) + 8px); padding: 4px 10px; }
  #hud { padding-top: calc(var(--safe-top) + 8px); }
  .icon-btn { width: 34px; height: 34px; }
  .icon-btn svg { width: 16px; height: 16px; }
}
