/* ============================================================
   PAPELITOS DE AMOR Y AMISTAD - Mobile first + animaciones
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --pink: #e84393;
    --pink-light: #fd79a8;
    --pink-soft: #ffe0ec;
    --red: #d63031;
    --dark: #2d3436;
    --gray: #636e72;
    --bg-top: #ffd6e0;
    --bg-bottom: #fff0f5;
    --white: #ffffff;
    --paper-bg: #fff8e1;
    --paper-edge: #ffe082;
    --shadow: 0 8px 30px rgba(232, 67, 147, 0.22);
    --ease-out: cubic-bezier(0.22, 1.2, 0.36, 1);
    --radius: 18px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bottom) 60%, #ffe9ef 100%);
    background-attachment: fixed;
    color: var(--dark);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100dvh;
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom);
}

/* ========================== CORAZONES FLOTANTES ========================== */

.hearts-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.hearts-bg .heart {
    position: absolute;
    bottom: -60px;
    display: block;
    font-size: 22px;
    color: rgba(232, 67, 147, 0.35);
    animation: float-up linear infinite;
    will-change: transform;
}

.hearts-bg .heart::before {
    content: '\2665';
}

.hearts-bg .heart:nth-child(1) {
    left: 6%;
    animation-duration: 14s;
    animation-delay: 0s;
    font-size: 18px;
}

.hearts-bg .heart:nth-child(2) {
    left: 14%;
    animation-duration: 17s;
    animation-delay: 3s;
    font-size: 26px;
}

.hearts-bg .heart:nth-child(3) {
    left: 24%;
    animation-duration: 13s;
    animation-delay: 6s;
    font-size: 16px;
}

.hearts-bg .heart:nth-child(4) {
    left: 36%;
    animation-duration: 19s;
    animation-delay: 1s;
    font-size: 30px;
}

.hearts-bg .heart:nth-child(5) {
    left: 48%;
    animation-duration: 15s;
    animation-delay: 5s;
    font-size: 20px;
}

.hearts-bg .heart:nth-child(6) {
    left: 58%;
    animation-duration: 18s;
    animation-delay: 9s;
    font-size: 24px;
}

.hearts-bg .heart:nth-child(7) {
    left: 68%;
    animation-duration: 14s;
    animation-delay: 2s;
    font-size: 17px;
}

.hearts-bg .heart:nth-child(8) {
    left: 78%;
    animation-duration: 20s;
    animation-delay: 7s;
    font-size: 28px;
}

.hearts-bg .heart:nth-child(9) {
    left: 88%;
    animation-duration: 16s;
    animation-delay: 4s;
    font-size: 19px;
}

.hearts-bg .heart:nth-child(10) {
    left: 95%;
    animation-duration: 21s;
    animation-delay: 8s;
    font-size: 32px;
}

@keyframes float-up {
    0% {
        transform: translateY(0) rotate(-12deg) scale(0.8);
        opacity: 0;
    }
    12% {
        opacity: 1;
    }
    60% {
        transform: translateY(-55vh) rotate(14deg) scale(1.05);
        opacity: 0.9;
    }
    100% {
        transform: translateY(-110vh) rotate(-8deg) scale(1.2);
        opacity: 0;
    }
}

/* ========================== CANVAS CONFETI ========================== */

#confetti-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

/* ========================== LAYOUT ========================== */

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    padding: clamp(0.75rem, 3vw, 1.5rem);
    padding-top: calc(1.25rem + env(safe-area-inset-top));
}

main {
    display: block;
}

header {
    text-align: center;
    margin-bottom: clamp(1rem, 4vw, 2rem);
}

.title-pop {
    display: inline-block;
    font-size: clamp(1.6rem, 6.5vw, 2.4rem);
    font-weight: 800;
    color: var(--red);
    line-height: 1.15;
    animation: title-bounce 2.4s var(--ease-out) infinite;
    transform-origin: center;
    letter-spacing: 0.5px;
}

