/* ==========================================================================
   COLORZ — style kawaii B (DÉCISION porteur C6 : contour épais net, aplat +
   une ombre plate, reflet brillant, formes rondes). Remplace le premium
   glassmorphism/glow : zéro backdrop-filter, zéro glow multi-couche,
   surfaces opaques, contour d'encre, ombre plate décalée (jamais de flou).
   Thème piloté par le hub (html[data-theme], voir /_kit/theme.js) plutôt
   que l'OS seul. Identité Colorz conservée : violet doux + accents pastel,
   ambiance "atelier de coloriage" plutôt que "jeu d'arcade".
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #171426;
  --bg-2: #100e1c;
  --panel: #201c35;
  --panel-2: #2a2444;
  --canvas-bg: #12101e;
  --ink: #f3f0ff;
  --muted: #a89cd6;
  --muted-2: #8478af;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  --primary: var(--cb-primary, #7c6cf0);
  --primary-ink: #ffffff;
  --accent: var(--cb-accent, #ffc107);
  --danger: var(--cb-danger, #ff5f6d);
  --success: var(--cb-primary, #3aff8f);

  --radius-lg: var(--cb-radius-xl, 20px);
  --radius-md: var(--cb-radius-lg, 14px);
  --radius-sm: var(--cb-radius-md, 12px);
  --radius-xs: var(--cb-radius-sm, 8px);

  --dur-fast: var(--cb-duration-fast, 0.14s);
  --dur-normal: var(--cb-duration-normal, 0.2s);
  --dur-slow: var(--cb-duration-slow, 0.35s);
  --ease: var(--cb-easing-ease-out, cubic-bezier(0.16, 1, 0.3, 1));
  --ease-bounce: var(--cb-easing-bounce, cubic-bezier(0.175, 0.885, 0.32, 1.275));

  /* Kawaii B : contour or accent sur fond sombre (encre foncée = invisible
     sur panneau sombre), reflet statique, ombre plate (jamais de flou). */
  --toon-outline: #f0c04d;
  --toon-outline-w: 2px;
  --kawaii-sheen: radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 46%);
  --shadow-sm: 0 3px 0 var(--toon-outline);
  --shadow-md: 0 4px 0 var(--toon-outline);
  --shadow-lg: 0 8px 0 var(--toon-outline);

  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f6f3ff;
  --bg-2: #ece5ff;
  --panel: #ffffff;
  --panel-2: #f1ecff;
  --canvas-bg: #fbfaf6;
  --ink: #241f3d;
  --muted: #6c619a;
  --muted-2: #7a6fa8;
  --border: rgba(40, 20, 80, 0.10);
  --border-strong: rgba(40, 20, 80, 0.18);
  --primary: #6c5ce7;
  --accent: #b8860b;
  /* Encre foncée sur fond clair = fort contraste (leçon FACETA : un contour
     sombre sur panneau sombre est invisible, l'inverse est vrai en clair). */
  --toon-outline: #241f3d;
  --kawaii-sheen: radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 46%);
  color-scheme: light;
}

