/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(145deg, #d4e4d1 0%, #b8d4b0 50%, #a8c8a0 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    user-select: none;
    overflow: hidden;
}

/* ========== SCREENS ========== */
.screen {
    display: none;
    width: 100%;
    max-width: 500px;
    padding: 20px;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: scale(1);
    animation: fadeInScale 0.25s ease-out;
}

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(0.92);
    }
    60% {
        opacity: 1;
        transform: scale(1.02);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========== BUTTONS ========== */
.btn {
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
                background 0.2s ease-out,
                box-shadow 0.2s ease-out;
    min-width: 200px;
    box-shadow:
        0 4px 8px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow:
        0 6px 16px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn:active {
    transform: scale(0.97) translateY(0);
    box-shadow:
        0 2px 4px rgba(0,0,0,0.15),
        inset 0 1px 2px rgba(0,0,0,0.1);
}

.btn-primary {
    background: linear-gradient(to bottom, #85b87a, #6b9a60);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.btn-primary:hover {
    background: linear-gradient(to bottom, #7dad71, #5f8a55);
}

.btn-secondary {
    background: linear-gradient(to bottom, #b8a090, #96806f);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.btn-secondary:hover {
    background: linear-gradient(to bottom, #a69080, #877060);
}

.btn-danger {
    background: linear-gradient(to bottom, #e85a4a, #c0392b);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.btn-danger:hover {
    background: linear-gradient(to bottom, #d64a3a, #a82a1d);
}

.icon-btn {
    background: rgba(255,255,255,0.5);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 10px;
    border-radius: 10px;
    transition: background 0.2s, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.icon-btn:hover {
    background: rgba(255,255,255,0.7);
    transform: scale(1.08);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.icon-btn:active {
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ========== HOME SCREEN ========== */
.home-screen {
    gap: 20px;
    justify-content: center;
    min-height: 100vh;
}

.home-title {
    font-size: 2.5rem;
    color: #5a6f52;
    font-weight: 700;
    text-align: center;
}

.home-pig {
    font-size: 6rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-12px) scale(1.05); }
    50% { transform: translateY(-14px) scale(1.02); }
    70% { transform: translateY(-8px) scale(1.03); }
}

.high-score-display {
    margin-top: 20px;
    font-size: 1.1rem;
    color: #5a6f52;
    display: flex;
    gap: 8px;
}

#high-score {
    font-weight: 700;
}

/* ========== GAME SCREEN ========== */
.game-screen {
    gap: 15px;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.header-buttons {
    display: flex;
    gap: 5px;
}

.score-container {
    background: linear-gradient(to bottom, #7dad71, #5f8a55);
    padding: 10px 16px;
    border-radius: 10px;
    text-align: center;
    min-width: 85px;
    box-shadow:
        0 3px 6px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.15);
}

.score-label {
    font-size: 0.7rem;
    color: #eee4da;
    text-transform: uppercase;
    font-weight: 600;
}

.score-value {
    font-size: 1.3rem;
    color: white;
    font-weight: 700;
}

/* ========== GAME BOARD ========== */
.board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 400px;
    background: #8b7355;
    border-radius: 16px;
    padding: 12px;
    box-shadow:
        0 8px 24px rgba(80, 60, 40, 0.35),
        0 4px 8px rgba(80, 60, 40, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(110, 85, 60, 0.6);
}

/* Board base shadow for depth/thickness illusion */
.board-container::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 4px;
    right: 4px;
    height: 8px;
    background: linear-gradient(to bottom, rgba(60, 45, 30, 0.4), transparent);
    border-radius: 0 0 16px 16px;
    z-index: -1;
}

.grid-background {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.cell {
    background: rgba(200, 220, 195, 0.35);
    border-radius: 10px;
    box-shadow:
        inset 0 2px 4px rgba(60, 45, 30, 0.25),
        inset 0 1px 2px rgba(60, 45, 30, 0.15);
}

.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    padding: 12px;
}

/* ========== TILES ========== */
.tile {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    border-radius: 10px;
    text-align: center;
    padding: 4px;
    overflow: hidden;
    /* Depth: soft drop shadow for elevation */
    box-shadow:
        0 3px 6px rgba(60, 45, 30, 0.2),
        0 1px 3px rgba(60, 45, 30, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
    /* Subtle border for definition */
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.tile-image {
    width: 85%;
    height: auto;
    max-height: 75%;
    object-fit: contain;
    pointer-events: none;
}

.tile-name {
    font-size: 0.6rem;
    line-height: 1.1;
    word-wrap: break-word;
    max-width: 100%;
}

.tile.new {
    animation: appear 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tile.merged {
    animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    70% {
        opacity: 1;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    40% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Tile text colors */
.tile-2, .tile-4, .tile-8, .tile-16, .tile-32 { color: #5a4a3a; }
.tile-64, .tile-128, .tile-256, .tile-512 { color: #fff; }
.tile-1024, .tile-2048 { color: #fff; }
.tile-4096, .tile-8192, .tile-16384, .tile-32768 { color: #fff; }
.tile-65536 { color: #fff; }
.tile-131072 {
    background: linear-gradient(135deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b59b6) !important;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.5), 0 2px 4px rgba(0,0,0,0.3);
}

/* Name sizes based on pig name length */
.tile-256 .tile-name,
.tile-2048 .tile-name,
.tile-4096 .tile-name,
.tile-8192 .tile-name,
.tile-16384 .tile-name,
.tile-32768 .tile-name,
.tile-65536 .tile-name,
.tile-131072 .tile-name {
    font-size: 0.5rem;
}

.instructions {
    color: #5a6f52;
    font-size: 0.85rem;
    text-align: center;
}

.feedback-link {
    color: #8a9a82;
    font-size: 0.85rem;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s;
    margin-top: 5px;
}

.feedback-link:hover {
    color: #5a6f52;
}

/* ========== OVERLAYS & MODALS ========== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: background 0.2s ease-out;
}

.overlay.active {
    display: flex;
    background: rgba(0,0,0,0.5);
    animation: overlayFadeIn 0.2s ease-out;
}

@keyframes overlayFadeIn {
    0% { background: rgba(0,0,0,0); }
    100% { background: rgba(0,0,0,0.5); }
}

.modal {
    background: linear-gradient(to bottom, #fdfcf8, #f5f2e8);
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    max-width: 300px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 15px;
    transform: scale(0.9);
    opacity: 0;
    animation: modalSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    box-shadow:
        0 12px 32px rgba(0,0,0,0.25),
        0 4px 12px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.5);
    border: 1px solid rgba(0,0,0,0.05);
}

@keyframes modalSlideIn {
    0% {
        transform: scale(0.9) translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal h2 {
    color: #5a6f52;
    font-size: 1.5rem;
}

.modal-text {
    color: #6b7d63;
    font-size: 1rem;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons .btn {
    min-width: 100px;
    padding: 12px 20px;
    font-size: 1rem;
}

.modal-subtext {
    color: #8a9a82;
    font-size: 0.85rem;
    font-style: italic;
}

/* ========== FEEDBACK MODAL ========== */
.feedback-modal {
    position: relative;
    max-width: 340px;
}

.feedback-modal h2 {
    margin-bottom: 5px;
}

.feedback-question {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.feedback-question label {
    font-size: 0.95rem;
    color: #5a6f52;
    font-weight: 600;
}

.feedback-input {
    width: 100%;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    border: 2px solid rgba(90, 111, 82, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.8);
    color: #5a6f52;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.feedback-input:focus {
    border-color: #85b87a;
    box-shadow: 0 2px 8px rgba(133, 184, 122, 0.25);
}

.feedback-input::placeholder {
    color: #8a9a82;
    font-size: 0.85rem;
}

.feedback-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    border: 2px solid rgba(90, 111, 82, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.8);
    color: #5a6f52;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.feedback-textarea:focus {
    border-color: #85b87a;
    box-shadow: 0 2px 8px rgba(133, 184, 122, 0.25);
}

.feedback-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.feedback-buttons .btn {
    flex: 1;
    min-width: auto;
    padding: 12px 16px;
    font-size: 0.95rem;
}

/* ========== GAME OVER SCREEN ========== */
.gameover-screen, .win-screen {
    gap: 20px;
    justify-content: center;
    min-height: 100vh;
}

.gameover-screen h2, .win-screen h2 {
    font-size: 2rem;
    color: #5a6f52;
}

.final-score {
    font-size: 1.3rem;
    color: #6b7d63;
    display: flex;
    gap: 10px;
}

#final-score {
    font-weight: 700;
    color: #5a6f52;
}

.highest-pig {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #6b7d63;
}

.pig-badge {
    padding: 15px 25px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    box-shadow:
        0 4px 8px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.new-pig-unlocked {
    background: linear-gradient(to bottom, #e8a68e, #d88068);
    padding: 20px;
    border-radius: 14px;
    text-align: center;
    animation: celebrate 0.5s ease-out;
    box-shadow:
        0 6px 16px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.new-pig-unlocked p {
    color: #fff;
    font-weight: 600;
    margin-bottom: 10px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

@keyframes celebrate {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ========== WIN SCREEN ========== */
.win-message {
    font-size: 1.2rem;
    color: #6b7d63;
}

.lion-pig-badge {
    background: linear-gradient(135deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b59b6);
    padding: 20px 30px;
    border-radius: 14px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.5), 0 2px 4px rgba(0,0,0,0.2);
    animation: rainbow 2s infinite;
    box-shadow:
        0 8px 20px rgba(0,0,0,0.25),
        inset 0 1px 0 rgba(255,255,255,0.3);
}

@keyframes rainbow {
    0%, 100% { filter: hue-rotate(0deg); }
    50% { filter: hue-rotate(30deg); }
}

.win-submessage {
    font-size: 3rem;
}

/* ========== COLLECTION SCREEN ========== */
.collection-screen {
    gap: 20px;
    min-height: auto;
    padding-top: 20px;
    padding-bottom: 40px;
    overflow-y: auto;
    max-height: 100vh;
}

.collection-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.collection-header h2 {
    font-size: 1.5rem;
    color: #5a6f52;
}

.collection-progress {
    font-size: 1rem;
    color: #6b7d63;
    font-weight: 600;
}

.badge-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 400px;
}

.badge-item {
    aspect-ratio: 1;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
    text-align: center;
    box-shadow:
        0 3px 8px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
    border: 1px solid rgba(0,0,0,0.05);
    transition: transform 0.15s, box-shadow 0.15s;
}

.badge-item:hover {
    transform: translateY(-2px);
    box-shadow:
        0 5px 12px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.badge-item.locked {
    background: linear-gradient(to bottom, #d0d0d0, #b8b8b8);
    color: #888;
}

.badge-item.locked .badge-name {
    color: #888;
}

.badge-item .badge-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.badge-item .badge-image {
    width: 60%;
    height: auto;
    max-height: 60%;
    object-fit: contain;
    margin-bottom: 5px;
}

.badge-item .badge-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    word-wrap: break-word;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.badge-item.unlocked {
    color: #fff;
}

/* ========== MOBILE RESPONSIVENESS ========== */
@media (max-width: 520px) {
    .home-title {
        font-size: 2rem;
    }

    .home-pig {
        font-size: 4rem;
    }

    .btn {
        padding: 12px 30px;
        font-size: 1rem;
        min-width: 160px;
    }

    .board-container {
        padding: 8px;
    }

    .grid-background {
        gap: 8px;
    }

    .tile-container {
        gap: 8px;
        padding: 8px;
    }

    .tile {
        padding: 2px;
    }

    .tile-image {
        width: 55%;
        max-height: 55%;
    }

    .tile-name {
        font-size: 0.5rem;
    }

    .tile-256 .tile-name,
    .tile-2048 .tile-name,
    .tile-4096 .tile-name,
    .tile-8192 .tile-name,
    .tile-16384 .tile-name,
    .tile-32768 .tile-name,
    .tile-65536 .tile-name,
    .tile-131072 .tile-name {
        font-size: 0.4rem;
    }

    .icon-btn {
        font-size: 1.2rem;
        padding: 6px;
    }

    .badge-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .badge-item .badge-icon {
        font-size: 1.5rem;
    }

    .badge-item .badge-name {
        font-size: 0.6rem;
    }

    .lang-toggle {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .lang-toggle-header {
        padding: 6px 8px;
        font-size: 0.7rem;
    }
}

/* ========== LANGUAGE TOGGLE ========== */
.lang-toggle {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #5a6f52;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 100;
}

.lang-toggle:hover {
    background: rgba(255, 255, 255, 0.7);
    transform: scale(1.05);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.lang-toggle:active {
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Language toggle in header (game screen, collection screen) */
.lang-toggle-header {
    position: static;
    padding: 8px 10px;
    font-size: 0.8rem;
}

/* Language toggle in modal (pause overlay) */
.lang-toggle-modal {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 6px 10px;
    font-size: 0.75rem;
}

/* Collection header right side container for progress + lang toggle */
.collection-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
