/* ==========================================================================
   Une petite mission pour toi — styles du jeu (mobile first, 320px+)
   ========================================================================== */

:root {
    --color-bg-deep: #1c1330;
    --color-bg-mid: #2c1f4a;
    --color-accent: #ff6f91;
    --color-accent-soft: #ffb3c6;
    --color-gold: #ffd479;
    --color-cream: #fff8f0;
    --color-text: #fdf6ff;
    --color-text-muted: #cbb9e6;
    --color-card: rgba(255, 255, 255, 0.06);
    --color-card-border: rgba(255, 255, 255, 0.14);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(circle at top, var(--color-bg-mid), var(--color-bg-deep) 70%);
    color: var(--color-text);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

button {
    font-family: inherit;
}

.app {
    min-height: 100dvh;
    position: relative;
}

.screen {
    min-height: 100dvh;
    padding: calc(20px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.5s ease both;
}

/* Author CSS setting display:flex on .screen would otherwise override the
   browser's built-in `[hidden] { display: none }` rule (author styles beat
   user-agent styles even at equal specificity), so screens toggled via the
   `hidden` attribute wouldn't actually disappear without this. */
.screen[hidden] {
    display: none;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Intro ---------------- */

.intro-card {
    max-width: 440px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.72rem;
    color: var(--color-accent-soft);
    margin: 0;
}

.intro-title {
    font-size: clamp(1.6rem, 6vw, 2.4rem);
    margin: 0;
    line-height: 1.15;
}

.intro-text {
    color: var(--color-text-muted);
    margin: 0;
    font-size: 1rem;
    line-height: 1.5;
}

.intro-duration {
    font-size: 0.9rem;
    color: var(--color-gold);
    margin: 0 0 6px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 16px 30px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.96);
}

.btn--primary {
    background: linear-gradient(135deg, var(--color-accent), #ff9770);
    color: #2b1330;
    box-shadow: 0 12px 24px rgba(255, 111, 145, 0.35);
}

.btn--play {
    width: min(260px, 80vw);
    font-size: 1.2rem;
    padding: 18px 30px;
}

.btn--ghost {
    background: transparent;
    border: 1px solid var(--color-card-border);
    color: var(--color-text);
}

.btn--link {
    background: none;
    border: none;
    color: var(--color-text-muted);
    text-decoration: underline;
    font-size: 0.9rem;
    padding: 8px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-music {
    background: var(--color-card);
    border: 1px solid var(--color-card-border);
    border-radius: 999px;
    color: var(--color-text-muted);
    padding: 8px 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-music img {
    width: 18px;
    height: 18px;
    filter: invert(1);
    opacity: 0.85;
}

.privacy-note {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    opacity: 0.7;
    margin-top: 10px;
    max-width: 320px;
}

/* ---------------- HUD ---------------- */

#screen-game {
    justify-content: flex-start;
    padding-top: calc(14px + var(--safe-top));
}

.hud {
    width: 100%;
    max-width: 520px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 auto 20px;
}

.hud-progress {
    flex: 1;
}

.hud-progress-bar {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}

.hud-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-accent), var(--color-gold));
    transition: width 0.4s ease;
}

.hud-progress-label {
    display: block;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.hud-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-timer {
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
    color: var(--color-gold);
    min-width: 48px;
    text-align: right;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--color-card-border);
    background: var(--color-card);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn img {
    width: 18px;
    height: 18px;
    filter: invert(1);
}

/* ---------------- Puzzle area ---------------- */

.puzzle-wrap {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.puzzle-title {
    font-size: 1.3rem;
    margin: 0 0 6px;
}

.puzzle-prompt {
    color: var(--color-text-muted);
    margin: 0 0 18px;
    line-height: 1.5;
}

.puzzle-root {
    background: var(--color-card);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-lg);
    padding: 18px;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feedback {
    min-height: 1.4em;
    font-size: 0.9rem;
    margin: 10px 2px 0;
}

.feedback.is-correct { color: #8ff2b0; }
.feedback.is-wrong { color: #ff9d9d; }

.hint-box {
    margin-top: 10px;
    padding: 12px 14px;
    background: rgba(255, 212, 121, 0.12);
    border: 1px solid rgba(255, 212, 121, 0.35);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: var(--color-gold);
}

.game-footer {
    width: 100%;
    max-width: 520px;
    margin: 18px auto 0;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.game-footer .btn {
    flex: 1;
}

/* ---------------- MCQ ---------------- */

.mcq-options {
    display: grid;
    gap: 10px;
}

.option-btn {
    text-align: left;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--color-text);
    font-size: 1rem;
    cursor: pointer;
}

.option-btn.is-selected {
    border-color: var(--color-accent);
    background: rgba(255, 111, 145, 0.18);
}

/* ---------------- Word scramble ---------------- */

.scramble-letters,
.scramble-answer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.scramble-answer {
    min-height: 48px;
    padding: 8px;
    border: 1px dashed var(--color-card-border);
    border-radius: var(--radius-sm);
}

.letter-tile {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--color-card-border);
    border-radius: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    user-select: none;
}

.letter-tile.is-used {
    opacity: 0.25;
    pointer-events: none;
}

/* ---------------- Code pad ---------------- */

.code-display {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 14px;
}

.code-digit {
    width: 44px;
    height: 54px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--color-card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
}

.code-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 260px;
    margin: 0 auto;
}

.code-key {
    padding: 14px 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--color-text);
    font-size: 1.1rem;
    cursor: pointer;
}

/* ---------------- Jigsaw ---------------- */

.jigsaw-grid {
    display: grid;
    gap: 2px;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.jigsaw-piece {
    aspect-ratio: 1;
    background-color: rgba(255, 255, 255, 0.08);
    background-repeat: no-repeat;
    cursor: pointer;
}

.jigsaw-piece.is-selected {
    outline: 3px solid var(--color-gold);
    outline-offset: -3px;
}

/* ---------------- Photo stack (swipe to search) ---------------- */

.photo-stack-wrap {
    position: relative;
    width: 100%;
    height: 260px;
    margin: 0 auto;
    max-width: 280px;
}

.photo-stack-card {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--color-card-border);
    box-shadow: var(--shadow-soft);
    touch-action: none;
    user-select: none;
}

.photo-stack-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.photo-stack-card.is-top {
    z-index: 3;
    cursor: grab;
}

.photo-stack-card.is-back-1 {
    z-index: 2;
    transform: scale(0.94) translateY(10px) rotate(-3deg);
    opacity: 0.85;
    pointer-events: none;
}

.photo-stack-card.is-back-2 {
    z-index: 1;
    transform: scale(0.88) translateY(18px) rotate(3deg);
    opacity: 0.55;
    pointer-events: none;
}

.stack-decoy-face {
    width: 100%;
    height: 100%;
    position: relative;
}

.stack-decoy-ear {
    position: absolute;
    top: 8%;
    width: 22%;
    height: 22%;
    border-radius: 50%;
}

.stack-decoy-ear--left {
    left: 14%;
}

.stack-decoy-ear--right {
    right: 14%;
}

.stack-decoy-eye {
    position: absolute;
    top: 46%;
    width: 8%;
    height: 8%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
}

.stack-decoy-eye--left {
    left: 36%;
}

.stack-decoy-eye--right {
    right: 36%;
}

.stack-decoy-nose {
    position: absolute;
    top: 58%;
    left: 50%;
    width: 10%;
    height: 7%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    transform: translateX(-50%);
}

.stack-caption {
    text-align: center;
    font-size: 0.76rem;
    color: var(--color-text-muted);
    margin-top: 12px;
}

/* ---------------- Memory ---------------- */

.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.memory-card {
    aspect-ratio: 1;
    border-radius: 12px;
    background-color: rgba(255, 255, 255, 0.08);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--color-card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.memory-card.is-hidden {
    font-size: 1.4rem;
}

.memory-card.is-hidden::after {
    content: '?';
    color: var(--color-text-muted);
}

.memory-card.is-matched {
    opacity: 0.35;
    pointer-events: none;
}

/* ---------------- Catch game ---------------- */

.catch-area {
    position: relative;
    height: 220px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.catch-target {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--color-accent), #ff9770);
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: pop-in 0.2s ease;
    box-shadow: 0 8px 18px rgba(255, 111, 145, 0.4);
}

.catch-counter {
    text-align: center;
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--color-gold);
    font-weight: 700;
}

/* ---------------- Crossword ---------------- */

.crossword-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.crossword-grid {
    display: grid;
    gap: 2px;
    background: rgba(255, 255, 255, 0.06);
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
}

.crossword-cell {
    position: relative;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.crossword-cell.is-blocked {
    background: transparent;
}

.crossword-number {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: 0.55rem;
    color: var(--color-text-muted);
}

.crossword-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--color-text);
    text-align: center;
    text-transform: uppercase;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 0;
}

.crossword-input:focus {
    outline: 1px solid var(--color-accent);
}

.crossword-clues {
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.crossword-clues h4 {
    color: var(--color-text);
    margin: 12px 0 6px;
    font-size: 0.85rem;
}

.crossword-clues h4:first-child {
    margin-top: 0;
}

.crossword-clues ul {
    margin: 0;
    padding-left: 18px;
}

.crossword-clues li {
    margin-bottom: 4px;
}

/* ---------------- Lyrics ---------------- */

.lyrics-line {
    font-size: 1.05rem;
    line-height: 1.8;
    text-align: center;
    white-space: pre-line;
}

.lyrics-blank-input {
    display: inline-block;
    width: 140px;
    padding: 4px 8px;
    margin: 0 4px;
    border: none;
    border-bottom: 2px solid var(--color-accent);
    background: transparent;
    color: var(--color-gold);
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
}

/* ---------------- Hidden image ---------------- */

.hidden-image-wrap {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.hidden-image-wrap img {
    width: 100%;
    display: block;
}

.magnifier {
    position: absolute;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    border: 3px solid var(--color-gold);
    pointer-events: none;
    display: none;
    background-repeat: no-repeat;
}

.hidden-answer-input {
    margin-top: 12px;
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-card-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-text);
    font-size: 1rem;
}

/* ---------------- Final screen ---------------- */

#screen-final {
    position: relative;
}

#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.final-card {
    position: relative;
    z-index: 1;
    max-width: 480px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.final-title {
    font-size: clamp(1.6rem, 6vw, 2.2rem);
    margin: 0;
}

.final-message {
    color: var(--color-text-muted);
    font-size: 1.05rem;
    line-height: 1.7;
    white-space: pre-line;
    min-height: 2em;
}

.final-response-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.final-response-form[hidden] {
    display: none;
}

.final-response-form textarea {
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-card-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-text);
    padding: 14px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
}

.final-confirmation {
    color: var(--color-gold);
    font-size: 1rem;
}

/* ---------------- Wrong-answer reaction ---------------- */

.wrong-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--color-accent);
    box-shadow: var(--shadow-soft);
    transform: translate(-50%, -50%) scale(0.6);
    opacity: 0;
    pointer-events: none;
    z-index: 20;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.wrong-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    animation: shake 0.4s ease;
}

/* ---------------- Utility ---------------- */

.shake {
    animation: shake 0.4s ease;
}

@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-8px); }
    40%, 60% { transform: translateX(8px); }
}

.pop-in {
    animation: pop-in 0.35s ease;
}

@keyframes pop-in {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@media (min-width: 600px) {
    .screen {
        padding-top: calc(40px + var(--safe-top));
    }
}