.title-flower {
    display: inline-block;
    background: linear-gradient(135deg, var(--pink), var(--pink-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: pulse-soft 1.6s ease-in-out infinite;
}

@keyframes title-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

@keyframes pulse-soft {
    0%, 100% {
        filter: none;
    }
    50% {
        filter: drop-shadow(0 0 14px rgba(232, 67, 147, 0.55));
    }
}

.subtitle {
    color: var(--gray);
    font-size: clamp(0.85rem, 3vw, 1rem);
    margin-top: 0.4rem;
}

/* ========================== TARJETAS ========================== */

.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: clamp(1.1rem, 4vw, 2rem);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    border: 1px solid rgba(232, 67, 147, 0.1);
}

.card-in {
    animation: card-in 0.55s var(--ease-out) both;
}

@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(26px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.card h2 {
    font-size: clamp(1.1rem, 4.5vw, 1.35rem);
    color: var(--pink);
    margin-bottom: 1rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.card h2::before {
    content: '\2665';
    animation: beat 1.2s ease-in-out infinite;
    font-size: 0.9em;
}

.hidden {
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ========================== SUBIDA DE ARCHIVO ========================== */

.upload-area {
    border: 2px dashed var(--pink-light);
    border-radius: 14px;
    padding: clamp(1.2rem, 5vw, 2rem);
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s var(--ease-out), border-color 0.3s, background 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    min-height: 120px;
    justify-content: center;
    outline: none;
}

.upload-area:hover,
.upload-area:focus-visible,
.upload-area.drag-over {
    transform: scale(1.02);
    background: var(--pink-soft);
    border-color: var(--pink);
    box-shadow: 0 0 0 4px rgba(232, 67, 147, 0.15);
}

.upload-icon {
    font-size: 2.4rem;
    animation: float-icon 2.2s ease-in-out infinite;
    line-height: 1;
}

@keyframes float-icon {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

.upload-text {
    font-weight: 700;
    color: var(--pink);
    font-size: 1rem;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--gray);
}

.file-name {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--pink);
    font-weight: 600;
    animation: card-in 0.4s var(--ease-out) both;
}

/* ========================== PROGRESO ========================== */

.progress-wrap {
    margin-top: 1.5rem;
}

.progress-bar {
    background: var(--bg-top);
    border-radius: 24px;
    height: 14px;
    overflow: hidden;
    margin-bottom: 0.6rem;
    box-shadow: inset 0 2px 4px rgba(232, 67, 147, 0.15);
}

.progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 24px;
    background: linear-gradient(90deg, var(--pink), var(--pink-light), var(--red));
    background-size: 200% 100%;
    animation: progress-glow 2s linear infinite, pop-width 0.6s var(--ease-out);
    transition: width 0.6s var(--ease-out);
}

@keyframes progress-glow {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 200% 50%;
    }
}

@keyframes pop-width {
    from {
        width: 0;
    }
}

.progress-text {
    text-align: center;
    color: var(--gray);
    font-size: 0.9rem;
    font-weight: 600;
}

/* ========================== JUGADORES ========================== */

.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.65rem;
}

.player-card {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--white);
    border: 2px solid var(--pink-light);
    border-radius: 14px;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--dark);
    animation: chip-pop 0.5s var(--ease-out) both;
    min-height: 46px;
}

.player-card.is-picked {
    background: linear-gradient(135deg, #e8f8e8, #d5f5d5);
    border-color: #7bd389;
    color: #1e7e34;
}

.player-status {
    font-size: 1.05rem;
    line-height: 1;
    flex-shrink: 0;
    color: var(--gray);
}

.player-card.is-picked .player-status {
    color: #27ae60;
    font-weight: 900;
}

.player-card:not(.is-picked) .player-status {
    color: var(--pink-light);
}

.player-name {
    word-break: break-word;
    line-height: 1.2;
}

/* ========================== CHIPS ========================== */

.player-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.chip {
    background: var(--bg-top);
    border: 1px solid var(--pink-light);
    color: var(--pink);
    border-radius: 24px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 700;
    animation: chip-pop 0.5s var(--ease-out) both;
    box-shadow: 0 2px 8px rgba(232, 67, 147, 0.15);
}

.chip:nth-child(2n) {
    animation-delay: 0.06s;
}

.chip:nth-child(3n) {
    animation-delay: 0.12s;
}

@keyframes chip-pop {
    from {
        opacity: 0;
        transform: scale(0.3) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ========================== BOTONES ========================== */

.btn {
    width: 100%;
    min-height: 52px;
    border: none;
    border-radius: 14px;
    padding: 0.9rem 1.5rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s var(--ease-out), box-shadow 0.3s, background 0.3s, filter 0.3s;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
    filter: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--pink), var(--pink-light));
    color: var(--white);
    box-shadow: 0 6px 18px rgba(232, 67, 147, 0.35);
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 10px 26px rgba(232, 67, 147, 0.45);
}

.btn-primary:not(:disabled):active {
    transform: translateY(0) scale(0.98);
}

/* Efecto de brillo que barre el boton */
.btn-shine::after {
    content: '';
    position: absolute;
    top: 0;
    left: -75%;
    width: 50%;
    height: 100%;
    background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.45), transparent);
    transform: skewX(-20deg);
    animation: shine 3s ease-in-out infinite;
}

