:root {
    --pink:   #FF6B9D;
    --green:  #6BCB77;
    --blue:   #4D96FF;
    --orange: #FF9A3C;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Nunito', 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', cursive;
    background: linear-gradient(135deg, #FFE5F0 0%, #FFF3B0 100%);
    min-height: 100vh;
    padding: 12px;
}

/* ── Caramelo candy pieces ──────────────────────────────────────── */

.cp-pink   { background: #FF6EB4; }
.cp-blue   { background: #5BB8F5; }
.cp-mint   { background: #2FD9A8; }
.cp-orange { background: #FFB347; }
.cp-purple { background: #9B6DFF; }

.caramelo-piece {
    display: inline-block;
    width: 10px; height: 14px;
    border-radius: 50% 50% 45% 45% / 55% 55% 45% 45%;
    vertical-align: middle;
    position: relative;
    flex-shrink: 0;
}
.caramelo-piece::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 3px; height: 3px;
    background: rgba(255,255,255,.3);
    border-radius: 50%;
}

/* ── Sound toggle ───────────────────────────────────────────────── */

.sound-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 4px 6px;
    opacity: .6;
    transition: opacity .15s, transform .1s;
    flex-shrink: 0;
    line-height: 1;
}
.sound-btn:hover { opacity: 1; transform: scale(1.15); }

/* ── Screens ────────────────────────────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }

/* ── Start screen ───────────────────────────────────────────────── */

.start-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.home-link {
    color: var(--blue);
    text-decoration: none;
    font-size: .95em;
    opacity: .75;
}
.home-link:hover { opacity: 1; }

.start-title {
    font-size: clamp(1.5em, 6vw, 2.2em);
    color: var(--pink);
    text-align: center;
    margin-bottom: 16px;
}

.rules-box {
    background: rgba(255,255,255,.7);
    border-radius: 14px;
    padding: 14px 18px;
    margin-bottom: 16px;
    font-size: .95em;
    line-height: 2;
    color: #444;
}

.difficulty-slider-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 12px 0 18px;
}
.diff-emoji { font-size: 1.5em; }
.difficulty-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    cursor: pointer;
}
.difficulty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--pink);
    cursor: pointer;
}

.play-btn {
    display: block;
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 28px;
    font-family: inherit;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    background: var(--pink);
    color: #fff;
    transition: transform .1s, opacity .15s;
    margin-bottom: 16px;
}
.play-btn:active { transform: scale(.97); }
.play-btn--versus {
    background: var(--blue);
    text-decoration: none;
    display: block;
    text-align: center;
    margin-bottom: 16px;
}

.scores-section { margin-top: 8px; }
.scores-section h3 { font-size: 1em; color: #888; margin-bottom: 8px; }

.scores-table { width: 100%; border-collapse: collapse; font-size: .9em; }
.scores-table th, .scores-table td {
    padding: 7px 10px;
    text-align: center;
    border-bottom: 1px solid #f0f0f0;
    color: #555;
}
.scores-table thead th {
    background: var(--blue);
    color: white;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 2;
}
.scores-table thead th:first-child { border-radius: 12px 0 0 0; }
.scores-table thead th:last-child  { border-radius: 0 12px 0 0; }
.scores-table tr:last-child td { border-bottom: none; }

/* ── Game header ────────────────────────────────────────────────── */

#game-screen { padding-top: 72px; }

#game-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    margin-bottom: 10px;
    gap: 8px;
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 736px;
    z-index: 100;
}

.home-link-small {
    color: var(--blue);
    text-decoration: none;
    font-size: .85em;
    opacity: .65;
    white-space: nowrap;
    flex-shrink: 0;
}
.home-link-small:hover { opacity: 1; }

#mem-phase-label {
    font-size: clamp(1.1em, 4.5vw, 1.6em);
    font-weight: bold;
    color: #333;
    transition: color .3s;
    white-space: nowrap;
}
#mem-phase-label.warning { color: var(--orange); }
#mem-phase-label.danger  { color: #e63946; animation: pulse 1s infinite; }

#caramelo-count {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: clamp(.85em, 3vw, 1.1em);
    color: #555;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Live top-3 bar ─────────────────────────────────────────────── */