html, body { height: 100%; }
body {
  font-family: var(--cb-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.app-container { display: flex; height: 100vh; flex-direction: column; }
.game-wrapper { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* ---------------------------------------------------------------- header */
.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 14px 10px;
  background: linear-gradient(135deg, var(--primary), #9b8cf5);
  border-bottom: var(--toon-outline-w) solid var(--toon-outline);
  z-index: 10;
}
.game-header h1 { flex: 1; text-align: center; font-size: 19px; font-weight: 800; color: #fff; letter-spacing: 0.01em; }

.btn-back, .btn-gallery {
  width: 38px; height: 38px; flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.16);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  color: white; border-radius: var(--radius-xs);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn-back svg, .btn-gallery svg { width: 18px; height: 18px; }
.btn-back:hover, .btn-gallery:hover { background: rgba(255, 255, 255, 0.28); }
.btn-back:active, .btn-gallery:active { transform: scale(0.92); }

.header-right { display: flex; align-items: center; gap: 8px; }

.wallet-hud { display: flex; gap: 6px; }
.wallet-chip {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 9px; border-radius: var(--cb-radius-full, 999px);
  background: rgba(255, 255, 255, 0.16);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  color: #fff; font-size: 12px; font-weight: 800;
  white-space: nowrap;
}
.wallet-chip svg { width: 13px; height: 13px; flex: 0 0 auto; }
.wallet-earn svg { color: var(--accent); }

/* ------------------------------------------------------------ jeu / grille */
.game-content { display: flex; flex: 1; overflow: hidden; gap: 0; }

.canvas-container {
  flex: 1; display: flex; position: relative;
  background: var(--canvas-bg);
  overflow: hidden; touch-action: none;
}
.game-canvas { width: 100%; height: 100%; display: block; cursor: pointer; touch-action: none; }

.touch-controls {
  position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 8px; z-index: 5;
}
.btn-zoom-in, .btn-zoom-out {
  width: 38px; height: 38px;
  background: var(--panel); color: var(--ink);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn-zoom-in svg, .btn-zoom-out svg { width: 18px; height: 18px; }
.btn-zoom-in:hover, .btn-zoom-out:hover { background: var(--panel-2); }
.btn-zoom-in:active, .btn-zoom-out:active { transform: scale(0.9); }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  width: 210px; background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.progress-section { display: flex; flex-direction: column; gap: 7px; }
.progress-section label, .palette-section label {
  font-size: 11px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.progress-bar { width: 100%; height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width var(--dur-slow) var(--ease);
}
.progress-percent { font-size: 12px; color: var(--muted); text-align: right; font-weight: 700; }

.palette-section { display: flex; flex-direction: column; gap: 8px; }
.color-palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }

.color-button {
  aspect-ratio: 1; border: var(--toon-outline-w) solid var(--toon-outline); border-radius: var(--radius-xs);
  background-image: var(--kawaii-sheen);
  cursor: pointer; transition: transform var(--dur-fast) var(--ease-bounce), box-shadow var(--dur-fast) var(--ease);
  position: relative; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  color: white; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.45);
}
.color-button:hover:not(.done) { transform: scale(1.06); }
.color-button.active { box-shadow: 0 0 0 3px rgba(124, 108, 240, 0.35); }
.color-button.done { opacity: 0.28; cursor: default; }
.color-badge {
  position: absolute; bottom: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 999px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--toon-outline);
  font-size: 9px; display: flex; align-items: center; justify-content: center;
}

.stats-section { padding-top: 10px; border-top: 1px solid var(--border); }
.stats-content { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ----------------------------------------------------------------- footer */
.game-footer {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--panel); border-top: var(--toon-outline-w) solid var(--toon-outline);
  justify-content: center;
}
.btn-footer {
  flex: 1 1 68px; max-width: 110px; height: 42px;
  background: var(--panel-2); color: var(--ink);
  border: var(--toon-outline-w) solid var(--toon-outline);
  background-image: var(--kawaii-sheen);
  border-radius: var(--radius-xs); cursor: pointer; font-size: 11px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn-footer svg { width: 17px; height: 17px; }

.btn-footer:hover:not(:disabled) { background: var(--primary); color: #fff; transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.btn-footer:active:not(:disabled) { transform: translateY(0) scale(0.96); }
.btn-footer:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-tool { background: linear-gradient(160deg, var(--panel-2), var(--panel)); }

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed; inset: 0; background: var(--cb-overlay-bg, rgba(8, 6, 16, 0.72));
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fadeIn var(--dur-normal) var(--ease); padding: 16px;
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
  background: var(--panel); border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: var(--radius-lg); padding: 26px;
  max-width: 92%; width: 420px; max-height: 88vh; overflow-y: auto;
  position: relative; box-shadow: var(--shadow-lg);
  animation: slideUp var(--dur-slow) var(--ease-bounce);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-close {
  position: absolute; top: 10px; right: 10px; background: none; border: none;
  color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1;
  width: 32px; height: 32px; border-radius: 50%;
  transition: background var(--dur-fast) var(--ease);
}
.modal-close:hover { background: var(--panel-2); color: var(--ink); }

.modal-content h2 { margin-bottom: 14px; font-size: 21px; font-weight: 800; }

.modal-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }
.btn-primary, .btn-secondary {
  padding: 12px 18px; border-radius: var(--radius-xs); cursor: pointer;
  font-size: 14px; font-weight: 800; transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn-primary { background: var(--primary); color: #fff; border: var(--toon-outline-w) solid var(--toon-outline); box-shadow: var(--shadow-sm); }
.btn-primary:hover { transform: translateY(-2px); }
.btn-primary:active { transform: translateY(0) scale(0.97); }
.btn-secondary { background: transparent; color: var(--primary); border: var(--toon-outline-w) solid var(--primary); }
.btn-secondary:hover { background: rgba(124, 108, 240, 0.10); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; filter: none; }

/* --------------------------------------------------------------- galerie */
.modal-gallery { width: 460px; }
.continue-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--panel-2); border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: var(--radius-sm); padding: 10px; margin-bottom: 16px;
  cursor: pointer; color: var(--ink); font-weight: 800; font-size: 14px;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.continue-card:hover { background: var(--primary); color: #fff; }
.continue-card canvas { width: 48px; height: 48px; border-radius: var(--radius-xs); background: var(--canvas-bg); }
.continue-card.hidden { display: none; }

.gallery-preview { display: flex; justify-content: center; margin-bottom: 16px; }
.gallery-preview canvas {
  width: 130px; height: 130px; border-radius: var(--radius-sm);
  background: var(--canvas-bg); border: var(--toon-outline-w) solid var(--toon-outline); box-shadow: var(--shadow-sm);
}

.picker-row { margin-bottom: 16px; }
.picker-row label {
  display: block; font-size: 11px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px;
}
.picker-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.pick-btn {
  position: relative; padding: 9px 13px; border-radius: var(--radius-xs);
  background: var(--panel-2); border: var(--toon-outline-w) solid transparent; color: var(--ink);
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.pick-btn:hover { transform: translateY(-1px); }
.pick-btn.active { border-color: var(--toon-outline); background: rgba(124, 108, 240, 0.14); background-image: var(--kawaii-sheen); }
.pick-btn.locked { opacity: 0.55; }
.pick-btn .lock-note { display: flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 600; color: var(--muted-2); margin-top: 2px; }
.pick-btn .lock-note svg { width: 11px; height: 11px; flex: 0 0 auto; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 768px) {
  .game-content { flex-direction: column; }
  .sidebar {
    width: 100%; max-height: 168px; border-left: none; border-top: 1px solid var(--border);
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 10px;
  }
  .stats-section { grid-column: 1 / -1; padding-top: 6px; }
  .game-header h1 { font-size: 16px; }
  .wallet-chip { font-size: 11px; padding: 4px 7px; }
  .btn-back, .btn-gallery { width: 34px; height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 480px) {
  .game-header { padding: 8px 12px; }
  .game-header h1 { font-size: 16px; }
  .btn-footer { font-size: 11px; height: 36px; }
}
