:root {
    --tile-size: clamp(64px, 15vw, 72px);
    --gap-size: clamp(4px, 1.5vw, 8px);
    --pink-500: #ec4899;
    --teal-500: #14b8a6;
    --indigo-500: #6366f1;
    --cyan-500: #06b6d4;
    --purple-500: #a855f7;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-700: #374151;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow: hidden;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: white;
    color: #1f2937;
    line-height: 1.5;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.container {
    width: fit-content;
    margin: 0;
    padding: 0.5rem;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.25);
    max-width: min(calc(4 * var(--tile-size) + 3 * var(--gap-size) + 2rem), 95vw);
}

.holder {
    display: flex;
    flex-direction: column;
    width: fit-content;
    max-width: 95vw;
    margin: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    flex-direction: row;
    gap: 1rem;
    border-bottom: 1px solid gray;
    width: 100vw;
    padding: 0.5rem 1rem;
    background: white;
    z-index: 10;
    font-family: "Righteous", sans-serif;
}

h1 { 
    font-size: 1.5rem;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-direction: column;
    gap: 0.5rem;
}

#nextGoal, #attemptCounter {
    font-size: 0.875rem;
    color: #374151;
}

.controls {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    background: white;
    color: var(--gray-700);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s;
    min-height: 44px;
}

#helpBtn {
    width: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 0;
    font-family: "Righteous", sans-serif;
}

#helpBtn strong {
    margin: 0 auto;
    width: 100%;
}

.control-btn:hover {
    background: var(--gray-200);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.game-layout {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    align-items: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(auto, var(--tile-size)));
    grid-template-rows: repeat(5, minmax(auto, var(--tile-size)));
    gap: var(--gap-size);
    justify-content: center;
    width: 100%;
    max-width: calc(4 * var(--tile-size) + 3 * var(--gap-size));
}

.tile {
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: none;
    border-radius: 0.5rem;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 44px;
    perspective: 1000px;
}

.tile-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease-in-out;
    transform-style: preserve-3d;
}

.tile.flipping .tile-inner {
    transform: rotateY(180deg);
}

.tile-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 0.5rem;
}

.tile-face-front {
    transform: rotateY(0deg);
}

.tile-face-back {
    transform: rotateY(180deg);
}

.tile-image {
    width: 100%;
    height: 100%;
    object-fit: fill;
    border-radius: 0.5rem;
}

.tile.valid-move:hover {
    outline: 2px solid #3b82f6;
}

.tile.current {
    outline: 4px solid #b4ed81;
    outline-offset: 2px;
}

.tile.revealed {
    background-color: var(--revealed-color, var(--gray-200));
}

.power-bubbles {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
}

.power-bubble {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-size: 0.875rem;
    min-height: 44px;
}

.power-bubble.hidden {
    display: none;
}

.power-bubble.pink { background-color: var(--pink-500); }
.power-bubble.teal { background-color: var(--teal-500); }
.power-bubble.indigo { background-color: var(--indigo-500); }
.power-bubble.cyan { background-color: var(--cyan-500); }
.power-bubble.purple { background-color: var(--purple-500); }

.game-message {
    text-align: center;
    margin-top: 1rem;
    color: var(--gray-700);
}

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

@keyframes flipBack {
    0% { transform: rotateY(180deg); }
    100% { transform: rotateY(0deg); }
}

.fade-in {
    animation: fadeIn 0.2s ease-in;
}

.tile.resetting .tile-inner {
    animation: flipBack 0.4s ease-in-out;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 0;
    box-sizing: border-box;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    animation: slideIn 0.3s ease-out;
    width: min(700px, 100%);
    height: 100%;
    max-height: 90vh;
    margin: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#victoryModal .modal-content {
    max-height: min(400px, 90vh);
    justify-content: center;
}

#victoryModal .modal-body {
    flex-grow: 0;
}

#victoryModal .modal-header {
    margin-bottom: 2rem;
}

#victoryModal .modal-footer {
    margin-top: 2rem;
}

.modal-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    text-align: center;
}

.modal-header h2 {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    margin: 0;
    color: #374151;
    width: 100%;
    font-family: "Righteous", sans-serif;
}

.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 0.5rem;
    margin: 0 -0.5rem;
    width: 100%;
}

.help-content {
    padding: 0.25rem;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.tile-group {
    margin-bottom: 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

h3 {
    margin-bottom: 0.75rem;
    color: #374151;
    font-size: clamp(0.875rem, 2vw, 1rem);
    text-align: center;
    width: 100%;
    font-family: "Righteous", sans-serif;
}

.tiles-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    background-color: #f9fafb;
    border-radius: 0.5rem;
    width: 100%;
    box-sizing: border-box;
}

.tiles-row .tile-explanation {
    display: flex;
    gap: 0.5rem;
    margin: 0 auto;
    padding: 0;
    background: none;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 90%;
    box-sizing: border-box;
}

.two-column-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    width: 100%;
    box-sizing: border-box;
}

.tile-explanation {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    background-color: #f9fafb;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}

.tile-explanation .tile {
    min-width: clamp(24px, 6vw, 32px);
    min-height: clamp(24px, 6vw, 32px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    font-weight: bold;
    font-size: clamp(0.875rem, 2vw, 1rem);
    color: white;
    flex-shrink: 0;
}

.tile-explanation p {
    margin: 0 auto;
    line-height: 1.3;
    text-align: center;
    max-width: 90%;
}

.help-tile {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0 auto;
}

.help-tile img {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.modal-footer {
    flex-shrink: 0;
    margin-top: 1rem;
    text-align: center;
    border-top: 1px solid #e5e7eb;
    padding-top: 1rem;
    width: 100%;
}

.close-button {
    display: none;
}

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

@media (max-width: 480px) {
    :root {
        --tile-size: clamp(54px, 22vw, 80px);
    }

    .container {
        box-shadow: none;
    }

    /* .game-board {
        width: 90vw;
        grid-template-columns: repeat(4, minmax(auto, var(--tile-size)));
        grid-template-rows: repeat(5, minmax(auto, var(--tile-size)));
    } */

    .power-bubbles {
        padding: 0.25rem;
    }

    .power-bubble {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .control-btn {
        padding: 0.25rem 0.75rem;
        font-size: 0.75rem;
        min-width: 44px;
    }

    .modal {
        padding: 0;
    }

    .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    
    #victoryModal .modal-content {
        max-height: 100%;
    }

    .modal-body {
        padding: 0 0.25rem;
        margin: 0 -0.25rem;
    }

    .help-content {
        padding: 0;
    }

    .tiles-row {
        padding: 0.5rem;
    }

    .tile-explanation {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .help-tile img {
        width: 40px;
        height: 40px;
    }
}

@media (min-width: 640px) {
    header {
        padding: 0.5rem 5rem;
    }

    .game-info {
        flex-direction: row;
    }
}