/* ============================================
   RESET Y VARIABLES
   ============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colores base - Modo oscuro por defecto */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: rgba(0, 0, 0, 0.4);
    --text-primary: #00ff88;
    --text-secondary: #6a6a7a;
    --text-body: #ffffff;
    --border-color: #4a4a5a;
    --shadow-color: rgba(0, 0, 0, 0.8);
    --modal-bg: rgba(0, 0, 0, 0.9);
    --focus-ring: 0 0 0 3px rgba(0, 255, 136, 0.6);
    --transition-speed: 0.3s;
    --font-family: 'Courier New', monospace, system-ui, -apple-system, sans-serif;
    --font-size-base: 16px;
    --line-height-base: 1.5;
    --container-max: 500px;
    --spacing-unit: 8px;
    --border-radius: 12px;
}

/* Tema claro */
[data-theme="light"] {
    --bg-primary: #f0f0f0;
    --bg-secondary: #e0e0e0;
    --bg-tertiary: #d0d0d0;
    --bg-card: rgba(255, 255, 255, 0.85);
    --text-primary: #1a7a4a;
    --text-secondary: #636e72;
    --text-body: #2d3436;
    --border-color: #b0b0b0;
    --shadow-color: rgba(0, 0, 0, 0.15);
    --modal-bg: rgba(255, 255, 255, 0.95);
    --focus-ring: 0 0 0 3px rgba(26, 122, 74, 0.6);
}

/* Preferencia del sistema */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg-primary: #f0f0f0;
        --bg-secondary: #e0e0e0;
        --bg-tertiary: #d0d0d0;
        --bg-card: rgba(255, 255, 255, 0.85);
        --text-primary: #1a7a4a;
        --text-secondary: #636e72;
        --text-body: #2d3436;
        --border-color: #b0b0b0;
        --shadow-color: rgba(0, 0, 0, 0.15);
        --modal-bg: rgba(255, 255, 255, 0.95);
        --focus-ring: 0 0 0 3px rgba(26, 122, 74, 0.6);
    }
}

/* ============================================
   ESTILOS BASE Y ACCESIBILIDAD
   ============================================ */
html {
    font-size: var(--font-size-base);
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary), var(--bg-tertiary));
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--text-body);
    padding: var(--spacing-unit);
    transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Skip link - Para accesibilidad por teclado */
.skip-link {
    position: absolute;
    top: -9999px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: calc(var(--spacing-unit) * 1.5);
    border-radius: var(--border-radius);
    z-index: 9999;
    font-weight: bold;
    text-decoration: none;
}

.skip-link:focus {
    top: var(--spacing-unit);
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: var(--container-max);
    padding: calc(var(--spacing-unit) * 0.5);
}

.tamagotchi-shell {
    background: linear-gradient(145deg, #2d3436, #1a1a2e);
    border-radius: calc(var(--border-radius) * 2.5);
    padding: calc(var(--spacing-unit) * 2);
    box-shadow: 
        0 20px 60px var(--shadow-color),
        inset 0 -5px 15px rgba(0, 0, 0, 0.5),
        inset 0 5px 15px rgba(255, 255, 255, 0.1);
    border: 3px solid var(--border-color);
    width: 100%;
    transition: all var(--transition-speed) ease;
}

[data-theme="light"] .tamagotchi-shell {
    background: linear-gradient(145deg, #e8e8e8, #d0d0d0);
    border-color: #b0b0b0;
}

/* ============================================
   HEADER
   ============================================ */
.tamagotchi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 calc(var(--spacing-unit) * 0.5) calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 0.5);
    color: var(--text-secondary);
}

.led-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #00ff88;
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
    animation: pulse 2s infinite;
    transition: all var(--transition-speed) ease;
    flex-shrink: 0;
}

.led-indicator.off {
    background: #444;
    box-shadow: none;
    animation: none;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.3;
        transform: scale(0.8);
    }
}

.title {
    color: var(--text-primary);
    font-size: clamp(14px, 4vw, 18px);
    font-weight: bold;
    letter-spacing: clamp(2px, 0.5vw, 3px);
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
    text-align: center;
    flex: 1;
    margin: 0 calc(var(--spacing-unit) * 0.5);
}

.battery-indicator {
    font-size: clamp(14px, 3vw, 16px);
    flex-shrink: 0;
}

