/* piramide.css */

/* ============================================================
   CONTAINER
   ============================================================ */
.container-pir {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 8px 24px;
    text-align: center;
}

/* ============================================================
   INSTRUCTION PHRASE
   ============================================================ */
.pir-instruction {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0 18px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #4e342e 0%, #3e2723 100%);
    border: 1px solid #6d4c41;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    color: #d4b896;
    font-size: 1rem;
    line-height: 1.4;
}

.pir-instruction-sub {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 6px;
    font-size: 0.82rem;
    color: rgba(212, 184, 150, 0.9);
    text-align: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px dashed rgba(212, 184, 150, 0.2);
    letter-spacing: 0.4px;
    font-style: italic;
}

.pir-sub-part {
    white-space: nowrap;
}

.pir-attr-name {
    font-family: 'Pirata One', cursive;
    font-size: 1.3rem;
    letter-spacing: 1px;
    color: #ffd700;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.55);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 215, 0, 0.25);
    line-height: 1.5;
}

/* ============================================================
   PYRAMID LAYOUT
   Card width formula: (row_width - (N-1) * gap) / N
   Bottom row has 4 cards with gap:6px → each card = calc(25% - 4.5px)
   ============================================================ */
.pir-pyramid-wrap {
    --card-h: clamp(75px, calc((100dvh - 265px) / 4 - 6px), 140px);
}

.pir-pyramid {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 0 0 16px;
}

.pir-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

.pir-legend {
    display: inline-block;
    font-size: 0.85rem;
    color: #6a4029;
    margin: -6px auto 16px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    text-align: center;
    letter-spacing: 0.02em;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(106, 64, 41, 0.1);
}

.pir-loading {
    padding: 40px;
    color: #8d6e63;
}

/* ============================================================
   CARD — base
   ============================================================ */
.pir-card {
    flex: 0 0 calc(25% - 4.5px);
    max-width: 148px;
    position: relative;
    background: linear-gradient(160deg, #2a1a12 0%, #1a0e08 100%);
    border: 2px solid #5d4037;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.14s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
}

.pir-card:hover:not(.correct):not(.wrong) {
    border-color: #9c7060;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.65);
    transform: translateY(-2px);
}

.pir-card-img {
    width: 100%;
    height: var(--card-h);
    object-fit: cover;
    object-position: top center;
    display: block;
    background: #1a0e08;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.pir-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top,
            rgba(0, 0, 0, 0.96) 0%,
            rgba(0, 0, 0, 0.72) 50%,
            rgba(0, 0, 0, 0.2) 80%,
            transparent 100%);
    padding: 20px 4px 5px;
    box-sizing: border-box;
    pointer-events: none;
}

.pir-card-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    color: #f5e6c8;
    font-size: clamp(0.52rem, 2.2vw, 0.72rem);
    font-weight: 700;
    text-align: center;
    line-height: 1.25;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

.pir-card-value {
    display: none;
    color: #ffd700;
    font-size: clamp(0.5rem, 2vw, 0.68rem);
    font-weight: bold;
    text-align: center;
    margin-top: 3px;
    letter-spacing: 0.3px;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.5);
}

/* Position badge (top-left) */
.pir-card-pos {
    position: absolute;
    top: 4px;
    left: 5px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.88), rgba(20, 10, 0, 0.82));
    color: #ffd700;
    font-family: 'Bangers', cursive;
    font-size: clamp(0.68rem, 2.4vw, 0.95rem);
    line-height: 1;
    padding: 2px 5px;
    border-radius: 5px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    z-index: 2;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

/* ============================================================
   CARD — FACE DOWN (not yet revealed)
   ============================================================ */
