/* iOS Safe Area Support */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
}

body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    /* Adjust for safe areas */
    min-height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    background-color: #18181b; /* zinc-900 */
    color: #d4d4d8; /* zinc-300 */
    overscroll-behavior: none;
    padding: 0;
    margin: 0;
    touch-action: manipulation;
    padding-top: 0.5rem;
}

.game-container {
    width: 100vw;
    height: 100vh;
    /* Adjust for safe areas */
    height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    max-width: 100vw;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0;
    margin: 0;
}

.game-wrapper {
    width: 100%;
    max-width: 450px;
    height: auto;
    aspect-ratio: 1/1.4;
    background-color: #27272a; /* zinc-800 */
    border-radius: 0.75rem;
    border: 1px solid #3f3f46; /* zinc-700 */
    padding: 1.25rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    margin: 1rem;
}

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

.title-area {
    position: relative;
}

.title-area h1 {
    font-size: 2.25rem;
    font-weight: 300;
    letter-spacing: -0.025em;
    color: #f4f4f5; /* zinc-100 */
}

.title-area h1 span {
    font-weight: 700;
}

.title-underline {
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 4rem;
    height: 2px;
    background-color: #65a39a; /* pastel teal */
}

.game-controls {
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff; /* white text for all buttons */
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid;
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn svg {
    width: 18px;
    height: 18px;
}

/* Restart Button - Teal */
#startTetrisBtn {
    background-color: #0d9488; /* teal-600 */
    border-color: #14b8a6; /* teal-500 */
}

#startTetrisBtn:hover {
    background-color: #0f766e; /* teal-700 */
}

/* Pause Button - Slate */
#pauseTetrisBtn {
    background-color: #475569; /* slate-600 */
    border-color: #64748b; /* slate-500 */
}

#pauseTetrisBtn:hover {
    background-color: #334155; /* slate-700 */
}

/* Help Button - Zinc */
#howToBtn {
    background-color: #52525b; /* zinc-600 */
    border-color: #71717a; /* zinc-500 */
}

#howToBtn:hover {
    background-color: #3f3f46; /* zinc-700 */
}