/* ============================================
   PANTALLA
   ============================================ */
.screen {
    background: #0a0a12;
    border-radius: calc(var(--border-radius) * 1.5);
    padding: calc(var(--spacing-unit) * 1.5);
    border: 4px solid #2a2a3a;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
    width: 100%;
    transition: all var(--transition-speed) ease;
}

[data-theme="light"] .screen {
    background: #ffffff;
    border-color: #d0d0d0;
}

/* ============================================
   BARRA DE ESTADO - RESPONSIVE
   ============================================ */
.status-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: calc(var(--spacing-unit) * 0.75);
    background: var(--bg-card);
    padding: calc(var(--spacing-unit) * 0.75);
    border-radius: var(--border-radius);
    margin-bottom: calc(var(--spacing-unit) * 1.5);
    border: 1px solid var(--border-color);
}

.status-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    padding: 4px 8px;
    border-radius: 8px;
    font-size: clamp(10px, 2vw, 12px);
    position: relative;
    min-height: 32px;
}

.status-item .icon {
    font-size: clamp(12px, 2.5vw, 14px);
    flex-shrink: 0;
}

.status-item .value {
    color: var(--text-primary);
    font-weight: bold;
    font-size: clamp(12px, 2.5vw, 14px);
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
    min-width: 20px;
    flex-shrink: 0;
}

.status-item .sub-text {
    color: var(--text-secondary);
    font-size: clamp(8px, 1.5vw, 10px);
}

.status-bar-fill {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin-top: 2px;
    overflow: hidden;
    position: relative;
    flex-basis: 100%;
}

.status-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    width: var(--progress, 100%);
}

#hungerFill::after {
    background: linear-gradient(90deg, #ff6b6b, #ffd93d);
}

#energyFill::after {
    background: linear-gradient(90deg, #4facfe, #00f2fe);
}

#happinessFill::after {
    background: linear-gradient(90deg, #f093fb, #f5576c);
}

/* ============================================
   MASCOTA
   ============================================ */
.pet-display {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 1.5);
    margin-bottom: calc(var(--spacing-unit) * 1.5);
    text-align: center;
    border: 1px solid var(--border-color);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.pet-container {
    position: relative;
    width: 100%;
}

.pet {
    margin: 0 auto calc(var(--spacing-unit) * 0.5);
    position: relative;
    width: clamp(80px, 20vw, 120px);
    height: clamp(80px, 20vw, 120px);
}

.pet-body {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 30% 30%, #ff6b6b, #c0392b);
    border-radius: 50%;
    position: relative;
    transition: all 0.5s ease;
    box-shadow: 0 5px 20px rgba(255, 107, 107, 0.3);
    animation: float 3s ease-in-out infinite;
    margin: 0 auto;
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

.pet-body.dead {
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0) rotate(0deg);
    }
    25% {
        transform: translateX(-5px) rotate(-5deg);
    }
    75% {
        transform: translateX(5px) rotate(5deg);
    }
}

.pet-eyes {
    position: absolute;
    top: 25%;
    left: 18%;
    width: 64%;
    display: flex;
    justify-content: space-between;
}

.eye {
    width: clamp(14px, 4vw, 20px);
    height: clamp(18px, 5vw, 25px);
    background: white;
    border-radius: 50%;
    position: relative;
    transition: all 0.3s ease;
    overflow: hidden;
}

.pupil {
    width: clamp(6px, 1.5vw, 8px);
    height: clamp(6px, 1.5vw, 8px);
    background: #2d3436;
    border-radius: 50%;
    position: absolute;
    bottom: 4px;
    left: 6px;
    transition: all 0.3s ease;
}

.eye.happy .pupil {
    bottom: 2px;
    left: 6px;
}

.eye.sad .pupil {
    bottom: 6px;
    left: 6px;
}

.eye.closed {
    height: 5px;
    background: #2d3436;
}

.pet-mouth {
    position: absolute;
    bottom: 20%;
    left: 35%;
    width: 30%;
    height: 20px;
    border-bottom: 3px solid #2d3436;
    border-radius: 0 0 20px 20px;
    transition: all 0.3s ease;
}

.pet-mouth.happy {
    border-bottom: 3px solid #2d3436;
    border-radius: 0 0 20px 20px;
    height: 20px;
}

.pet-mouth.sad {
    border-top: 3px solid #2d3436;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    height: 20px;
}