.pir-card.pir-face-down {
    background: linear-gradient(160deg, #1c1008 0%, #110a04 100%);
    border-color: #6d4c41;
}

.pir-card.pir-face-down:hover {
    border-color: #9c7060;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.65);
    transform: translateY(-2px);
}

.pir-card-back {
    width: 100%;
    height: var(--card-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.pir-card-back-icon {
    font-family: 'Pirata One', cursive;
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    color: #4a3728;
    text-shadow: 0 0 14px rgba(93, 64, 55, 0.8);
    line-height: 1;
    user-select: none;
}

.pir-card-back-hint {
    font-size: clamp(0.55rem, 1.4vw, 0.7rem);
    color: rgba(74, 55, 40, 1);
    font-family: 'Roboto', sans-serif;
    letter-spacing: 0.02em;
    user-select: none;
    text-align: center;
    line-height: 1;
}

@keyframes pirFlip {
    0% {
        transform: scale(0.72);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pir-card.pir-revealing {
    animation: pirFlip 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes pirDemoA {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    15% {
        transform: translate(0, -13px) scale(1.1);
        opacity: 1;
    }

    65% {
        transform: translate(var(--pir-dx), calc(var(--pir-dy) - 13px)) scale(1.1);
        opacity: 1;
    }

    80% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 1;
    }

    92% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 0;
    }
}

@keyframes pirDemoB {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    15% {
        transform: translate(0, 6px) scale(0.93);
        opacity: 0.65;
    }

    65% {
        transform: translate(var(--pir-dx), calc(var(--pir-dy) + 6px)) scale(0.93);
        opacity: 0.65;
    }

    80% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 1;
    }

    92% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--pir-dx), var(--pir-dy)) scale(1);
        opacity: 0;
    }
}

@keyframes pirDemoBadge {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.7);
    }

    14% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    86% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.7);
    }
}

.pir-demo-badge {
    position: fixed;
    padding: 6px 16px;
    background: rgba(8, 4, 1, 0.93);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.55);
    border-radius: 20px;
    font-size: 0.78rem;
    font-family: 'Roboto', sans-serif;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1001;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.65);
    transform: translate(-50%, -50%);
    animation: pirDemoBadge 2.2s ease-in-out forwards;
}

@keyframes pirIdlePulse {

    0%,
    100% {
        border-color: #6d4c41;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
        transform: translateY(0);
    }

    50% {
        border-color: #ffd700;
        box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.2), 0 0 18px rgba(255, 215, 0, 0.5);
        transform: translateY(-3px);
    }
}

.pir-card.pir-idle-hint {
    animation: pirIdlePulse 1.1s ease-in-out 2;
}

/* ============================================================
   CARD — DRAG STATES
   ============================================================ */
.pir-card[draggable="true"] {
    cursor: grab;
}

.pir-card.dragging {
    opacity: 0.38;
    transform: scale(0.95);
    border-style: dashed;
}

.pir-card.drag-over {
    border-color: #ffd700;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.3), 0 0 20px rgba(255, 215, 0, 0.6);
    transform: scale(1.06) translateY(-2px);
}

/* ============================================================
   CARD — SELECTED STATE (gold glow)
   ============================================================ */
.pir-card.selected {
    border-color: #ffd700;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.25), 0 0 22px rgba(255, 215, 0, 0.65);
    transform: scale(1.07) translateY(-2px);
    z-index: 5;
}

/* ============================================================
   CARD — CORRECT (green)
   ============================================================ */