@keyframes shine {
    0% {
        left: -75%;
    }
    55% {
        left: 125%;
    }
    100% {
        left: 125%;
    }
}

/* Onda/burbuja al pulsar */
.btn-primary:not(:disabled)::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    transform: translate(-50%, -50%);
    opacity: 0;
}

.btn-primary:not(:disabled):active::before {
    animation: ripple 0.5s ease-out;
}

@keyframes ripple {
    from {
        width: 0;
        height: 0;
        opacity: 0.6;
    }
    to {
        width: 300px;
        height: 300px;
        opacity: 0;
    }
}

.btn-secondary {
    background: var(--white);
    color: var(--pink);
    border: 2px solid var(--pink-light);
    margin-top: 1rem;
}

.btn-secondary:not(:disabled):hover {
    background: var(--pink-soft);
    transform: translateY(-2px);
}

.btn-danger {
    background: #ffe4e4;
    color: var(--red);
    border: 2px solid #f3b1b1;
    margin-top: 0.75rem;
}

.btn-danger:not(:disabled):hover {
    background: #ffd6d6;
    transform: translateY(-2px);
}

.btn-link {
    background: none;
    border: none;
    color: var(--gray);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 1rem;
    padding: 0.6rem 1rem;
    min-height: 44px;
    font-family: inherit;
    transition: color 0.3s, transform 0.2s;
}

.btn-link:hover {
    color: var(--pink);
    transform: translateY(-1px);
}

/* ========================== SELECT ========================== */

.name-selector {
    margin-bottom: 1.25rem;
}

.name-selector select {
    width: 100%;
    min-height: 52px;
    padding: 0.75rem 1rem;
    border: 2px solid var(--pink-light);
    border-radius: 14px;
    font-size: 1rem;
    color: var(--dark);
    background: var(--white);
    cursor: pointer;
    outline: none;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23e84393' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 2.5rem;
}

.name-selector select:focus {
    border-color: var(--pink);
    box-shadow: 0 0 0 4px rgba(232, 67, 147, 0.18);
    transform: scale(1.01);
}

/* ========================== PAPELITO ========================== */

.paper {
    background: linear-gradient(160deg, var(--paper-bg), #fff6e0);
    border-radius: 14px;
    padding: 2.2rem 1.4rem 1.6rem;
    text-align: center;
    box-shadow: inset 0 0 0 1px var(--paper-edge), 0 10px 30px rgba(255, 193, 7, 0.25);
    position: relative;
    margin-bottom: 1.25rem;
    transform-origin: top center;
    animation: paper-unfold 0.8s var(--ease-out) both;
}

@keyframes paper-unfold {
    0% {
        opacity: 0;
        transform: perspective(700px) rotateX(-65deg) scale(0.8) translateY(-30px);
    }
    100% {
        opacity: 1;
        transform: perspective(700px) rotateX(0) scale(1) translateY(0);
    }
}

.paper-tape {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%) rotate(-3deg);
    width: 120px;
    height: 28px;
    background: linear-gradient(135deg, var(--pink), var(--pink-light));
    border-radius: 4px;
    box-shadow: 0 3px 10px rgba(232, 67, 147, 0.4);
}

.paper-tape::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px dashed rgba(255, 255, 255, 0.5);
    border-radius: 2px;
}

.paper:hover {
    animation: paper-sway 0.8s ease-in-out;
}

@keyframes paper-sway {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-1.2deg);
    }
    75% {
        transform: rotate(1.2deg);
    }
}

