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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #002868 0%, #FFFFFF 50%, #CE1126 100%); /* Costa Rican flag colors */
    background-size: 200% 200%;
    animation: costaRicanWave 15s ease infinite;
    min-height: 100vh;
    color: #333;
    position: relative;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* Costa Rican flag pattern overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255,255,255,0.03) 2px,
            rgba(255,255,255,0.03) 4px
        );
    pointer-events: none;
    z-index: 0;
}

body > * {
    position: relative;
    z-index: 1;
}

@keyframes costaRicanWave {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    animation: slideIn 0.5s ease-out;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
}

/* Character selection: container pushes Volver to bottom */
.character-selection-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
}
.character-selection-container .characters-grid {
    flex: 1 1 auto;
}
.character-selection-container .volver-link {
    margin-top: 20px;
    margin-bottom: 0;
    align-self: flex-start;
}

.volver-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.35);
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.25s;
    backdrop-filter: blur(8px);
}

.volver-link:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
    color: white;
    transform: translateX(-4px);
}

.screen {
    display: none;
    min-height: 100vh;
    padding: 20px 0;
}

.screen.active {
    display: block;
}

h1 {
    text-align: center;
    color: white;
    margin-bottom: 25px;
    font-family: 'Bungee Spice', 'Orbitron', 'Russo One', sans-serif;
    font-size: clamp(2.1em, 7vw, 4.2em);
    font-weight: 400; /* Bungee Spice has fixed weight */
    text-shadow: 
        4px 4px 0px #002868,
        6px 6px 10px rgba(0, 0, 0, 0.8),
        0 0 30px rgba(255, 215, 0, 0.5);
    letter-spacing: 3px;
    text-transform: uppercase;
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { 
        text-shadow: 
            4px 4px 0px #002868,
            6px 6px 10px rgba(0, 0, 0, 0.8),
            0 0 30px rgba(255, 215, 0, 0.5);
    }
    50% { 
        text-shadow: 
            4px 4px 0px #002868,
            6px 6px 10px rgba(0, 0, 0, 0.8),
            0 0 50px rgba(255, 215, 0, 0.8);
    }
}

h2 {
    color: white;
    margin-bottom: 20px;
    text-align: center;
    font-family: 'Orbitron', 'Russo One', sans-serif;
    font-size: clamp(1.3em, 4vw, 1.8em);
    text-shadow: 
        2px 2px 0px #002868,
        3px 3px 6px rgba(0, 0, 0, 0.6),
        0 0 15px rgba(255, 215, 0, 0.3);
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* Character Selection */
.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
    animation: slideIn 0.6s ease-out;
    padding: 0 5px;
}

/* Extra small mobile devices (≤360px) */
@media (max-width: 360px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 10px;
        padding: 0;
    }
}

/* Small mobile devices (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 10px;
        padding: 0 2px;
    }
}

/* Medium mobile / small tablets (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 12px;
        padding: 0 5px;
    }
}

/* Large tablets (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 14px;
    }
}

.character-card {
    background: linear-gradient(135deg, #FFFFFF 0%, #f8f9fa 100%);
    border-radius: 20px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0,40,104,0.25);
    border: 3px solid #002868;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.character-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(206,17,38,0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
}

.character-card:active {
    transform: scale(0.95);
}

.character-card:hover,
.character-card:focus {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0,40,104,0.35);
}

.character-card:hover::before {
    opacity: 1;
}

.character-card.selected {
    border: 4px solid #CE1126;
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    box-shadow: 0 12px 28px rgba(206,17,38,0.5), 0 0 0 4px rgba(206,17,38,0.2);
    transform: scale(1.05);
    animation: pulse 2s ease-in-out infinite;
}

/* Mobile: reduce selected scale to prevent overflow */
@media (max-width: 768px) {
    .character-card.selected {
        transform: scale(1.03);
    }
}

@media (max-width: 480px) {
    .character-card.selected {
        transform: scale(1.02);
    }
}

.character-card.selected::before {
    opacity: 1;
    background: radial-gradient(circle, rgba(206,17,38,0.2) 0%, transparent 70%);
}

.character-card img {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 12px;
    border: 3px solid #002868;
    box-shadow: 0 4px 12px rgba(0,40,104,0.4);
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    /* Image loading optimizations */
    content-visibility: auto;
    will-change: transform;
}

