* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    position: relative;
    width: 100%;
    min-height: 100vh;
}

/* Base Screen Layout */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

/* Telas normais - ficam invisíveis quando não ativas */
#menu-screen,
#create-screen,
#join-screen,
#tutorial-screen {
    opacity: 0;
    visibility: hidden;
}

#menu-screen.active,
#create-screen.active,
#join-screen.active,
#tutorial-screen.active {
    opacity: 1;
    visibility: visible;
}

/* Tela do jogo - fica visível quando ativa OU quando game-over está ativo */
#game-screen {
    opacity: 0;
    visibility: hidden;
}

#game-screen.active,
#game-screen.keep-visible {
    opacity: 1;
    visibility: visible;
}

/* Tela de Game Over - sempre visível para mostrar tabuleiro atrás */
#game-over-screen {
    opacity: 1;
    visibility: visible;
    transform: translateY(-100vh);
    transition: transform 0.3s ease;
    pointer-events: none;
}

#game-over-screen.active {
    transform: translateY(0);
    pointer-events: auto;
}

/* Menu Screen */
.menu-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 90%;
}

.menu-container h1 {
    font-size: 2.5rem;
    color: #000000;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.white-sheep {
    /* filter: ... */
}

.black-sheep {
    filter: grayscale(100%) brightness(0.5) hue-rotate(180deg);
}

.menu-container p {
    color: #718096;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.menu-btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(45deg, #48bb78, #38a169);
    color: white;
    box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
}

.menu-btn:hover:not(.disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(72, 187, 120, 0.4);
}

.menu-btn.disabled {
    background: #a0aec0;
    cursor: not-allowed;
    box-shadow: none;
}

/* Create/Join Screens */
.create-container,
.join-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    max-width: 450px;
    width: 90%;
}

.create-container h2,
.join-container h2 {
    color: #4a5568;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.game-code-container {
    margin: 1.5rem 0;
}

.game-code-container label {
    display: block;
    color: #718096;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#game-code {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2d3748;
    background: #f7fafc;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.copy-btn {
    background: #4299e1;
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: #3182ce;
    transform: scale(1.05);
}

.input-container {
    margin: 1.5rem 0;
}

.input-container label {
    display: block;
    color: #718096;
    margin-bottom: 0.5rem;
    font-weight: 600;
    text-align: left;
}

#join-code {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease;
}

#join-code:focus {
    border-color: #4299e1;
}

.create-buttons,
.join-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.game-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.game-btn:not(.secondary) {
    background: linear-gradient(45deg, #48bb78, #38a169);
    color: white;
    box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
}

.game-btn.secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.game-btn:hover {
    transform: translateY(-1px);
}

/* Game Screen */
.game-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
}

.game-header {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.player {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.player1 {
    color: #48bb78;
}

.player2 {
    color: #ed8936;
}

.player.active {
    background: rgba(255, 215, 0, 0.2);
    padding: 0.5rem;
    border-radius: 8px;
    border: 2px solid #ffd700;
}

.player-icon {
    font-size: 1.5rem;
}

.game-info {
    text-align: center;
}

#current-turn {
    font-size: 1.2rem;
    font-weight: bold;
    color: #2d3748;
}

#moves-count {
    color: #718096;
    font-size: 0.9rem;
}

/* Game Board */
.game-board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    max-width: min(80vw, 80vh);
    width: 100%;
    aspect-ratio: 1;
    perspective: 1000px;
}

.terrain {
    position: relative;
    background: linear-gradient(135deg, #68d391 0%, #48bb78 100%);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    transform-style: preserve-3d;
    border: 3px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.terrain::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.2));
    border-radius: 15px;
    z-index: -1;
}

.terrain:hover:not(.disabled) {
    transform: translateZ(10px) rotateX(5deg) rotateY(5deg);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.terrain.possible {
    border-color: #2d3748;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
    }

    50% {
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
    }
}

.terrain.disabled {
    background: linear-gradient(135deg, #a0aec0 0%, #718096 100%);
    cursor: not-allowed;
    opacity: 0.5;
}

.terrain.player1-start {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
}

.terrain.player2-start {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
}

/* Terrain Values */
.terrain.value-1 {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
}

.terrain.value-2 {
    background: linear-gradient(135deg, #9f7aea 0%, #805ad5 100%);
}

.terrain.value-3 {
    background: linear-gradient(135deg, #ed64a6 0%, #d53f8c 100%);
}

.terrain.value-4 {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
}

.terrain.current-player {
    border-color: #ffd700;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
    animation: currentPlayerPulse 2s infinite;
    transform: scale(1.05);
}

@keyframes currentPlayerPulse {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
        border-width: 3px;
    }

    50% {
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.9);
        border-width: 4px;
    }
}

/* Sheep */
.sheep {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    z-index: 10;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    transition: all 0.5s ease;
}

.sheep.white::before {
    content: '🐑';
}

.sheep.black::before {
    content: '🐑';
    filter: brightness(0.3);
}

/* Game Controls */
.game-controls {
    padding: 1rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
}

.control-btn {
    padding: 0.75rem 2rem;
    background: #f56565;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #e53e3e;
    transform: translateY(-1px);
}

/* Tutorial Screen */
.tutorial-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.tutorial-container h2 {
    text-align: center;
    color: #4a5568;
    margin-bottom: 2rem;
    font-size: 2rem;
}

.tutorial-content {
    text-align: left;
}

.tutorial-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: rgba(247, 250, 252, 0.8);
    border-radius: 12px;
    border-left: 4px solid #48bb78;
}