.paper-content {
    position: relative;
}

.paper-label {
    color: var(--gray);
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
}

.paper-message {
    color: var(--pink);
    font-size: 0.9rem;
    margin-top: 1rem;
    font-style: italic;
}

.paper-hint {
    margin-top: 1.25rem;
    color: var(--gray);
    font-size: 0.78rem;
    border-top: 1px dashed var(--paper-edge);
    padding-top: 0.9rem;
}

.assigned-name {
    font-size: clamp(1.9rem, 8vw, 2.6rem);
    color: var(--red);
    text-transform: capitalize;
    letter-spacing: 2px;
    margin: 0.4rem 0;
    animation: name-pop 0.9s var(--ease-out) both;
    word-break: break-word;
}

@keyframes name-pop {
    0% {
        transform: scale(0.2) rotate(-8deg);
        opacity: 0;
        filter: blur(6px);
    }
    60% {
        transform: scale(1.15) rotate(2deg);
        opacity: 1;
        filter: blur(0);
    }
    100% {
        transform: scale(1) rotate(0);
    }
}

/* ========================== RESULTADOS ========================== */

.results-list {
    max-height: 260px;
    overflow-y: auto;
    margin-bottom: 1.25rem;
    border: 1px solid var(--paper-edge);
    border-radius: 14px;
    -webkit-overflow-scrolling: touch;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid #fce3a7;
    font-size: 0.92rem;
    animation: chip-pop 0.4s var(--ease-out) both;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item .from {
    color: var(--pink);
    font-weight: 700;
}

.result-item .to {
    color: var(--red);
    font-weight: 700;
}

.result-item .arrow {
    color: var(--gray);
    margin: 0 auto;
}

.result-item .seen {
    font-size: 0.72rem;
    color: #27ae60;
    font-weight: 700;
    margin-left: 0.25rem;
}

.result-empty {
    text-align: center;
    color: var(--gray);
    padding: 1.25rem;
    font-size: 0.9rem;
}

/* ========================== FOOTER ========================== */

footer {
    text-align: center;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* ========================== MODAL ========================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 52, 54, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
    animation: fade-in 0.25s ease both;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background: var(--white);
    border-radius: 20px;
    padding: 1.8rem 1.4rem 1.4rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    text-align: center;
    animation: modal-pop 0.4s var(--ease-out) both;
    position: relative;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-hearts {
    font-size: 1.2rem;
    color: var(--pink);
    margin-bottom: 0.35rem;
    animation: pulse-soft 1.6s ease-in-out infinite;
}

.modal-card h2 {
    color: var(--red);
    font-size: 1.2rem;
    margin-bottom: 0.35rem;
}

.modal-sub {
    color: var(--gray);
    font-size: 0.9rem;
    margin-bottom: 1.1rem;
    word-break: break-word;
}

.modal-hint {
    color: var(--gray);
    font-size: 0.78rem;
    margin-top: 0.85rem;
}

.modal-card #code-input {
    width: 100%;
    min-height: 52px;
    padding: 0.75rem 1rem;
    border: 2px solid var(--pink-light);
    border-radius: 14px;
    font-size: 1.15rem;
    text-align: center;
    letter-spacing: 3px;
    color: var(--dark);
    background: var(--white);
    outline: none;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.2s;
}

.modal-card #code-input:focus {
    border-color: var(--pink);
    box-shadow: 0 0 0 4px rgba(232, 67, 147, 0.18);
}

.modal-error {
    color: var(--red);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.7rem;
}

.modal-error.shake {
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-6px);
    }
    40% {
        transform: translateX(6px);
    }
    60% {
        transform: translateX(-4px);
    }
    80% {
        transform: translateX(4px);
    }
}

.modal-card.shake-card {
    animation: shake 0.4s ease;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.3rem;
}

.modal-actions .btn {
    flex: 1;
    min-height: 48px;
    padding: 0.75rem 0.5rem;
    font-size: 0.95rem;
    margin: 0;
}

/* ========================== REDUCED MOTION ========================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hearts-bg {
        display: none;
    }
}

/* ========================== PANTALLAS GRANDES ========================== */

@media (min-width: 640px) {
    .container {
        padding-top: 3rem;
    }

    .btn:hover {
        transform: translateY(-3px);
    }
}