/* Optimize image sizes for different screen sizes */
@media (max-width: 360px) {
    .character-card img {
        width: 65px;
        height: 65px;
        margin-bottom: 8px;
        border-width: 2.5px;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .character-card img {
        width: 72px;
        height: 72px;
        margin-bottom: 10px;
        border-width: 2.5px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .character-card img {
        width: 80px;
        height: 80px;
        margin-bottom: 10px;
    }
}

.character-card:hover img {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 16px rgba(0,40,104,0.5);
}

.character-card.selected img {
    border-color: #CE1126;
    border-width: 4px;
    transform: scale(1.12);
    box-shadow: 0 8px 20px rgba(206,17,38,0.6);
}

/* Reduce selected image scale on mobile */
@media (max-width: 768px) {
    .character-card.selected img {
        transform: scale(1.08);
        border-width: 3.5px;
    }
}

@media (max-width: 480px) {
    .character-card.selected img {
        transform: scale(1.05);
        border-width: 3px;
    }
}

.character-card h3 {
    color: #002868;
    font-size: clamp(0.85em, 2.8vw, 1.1em);
    font-weight: 600;
    margin: 0;
    position: relative;
    z-index: 1;
    text-transform: capitalize;
    line-height: 1.3;
    word-break: break-word;
    hyphens: auto;
    padding: 0 2px;
}

/* Optimize text size for mobile */
@media (max-width: 360px) {
    .character-card h3 {
        font-size: 0.75em;
        line-height: 1.2;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .character-card h3 {
        font-size: 0.8em;
        line-height: 1.25;
    }
}

.character-card.selected h3 {
    color: #CE1126;
    font-weight: 700;
}

/* Buttons */
.btn {
    padding: 16px 32px;
    border: none;
    border-radius: 12px;
    font-family: 'Orbitron', 'Russo One', sans-serif;
    font-size: clamp(1em, 4vw, 1.1em);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
    min-height: 48px; /* Mobile touch target */
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, #CE1126 0%, #a00e1e 100%);
    color: white;
    border: 2px solid #CE1126;
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, #e0132a 0%, #CE1126 100%);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(206,17,38,0.4);
}

.btn-primary:active {
    transform: translateY(-1px) scale(0.98);
}

.btn-secondary {
    background: linear-gradient(135deg, #002868 0%, #001d4d 100%);
    color: white;
    border: 2px solid #002868;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: linear-gradient(135deg, #003080 0%, #002868 100%);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(0,40,104,0.4);
}

.btn-secondary:active {
    transform: translateY(-1px) scale(0.98);
}

.btn-small {
    padding: 12px 24px;
    font-size: clamp(0.85em, 3.5vw, 0.95em);
    min-height: 44px;
}

@media (max-width: 480px) {
    .btn {
        padding: 14px 28px;
        font-size: 0.95em;
    }
}

/* Game Screen */
.game-header {
    background: linear-gradient(135deg, #FFFFFF 0%, #f8f9fa 100%);
    border-radius: 24px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 
        0 8px 32px rgba(0,40,104,0.15),
        0 2px 8px rgba(0,0,0,0.08),
        inset 0 1px 0 rgba(255,255,255,0.9);
    border: 2px solid rgba(0,40,104,0.1);
    position: relative;
    overflow: hidden;
    animation: slideIn 0.5s ease-out;
}

.game-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #CE1126 0%, #002868 50%, #CE1126 100%);
}

@media (max-width: 768px) {
    .game-header {
        padding: 12px 16px;
        border-radius: 16px;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    .game-header {
        padding: 10px 12px;
        border-radius: 12px;
        margin-bottom: 10px;
    }
}

.player-info {
    display: grid;
    grid-template-columns: minmax(250px, 1fr) auto minmax(250px, 1fr);
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .player-info {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    .player-info {
        gap: 8px;
        margin-bottom: 10px;
    }
}

.player {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-left {
    justify-content: flex-start;
}

.player-right {
    justify-content: flex-end;
    flex-direction: row-reverse;
}

@media (max-width: 768px) {
    .player-left,
    .player-right {
        justify-content: center;
        flex-direction: row;
    }
}

.player-avatar-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #FFFFFF;
    box-shadow: 
        0 4px 12px rgba(0,40,104,0.25),
        0 0 0 3px rgba(0,40,104,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #f8f9fa;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .player img {
        width: 48px;
        height: 48px;
        border-width: 2px;
    }
}

.player:hover img {
    transform: scale(1.05);
    box-shadow: 
        0 6px 16px rgba(0,40,104,0.35),
        0 0 0 3px rgba(206,17,38,0.2);
}

.player-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #CE1126;
    border: 3px solid #FFFFFF;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.3s;
}

.player.active .player-indicator {
    opacity: 1;
    animation: pulse-indicator 2s ease-in-out infinite;
}

@keyframes pulse-indicator {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.player-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

.player-name {
    font-family: 'Orbitron', 'Russo One', sans-serif;
    font-weight: 700;
    color: #002868;
    font-size: clamp(1em, 2.5vw, 1.2em);
    line-height: 1.2;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

@media (max-width: 480px) {
    .player-name {
        font-size: 0.9em;
    }
}

.player-label {
    font-size: clamp(0.75em, 2vw, 0.85em);
    color: rgba(0,40,104,0.6);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (max-width: 480px) {
    .player-label {
        font-size: 0.65em;
        display: none; /* Hide label on very small screens */
    }
}

.game-status-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 180px;
}

@media (max-width: 768px) {
    .game-status-wrapper {
        order: -1;
        width: 100%;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .game-status-wrapper {
        gap: 2px;
    }
}

.game-status {
    font-family: 'Orbitron', 'Russo One', sans-serif;
    font-size: clamp(1.1em, 3vw, 1.4em);
    font-weight: 900;
    color: #FFFFFF;
    text-align: center;
    padding: 12px 24px;
    background: linear-gradient(135deg, #CE1126 0%, #a00d1e 100%);
    border-radius: 16px;
    box-shadow: 
        0 4px 12px rgba(206,17,38,0.4),
        inset 0 1px 0 rgba(255,255,255,0.2),
        0 0 20px rgba(255, 215, 0, 0.3);
    min-width: 160px;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.3s;
    text-shadow: 
        2px 2px 0px rgba(0, 0, 0, 0.5),
        0 0 10px rgba(255, 255, 255, 0.3);
}

@media (max-width: 480px) {
    .game-status {
        font-size: 0.85em;
        padding: 8px 16px;
        min-width: 120px;
        border-radius: 12px;
        letter-spacing: 0.3px;
    }
}

.game-status:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 16px rgba(206,17,38,0.5),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.game-info-text {
    font-size: clamp(0.8em, 2vw, 0.9em);
    color: rgba(0,40,104,0.7);
    text-align: center;
    font-weight: 500;
    min-height: 20px;
}

@media (max-width: 480px) {
    .game-info-text {
        font-size: 0.7em;
        min-height: 16px;
    }
}

.game-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 16px;
    border-top: 1px solid rgba(0,40,104,0.1);
}

@media (max-width: 480px) {
    .game-actions {
        flex-direction: row;
        gap: 8px;
        padding-top: 10px;
    }
}

.btn-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #002868 0%, #001a4d 100%);
    color: #FFFFFF;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 12px rgba(0,40,104,0.3),
        inset 0 1px 0 rgba(255,255,255,0.1);
}

@media (max-width: 480px) {
    .btn-action {
        padding: 8px 14px;
        font-size: 0.8em;
        gap: 6px;
        border-radius: 10px;
    }
    
    /* Keep text visible for refresh button */
    #new-game-btn .btn-text {
        display: inline;
    }
}

.btn-action:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 16px rgba(0,40,104,0.4),
        inset 0 1px 0 rgba(255,255,255,0.1);
    background: linear-gradient(135deg, #003080 0%, #002060 100%);
}

.btn-action:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.2em;
    line-height: 1;
}

.btn-text {
    line-height: 1;
}

.game-board-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.move-history h3 {
    color: #002868;
    margin-bottom: 10px;
    font-size: 1em;
    border-bottom: 1px solid #CE1126;
    padding-bottom: 5px;
}

#move-history-list {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.85em;
}

.move-item {
    padding: 8px;
    font-size: 0.9em;
    line-height: 1.6;
    word-wrap: break-word;
}

.move-white {
    color: #002868; /* Costa Rican blue for white pieces */
    font-weight: 500;
}

.move-black {
    color: #CE1126; /* Costa Rican red for black pieces */
    font-weight: 500;
}

.game-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #CE1126;
}

#game-info-text {
    color: #666;
    font-size: 0.9em;
}

/* Modal - glasslike overlay and content */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,40,104,0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: linear-gradient(135deg, rgba(255,255,255,0.55) 0%, rgba(248,249,250,0.4) 100%);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    margin: auto;
    padding: 25px;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    position: relative;
    border: 1px solid rgba(255,255,255,0.5);
    box-shadow: 0 8px 32px rgba(0,40,104,0.25), inset 0 1px 0 rgba(255,255,255,0.6);
    animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 480px) {
    .modal-content {
        padding: 20px;
        border-radius: 15px;
        max-height: 95vh;
    }
}

.modal-subtitle {
    color: #666;
    margin: -8px 0 20px 0;
    font-size: 1em;
}

.game-mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}

