:root {
  --pen: #3a3042;
  --paper: #fffaf0;
  --sky: #bfe6ff;
  --red: #e8424b;
  --yellow: #ffd23f;
  --blue: #4a90e2;
  --green: #7bc950;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Marker Felt", cursive;
  --wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9edb72; font-family: var(--font); color: var(--pen); }
body { display: flex; align-items: center; justify-content: center; background: linear-gradient(#bfe6ff 0 60%, #9edb72 60%); touch-action: none; user-select: none; -webkit-user-select: none; }
#stage { position: relative; width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; }
#game { display: block; touch-action: none; }
.hidden { display: none !important; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.2vh; padding: 16px; }
#loading { background: var(--paper); }
.logo { width: min(80vw, 720px); filter: drop-shadow(0 6px 0 rgba(58, 48, 66, .2)); animation: bob 2.4s ease-in-out infinite; }
.tagline { font-size: clamp(16px, 2.4vw, 28px); margin: 0; background: var(--paper); padding: 6px 18px; border: 3px solid var(--pen); border-radius: var(--wobble); transform: rotate(-1deg); }
h1 { margin: 0; font-size: clamp(28px, 5vw, 60px); color: var(--paper); -webkit-text-stroke: 2px var(--pen); text-shadow: 0 5px 0 var(--pen); transform: rotate(-1.5deg); }
.col { display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.progress { width: min(70vw, 480px); height: 28px; border: 4px solid var(--pen); border-radius: var(--wobble); overflow: hidden; background: #fff; }
#bar { height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--yellow) 0 14px, #ffb53c 14px 28px); transition: width .2s; }

.paper { background: var(--paper); border: 4px solid var(--pen); border-radius: var(--wobble); box-shadow: 4px 6px 0 rgba(58, 48, 66, .25); }

.btn { font-family: var(--font); font-weight: bold; font-size: clamp(16px, 2vw, 24px); color: var(--pen); background: var(--paper); border: 4px solid var(--pen); border-radius: var(--wobble); padding: 10px 22px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 3px 5px 0 var(--pen); transition: transform .1s; }
.btn img { width: 1.6em; height: 1.6em; }
.btn:hover { transform: rotate(-2deg) scale(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 1px 2px 0 var(--pen); }
.btn.primary { background: var(--yellow); }
.btn.big { font-size: clamp(22px, 3.2vw, 38px); padding: 14px 40px; }
.btn.small { font-size: 18px; padding: 6px 16px; }
.btn.icon { padding: 6px; background: #8fd0ff; }
.btn.icon img { width: 44px; height: 44px; }
#btn-sound { position: absolute; right: 16px; bottom: 16px; z-index: 20; }

/* Niveaux */
#level-list { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; max-width: 1100px; }
.card { font-family: var(--font); color: var(--pen); background: var(--paper); border: 4px solid var(--pen); border-radius: var(--wobble); cursor: pointer; box-shadow: 3px 5px 0 var(--pen); }
.card.level { width: 180px; height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 12px 8px; }
.card.level:nth-child(odd) { transform: rotate(-1.5deg); }
.card.level:nth-child(even) { transform: rotate(1.5deg); }
.card.level:hover { background: #fff3c4; }
.card.level .num { font-size: 56px; font-weight: bold; line-height: 1; color: var(--blue); -webkit-text-stroke: 1.5px var(--pen); }
.card.level .lname { font-size: 17px; font-weight: bold; text-align: center; }
.card.level .stars img { width: 42px; }
.card.level.locked { opacity: .65; cursor: not-allowed; background: #e9e4d8; }
.card.level .lock { width: 56px; }

/* Garde-robe */
#wardrobe { gap: 1.6vh; }
.wardrobe-wrap { display: flex; gap: 20px; width: min(1180px, 96vw); max-height: 74vh; }
.preview-panel { flex: 0 0 auto; width: min(360px, 34vw); display: flex; flex-direction: column; align-items: center; padding: 12px; gap: 10px; background: linear-gradient(var(--paper) 70%, #d9f2c4 70%); }
#preview { width: 100%; height: auto; aspect-ratio: 1; }
.name { display: flex; flex-direction: column; align-items: center; font-weight: bold; gap: 4px; width: 100%; }
#name-input { font-family: var(--font); font-size: 24px; font-weight: bold; text-align: center; width: 90%; padding: 4px 8px; border: 3px solid var(--pen); border-radius: var(--wobble); background: #fff; color: var(--pen); }
.options-panel { flex: 1; display: flex; flex-direction: column; padding: 12px; min-width: 0; }
#tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tab { font-family: var(--font); font-weight: bold; font-size: 18px; color: var(--pen); background: #e9e4d8; border: 3px solid var(--pen); border-radius: 14px 14px 4px 4px; padding: 6px 14px; cursor: pointer; }
.tab.on { background: var(--yellow); transform: translateY(-3px); }
#options { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; overflow-y: auto; padding: 4px; }
.card.opt { display: flex; flex-direction: column; align-items: center; padding: 6px; font-size: 14px; font-weight: bold; box-shadow: 2px 3px 0 var(--pen); }
.card.opt canvas { width: 96px; height: 96px; }
.card.opt.on { background: #fff3c4; outline: 4px dashed var(--red); outline-offset: 2px; }
.card.opt:hover { transform: rotate(-2deg); }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-left { position: absolute; left: 16px; top: 16px; padding: 8px 18px; font-weight: bold; font-size: clamp(14px, 1.6vw, 20px); }
.hud-score { display: flex; align-items: center; gap: 8px; font-size: clamp(22px, 2.6vw, 34px); }
.hud-score img { width: 1.3em; }
.hud-center { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; }
#hud-queue { display: flex; gap: 2px; }
#hud-queue canvas { width: 52px; height: 52px; transition: opacity .3s, transform .3s; }
#hud-queue canvas.used { opacity: .25; transform: scale(.8); filter: grayscale(1); }
.wolves { display: flex; align-items: center; gap: 6px; padding: 4px 14px; font-weight: bold; font-size: 24px; }
.wolves img { width: 40px; }
.hud-right { position: absolute; right: 16px; top: 16px; display: flex; gap: 10px; }
#hint { position: absolute; left: 50%; top: 110px; transform: translateX(-50%) rotate(-1deg); padding: 10px 22px; font-size: clamp(14px, 1.7vw, 22px); font-weight: bold; max-width: min(860px, 80vw); text-align: center; animation: pop .4s ease-out; pointer-events: none; }

/* Modale */
#modal { position: absolute; inset: 0; background: rgba(58, 48, 66, .45); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
#modal-box { padding: 24px 36px; text-align: center; min-width: min(520px, 92vw); animation: pop .35s ease-out; }
#modal-box h2 { font-size: clamp(30px, 4.5vw, 54px); margin: 0 0 8px; color: var(--red); -webkit-text-stroke: 1.5px var(--pen); }
#modal-box p { font-size: 20px; margin: 8px 0 18px; }
#modal-box .score { font-size: 34px; font-weight: bold; }
.bigstars { display: flex; justify-content: center; gap: 6px; }
.bigstars .star { width: 110px; opacity: 0; animation: starIn .45s ease-out forwards; }
.bigstars .s1 { width: 130px; margin-top: -18px; animation-delay: .7s; }
.bigstars .s0 { animation-delay: .35s; }
.bigstars .s2 { animation-delay: 1.05s; }
.sadwolf { width: 140px; animation: bob 1s ease-in-out infinite; }

@keyframes bob { 50% { transform: translateY(-8px) rotate(1deg); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#hint { animation-name: hintpop; }
@keyframes hintpop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

@media (max-width: 760px), (max-height: 560px) {
  .wardrobe-wrap { flex-direction: column; max-height: 78vh; overflow-y: auto; }
  .preview-panel { width: 100%; flex-direction: row; flex-wrap: wrap; justify-content: center; }
  #preview { width: 160px; }
  .btn.icon img { width: 32px; height: 32px; }
  #hud-queue canvas { width: 36px; height: 36px; }
  .hud-center { top: 70px; }
}
