:root {
    /* Paleta de colores */
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 0.5rem 2rem 0 rgba(31, 38, 135, 0.37);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    --accent-color: #ffd700;
    --highlight-cell: rgba(255, 255, 255, 0.2);
    --selected-cell: rgba(255, 255, 255, 0.4);
    --error-color: #ff6b6b;
    --success-color: #51cf66;

    --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
    font-size: 16px;
    /* BASE PARA ZOOM */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
    /* Evitar scroll horizontal */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    padding: 1rem;
    /* Padding seguro */
}

/* Background */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(5rem);
    opacity: 0.6;
    animation: move 20s infinite alternate;
}

.blob-1 {
    background: #43c6ac;
    width: 25rem;
    height: 25rem;
    top: -6rem;
    left: -6rem;
}

.blob-2 {
    background: #f8ffaE;
    width: 18rem;
    height: 18rem;
    bottom: -3rem;
    right: -3rem;
    animation-delay: -5s;
}

.blob-3 {
    background: #ff9a9e;
    width: 22rem;
    height: 22rem;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes move {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(2rem, -2rem) scale(1.1);
    }
}

/* Glassmorphism General */
.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(1rem);
    -webkit-backdrop-filter: blur(1rem);
    border-radius: 1.25rem;
    border: 0.0625rem solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    padding: 2rem;
    width: 100%;
    max-width: 31.25rem;
    /* ~500px */
    transition: all 0.3s ease;
    margin: auto;
}

/* Vistas */
.view {
    display: none;
    width: 100%;
    min-height: 100vh;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    transition: opacity 0.4s ease;
    padding: 1rem;
    box-sizing: border-box;
}

.view.active-view {
    display: flex;
    opacity: 1;
    z-index: 10;
    position: relative;
    /* Cambiado de absolute para permitir scroll natural si crece mucho */
    min-height: auto;
    height: auto;
}

.hidden {
    display: none !important;
}

/* HOME */
.home-container {
    text-align: center;
}

.main-title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    letter-spacing: -0.06rem;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.difficulty-selector {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn-difficulty {
    background: rgba(255, 255, 255, 0.1);
    border: 0.0625rem solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 1rem;
    border-radius: 0.75rem;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.625rem;
}

.btn-difficulty:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-0.125rem);
}

.progress-bar-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 0.25rem;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
}

.progress-bar-fill {
    height: 100%;
    background: var(--success-color);
    width: 0%;
    transition: width 0.5s ease;
}

.stats-overview {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.menu-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.625rem;
    justify-content: center;
}

.btn-secondary.small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

/* NIVELES */
.levels-header {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.btn-icon {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.btn-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.625rem;
}

.level-btn {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 0.0625rem solid rgba(255, 255, 255, 0.2);
    border-radius: 0.625rem;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.level-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.level-btn.completed {
    border-color: var(--success-color);
    color: var(--success-color);
}

/* JUEGO */
.game-container {
    /* REMOVED TRANSFORM SCALE logic from here - now global via rem */
    position: relative;
    max-width: 34rem;
    /* Un poco mas ancho para el zoom */
}

.zoom-controls {
    position: absolute;
    top: -3rem;
    /* Encima del header */
    right: 0;
    display: flex;
    gap: 0.5rem;
}

.btn-zoom {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    border-radius: 0.3rem;
    width: 2rem;
    height: 2rem;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.625rem;
}

.game-stats {
    display: flex;
    gap: 1rem;
}

.stat-box {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.3rem 0.6rem;
    border-radius: 0.5rem;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
}

.error-box {
    color: var(--error-color);
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.0625rem;
    background: rgba(255, 255, 255, 0.1);
    border: 0.125rem solid var(--text-primary);
    margin-bottom: 1.5rem;
    aspect-ratio: 1;
}

.cell {
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    user-select: none;
    color: var(--text-primary);
    position: relative;
    /* responsive font size handled by rem */
}

/* Bordes Gruesos */
.cell:nth-child(3n) {
    border-right: 0.0625rem solid rgba(255, 255, 255, 0.5);
}

.cell:nth-child(9n) {
    border-right: none;
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 0.0625rem solid rgba(255, 255, 255, 0.5);
}

/* Estados */
.cell.initial {
    font-weight: bold;
}

.cell.selected {
    background: var(--selected-cell) !important;
    border: 0.125rem solid rgba(255, 255, 255, 0.8);
}

.cell.highlighted {
    background: var(--highlight-cell);
}

.cell.completed-group {
    background: rgba(81, 207, 102, 0.2);
    transition: background-color 0.5s ease;
}

.cell.error {
    color: var(--error-color);
    background: rgba(255, 107, 107, 0.2) !important;
}

.cell.same-num {
    background: rgba(255, 215, 0, 0.2);
}

/* Numpad */
.numpad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.num-btn {
    padding: 1rem 0;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 0.5rem;
    color: white;
    font-size: 1.2rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s;
}

.num-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.num-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.3);
}

.num-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* MODAL */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(0.3rem);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    padding: 1rem;
}

.modal.visible {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    text-align: center;
    background: rgba(30, 30, 50, 0.95);
    border: 0.0625rem solid rgba(255, 255, 255, 0.1);
    position: relative;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    border-radius: 1.25rem;
}

.victory-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

.victory-icon {
    font-size: 4rem;
    margin: 1rem 0;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: transform 0.1s;
}

.btn-primary {
    background: var(--success-color);
    color: white;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Help Modal specific */
.help-modal {
    text-align: left;
    padding-top: 3rem;
    max-width: 37.5rem;
}

.btn-close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.text-content ul {
    margin-left: 1.2rem;
    margin-bottom: 1rem;
    line-height: 1.6;
}

.text-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

@media (max-width: 400px) {
    html {
        font-size: 14px;
    }

    /* Ajuste base automovil */
    .glass-container {
        padding: 1rem;
    }

    .cell:nth-child(3n) {
        border-right: 0.125rem solid rgba(255, 255, 255, 0.4);
    }

    .cell:nth-child(n+19):nth-child(-n+27),
    .cell:nth-child(n+46):nth-child(-n+54) {
        border-bottom: 0.125rem solid rgba(255, 255, 255, 0.4);
    }
}