/* =========================================================
   L'atelier (atelier.html) : décorer un gâteau en WebGL
   Complète style.css, chargé uniquement sur cette page.
   ========================================================= */
.atelier-hero { position: relative; overflow: hidden; padding-block: 2.5rem 2rem; }
.atelier-hero .container { position: relative; }
.atelier-hero .confetti { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .6; pointer-events: none; }
.atelier-hero .eyebrow { display: flex; }
.atelier-hero h1 { font-size: clamp(2.6rem, 6vw, 4.2rem); line-height: 1; letter-spacing: -.035em; }
.atelier-lead { margin-top: 1.1rem; max-width: 60ch; font-size: 1.1rem; color: var(--muted); }

.atelier { padding-bottom: clamp(3rem, 7vw, 5rem); }
/* Le cadre de jeu : plan de travail + outils + barre, comme un jeu en ligne */
.game {
    position: relative; display: flex; flex-direction: column; overflow: hidden;
    border-radius: 28px; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(36, 35, 58, .12);
    background:
        radial-gradient(90% 70% at 25% 15%, rgba(255, 255, 255, .85), transparent 60%),
        linear-gradient(160deg, #f6efe4, #ede3d3);
}
.game-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: clamp(1rem, 3vw, 2rem); padding: clamp(1rem, 3vw, 2rem); align-items: center; }
@media (max-width: 960px) { .game-body { grid-template-columns: 1fr; } }
.stage-cell { min-width: 0; display: grid; place-items: center; }
.stage { position: relative; width: 100%; max-width: 640px; aspect-ratio: 1; }
.stage canvas {
    position: absolute; inset: 0; width: 100%; height: 100%; display: block;
    touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none;
}