.game-info {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.next-number-container, .score-container {
    flex: 1;
    background-color: #3f3f46; /* zinc-700 */
    border-radius: 0.375rem;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #a1a1aa; /* zinc-400 */
    margin-bottom: 0.25rem;
}

.next-number {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto;
    border-radius: 0.375rem;
    font-size: 1.25rem;
    font-weight: 500;
    color: #f4f4f5; /* zinc-100 */
    background-color: #3f3f46; /* zinc-700 - fallback color */
}

/* Apply number colors to next-number */
.next-number.number-2 {
    background-color: #2dd4bf; /* bright teal */
}

.next-number.number-3 {
    background-color: #c084fc; /* bright purple */
}

.next-number.number-4 {
    background-color: #fb923c; /* bright orange */
}

.next-number.number-5 {
    background-color: #ec4899; /* bright pink */
}

.next-number.number-6 {
    background-color: #3b82f6; /* bright blue */
}

.next-number.number-7 {
    background-color: #ef4444; /* bright red */
}

.next-number.number-8 {
    background-color: #22c55e; /* bright green */
}

.next-number.number-9 {
    background-color: #facc15; /* bright yellow */
}

.score {
    font-size: 1.5rem;
    font-weight: 300;
    color: #f4f4f5; /* zinc-100 */
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.tetris-board-container {
    margin-bottom: 1.5rem;
    width: 100%;
    aspect-ratio: 1/1;
    position: relative;
}

.tetris-board {
    display: grid;
    gap: 0.5rem;
    padding: 0.75rem;
    background-color: #18181b; /* zinc-900 */
    border-radius: 0.375rem;
    border: 1px solid #3f3f46; /* zinc-700 */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.tetris-cell {
    aspect-ratio: 1/1;
    border-radius: 0.375rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.8rem, 2vw, 1.25rem);
    font-weight: 800;
    background-color: #27272a; /* zinc-800 */
    border: 1px solid #3f3f46; /* zinc-700 */
    color: #f4f4f5; /* zinc-100 */
    transition: background-color 0.15s ease-out, transform 0.1s ease-out;
    position: relative;
    width: 100%;
    height: 100%;
    will-change: background-color, transform;
}

.tetris-cell.active {
    animation: none;
    transition: background-color 0.15s ease-out, transform 0.1s ease-out;
    transform: scale(1.02);
}

.tetris-cell.filled {
    color: #f4f4f5; /* zinc-100 */
    border: none;
    transition: background-color 0.15s ease-out;
}

/* Number-specific colors */
.tetris-cell.number-2,
.tetris-cell.active.number-2 {
    background-color: #2dd4bf; /* bright teal */
}

.tetris-cell.number-3,
.tetris-cell.active.number-3 {
    background-color: #c084fc; /* bright purple */
}

.tetris-cell.number-4,
.tetris-cell.active.number-4 {
    background-color: #fb923c; /* bright orange */
}

.tetris-cell.number-5,
.tetris-cell.active.number-5 {
    background-color: #ec4899; /* bright pink */
}

.tetris-cell.number-6,
.tetris-cell.active.number-6 {
    background-color: #3b82f6; /* bright blue */
}

.tetris-cell.number-7,
.tetris-cell.active.number-7 {
    background-color: #ef4444; /* bright red */
}

.tetris-cell.number-8,
.tetris-cell.active.number-8 {
    background-color: #22c55e; /* bright green */
}

.tetris-cell.number-9,
.tetris-cell.active.number-9 {
    background-color: #facc15; /* bright yellow */
}

.game-footer {
    text-align: center;
}

.tap-instruction {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #71717a; /* zinc-500 */
    font-weight: 500;
}

/* Animation keyframes */
@keyframes appearAnimation {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes clearAnimation {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(0.9);
        opacity: 0.5;
    }
    100% {
        transform: scale(0.8);
        opacity: 0;
    }
}

@keyframes combineAnimation {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        filter: brightness(1.2);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes fallAnimation {
    0% {
        transform: translateY(-100%);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.tetris-cell.clearing {
    animation: clearAnimation 0.15s ease-out forwards;
}

.tetris-cell.combined {
    animation: combineAnimation 0.25s ease-out forwards;
}

.tetris-cell.falling {
    animation: fallAnimation 0.15s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* Visual indicator for cell movement */
.tetris-cell.visual-move {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

.modal-content {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: #27272a; /* zinc-800 */
    padding: 2rem;
    border-radius: 0.75rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    max-height: calc(90vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    color: #d4d4d8; /* zinc-300 */
    border: 1px solid #3f3f46; /* zinc-700 */
}

.close-modal {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    color: #a1a1aa; /* zinc-400 */
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: #3f3f46; /* zinc-700 */
    border: none;
}

.close-modal:hover {
    background-color: #52525b; /* zinc-600 */
    color: #f4f4f5; /* zinc-100 */
}

.modal h2 {
    color: #f4f4f5; /* zinc-100 */
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    padding-right: 2.5rem;
}

.modal h3 {
    color: #d4d4d8; /* zinc-300 */
    font-size: 1.125rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.modal-body {
    color: #a1a1aa; /* zinc-400 */
}

.modal-body ul {
    list-style: none;
    padding-left: 0;
}

.modal-body li {
    margin-bottom: 0.75rem;
    line-height: 1.5;
    padding-left: 1.25rem;
    position: relative;
}

.modal-body li:before {
    content: "•";
    position: absolute;
    left: 0;
    color: #65a39a; /* pastel teal */
}

/* Level up and win messages */
.level-up-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #65a39a; /* pastel teal */
    color: #f4f4f5; /* zinc-100 */
    padding: 1.5rem 3rem;
    border-radius: 0.75rem;
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    margin-top: var(--safe-area-inset-top);
    margin-bottom: var(--safe-area-inset-bottom);
    margin-left: var(--safe-area-inset-left);
    margin-right: var(--safe-area-inset-right);
}

.level-up-message.fade-out {
    animation: fadeOut 1s ease-in forwards;
}

.win-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #65a39a; /* pastel teal */
    color: #f4f4f5; /* zinc-100 */
    padding: 2.5rem 3.5rem;
    border-radius: 1rem;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    margin-top: var(--safe-area-inset-top);
    margin-bottom: var(--safe-area-inset-bottom);
    margin-left: var(--safe-area-inset-left);
    margin-right: var(--safe-area-inset-right);
}

.win-message h2 {
    font-size: 2rem;
    margin-bottom: 1.25rem;
    font-weight: 700;
}

.win-message p {
    font-size: 1.125rem;
    margin: 0.75rem 0;
    opacity: 0.9;
}

.win-message button {
    margin-top: 1.5rem;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    background-color: #f4f4f5; /* zinc-100 */
    color: #65a39a; /* pastel teal */
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.win-message button:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

@keyframes popIn {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes fadeOut {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Mobile and Tablet Full Screen Styles */
@media (max-width: 768px) {
    html, body {
        width: 100%;
        height: 100%;
        overflow: hidden;
        position: fixed;
        margin: 0;
        padding: 0;
    }

    body {
        display: flex;
        justify-content: center;
        align-items: flex-start;
        min-height: 100vh;
        /* Adjust for safe areas */
        min-height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
        background-color: #18181b; /* zinc-900 */
        color: #d4d4d8; /* zinc-300 */
        overscroll-behavior: none;
        padding: 0;
        margin: 0;
        touch-action: manipulation;
    }

    .game-container {
        width: 100vw;
        height: 100vh;
        /* Adjust for safe areas */
        height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
        max-width: 100vw;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        padding: 0;
        margin: 0;
    }

    .game-wrapper {
        width: 100vw;
        height: 100vh;
        /* Adjust for safe areas */
        height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
        max-width: 100vw;
        background-color: #27272a; /* zinc-800 */
        border-radius: 0;
        border: none;
        padding: 1rem;
        /* Add safe area padding - reduced for iOS compatibility */
        padding-top: max(1rem, var(--safe-area-inset-top));
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
        box-shadow: none;
        position: relative;
        margin: 0;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .game-header {
        flex-shrink: 0;
        margin-bottom: 0.75rem;
    }

    .game-info {
        flex-shrink: 0;
        margin-bottom: 1rem;
    }

    .tetris-board-container {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 1rem;
        width: 100%;
        max-height: calc(100vh - 200px - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    }

    .tetris-board {
        width: 100%;
        height: 100%;
        /* Fix width calculation to match game-info width */
        max-width: calc(100vw - 2rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
        max-height: calc(100vw - 2rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
        aspect-ratio: 1/1;
    }

    .game-footer {
        flex-shrink: 0;
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-wrapper {
        padding: 0.75rem;
        /* Add safe area padding for small screens - iOS compatible */
        padding-top: max(1rem, var(--safe-area-inset-top));
        padding-bottom: calc(0.75rem + var(--safe-area-inset-bottom));
        padding-left: calc(0.75rem + var(--safe-area-inset-left));
        padding-right: calc(0.75rem + var(--safe-area-inset-right));
    }

    .title-area h1 {
        font-size: 1.75rem;
    }

    .control-btn {
        width: 2.25rem;
        height: 2.25rem;
    }

    .control-btn svg {
        width: 16px;
        height: 16px;
    }

    .game-info {
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .next-number-container, .score-container {
        padding: 0.5rem;
    }

    .info-label {
        font-size: 0.7rem;
    }

    .score {
        font-size: 1.25rem;
    }

    .tetris-board {
        gap: 0.35rem;
        padding: 0.5rem;
        /* Fix width calculation for small screens */
        max-width: calc(100vw - 1.5rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
        max-height: calc(100vw - 1.5rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
    }

    .tetris-cell {
        font-size: 1.25rem;
        border-radius: 0.25rem;
    }

    .tap-instruction {
        font-size: 0.7rem;
    }

    .tetris-board-container {
        max-height: calc(100vh - 180px - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .game-wrapper {
        padding: 1rem;
        /* Add safe area padding for medium screens - iOS compatible */
        padding-top: max(1rem, var(--safe-area-inset-top));
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
    }

    .title-area h1 {
        font-size: 2rem;
    }

    .control-btn {
        width: 2.5rem;
        height: 2.5rem;
    }

    .control-btn svg {
        width: 17px;
        height: 17px;
    }

    .tetris-board {
        gap: 0.4rem;
        /* Fix width calculation for medium screens */
        max-width: calc(100vw - 2rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
        max-height: calc(100vw - 2rem - var(--safe-area-inset-left) - var(--safe-area-inset-right));
    }

    .tetris-cell {
        font-size: 1.5rem;
    }

    .tetris-board-container {
        max-height: calc(100vh - 220px - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    }
}

/* Desktop styles remain unchanged */
@media (min-width: 769px) {
    .game-container {
        width: 100%;
        height: 100%;
        max-width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0;
    }

    .game-wrapper {
        width: 100%;
        max-width: 450px;
        height: auto;
        aspect-ratio: 1/1.4;
        background-color: #27272a; /* zinc-800 */
        border-radius: 0.75rem;
        border: 1px solid #3f3f46; /* zinc-700 */
        padding: 1.25rem;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        position: relative;
        margin: 1rem;
    }
}

/* Portrait orientation adjustments */
@media (orientation: portrait) and (max-height: 800px) {
    .game-wrapper {
        aspect-ratio: 1/1.3;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .game-wrapper {
        aspect-ratio: 1.5/1;
        margin: 0.5rem;
        padding: 0.75rem;
    }

    .game-info {
        flex-direction: row;
        margin-bottom: 0.75rem;
    }

    .tetris-board-container {
        margin-bottom: 0.75rem;
    }
} 