.pet-mouth.sleeping {
    border: none;
    width: 16%;
    height: 3px;
    background: #2d3436;
    border-radius: 2px;
    left: 42%;
    top: 55%;
}

.pet-mouth.open {
    width: 25%;
    height: 25px;
    background: #2d3436;
    border-radius: 50%;
    border: none;
}

.pet-blush {
    position: absolute;
    width: clamp(12px, 3vw, 20px);
    height: clamp(8px, 2vw, 12px);
    background: rgba(255, 100, 100, 0.3);
    border-radius: 50%;
    bottom: 35%;
    opacity: 0;
    transition: all 0.3s ease;
}

.pet-blush.left {
    left: 8%;
}

.pet-blush.right {
    right: 8%;
}

.pet-blush.show {
    opacity: 1;
}

.pet-name {
    color: var(--text-primary);
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: bold;
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
    letter-spacing: clamp(1px, 0.3vw, 2px);
    margin-top: calc(var(--spacing-unit) * 0.5);
}

.pet-stage {
    color: var(--text-secondary);
    font-size: clamp(10px, 2vw, 12px);
    margin-top: 2px;
}

.pet-friendship {
    margin-top: calc(var(--spacing-unit) * 0.75);
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 0.75);
    color: var(--text-secondary);
    font-size: clamp(10px, 2vw, 12px);
    flex-wrap: wrap;
    justify-content: center;
}

.friendship-bar {
    flex: 1;
    min-width: 60px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.friendship-fill {
    height: 100%;
    background: linear-gradient(90deg, #f093fb, #f5576c);
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}

/* ============================================
   PESTAÑAS - RESPONSIVE
   ============================================ */
.tab-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: calc(var(--spacing-unit) * 0.5);
    margin-bottom: calc(var(--spacing-unit) * 0.75);
}

.tab-btn {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: calc(var(--border-radius) * 0.75);
    padding: calc(var(--spacing-unit) * 0.5) calc(var(--spacing-unit) * 0.75);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: clamp(9px, 2vw, 11px);
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 36px;
    touch-action: manipulation;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.tab-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.tab-btn.active {
    background: var(--text-primary);
    color: #000;
    border-color: var(--text-primary);
    font-weight: bold;
}

.tab-btn span:last-child {
    display: inline;
}

@media (max-width: 380px) {
    .tab-btn span:last-child {
        display: none;
    }
}

.tab-content {
    margin-bottom: calc(var(--spacing-unit) * 0.75);
}

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   BOTONES DE ACCIÓN - RESPONSIVE
   ============================================ */
.action-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: calc(var(--spacing-unit) * 0.5);
}

.action-btn {
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 0.5);
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-family: var(--font-family);
    position: relative;
    min-height: 52px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:hover:not(:disabled) {
    background: linear-gradient(145deg, #3a3a4a, #2a2a3a);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0px);
}

.action-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.action-btn .btn-icon {
    font-size: clamp(18px, 4vw, 20px);
    line-height: 1;
}

.action-btn .btn-text {
    font-size: clamp(8px, 1.8vw, 10px);
    color: #aaaaaa;
}

.action-btn .btn-cooldown {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: clamp(18px, 4vw, 20px);
    height: clamp(18px, 4vw, 20px);
    font-size: clamp(8px, 1.5vw, 10px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    font-weight: bold;
}

.action-btn .btn-cooldown.active {
    opacity: 1;
}

@media (max-width: 420px) {
    .action-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 340px) {
    .action-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   MINIJUEGOS - RESPONSIVE
   ============================================ */
.minigames-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: calc(var(--spacing-unit) * 0.75);
}

.minigame-btn {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 1);
    color: var(--text-body);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: var(--font-family);
    min-height: 80px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
}

.minigame-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--text-primary);
}

.minigame-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.minigame-btn .game-icon {
    font-size: clamp(24px, 5vw, 30px);
}

.minigame-btn .game-name {
    font-size: clamp(11px, 2.5vw, 14px);
    font-weight: bold;
    color: var(--text-primary);
}

.minigame-btn .game-desc {
    font-size: clamp(8px, 1.8vw, 10px);
    color: var(--text-secondary);
}

.minigame-btn .game-reward {
    font-size: clamp(8px, 1.8vw, 10px);
    color: #ffd93d;
}