.game-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .65rem .8rem .65rem 1.1rem; background: var(--navy); color: #fff;
}
.game-title { display: flex; align-items: center; gap: .7rem; }
.game-title .brand-mark { width: 32px; height: 32px; font-size: .8rem; background: #fff; color: var(--navy); }
.game-title strong { display: block; font-size: 1rem; line-height: 1.1; }
.game-title small { display: block; font-family: var(--font-hand); font-size: 1.1rem; line-height: 1; color: var(--butter); }
.game-btn {
    display: inline-flex; align-items: center; gap: .5rem; padding: .6rem 1.05rem; border-radius: 999px;
    border: 1.5px solid rgba(255, 255, 255, .45); background: transparent; color: #fff; cursor: pointer;
    font-family: var(--font-label); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; font-size: .85rem;
    transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.game-btn:hover { background: #fff; border-color: #fff; color: var(--navy); }
.game-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.game-btn svg { width: 18px; height: 18px; }
.game-btn .i-exit, .game.is-full .game-btn .i-enter { display: none; }
.game.is-full .game-btn .i-exit { display: block; }

/* Plein écran : API native, ou repli CSS (iPhone) */
.game:fullscreen { width: 100%; height: 100%; border: 0; border-radius: 0; }
.game:-webkit-full-screen { width: 100%; height: 100%; border: 0; border-radius: 0; }
.game.is-fullscreen { position: fixed; inset: 0; z-index: 1000; height: 100vh; height: 100dvh; border: 0; border-radius: 0; }
html.game-open { overflow: hidden; }
.game.is-full .game-body { flex: 1; min-height: 0; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
.game.is-full .stage-cell { container-type: size; min-height: 0; }
.game.is-full .stage { width: min(100cqw, 100cqh); max-width: none; }
.game.is-full .tools { align-self: center; max-height: 100%; overflow: auto; overscroll-behavior: contain; }
@media (max-width: 960px) {
    .game.is-full .game-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: .75rem; padding: .75rem; }
    .game.is-full .tools { max-height: 44vh; max-height: 44dvh; max-width: none; padding: .9rem; gap: .9rem; box-shadow: none; }
    .game.is-full .tool-grid { grid-template-columns: repeat(5, 1fr); }
    .game.is-full .tool { padding: .55rem .2rem .45rem; font-size: .72rem; }
    .game.is-full .tool svg { width: 24px; height: 24px; }
    .game.is-full .tool-help { display: none; }
    .game.is-full .tool-group legend, .game.is-full .tool-group .legend { margin-bottom: .5rem; }
    .game.is-full .swatch { width: 30px; height: 30px; }
    .game.is-full .tool-actions { grid-template-columns: 1fr 1fr; }
    .game.is-full .tool-actions .btn { padding: .8rem .6rem; font-size: .8rem; }
    .game.is-full .tool-actions .btn-link { grid-column: 1 / -1; padding: .2rem; }
}
/* Écran large mais peu haut (téléphone à l'horizontale) : outils sur le côté, plus compacts */
@media (max-height: 560px) and (orientation: landscape) {
    .game.is-full .game-body { grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: minmax(0, 1fr); padding: .6rem; gap: .6rem; }
    .game.is-full .tools { max-height: 100%; padding: .8rem; gap: .8rem; }
    .game.is-full .tool-help { display: none; }
    .game.is-full .game-bar { padding-block: .35rem; }
}
.stage-hint {
    position: absolute; top: 6%; right: 5%; font-size: clamp(1.15rem, 2.4vw, 1.5rem); text-align: right;
    transform: rotate(4deg); pointer-events: none; transition: opacity .5s var(--ease), transform .5s var(--ease);
}
.stage-hint svg { display: block; width: 40px; height: 44px; margin: .1rem 0 0 auto; transform: scaleX(-1); }
.stage-hint.is-hidden { opacity: 0; transform: rotate(4deg) translateY(-8px); }
.stage-fallback { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 1rem; padding: 2rem; text-align: center; color: var(--muted); }
.stage-fallback[hidden] { display: none; }
.stage-fallback strong { color: var(--ink); }

/* Panneau d'outils */
.tools {
    display: grid; gap: 1.5rem; min-width: 0;
    padding: 1.5rem; border-radius: var(--radius); background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow);
}
@media (max-width: 960px) { .tools { max-width: 640px; width: 100%; justify-self: center; } }
.tool-group { border: 0; padding: 0; margin: 0; min-width: 0; transition: opacity .2s var(--ease); }
.tool-group:disabled { opacity: .35; }
.tool-group legend, .tool-group .legend {
    display: block; padding: 0; margin-bottom: .75rem;
    font-family: var(--font-label); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; color: var(--navy);
}
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
@media (max-width: 960px) and (min-width: 520px) { .tool-grid { grid-template-columns: repeat(5, 1fr); } }
.tool {
    position: relative; display: grid; justify-items: center; gap: .3rem; padding: .75rem .25rem .6rem;
    border-radius: 14px; border: 1px solid var(--line); background: var(--cream); cursor: pointer;
    font-size: .8rem; font-weight: 500; color: var(--ink);
    transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease);
}
.tool:hover { border-color: var(--navy); transform: translateY(-1px); }
.tool input, .swatch input { position: absolute; opacity: 0; pointer-events: none; }
.tool svg { width: 30px; height: 30px; color: var(--navy); transition: color .2s var(--ease); }
.tool:has(input:checked) { background: var(--navy); border-color: var(--navy); color: #fff; }
.tool:has(input:checked) svg { color: #fff; }
.tool:has(input:focus-visible), .swatch:has(input:focus-visible) { outline: 2px solid var(--navy); outline-offset: 2px; }
/* Aperçu réel du trait (généré par la simulation au chargement) */
.tool-preview { display: block; width: 100%; height: 32px; background: center / contain no-repeat; transition: transform .25s var(--ease); }
.tools.has-previews .tool svg { display: none; }
.tools.has-previews .tool { gap: .35rem; padding: .55rem .35rem .5rem; }
.tool:hover .tool-preview { transform: scale(1.06); }
.game.is-full .tool-preview { height: 24px; }
.tool-help { margin-top: .7rem; font-size: .88rem; color: var(--muted); min-height: 2.6em; }

.swatches { display: flex; flex-wrap: wrap; gap: .6rem; }
.swatch {
    position: relative; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    background: var(--c); box-shadow: inset 0 0 0 1px rgba(36, 35, 58, .12);
    transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.swatch:hover { transform: scale(1.08); }
.swatch:has(input:checked) { box-shadow: inset 0 0 0 1px rgba(36, 35, 58, .12), 0 0 0 3px var(--paper), 0 0 0 5px var(--navy); }
.tools input[type="range"] { width: 100%; accent-color: var(--navy); }

.tool-actions { display: grid; gap: .6rem; padding-top: .25rem; }
.tool-actions .btn { width: 100%; }
.btn-link {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .4rem;
    background: none; border: 0; cursor: pointer; color: var(--muted);
    font-family: var(--font-label); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; font-size: .85rem;
    text-decoration: underline; text-underline-offset: 4px; transition: color .2s var(--ease);
}
.btn-link:hover { color: var(--navy); }
.btn-link svg { width: 16px; height: 16px; transition: transform .2s var(--ease); }
.btn-link:hover svg { transform: translateX(3px); }

/* Sous le glaçage */
.under { border-top: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 70%, transparent); }
.under-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 1080px) { .under-steps { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .under-steps { grid-template-columns: 1fr; } }
.under-steps li {
    display: flex; flex-direction: column; align-items: flex-start; gap: .6rem;
    padding: 1.5rem; border-radius: var(--radius); background: var(--paper); border: 1px solid var(--line);
}
.under-num {
    display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: 50%;
    background: var(--navy); color: #fff; font-family: var(--font-label); font-weight: 500;
}
.under-steps h3 { font-size: 1.1rem; letter-spacing: -.01em; }
.under-steps p { flex: 1; color: var(--muted); font-size: .95rem; }
.under-steps .btn-link { padding-left: 0; }
.under-code {
    position: relative; overflow: hidden; margin-top: 1.5rem; padding: clamp(1.5rem, 4vw, 2.25rem);
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem 2rem; align-items: center;
    border-radius: calc(var(--radius) + 6px); background: var(--navy); color: rgba(255, 255, 255, .85);
}
.under-code .hand { grid-column: 1 / -1; color: var(--butter); font-size: 1.5rem; }
@media (max-width: 760px) { .under-code { grid-template-columns: 1fr; } .under-code .btn { justify-self: start; } }

/* Fenêtre « Signer et télécharger » */
.sign-dialog {
    width: min(880px, 100% - 32px); max-height: calc(100% - 32px); padding: 0; border: 0; margin: auto;
    border-radius: 24px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px rgba(30, 29, 82, .35);
}
.sign-dialog::backdrop { background: rgba(30, 29, 82, .5); backdrop-filter: blur(4px); }
.sign-dialog[open] { animation: rise .45s var(--ease) both; }
.sign-form { display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .sign-form { grid-template-columns: 1fr; } }
.sign-preview { display: grid; place-items: center; padding: 1.5rem; background: var(--cream); }
.sign-preview img { width: 100%; max-width: 360px; aspect-ratio: 4 / 5; object-fit: contain; border-radius: 12px; box-shadow: var(--shadow); background: #faf6f0; }
@media (max-width: 720px) { .sign-preview img { max-width: 220px; } }
.sign-body { position: relative; display: flex; flex-direction: column; gap: .6rem; padding: clamp(1.5rem, 4vw, 2.5rem); }
.sign-body .hand { font-size: 1.4rem; }
.sign-body h2 { font-size: 1.7rem; letter-spacing: -.02em; margin-bottom: .75rem; }
.sign-body label { font-family: var(--font-label); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; color: var(--navy); }
.sign-body input {
    font: inherit; padding: .85rem 1rem; border-radius: 12px; border: 1px solid var(--line); background: var(--cream); color: var(--ink);
}
.sign-body input:focus { outline: 2px solid var(--navy); outline-offset: 1px; border-color: transparent; }
.sign-actions { display: grid; gap: .6rem; margin-top: auto; padding-top: 1.25rem; }
.sign-actions .btn { width: 100%; }
.sign-close {
    position: absolute; top: .9rem; right: .9rem; width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.sign-close:hover { border-color: var(--navy); color: var(--navy); }

/* Curseur : aperçu rond de la douille au-dessus du gâteau */
.cursor--paint .cursor-ring { opacity: 0 !important; }
.cursor--paint .cursor-dot {
    width: var(--brush, 24px); height: var(--brush, 24px); margin: calc(var(--brush, 24px) / -2) 0 0 calc(var(--brush, 24px) / -2);
    background: transparent; border: 1.5px solid var(--navy); box-shadow: 0 0 0 1px rgba(255, 255, 255, .8);
}
html.custom-cursor .stage canvas { cursor: none; }
@media (prefers-reduced-motion: reduce) { .sign-dialog[open] { animation: none; } }