@keyframes pirFill {
    0% {
        transform: scale(0.82);
        opacity: 0.5;
    }

    60% {
        transform: scale(1.07);
    }

    80% {
        transform: scale(0.97);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pir-card.correct {
    background: linear-gradient(160deg, #0a2410 0%, #071a0c 100%);
    border: 2px solid #4CAF50;
    cursor: default;
    box-shadow:
        0 0 0 1px rgba(76, 175, 80, 0.2),
        0 0 22px rgba(76, 175, 80, 0.4),
        0 4px 14px rgba(0, 0, 0, 0.55);
    animation: pirFill 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.pir-card.correct .pir-card-name {
    color: #e8ffe8;
}

.pir-card.correct .pir-card-value {
    display: block;
    color: #a5d6a7;
}

/* ============================================================
   CARD — WRONG (red)
   ============================================================ */
@keyframes pirReveal {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }

    70% {
        transform: scale(1.04);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pir-card.wrong {
    background: linear-gradient(160deg, #2a0e0e 0%, #1c0808 100%);
    border: 2px solid #e57373;
    cursor: default;
    box-shadow:
        0 0 0 1px rgba(229, 115, 115, 0.2),
        0 0 18px rgba(229, 115, 115, 0.38),
        0 4px 14px rgba(0, 0, 0, 0.55);
    animation: pirReveal 0.4s ease-out forwards;
}

.pir-card.wrong .pir-card-img {
    opacity: 0.72;
}

.pir-card.wrong .pir-card-overlay {
    background: linear-gradient(to top,
            rgba(100, 20, 20, 0.96) 0%,
            rgba(80, 20, 20, 0.55) 55%,
            transparent 100%);
}

.pir-card.wrong .pir-card-name {
    color: #ffcdd2;
}

.pir-card.wrong .pir-card-value {
    display: block;
    color: #ef9a9a;
}

/* ============================================================
   FOOTER: HINT + SUBMIT
   ============================================================ */
.pir-footer {
    margin: 10px 0 6px;
}

.pir-hint {
    color: #b0845a;
    font-size: 0.82rem;
    margin: 0 0 10px;
}

.pir-submit-btn {
    font-family: 'Pirata One', cursive;
    font-size: 1.2rem;
    letter-spacing: 1.5px;
    padding: 10px 48px;
    background: linear-gradient(135deg, #4e342e 0%, #3e2723 100%);
    color: #ffd700;
    border: 1px solid #6d4c41;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    display: inline-block;
}

.pir-submit-btn:hover {
    background: linear-gradient(135deg, #6d4c41 0%, #4e342e 100%);
    border-color: #8d6e63;
}

.pir-submit-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.pir-submit-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

/* ============================================================
   RANKING DISTRIBUTION CHART
   ============================================================ */
.pir-ranking-container {
    width: 100%;
}

.pir-ranking {
    width: 100%;
    padding: 14px 18px 16px;
    box-sizing: border-box;
    background: linear-gradient(135deg, #1c1408, #251a0a);
    border: 2px solid rgba(255, 179, 0, 0.45);
    border-radius: 10px;
}

.pir-ranking-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
}

.pir-ranking-header::before,
.pir-ranking-header::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 179, 0, 0.4);
}

.pir-ranking-title {
    font-family: 'Pirata One', cursive;
    font-size: 0.82rem;
    color: #ffd54f;
    letter-spacing: 2px;
    text-transform: uppercase;
    white-space: nowrap;
}

.pir-ranking-rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.pir-ranking-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pir-ranking-label {
    font-family: 'Pirata One', cursive;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.5);
    width: 34px;
    flex-shrink: 0;
    text-align: right;
    line-height: 1;
}

.pir-ranking-bar-wrap {
    flex: 1;
    height: 24px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 4px;
    overflow: hidden;
}

.pir-ranking-bar {
    height: 100%;
    background: rgba(255, 255, 255, 0.32);
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.65s cubic-bezier(0.4, 0, 0.2, 1);
}

.pir-ranking-pct {
    font-size: 0.8rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.6);
    font-family: 'Roboto', sans-serif;
    width: 36px;
    flex-shrink: 0;
    text-align: right;
}

.pir-ranking-pct.is-zero {
    color: rgba(255, 255, 255, 0.2);
}

.pir-ranking-row.pir-ranking-user .pir-ranking-label {
    color: #ffd54f;
}

.pir-ranking-row.pir-ranking-user .pir-ranking-bar {
    background: #ffd54f;
    box-shadow: 0 0 10px rgba(255, 213, 79, 0.5);
}

.pir-ranking-row.pir-ranking-user .pir-ranking-pct {
    color: #fff;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 480px) {
    .pir-pyramid-wrap {
        --card-h: clamp(66px, calc((100dvh - 240px) / 4 - 5px), 120px);
    }

    .pir-pyramid {
        gap: 5px;
    }

    .pir-row {
        gap: 5px;
    }

    /* gap=5px → flex-basis adjustment: 5*3/4 = 3.75px */
    .pir-card {
        flex: 0 0 calc(25% - 3.75px);
        border-radius: 8px;
    }

    .pir-card-overlay {
        padding: 18px 3px 4px;
    }

    .pir-card.correct,
    .pir-card.wrong {
        border-width: 2px;
    }

    .pir-submit-btn {
        padding: 10px 32px;
        font-size: 1rem;
    }
}

@media (max-width: 360px) {
    .pir-pyramid {
        gap: 4px;
    }

    .pir-row {
        gap: 4px;
    }

    /* gap=4px → flex-basis adjustment: 4*3/4 = 3px */
    .pir-card {
        flex: 0 0 calc(25% - 3px);
    }

    .pir-card-name {
        -webkit-line-clamp: 1;
        line-clamp: 1;
    }

    .pir-card-overlay {
        padding: 14px 3px 3px;
    }
}

/* ============================================================
   SCALE BAR (Mayor ↑ / ↓ Menor)
   ============================================================ */
.pir-pyramid-wrap {
    display: flex;
    align-items: stretch;
    gap: 6px;
    width: 100%;
    position: relative;
}

@media (min-width: 481px) {
    .pir-pyramid-wrap {
        padding: 0 34px;
    }
}

.pir-pyramid {
    position: relative;
    z-index: 1;
}

.pir-scale-bar {
    display: none;
}

.pir-scale-label {
    writing-mode: vertical-rl;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    line-height: 1;
    white-space: nowrap;
}

.pir-scale-high {
    transform: rotate(180deg);
    color: #ff8c00;
    text-shadow: 0 0 8px rgba(255, 140, 0, 0.45);
    padding-bottom: 10px;
    margin-bottom: 5px;
}

.pir-scale-low {
    color: #4a3728;
    padding-top: 4px;
}

.pir-scale-gradient {
    flex: 1;
    width: 3px;
    border-radius: 2px;
    background: linear-gradient(to bottom, #ff8c00 0%, #8d6e63 55%, #3e2723 100%);
    box-shadow: 0 0 8px rgba(255, 140, 0, 0.25);
    min-height: 24px;
}

@media (max-width: 480px) {
    .pir-scale-bar {
        display: none;
    }
}

/* ============================================================
   BACKGROUND ARROW (both sides, desktop full height / mobile 3 rows)
   ============================================================ */
.pir-mobile-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    top: 0;
    bottom: 0;
    width: 28px;
    z-index: 0;
    opacity: 0.5;
    pointer-events: none;
}

.pir-mobile-arrow--left  { left: 4px; }
.pir-mobile-arrow--right { right: 4px; }

.pir-mobile-arrow-label {
    font-size: 0.52rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #000;
    white-space: nowrap;
    writing-mode: vertical-rl;
    line-height: 1;
    flex-shrink: 0;
    margin: 7px 0;
}

.pir-mobile-arrow-high {
    transform: rotate(180deg);
}

.pir-mobile-arrow-shaft {
    flex: 1;
    width: 8px;
    background: #000;
    border-radius: 2px;
    position: relative;
    margin: 7px 0;
}

.pir-mobile-arrow-shaft::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 12px solid #000;
}

.pir-mobile-arrow-shaft::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 12px solid #000;
}

@media (max-width: 480px) {
    .pir-mobile-arrow {
        bottom: auto;
        height: calc(3 * var(--card-h) + 10px);
    }
}