#live-top3 {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 6px;
    border-top: 1px solid #f0f0f0;
    font-size: .8em;
    color: #555;
}
.top3-entry { white-space: nowrap; }
.top3-me    { font-weight: bold; color: var(--pink); }
.top3-placeholder { color: #aaa; font-style: italic; }

.lead-toast {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #FFE5F0, #FFF3B0);
    border: 2px solid var(--orange);
    border-radius: 24px;
    padding: 10px 24px;
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
    z-index: 200;
    animation: lead-toast-anim 3s ease-out forwards;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    pointer-events: none;
}

@keyframes lead-toast-anim {
    0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    10%  { opacity: 1; transform: translateX(-50%) translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Versus row ─────────────────────────────────────────────────── */

#vs-row {
    width: 100%;
    padding-top: 6px;
    border-top: 1px solid #f0f0f0;
    font-size: .8em;
}

.vs-row-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.vs-score       { white-space: nowrap; }
.vs-score.vs-me { font-weight: bold; color: var(--pink); }
.vs-sep         { color: #ccc; }
.vs-turn-mine   { color: var(--green); font-weight: bold; white-space: nowrap; }
.vs-turn-wait   { color: #aaa; white-space: nowrap; }

/* ── Study bar ──────────────────────────────────────────────────── */

#study-bar-wrap {
    text-align: center;
    margin: 0 0 12px;
    padding: 10px 16px;
    background: rgba(255,255,255,.8);
    border-radius: 14px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

#study-bar-label {
    font-size: 1em;
    font-weight: bold;
    color: var(--blue);
    margin-bottom: 8px;
    letter-spacing: .04em;
}

#study-bar-track {
    width: 100%;
    height: 10px;
    background: #e8e8e8;
    border-radius: 5px;
    overflow: hidden;
}

#study-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--pink));
    border-radius: 5px;
    width: 100%;
}

/* ── Target display ─────────────────────────────────────────────── */

#target-wrap {
    text-align: center;
    margin: 0 auto 12px;
    padding: 10px 16px;
    background: rgba(255,255,255,.85);
    border-radius: 14px;
    max-width: 300px;
}

#target-label {
    font-size: .85em;
    color: #888;
    margin-bottom: 2px;
}

#target-emoji {
    font-size: clamp(2.5em, 12vw, 4em);
    line-height: 1.1;
    animation: target-pop .25s ease-out;
}

@keyframes target-pop {
    0%   { transform: scale(.6); opacity: .4; }
    100% { transform: scale(1);  opacity: 1; }
}

/* ── Memory grid ────────────────────────────────────────────────── */

#mem-grid {
    display: grid;
    gap: 6px;
    max-width: 480px;
    margin: 0 auto;
}

/* ── Memory cards ───────────────────────────────────────────────── */

.mem-card {
    aspect-ratio: 1;
    cursor: pointer;
    border-radius: 12px;
    perspective: 600px;
    -webkit-tap-highlight-color: transparent;
}

.mem-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform .35s ease;
    border-radius: 12px;
}

.mem-card.face-up .mem-card-inner { transform: rotateY(180deg); }

.mem-card-cover,
.mem-card-emoji {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
}

.mem-card-cover {
    background: var(--blue);
    color: rgba(255,255,255,.5);
    font-size: clamp(1em, 4.5vw, 1.8em);
    transform: rotateY(0deg);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
}

.mem-card-emoji {
    background: white;
    border: 2px solid #e8e8e8;
    font-size: clamp(2em, 9vw, 3.4em);
    transform: rotateY(180deg);
    user-select: none;
}

.mem-card.found .mem-card-emoji {
    background: #f0fff4;
    border-color: var(--green);
}

.mem-card.wrong {
    animation: card-wrong .4s ease;
}

@keyframes card-wrong {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-7px); }
    60%       { transform: translateX(7px); }
}

/* ── Result screens ─────────────────────────────────────────────── */

#win-screen, #lose-screen {
    text-align: center;
    padding-top: 24px;
}

.result-emoji {
    font-size: 4em;
    display: block;
    margin: 12px 0;
}

.result-title {
    font-size: 2em;
    margin-bottom: 8px;
}
.result-title.win  { color: var(--green); }
.result-title.lose { color: #e63946; }

.result-message {
    color: #555;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.5;
}

/* ── Candy rain ─────────────────────────────────────────────────── */

.candy-rain { position: fixed; inset: 0; pointer-events: none; z-index: 999; }
.candy-fall {
    position: absolute;
    top: -20px;
    width: 10px; height: 14px;
    border-radius: 50% 50% 45% 45% / 55% 55% 45% 45%;
    animation: candy-drop linear forwards;
}
@keyframes candy-drop {
    to { transform: translateY(110vh) rotate(360deg); }
}

/* ── Row exclamation ────────────────────────────────────────────── */

.row-exclamation {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(1.4em, 6vw, 2em);
    font-weight: bold;
    color: var(--pink);
    pointer-events: none;
    z-index: 300;
    animation: exclaim 1.6s ease-out forwards;
    white-space: nowrap;
}
@keyframes exclaim {
    0%   { opacity: 0; transform: translateX(-50%) scale(.7); }
    15%  { opacity: 1; transform: translateX(-50%) scale(1.1); }
    70%  { opacity: 1; transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) scale(.9) translateY(-20px); }
}

/* ── Pulse ──────────────────────────────────────────────────────── */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .5; }
}

/* ── Capybara animation on lose ─────────────────────────────────── */

.capybara-anim {
    display: inline-block;
    animation: bounce 1s infinite;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-10px); }
}