.game-mode-buttons .btn {
    width: 100%;
    margin: 0;
    justify-content: center;
}

.close {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 32px;
    font-weight: bold;
    color: #CE1126;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(206,17,38,0.1);
    transition: all 0.3s;
    line-height: 1;
    touch-action: manipulation;
}

.close:hover,
.close:focus {
    color: white;
    background: #CE1126;
    transform: rotate(90deg) scale(1.1);
}

.close:active {
    transform: rotate(90deg) scale(0.95);
}

#share-link-input {
    width: 100%;
    padding: 14px;
    margin: 15px 0;
    border: 3px solid #002868;
    border-radius: 12px;
    font-size: clamp(0.9em, 4vw, 1em);
    transition: all 0.3s;
    background: white;
    font-family: 'Courier New', monospace;
    touch-action: manipulation;
}

#share-link-input:focus {
    outline: none;
    border-color: #CE1126;
    box-shadow: 0 0 0 4px rgba(206,17,38,0.15), 0 4px 12px rgba(206,17,38,0.2);
    transform: scale(1.02);
}

@media (max-width: 480px) {
    #share-link-input {
        padding: 12px;
        font-size: 0.85em;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .screen {
        padding: 10px 0;
    }
    
    h1 {
        margin-bottom: 20px;
        font-size: clamp(1.7em, 8.5vw, 3em);
        line-height: 1.2;
    }
}