@media (max-width: 360px) {
    .minigames-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   TIENDA - RESPONSIVE
   ============================================ */
.shop-header {
    color: var(--text-primary);
    font-size: clamp(14px, 3vw, 16px);
    padding: calc(var(--spacing-unit) * 0.75);
    text-align: center;
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: calc(var(--spacing-unit) * 0.75);
}

.shop-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75);
    text-align: center;
    transition: all var(--transition-speed) ease;
}

.shop-item:hover {
    transform: translateY(-2px);
    border-color: var(--text-primary);
}

.shop-item .item-icon {
    font-size: clamp(24px, 5vw, 30px);
    display: block;
}

.shop-item .item-name {
    display: block;
    font-size: clamp(10px, 2vw, 12px);
    color: var(--text-body);
    margin: 4px 0;
}

.shop-item .item-price {
    display: block;
    font-size: clamp(10px, 2vw, 11px);
    color: #ffd93d;
}

.shop-item .item-effect {
    display: block;
    font-size: clamp(8px, 1.8vw, 10px);
    color: var(--text-secondary);
    margin: 4px 0;
}

.shop-buy {
    background: var(--text-primary);
    border: none;
    border-radius: 6px;
    padding: 4px 12px;
    color: #000;
    cursor: pointer;
    font-weight: bold;
    font-family: var(--font-family);
    font-size: clamp(10px, 2vw, 12px);
    transition: all var(--transition-speed) ease;
    min-height: 32px;
    touch-action: manipulation;
}

.shop-buy:hover {
    transform: scale(1.05);
}

.shop-buy:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.shop-buy:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

@media (max-width: 380px) {
    .shop-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 320px) {
    .shop-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   LOGROS - RESPONSIVE
   ============================================ */
.achievements-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: calc(var(--spacing-unit) * 0.75);
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
}

.achievement-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: calc(var(--border-radius) * 0.75);
    padding: calc(var(--spacing-unit) * 0.75);
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 0.5);
    transition: all var(--transition-speed) ease;
}

.achievement-item.unlocked {
    border-color: #ffd93d;
    background: rgba(255, 217, 61, 0.08);
}

.achievement-item.locked {
    opacity: 0.5;
}

.achievement-item .ach-icon {
    font-size: clamp(20px, 4vw, 24px);
    flex-shrink: 0;
}

.achievement-item .ach-info {
    flex: 1;
    min-width: 0;
}

.achievement-item .ach-name {
    font-size: clamp(10px, 2vw, 12px);
    color: var(--text-body);
}

.achievement-item .ach-desc {
    font-size: clamp(8px, 1.6vw, 10px);
    color: var(--text-secondary);
}

.achievement-item .ach-progress {
    font-size: clamp(8px, 1.6vw, 10px);
    color: var(--text-primary);
}