.tutorial-section h3 {
    color: #2d3748;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.tutorial-section p {
    color: #4a5568;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.tutorial-section ul {
    color: #4a5568;
    line-height: 1.8;
    padding-left: 1.5rem;
}

.tutorial-section li {
    margin-bottom: 0.5rem;
}

.board-example {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.mini-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    width: 200px;
    height: 200px;
}

.mini-terrain {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.mini-terrain.start1 {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
}

.mini-terrain.start2 {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
}

.mini-terrain.value-1 {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
}

.mini-terrain.value-2 {
    background: linear-gradient(135deg, #9f7aea 0%, #805ad5 100%);
}

.mini-terrain.value-3 {
    background: linear-gradient(135deg, #ed64a6 0%, #d53f8c 100%);
}

.mini-terrain.value-4 {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
}

.movement-rules {
    display: grid;
    gap: 0.5rem;
}

.rule {
    background: rgba(255, 255, 255, 0.7);
    padding: 0.75rem;
    border-radius: 8px;
    border-left: 3px solid #4299e1;
}

.terrain-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.terrain-badge.value-3 {
    background: linear-gradient(135deg, #ed64a6 0%, #d53f8c 100%);
}

.example-grid {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
    background: rgba(255, 255, 255, 0.5);
    padding: 1rem;
    border-radius: 8px;
}

.example-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.example-cell {
    font-size: 1.2rem;
    padding: 0.5rem;
}

.tutorial-buttons {
    text-align: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid #e2e8f0;
}

/* Game Over Screen Container - sem fundo para mostrar tabuleiro */

.game-over-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.15);
    /* Fundo bem transparente */
    backdrop-filter: blur(10px);
    /* Efeito de vidro fosco */
    border: 2px solid rgba(255, 255, 255, 0.2);
    /* Borda sutil */
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 90%;
}

.game-over-container h2 {
    font-size: 2rem;
    color: #2d3748;
    /* Cor mais escura para melhor contraste */
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.8);
    /* Sombra branca para destacar */
    font-weight: 700;
}

.game-over-container p {
    color: #4a5568;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
    font-weight: 600;
}

.game-over-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .player-info {
        flex-direction: column;
        gap: 1rem;
    }

    .game-board {
        max-width: 90vw;
    }

    .terrain {
        font-size: 1.2rem;
    }

    .sheep {
        font-size: 1.5rem;
    }

    .create-buttons,
    .join-buttons,
    .game-over-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {

    .menu-container,
    .create-container,
    .join-container,
    .game-over-container,
    .tutorial-container {
        padding: 1.5rem;
    }

    .game-over-container {
        backdrop-filter: blur(8px);
        /* Reduz o blur em telas menores */
    }

    .terrain {
        font-size: 1rem;
    }

    .sheep {
        font-size: 1.2rem;
    }

    .tutorial-container {
        max-height: 90vh;
    }

    .tutorial-section {
        padding: 1rem;
    }

    .mini-board {
        width: 150px;
        height: 150px;
    }

    .mini-terrain {
        font-size: 0.7rem;
    }
}

/* PWA Specific Styles */
.install-btn {
    background: linear-gradient(45deg, #667eea, #764ba2) !important;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
}

.install-btn:hover:not(.disabled) {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
}

.update-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    animation: slideInRight 0.3s ease;
}

.update-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.update-content span {
    color: #4a5568;
    font-weight: 600;
}

.update-content button {
    background: #48bb78;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.update-content button:hover {
    background: #38a169;
    transform: scale(1.05);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* PWA display mode adjustments */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .screen {
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

/* iOS PWA specific styles */
@supports (-webkit-touch-callout: none) {
    @media (display-mode: standalone) {

        .menu-container,
        .create-container,
        .join-container,
        .tutorial-container,
        .game-over-container {
            margin-top: 20px;
        }

        .game-over-container {
            backdrop-filter: blur(8px);
            /* Reduz o blur no iOS */
        }
    }
}