@media (max-width: 360px) {
    .screen {
        padding: 5px 0;
    }
    
    .container {
        padding: 6px;
    }
    
    h1 {
        margin-bottom: 12px;
        font-size: 1.6em;
    }
    
    .character-card {
        padding: 10px 8px;
        border-radius: 12px;
        min-height: 120px;
        border-width: 2.5px;
    }
}

@media (min-width: 361px) and (max-width: 480px) {
    .screen {
        padding: 5px 0;
    }
    
    .container {
        padding: 8px;
    }
    
    h1 {
        margin-bottom: 15px;
        font-size: clamp(1.5em, 10vw, 2.4em);
        letter-spacing: 2px;
        line-height: 1.1;
        font-size: 1.8em;
    }
    
    .character-card {
        padding: 12px 10px;
        border-radius: 15px;
        min-height: 130px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .character-card {
        padding: 14px 12px;
        min-height: 140px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .character-card:hover {
        transform: none;
    }
    
    .character-card:active {
        transform: scale(0.92);
    }
    
    .character-card.selected:active {
        transform: scale(0.98);
    }
    
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.95);
    }
    
    /* Ensure minimum touch target size (44x44px recommended) */
    .character-card {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Waiting Screen Styles */
.waiting-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 40px 20px;
    text-align: center;
    animation: slideIn 0.5s ease-out;
}

.waiting-header {
    margin-bottom: 40px;
}

.waiting-subtitle {
    color: white;
    font-size: clamp(1em, 3vw, 1.2em);
    margin-top: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    font-weight: 500;
}

.share-section {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 249, 250, 0.95) 100%);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 
        0 8px 32px rgba(0, 40, 104, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    border: 3px solid rgba(0, 40, 104, 0.7);
    backdrop-filter: blur(10px);
}

.share-link-container {
    margin-bottom: 20px;
}

.share-link-container label {
    display: block;
    font-family: 'Orbitron', 'Russo One', sans-serif;
    font-weight: 700;
    color: #002868;
    margin-bottom: 12px;
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.link-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

#waiting-share-link {
    flex: 1;
    padding: 14px 18px;
    border: 3px solid #002868;
    border-radius: 12px;
    font-size: clamp(0.9em, 3vw, 1em);
    font-family: 'Courier New', monospace;
    background: white;
    color: #002868;
    transition: all 0.3s;
}

#waiting-share-link:focus {
    outline: none;
    border-color: #CE1126;
    box-shadow: 0 0 0 4px rgba(206, 17, 38, 0.15), 0 4px 12px rgba(206, 17, 38, 0.2);
}

.btn-copy {
    white-space: nowrap;
    min-width: 120px;
}

.share-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.waiting-status {
    margin: 40px 0;
    padding: 30px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #FFD700;
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.status-text {
    color: white;
    font-size: clamp(1em, 3vw, 1.2em);
    font-weight: 600;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin: 0;
}

.waiting-actions {
    margin-top: 30px;
}

@media (max-width: 768px) {
    .waiting-content {
        padding: 30px 15px;
    }
    
    .share-section {
        padding: 20px;
    }
    
    .link-input-wrapper {
        flex-direction: column;
    }
    
    .btn-copy {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .waiting-content {
        padding: 20px 10px;
    }
    
    .share-section {
        padding: 15px;
        border-radius: 15px;
    }
    
    .waiting-status {
        padding: 20px;
    }
    
    .loading-spinner {
        width: 40px;
        height: 40px;
        margin-bottom: 15px;
    }
}

/* Landscape orientation optimizations for mobile */
@media (orientation: landscape) and (max-height: 500px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .character-card {
        padding: 8px;
        min-height: 110px;
    }
    
    .character-card img {
        width: 60px;
        height: 60px;
        margin-bottom: 6px;
    }
    
    .character-card h3 {
        font-size: 0.7em;
    }
    
    h1 {
        margin-bottom: 10px;
        font-size: 1.5em;
    }
    
    .waiting-content {
        padding: 20px 15px;
    }
}
