.ruta-level-selector-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100svh;
}

.ruta-level-selector-page > header,
.ruta-level-selector-page > footer {
    flex: 0 0 auto;
}

.ruta-level-selector-footer {
    color: #BABABA;
    font-size: 0.9rem;
    min-height: 42px;
}

.ruta-container[data-ruta-levels] {
    background: linear-gradient(145deg, #101426 0%, #18213a 55%, #291342 100%);
    color: #fff;
    flex: 1 0 auto;
    min-height: 0;
    padding: 22px 16px 40px;
}

.ruta-level-page {
    margin: 0 auto;
    max-width: 960px;
}

.ruta-level-back {
    align-items: center;
    color: rgba(255, 255, 255, 0.82);
    display: inline-flex;
    font-size: 0.95rem;
    gap: 9px;
    min-height: 44px;
    padding: 6px 10px;
    text-decoration: none;
}

.ruta-level-back:hover,
.ruta-level-back:focus-visible {
    color: #fff;
}

.ruta-level-header {
    align-items: center;
    display: flex;
    flex-direction: column;
    margin: 10px auto 26px;
    text-align: center;
}

.ruta-level-header__chest.ruta-reveal {
    aspect-ratio: 1;
    cursor: default;
    flex: 0 0 auto;
    margin: 0 auto 10px;
    max-width: 100%;
    outline: none;
    position: relative;
    width: clamp(112px, 24vw, 148px);
}

.ruta-level-header__chest.is-ready {
    cursor: pointer;
}

.ruta-level-header__chest:focus-visible {
    border-radius: 14px;
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.45);
}

.ruta-reveal__image {
    height: 100%;
    left: 50%;
    object-fit: contain;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.28s ease, transform 0.28s ease;
    width: 100%;
}

.ruta-reveal__image--chest {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.82);
}

.ruta-reveal__shine {
    background: radial-gradient(circle, rgba(251, 191, 36, 0.95) 0%, rgba(251, 191, 36, 0.38) 34%, transparent 68%);
    border-radius: 50%;
    height: 70%;
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 48%;
    transform: translate(-50%, -50%) scale(0.35);
    width: 70%;
}

.ruta-reveal.is-chest .ruta-reveal__image--module {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.72) rotate(-5deg);
}

.ruta-reveal.is-chest .ruta-reveal__image--chest {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.ruta-reveal.is-ready.is-chest .ruta-reveal__image--chest {
    animation: chestPulse 1.8s ease-in-out infinite;
}

.ruta-reveal.is-opening .ruta-reveal__image--chest,
.ruta-reveal.is-opening.is-chest .ruta-reveal__image--chest {
    animation: chestOpen 1.1s ease-in-out forwards;
}

.ruta-reveal.is-opening .ruta-reveal__image--module {
    animation: moduleReveal 1.1s ease-in-out forwards;
}

.ruta-reveal.is-opening .ruta-reveal__shine {
    animation: revealShine 1.1s ease-out forwards;
}

@keyframes chestOpen {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    22% { transform: translate(-50%, -53%) scale(1.06) rotate(-3deg); }
    42% { transform: translate(-50%, -49%) scale(1.04) rotate(3deg); }
    62% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -58%) scale(1.28); }
}

@keyframes chestPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    45% { transform: translate(-50%, -50%) scale(1.07); }
}

@keyframes moduleReveal {
    0%, 48% { opacity: 0; transform: translate(-50%, -38%) scale(0.42); }
    72% { opacity: 1; transform: translate(-50%, -56%) scale(1.12); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes revealShine {
    0%, 32% { opacity: 0; transform: translate(-50%, -50%) scale(0.25); }
    58% { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.45); }
}

.ruta-level-header h1 {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    font-weight: 800;
    margin: 0 0 6px;
}

.ruta-level-header p {
    color: rgba(255, 255, 255, 0.74);
    margin: 0;
}

.levels-container {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    margin: 0 auto;
    min-height: 104px;
    padding: 8px 0;
}

.level-route-group + .level-route-group {
    margin-top: 22px;
}

.level-route-title {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin: 0 auto 4px;
    text-align: center;
}

.levels-container.is-focusing {
    align-items: center;
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    justify-items: center;
    overflow: visible;
}

.module-level-grid {
    align-items: stretch;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 220px));
    justify-content: center;
    margin: 0 auto;
}