@media (max-width: 400px) {
    .achievements-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   MENSAJES Y ESTADÍSTICAS EXTRAS - RESPONSIVE
   ============================================ */
.message-area {
    background: var(--bg-card);
    border-radius: calc(var(--border-radius) * 0.75);
    padding: calc(var(--spacing-unit) * 0.75);
    text-align: center;
    color: var(--text-primary);
    font-size: clamp(12px, 2.5vw, 14px);
    min-height: 40px;
    border: 1px solid var(--border-color);
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(var(--spacing-unit) * 0.5);
    margin-bottom: calc(var(--spacing-unit) * 0.75);
}

.message-icon {
    font-size: clamp(14px, 3vw, 18px);
    flex-shrink: 0;
}

.message-text {
    flex: 1;
    word-break: break-word;
}

.stats-extras {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: calc(var(--spacing-unit) * 0.5);
    padding: calc(var(--spacing-unit) * 0.75);
    background: var(--bg-card);
    border-radius: calc(var(--border-radius) * 0.75);
    border: 1px solid var(--border-color);
}

.stat-extra {
    display: flex;
    justify-content: center;
    gap: 3px;
    color: var(--text-secondary);
    font-size: clamp(9px, 2vw, 11px);
    flex-wrap: wrap;
}

.stat-extra span:last-child {
    color: var(--text-primary);
    font-weight: bold;
}

@media (max-width: 420px) {
    .stats-extras {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }
}

/* ============================================
   CONTROLES - RESPONSIVE
   ============================================ */
.controls {
    display: flex;
    justify-content: center;
    gap: calc(var(--spacing-unit) * 0.5);
    margin-top: calc(var(--spacing-unit) * 1.25);
    flex-wrap: wrap;
}

.control-btn {
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: 2px solid var(--border-color);
    border-radius: calc(var(--border-radius) * 0.75);
    padding: calc(var(--spacing-unit) * 0.5) calc(var(--spacing-unit) * 1);
    color: #ffffff;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: clamp(10px, 2vw, 12px);
    transition: all 0.3s ease;
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.control-btn:hover {
    background: linear-gradient(145deg, #3a3a4a, #2a2a3a);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.control-btn:active {
    transform: translateY(0px);
}

.control-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@media (max-width: 420px) {
    .controls {
        gap: 4px;
    }
    .control-btn {
        padding: 4px 8px;
        font-size: 10px;
        min-height: 30px;
    }
}

/* ============================================
   MODALES - ACCESIBLES
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: var(--modal-bg);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
    padding: var(--spacing-unit);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: calc(var(--border-radius) * 1.5);
    padding: calc(var(--spacing-unit) * 1.5);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    border: 2px solid var(--border-color);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: calc(var(--spacing-unit) * 1.25);
    color: var(--text-primary);
}

.modal-header h2 {
    font-size: clamp(16px, 3.5vw, 20px);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: clamp(20px, 4vw, 24px);
    cursor: pointer;
    padding: 0 calc(var(--spacing-unit) * 0.5);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #ffffff;
}

.modal-close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.modal-body {
    color: var(--text-body);
}

/* ============================================
   NOTIFICACIONES - ACCESIBLES
   ============================================ */
.notification {
    position: fixed;
    top: calc(var(--spacing-unit) * 1.5);
    right: calc(var(--spacing-unit) * 1.5);
    background: var(--bg-secondary);
    border: 2px solid var(--text-primary);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 1.5);
    color: var(--text-body);
    transform: translateX(calc(100% + 20px));
    transition: transform 0.5s ease, opacity 0.5s ease;
    z-index: 2000;
    max-width: min(90vw, 320px);
    opacity: 0;
    box-shadow: 0 10px 30px var(--shadow-color);
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification .notif-icon {
    font-size: clamp(20px, 4vw, 24px);
    margin-right: calc(var(--spacing-unit) * 0.5);
}

.notification .notif-text {
    font-size: clamp(12px, 2.5vw, 14px);
}

/* ============================================
   ESTADOS DE COLOR
   ============================================ */
.status-item .value.danger {
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

.status-item .value.warning {
    color: #ffaa00;
    text-shadow: 0 0 20px rgba(255, 170, 0, 0.3);
}

.status-item .value.good {
    color: var(--text-primary);
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

/* ============================================
   ANIMACIONES
   ============================================ */
@keyframes heartBeat {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

.pet-body.happy {
    animation: float 2s ease-in-out infinite, heartBeat 1s ease-in-out infinite;
}

.pet-body.sleeping {
    animation: none;
    filter: brightness(0.7);
}

.pet-body.sleeping .eye {
    height: 5px;
    background: #2d3436;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-card);
}

::-webkit-scrollbar-thumb {
    background: var(--text-primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #00cc6a;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .controls,
    .action-buttons,
    .tab-buttons,
    .minigames-grid,
    .shop-grid {
        display: none !important;
    }
    .tamagotchi-shell {
        box-shadow: none !important;
        border: 1px solid #000 !important;
    }
    .screen {
        border: 1px solid #000 !important;
        box-shadow: none !important;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   ALTA CONTRASTO
   ============================================ */
@media (prefers-contrast: high) {
    :root {
        --text-primary: #00ff00;
        --border-color: #ffffff;
        --bg-card: rgba(0, 0, 0, 0.7);
    }
    [data-theme="light"] {
        --text-primary: #004400;
        --border-color: #000000;
        --bg-card: rgba(255, 255, 255, 0.9);
    }
    .action-btn,
    .control-btn,
    .tab-btn,
    .minigame-btn {
        border-width: 3px !important;
    }
    .status-item .value {
        text-shadow: none !important;
    }
}

/* ============================================
   PANTALLAS MUY PEQUEÑAS (<= 320px)
   ============================================ */
@media (max-width: 320px) {
    .tamagotchi-shell {
        padding: calc(var(--spacing-unit) * 0.75);
        border-radius: calc(var(--border-radius) * 1.5);
    }
    .screen {
        padding: calc(var(--spacing-unit) * 0.75);
    }
    .status-bar {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        padding: 4px;
    }
    .status-item {
        padding: 2px 4px;
        font-size: 9px;
    }
    .action-buttons {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }
    .action-btn {
        padding: 4px;
        min-height: 40px;
    }
    .action-btn .btn-icon {
        font-size: 16px;
    }
    .action-btn .btn-text {
        font-size: 7px;
    }
    .pet {
        width: 70px;
        height: 70px;
    }
}

/* ============================================
   PANTALLAS GRANDES (>= 768px)
   ============================================ */
@media (min-width: 768px) {
    .container {
        padding: calc(var(--spacing-unit) * 2);
    }
    .tamagotchi-shell {
        padding: calc(var(--spacing-unit) * 2.5);
        border-radius: calc(var(--border-radius) * 3);
    }
    .screen {
        padding: calc(var(--spacing-unit) * 2);
    }
    .action-btn:hover {
        transform: translateY(-3px);
    }
}

/* ============================================
   SOPORTE PARA ORIENTACIÓN LANDSCAPE EN MÓVILES
   ============================================ */
@media (max-height: 600px) and (orientation: landscape) {
    .tamagotchi-shell {
        max-height: 95vh;
        overflow-y: auto;
    }
    .screen {
        padding: calc(var(--spacing-unit) * 0.75);
    }
    .pet-display {
        min-height: 120px;
        padding: calc(var(--spacing-unit) * 0.75);
    }
    .pet {
        width: 60px;
        height: 60px;
    }
    .status-bar {
        padding: 4px;
        gap: 4px;
    }
    .status-item {
        padding: 2px 6px;
        font-size: 9px;
        min-height: 24px;
    }
    .action-btn {
        min-height: 36px;
        padding: 4px;
    }
    .action-btn .btn-icon {
        font-size: 14px;
    }
    .message-area {
        min-height: 30px;
        padding: 4px 8px;
        font-size: 11px;
    }
    .stats-extras {
        padding: 4px 8px;
    }
    .controls {
        margin-top: calc(var(--spacing-unit) * 0.5);
        gap: 4px;
    }
    .control-btn {
        padding: 4px 8px;
        font-size: 10px;
        min-height: 28px;
    }
    .tab-buttons {
        gap: 4px;
        margin-bottom: 4px;
    }
    .tab-btn {
        padding: 4px 6px;
        font-size: 9px;
        min-height: 28px;
    }
}
/* ============================================
   MEJORAS ESPECÍFICAS PARA MÓVILES
   ============================================ */

/* Ajustes para pantallas muy pequeñas */
@media (max-width: 420px) {
    /* Reducir padding general */
    .tamagotchi-shell {
        padding: 12px;
        border-radius: 20px;
    }

    .screen {
        padding: 12px;
        border-radius: 14px;
    }

    /* Barra de estado más compacta */
    .status-bar {
        gap: 4px;
        padding: 6px;
    }

    .status-item {
        padding: 3px 6px;
        font-size: 10px;
        min-height: 28px;
    }

    .status-item .value {
        font-size: 12px;
        min-width: 18px;
    }

    .status-item .icon {
        font-size: 12px;
    }

    .status-bar-fill {
        height: 3px;
    }

    /* Mascota más pequeña */
    .pet-display {
        min-height: 160px;
        padding: 12px;
    }

    .pet {
        width: 80px;
        height: 80px;
    }

    .pet-body {
        width: 80px;
        height: 80px;
    }

    .pet-eyes {
        top: 22%;
        left: 16%;
        width: 68%;
    }

    .eye {
        width: 14px;
        height: 18px;
    }

    .pupil {
        width: 6px;
        height: 6px;
        bottom: 3px;
        left: 4px;
    }

    .pet-mouth {
        bottom: 18%;
        left: 32%;
        width: 36%;
        height: 14px;
    }

    .pet-name {
        font-size: 14px;
    }

    .pet-stage {
        font-size: 10px;
    }

    .pet-friendship {
        font-size: 10px;
        gap: 4px;
        margin-top: 4px;
    }

    .friendship-bar {
        height: 4px;
        min-width: 40px;
    }

    /* Botones de acción más compactos */
    .action-buttons {
        gap: 4px;
    }

    .action-btn {
        padding: 6px 4px;
        min-height: 40px;
        border-radius: 8px;
    }

    .action-btn .btn-icon {
        font-size: 16px;
    }

    .action-btn .btn-text {
        font-size: 8px;
    }

    .action-btn .btn-cooldown {
        width: 16px;
        height: 16px;
        font-size: 8px;
        top: -4px;
        right: -4px;
    }

    /* Pestañas más compactas */
    .tab-btn {
        padding: 4px 6px;
        font-size: 9px;
        min-height: 30px;
        border-radius: 6px;
    }

    /* Estadísticas extras */
    .stats-extras {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        padding: 6px;
    }

    .stat-extra {
        font-size: 9px;
        gap: 2px;
    }

    /* Mensajes */
    .message-area {
        min-height: 32px;
        padding: 6px 10px;
        font-size: 11px;
        gap: 4px;
    }

    .message-icon {
        font-size: 14px;
    }

    /* Controles */
    .controls {
        gap: 4px;
        margin-top: 10px;
    }

    .control-btn {
        padding: 4px 8px;
        font-size: 9px;
        min-height: 28px;
        border-radius: 6px;
    }

    /* Minijuegos */
    .minigames-grid {
        gap: 4px;
    }

    .minigame-btn {
        padding: 8px;
        min-height: 60px;
        border-radius: 8px;
    }

    .minigame-btn .game-icon {
        font-size: 20px;
    }
    .minigame-btn .game-name {
        font-size: 10px;
    }
    .minigame-btn .game-desc {
        font-size: 8px;
    }
    .minigame-btn .game-reward {
        font-size: 8px;
    }

    /* Tienda */
    .shop-grid {
        gap: 4px;
    }

    .shop-item {
        padding: 6px;
        border-radius: 8px;
    }

    .shop-item .item-icon {
        font-size: 20px;
    }
    .shop-item .item-name {
        font-size: 9px;
    }
    .shop-item .item-price {
        font-size: 9px;
    }
    .shop-item .item-effect {
        font-size: 8px;
    }

    .shop-buy {
        padding: 3px 10px;
        font-size: 10px;
        min-height: 28px;
    }

    /* Logros */
    .achievements-grid {
        gap: 4px;
        max-height: 150px;
    }

    .achievement-item {
        padding: 6px 8px;
        border-radius: 6px;
    }

    .achievement-item .ach-icon {
        font-size: 18px;
    }
    .achievement-item .ach-name {
        font-size: 10px;
    }
    .achievement-item .ach-desc {
        font-size: 8px;
    }
    .achievement-item .ach-progress {
        font-size: 8px;
    }

    /* Header */
    .tamagotchi-header {
        padding-bottom: 10px;
    }

    .title {
        font-size: 14px;
        letter-spacing: 2px;
    }

    .led-indicator {
        width: 10px;
        height: 10px;
    }

    .battery-indicator {
        font-size: 12px;
    }
}

/* Ajustes para pantallas entre 420px y 500px */
@media (min-width: 421px) and (max-width: 500px) {
    .tamagotchi-shell {
        padding: 16px;
    }

    .screen {
        padding: 16px;
    }

    .pet {
        width: 100px;
        height: 100px;
    }

    .pet-body {
        width: 100px;
        height: 100px;
    }

    .action-btn {
        padding: 8px 6px;
        min-height: 48px;
    }

    .action-btn .btn-icon {
        font-size: 18px;
    }
}

/* Ajustes para orientación landscape en móviles */
@media (max-height: 600px) and (orientation: landscape) {
    .tamagotchi-shell {
        max-height: 98vh;
        overflow-y: auto;
        padding: 10px;
    }

    .screen {
        padding: 10px;
    }

    .pet-display {
        min-height: 100px;
        padding: 8px;
    }

    .pet {
        width: 60px;
        height: 60px;
    }

    .pet-body {
        width: 60px;
        height: 60px;
    }

    .pet-eyes {
        top: 20%;
        left: 14%;
        width: 72%;
    }

    .eye {
        width: 12px;
        height: 14px;
    }

    .pupil {
        width: 5px;
        height: 5px;
        bottom: 2px;
        left: 4px;
    }

    .pet-mouth {
        bottom: 16%;
        left: 30%;
        width: 40%;
        height: 12px;
        border-bottom-width: 2px;
    }

    .pet-name {
        font-size: 12px;
        margin-top: 2px;
    }

    .pet-stage {
        font-size: 9px;
    }

    .pet-friendship {
        font-size: 9px;
        margin-top: 2px;
    }

    .friendship-bar {
        height: 3px;
        min-width: 30px;
    }

    .status-bar {
        grid-template-columns: 1fr 1fr 1fr 1fr;
        gap: 3px;
        padding: 4px;
        margin-bottom: 8px;
    }

    .status-item {
        padding: 2px 4px;
        font-size: 8px;
        min-height: 20px;
    }

    .status-item .value {
        font-size: 10px;
        min-width: 14px;
    }

    .status-item .icon {
        font-size: 10px;
    }

    .status-bar-fill {
        height: 2px;
    }

    .action-buttons {
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
    }

    .action-btn {
        padding: 4px 2px;
        min-height: 30px;
        border-radius: 6px;
    }

    .action-btn .btn-icon {
        font-size: 14px;
    }

    .action-btn .btn-text {
        font-size: 7px;
    }

    .tab-buttons {
        gap: 3px;
        margin-bottom: 4px;
    }

    .tab-btn {
        padding: 3px 4px;
        font-size: 8px;
        min-height: 24px;
    }

    .stats-extras {
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
        padding: 4px;
    }

    .stat-extra {
        font-size: 8px;
    }

    .message-area {
        min-height: 24px;
        padding: 4px 8px;
        font-size: 10px;
        margin-bottom: 4px;
    }

    .controls {
        gap: 3px;
        margin-top: 6px;
    }

    .control-btn {
        padding: 3px 6px;
        font-size: 8px;
        min-height: 22px;
    }

    .minigames-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }

    .minigame-btn {
        padding: 6px;
        min-height: 50px;
    }

    .minigame-btn .game-icon {
        font-size: 18px;
    }
    .minigame-btn .game-name {
        font-size: 9px;
    }
    .minigame-btn .game-desc {
        font-size: 7px;
    }
    .minigame-btn .game-reward {
        font-size: 7px;
    }

    .shop-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }

    .shop-item {
        padding: 4px;
    }

    .shop-item .item-icon {
        font-size: 18px;
    }
    .shop-item .item-name {
        font-size: 8px;
    }
    .shop-item .item-price {
        font-size: 8px;
    }
    .shop-item .item-effect {
        font-size: 7px;
    }

    .shop-buy {
        padding: 2px 8px;
        font-size: 8px;
        min-height: 24px;
    }

    .achievements-grid {
        grid-template-columns: 1fr 1fr;
        gap: 3px;
        max-height: 120px;
    }

    .achievement-item {
        padding: 4px 6px;
    }

    .achievement-item .ach-icon {
        font-size: 16px;
    }
    .achievement-item .ach-name {
        font-size: 9px;
    }
    .achievement-item .ach-desc {
        font-size: 7px;
    }
}

/* Ajustes para pantallas con notch o muesca */
@supports (padding: max(0px)) {
    .tamagotchi-shell {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* Modo oscuro/claro - mantener consistencia */
[data-theme="light"] .action-btn {
    color: #2d3436;
}

[data-theme="light"] .action-btn .btn-text {
    color: #636e72;
}

[data-theme="light"] .minigame-btn {
    color: #2d3436;
}

[data-theme="light"] .minigame-btn .game-name {
    color: #1a7a4a;
}

[data-theme="light"] .shop-item .item-name {
    color: #2d3436;
}

[data-theme="light"] .achievement-item .ach-name {
    color: #2d3436;
}

[data-theme="light"] .control-btn {
    color: #2d3436;
}

/* Mejoras de touch en móviles */
@media (hover: none) and (pointer: coarse) {
    .action-btn:hover:not(:disabled) {
        transform: none;
        box-shadow: none;
    }

    .minigame-btn:hover {
        transform: none;
        box-shadow: none;
    }

    .shop-item:hover {
        transform: none;
    }

    .control-btn:hover {
        transform: none;
        box-shadow: none;
    }

    /* Aumentar área de touch */
    .action-btn,
    .minigame-btn,
    .shop-buy,
    .control-btn,
    .tab-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Feedback táctil */
    .action-btn:active:not(:disabled) {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .minigame-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .control-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Scroll suave en móviles */
@media (max-width: 768px) {
    .achievements-grid,
    .modal-content {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}