.level-card,
.module-level-option {
    background: #fff;
    border: 1px solid rgba(255, 255, 255, 0.76);
    border-radius: 16px;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
    color: #172033;
    min-width: 0;
    overflow: hidden;
    position: relative;
}

.level-card {
    display: flex;
    flex: 0 1 360px;
    flex-direction: column;
    width: min(360px, 100%);
}

.level-card::before {
    display: none;
}

.level-card.is-collapsed {
    align-items: center;
    aspect-ratio: 1;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    flex: 0 0 96px;
    height: 96px;
    justify-content: center;
    min-height: 96px;
    padding: 0;
    width: 96px;
}

.level-header {
    align-items: stretch;
    background: linear-gradient(145deg, color-mix(in srgb, var(--level-color, #667eea) 72%, #101827), var(--level-color, #667eea));
    box-shadow: none;
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    gap: 14px;
    inset: auto;
    justify-content: space-between;
    min-height: 142px;
    padding: 15px;
    position: relative;
}

.level-card.is-collapsed .level-header {
    align-items: center;
    border-radius: 50%;
    inset: 0;
    justify-content: center;
    min-height: 0;
    padding: 0;
    position: absolute;
}

.level-name {
    align-items: center;
    color: #fff;
    display: flex;
    flex: 0 1 auto;
    font-size: 1.12rem;
    gap: 10px;
    justify-content: flex-start;
    line-height: 1.15;
    margin: 0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}

.level-name i {
    align-items: center;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 9px;
    box-shadow: none;
    display: inline-flex;
    flex: 0 0 36px;
    font-size: 1rem;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.level-card.is-collapsed .level-name {
    flex: 0 0 auto;
    gap: 0;
    justify-content: center;
}

.level-card.is-collapsed .level-name i {
    background: transparent;
    border: 0;
    box-shadow: none;
    font-size: 2.1rem;
    height: auto;
    width: auto;
}

.level-card.is-collapsed .level-name span,
.level-card.is-collapsed .level-action,
.level-card.is-collapsed .level-body,
.level-card.is-collapsed .status-badge {
    display: none;
}

.level-card.is-collapsed .lock-badge {
    left: 50%;
    right: auto;
    top: 50%;
    transform: translate(-50%, -50%);
}

.level-card.is-expanded {
    border-radius: 16px;
    flex: none;
    grid-column: 1 / -1;
    grid-row: 1;
    justify-self: center;
    order: -1;
    width: min(360px, 100%);
}

.level-card--carpintero.is-expanded .level-header {
    gap: 8px;
    justify-content: flex-start;
    min-height: 0;
    padding: 10px 12px;
}

.level-card--carpintero.is-expanded .level-name {
    font-weight: 800;
}

.level-action {
    flex: 0 0 auto;
    width: 100%;
}

.level-button {
    align-items: center;
    border: 0;
    border-radius: 9px;
    display: inline-flex;
    font-size: 0.9rem;
    font-weight: 800;
    gap: 8px;
    justify-content: center;
    min-height: 42px;
    padding: 9px 12px;
    width: 100%;
}

.level-button.play {
    background: #fff;
    color: var(--level-color, #667eea);
    text-decoration: none;
}

.level-button.play:hover {
    background: #f1f5f9;
    color: var(--level-color, #667eea);
}

.level-button.locked {
    background: rgba(255, 255, 255, 0.68);
    color: #64748b;
}

.level-body {
    background: #fff;
    display: block;
    padding: 12px;
    position: relative;
    text-align: left;
}

.level-stats {
    display: grid;
    font-size: 0.76rem;
    gap: 4px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 10px;
}

.level-stats--carpintero {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.level-stats--carpintero .stat-label {
    line-height: 1.2;
}

.level-stats--carpintero .stat-value {
    font-size: 0.95rem;
    text-align: center;
}

.level-stats-item--effectiveness {
    position: relative;
}

.carpintero-effectiveness-progress {
    background: #e2e8f0;
    border-radius: 99px;
    bottom: 4px;
    height: 3px;
    left: 7px;
    overflow: hidden;
    position: absolute;
    right: 7px;
}

.carpintero-effectiveness-progress > span {
    background: var(--precision-color, #16a34a);
    border-radius: inherit;
    display: block;
    height: 100%;
}

.carpintero-chart-button {
    background: linear-gradient(145deg, #f5f3ff, #ede9fe);
    border: 0;
    box-shadow: inset 0 0 0 1px rgba(124, 58, 237, 0.34);
    cursor: pointer;
    color: #5b21b6;
    font: inherit;
    grid-column: span 2;
    transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
    width: 100%;
}

.carpintero-chart-button:hover,
.carpintero-chart-button:focus-visible {
    background: linear-gradient(145deg, #ede9fe, #ddd6fe);
    box-shadow: inset 0 0 0 2px rgba(124, 58, 237, 0.62), 0 3px 9px rgba(91, 33, 182, 0.16);
    color: #4c1d95;
    outline: 2px solid #8b5cf6;
    outline-offset: 1px;
    transform: translateY(-2px);
}

.carpintero-chart-button .stat-label {
    color: inherit;
    font-weight: 800;
}

.carpintero-chart-button .stat-value {
    color: inherit;
    filter: drop-shadow(0 2px 3px rgba(91, 33, 182, 0.18));
}

.carpintero-chart-button:hover .stat-value i,
.carpintero-chart-button:focus-visible .stat-value i {
    transform: scale(1.12);
}

.carpintero-chart-button .stat-value i {
    transition: transform 160ms ease;
}

.carpintero-chart-modal {
    border: 0;
    border-radius: 18px;
    color: #1e293b;
    max-height: min(88vh, 850px);
    max-width: min(860px, calc(100vw - 28px));
    overflow: hidden;
    padding: 0;
    width: 860px;
}

.carpintero-chart-modal::backdrop {
    background: rgba(8, 15, 32, 0.72);
    backdrop-filter: blur(3px);
}

.carpintero-chart-modal__panel {
    max-height: min(88vh, 850px);
    overflow-y: auto;
    padding: 22px;
}

.carpintero-chart-modal__header {
    align-items: flex-start;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.carpintero-chart-modal__eyebrow {
    color: #64748b;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    margin: 0 0 3px;
    text-transform: uppercase;
}

.carpintero-chart-modal__header h2 {
    font-size: clamp(1.25rem, 4vw, 1.65rem);
    font-weight: 800;
    margin: 0;
}

.carpintero-chart-modal__subtitle {
    color: #64748b;
    margin: 4px 0 0;
}

.carpintero-chart-modal__close {
    align-items: center;
    background: #f1f5f9;
    border: 0;
    border-radius: 50%;
    color: #334155;
    display: inline-flex;
    flex: 0 0 40px;
    height: 40px;
    justify-content: center;
    width: 40px;
}

.carpintero-chart-modal__content {
    min-height: 120px;
}

.carpintero-chart-options {
    background: #f1f5f9;
    border-radius: 10px;
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 14px;
    padding: 4px;
}

.carpintero-chart-options button {
    background: transparent;
    border: 0;
    border-radius: 7px;
    color: #475569;
    font-size: 0.88rem;
    font-weight: 700;
    min-height: 40px;
    padding: 7px 8px;
}

.carpintero-chart-options button.is-active {
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.14);
    color: #1e293b;
}

.carpintero-chart-loading,
.carpintero-chart-empty {
    color: #64748b;
    margin: 30px 0;
    text-align: center;
}

.carpintero-chart-scroll {
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.carpintero-chart {
    display: block;
    height: 220px;
    min-width: 100%;
}

.carpintero-chart-gridline {
    stroke: #e2e8f0;
    stroke-width: 1;
}

.carpintero-chart-axis,
.carpintero-chart-date {
    fill: #64748b;
    font-family: inherit;
    font-size: 10px;
}

.carpintero-chart-bar--correct {
    fill: #16a34a;
}

.carpintero-chart-bar--error {
    fill: #ef4444;
}

.carpintero-chart-bar--accuracy {
    fill: #7c3aed;
}

.carpintero-chart-bar--time {
    fill: #0284c7;
}

.carpintero-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    margin: 4px 0 18px;
}

.carpintero-chart-legend span {
    align-items: center;
    color: #475569;
    display: inline-flex;
    font-size: 0.84rem;
    gap: 7px;
}

.carpintero-chart-legend__dot {
    border-radius: 50%;
    height: 10px;
    width: 10px;
}

.carpintero-chart-legend__dot--correct {
    background: #16a34a;
}

.carpintero-chart-legend__dot--error {
    background: #ef4444;
}

.carpintero-chart-table-wrap {
    overflow-x: auto;
}

.carpintero-chart-table {
    border-collapse: collapse;
    font-size: 0.86rem;
    min-width: 610px;
    width: 100%;
}

.carpintero-chart-table th,
.carpintero-chart-table td {
    border-bottom: 1px solid #e2e8f0;
    padding: 9px 8px;
    text-align: right;
    white-space: nowrap;
}

.carpintero-chart-table th:first-child,
.carpintero-chart-table td:first-child {
    text-align: left;
}

.carpintero-chart-table th {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.level-stats-item {
    align-items: center;
    background: #f1f5f9;
    border-radius: 7px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
    padding: 7px 3px;
}

.stat-label {
    color: #64748b;
    font-size: 0.65rem;
    text-align: center;
}

.stat-value {
    color: var(--level-color, #667eea);
    font-size: 1.05rem;
    font-weight: 800;
}

.precision-progress {
    align-items: center;
    display: flex;
    gap: 8px;
}

.cycle-meter {
    align-items: center;
    background: #e2e8f0;
    border-radius: 8px;
    color: #334155;
    display: flex;
    flex: 0 0 auto;
    font-size: 0.7rem;
    gap: 4px;
    padding: 5px 7px;
}

.cycle-meter__value {
    font-weight: 800;
}

.progress-visual {
    background: #e2e8f0;
    border-radius: 99px;
    flex: 1;
    height: 9px;
    overflow: hidden;
}

.progress-bar {
    background: var(--precision-color, var(--level-color, #667eea));
    height: 100%;
}

.unlock-condition {
    color: #991b1b;
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1.25;
    margin-top: 8px;
}

.lock-badge {
    align-items: center;
    background: rgba(15, 23, 42, 0.58);
    border-radius: 99px;
    color: #fff;
    display: flex;
    height: 28px;
    justify-content: center;
    position: absolute;
    right: 10px;
    top: 10px;
    width: 28px;
    z-index: 3;
}

.status-badge {
    background: #15803d;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 7px 10px;
    text-align: center;
    text-transform: uppercase;
}

.status-badge.in-progress {
    background: #b45309;
}

.level-card.locked {
    filter: grayscale(0.8);
    opacity: 0.7;
}

.module-level-option {
    align-items: center;
    background: linear-gradient(145deg, color-mix(in srgb, var(--level-color, #667eea) 70%, #101827), var(--level-color, #667eea));
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    min-height: 154px;
    padding: 16px 10px;
    text-align: center;
    text-decoration: none;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.module-level-option:hover {
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.32);
    color: #fff;
    transform: translateY(-3px);
}

.module-level-option:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

.module-level-option__icon {
    align-items: center;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 14px;
    display: flex;
    font-size: 1.5rem;
    height: 48px;
    justify-content: center;
    width: 48px;
}

.module-level-option__title {
    font-size: 1rem;
    font-weight: 800;
}

.module-level-option.locked {
    filter: grayscale(1);
    opacity: 0.56;
}

.module-level-option.locked:hover {
    box-shadow: none;
    transform: none;
}

.module-level-message {
    background: rgba(15, 23, 42, 0.66);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 18px;
    margin: 0 auto;
    max-width: 560px;
    padding: 24px;
    text-align: center;
}

.module-level-message .btn {
    min-height: 44px;
}

@media (max-width: 700px) {
    .ruta-container[data-ruta-levels] {
        padding: 8px 12px 14px;
    }

    .ruta-level-back {
        min-height: 36px;
        padding: 3px 8px;
    }

    .ruta-level-header {
        margin: 2px auto 12px;
    }

    .ruta-level-header__chest.ruta-reveal {
        width: 88px;
        margin-bottom: 6px;
    }

    .ruta-level-header h1 {
        font-size: clamp(1.4rem, 5vw, 1.8rem);
    }

    .ruta-level-header p {
        font-size: 0.9rem;
    }

    .levels-container,
    .module-level-grid {
        gap: 9px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .module-level-option {
        gap: 7px;
        min-height: 112px;
        padding: 10px 8px;
    }

    .module-level-option__icon {
        border-radius: 11px;
        font-size: 1.25rem;
        height: 40px;
        width: 40px;
    }

    .levels-container.is-focusing {
        gap: 5px;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .level-route-group + .level-route-group {
        margin-top: 14px;
    }

    .level-route-title {
        font-size: 0.98rem;
    }

    .module-level-grid > :only-child {
        grid-column: 1 / -1;
        justify-self: center;
        width: min(100%, 260px);
    }

    .module-level-grid > :nth-child(3):last-child {
        grid-column: 1 / -1;
        justify-self: center;
        width: calc(50% - 5px);
    }

    .level-header {
        min-height: 132px;
        padding: 11px;
    }

    .level-card.is-collapsed {
        flex-basis: 70px;
        height: 70px;
        min-height: 70px;
        width: 70px;
    }

    .level-card.is-collapsed .level-header {
        min-height: 0;
        padding: 0;
    }

    .level-name,
    .level-card.is-collapsed .level-name {
        font-size: 0.95rem;
        gap: 7px;
    }

    .level-name i,
    .level-card.is-collapsed .level-name i {
        flex-basis: 30px;
        height: 30px;
        width: 30px;
    }

    .level-card.is-collapsed .level-name i {
        flex-basis: auto;
        font-size: 1.85rem;
        height: auto;
        width: auto;
    }

    .level-body {
        padding: 9px;
    }

}

@media (max-width: 360px) {
    .levels-container,
    .module-level-grid {
        gap: 7px;
    }

    .levels-container.is-focusing {
        gap: 2px;
    }

    .level-card.is-collapsed {
        flex-basis: 70px;
        height: 70px;
        min-height: 70px;
        width: 70px;
    }

    .level-stats {
        font-size: 0.68rem;
    }

    .stat-label {
        font-size: 0.58rem;
    }
}

@media (max-width: 520px) {
    .carpintero-chart-modal__panel {
        padding: 17px 14px;
    }

    .carpintero-chart-table {
        font-size: 0.78rem;
        min-width: 610px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ruta-reveal__image,
    .module-level-option,
    .carpintero-chart-button,
    .carpintero-chart-button .stat-value i {
        transition: none;
    }

    .carpintero-chart-button:hover,
    .carpintero-chart-button:focus-visible {
        transform: none;
    }

    .ruta-reveal.is-ready.is-chest .ruta-reveal__image--chest {
        animation: none;
    }

    .ruta-reveal.is-opening .ruta-reveal__image--chest,
    .ruta-reveal.is-opening.is-chest .ruta-reveal__image--chest,
    .ruta-reveal.is-opening .ruta-reveal__image--module,
    .ruta-reveal.is-opening .ruta-reveal__shine {
        animation-duration: 1ms;
    }
}
