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

html {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 20px;
    overflow-x: hidden;
    position: fixed;
    width: 100%;
}

/* Native app environment detection */
.native-app,
.native-app body {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.native-app body {
    padding: 0 !important;
    /* Don't add safe area padding to body - let container handle it */
}

.native-app .hide-on-native {
    display: none !important;
}

/* Hide HOME button in native apps */
.native-app .home-button,
.home-button {
    display: none !important;
}

/* Safe area insets for notch devices - only add minimal padding */
@supports (padding: max(0px)) {
    .native-app .container {
        /* Only add safe area to top padding, not margin */
        padding-top: max(10px, calc(10px + env(safe-area-inset-top, 0px)));
        padding-bottom: max(30px, calc(30px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(30px, calc(30px + env(safe-area-inset-left, 0px)));
        padding-right: max(30px, calc(30px + env(safe-area-inset-right, 0px)));
        margin-top: 0;
    }
    
    .native-app header.compact-header {
        padding-top: 0;
        margin-top: 0;
        margin-bottom: 15px;
    }
    
    .native-app .header-content {
        padding-top: 0;
    }
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 900px;
    margin: 0 auto;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* Safe area support for notch devices - web version */
@supports (padding: max(0px)) {
    body:not(.native-app) .container {
        padding-top: max(30px, calc(30px + env(safe-area-inset-top, 0px)));
        padding-bottom: max(30px, calc(30px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(30px, calc(30px + env(safe-area-inset-left, 0px)));
        padding-right: max(30px, calc(30px + env(safe-area-inset-right, 0px)));
        max-height: calc(100vh - max(40px, calc(40px + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px))));
        margin-top: 0;
    }
    
    body:not(.native-app) header.compact-header {
        padding-top: 0;
        margin-top: 0;
    }
    
    body:not(.native-app) .header-content {
        padding-top: 0;
    }
}

/* Header - Compact (Tetris style) */
header.compact-header {
    margin-bottom: 15px;
    flex-shrink: 0;
}

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

.back-btn {
    text-decoration: none;
    color: #F59E0B;
    font-size: 0.85em;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.3s;
    background: #FEF3C7;
    white-space: nowrap;
    /* Ensure it's visible and clickable on native apps */
    display: inline-block;
    z-index: 10;
    position: relative;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245, 158, 11, 0.2);
}

.back-btn:hover {
    background: #FDE68A;
    transform: translateX(-2px);
}

h1 {
    text-align: center;
    color: #667eea;
    margin: 0;
    font-size: 1.6em;
    flex: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

/* Icon buttons (Tetris style) */
.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: #FEF3C7;
    border: none;
    color: #F59E0B;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: #FDE68A;
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Play Row Layout (Tetris style) */
.play-row {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.info-side {
    flex-shrink: 0;
}

.game-info.compact {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 150px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.info-item .label {
    font-size: 0.9em;
    opacity: 0.9;
}

.info-item .value {
    font-size: 1.3em;
    font-weight: bold;
}

.game-board {
    flex: 1;
    min-width: 0;
}

/* Game Board */
.game-board-inner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 15px;
    padding: 20px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 15px;
    min-height: 400px;
    justify-items: center;
    align-items: start;
    /* iOS Capacitor touch fixes */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior: none;
}

/* Bottle Styles */
.bottle {
    width: 80px;
    height: 200px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    /* iOS Capacitor touch fixes */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.bottle:hover {
    transform: translateY(-5px);
}

.bottle.selected {
    transform: translateY(-10px) scale(1.05);
    filter: drop-shadow(0 0 15px rgba(102, 126, 234, 0.8));
}

.bottle.dragging {
    opacity: 0.8;
    transform: scale(1.05);
    z-index: 1000;
    cursor: grabbing;
}

.bottle.drag-target {
    transform: translateY(-5px) scale(1.02);
    filter: drop-shadow(0 0 10px rgba(16, 185, 129, 0.6));
}

.bottle.empty {
    opacity: 0.5;
}

.bottle.complete {
    animation: completePulse 1s ease-in-out infinite;
}

@keyframes completePulse {
    0%, 100% {
        filter: drop-shadow(0 0 10px rgba(16, 185, 129, 0.6));
    }
    50% {
        filter: drop-shadow(0 0 20px rgba(16, 185, 129, 1));
    }
}

.bottle-body {
    width: 60px;
    height: 180px;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #667eea;
    border-radius: 0 0 30px 30px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}

.bottle-neck {
    width: 30px;
    height: 20px;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #667eea;
    border-bottom: none;
    border-radius: 15px 15px 0 0;
    position: relative;
    z-index: 2;
}

/* Liquid Layers */
.liquid-layer {
    width: 100%;
    position: absolute;
    left: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 0 25px 25px;
    box-shadow: inset 0 -5px 10px rgba(0,0,0,0.2);
}

.liquid-layer.pouring {
    animation: pourAnimation 0.6s ease-out;
}

@keyframes pourAnimation {
    0% {
        transform: translateY(0) scaleY(1);
    }
    50% {
        transform: translateY(-10px) scaleY(0.8);
    }
    100% {
        transform: translateY(0) scaleY(1);
    }
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 1em;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

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

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

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

/* Modal Overlay (Tetris style) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.3s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

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

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    border: 3px solid #667eea;
    animation: modalSlideIn 0.3s ease-out;
    position: relative;
}

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

.modal-content h2 {
    color: #667eea;
    margin: 0 0 20px 0;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #667eea;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.8em;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    font-weight: bold;
    padding: 0;
}

.close-btn:hover {
    background: #764ba2;
    transform: rotate(90deg);
}

.instructions-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.tip {
    padding: 12px;
    background: #FEF3C7;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    color: #4a5568;
    line-height: 1.6;
}

/* Game Over */
.game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    z-index: 1000;
    text-align: center;
    min-width: 300px;
}

.game-over.hidden {
    display: none;
}

.game-over h2 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 2em;
}

.game-over p {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 1.1em;
}

.game-over .btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.1em;
    border-radius: 25px;
    cursor: pointer;
    margin: 5px;
    transition: all 0.3s;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.game-over .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* Hint Animation */
.hint-active {
    animation: hintPulse 1s ease-in-out;
}

@keyframes hintPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        filter: drop-shadow(0 0 20px rgba(255, 193, 7, 1));
    }
}

/* Pouring Animation */
.pour-effect {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1001;
    animation: pourDrop 0.6s ease-out forwards;
}

@keyframes pourDrop {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(50px) scale(0.5);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 15px;
        max-height: calc(100vh - 20px);
    }
    
    h1 {
        font-size: 1.3em;
    }
    
    .header-content {
        flex-wrap: wrap;
    }
    
    .play-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .info-side {
        width: 100%;
    }
    
    .game-info.compact {
        flex-direction: row;
        justify-content: space-around;
        min-width: auto;
    }
    
    .game-board-inner {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 15px;
        min-height: 300px;
        justify-items: center;
    }
    
    .bottle {
        width: 70px;
        height: 180px;
    }
    
    .bottle-body {
        width: 50px;
        height: 160px;
    }
    
    .bottle-neck {
        width: 25px;
        height: 18px;
    }
    
    .controls {
        gap: 10px;
        flex-wrap: wrap;
    }
    
    .control-btn {
        padding: 10px 15px;
        font-size: 0.9em;
        flex: 1;
        min-width: 100px;
    }
    
    .icon-btn {
        width: 34px;
        height: 34px;
    }
    
    .icon-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .game-over {
        min-width: 90%;
        padding: 20px;
    }
    
    .modal-content {
        padding: 20px;
        max-width: 95%;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .game-board {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1025px) {
    .game-board {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* iOS Safe Area - Additional support */
@supports (padding: max(0px)) {
    body:not(.native-app) {
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    
    /* Ensure modal respects safe area */
    .modal-content {
        padding-top: max(30px, calc(30px + env(safe-area-inset-top, 0px)));
        padding-bottom: max(30px, calc(30px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(30px, calc(30px + env(safe-area-inset-left, 0px)));
        padding-right: max(30px, calc(30px + env(safe-area-inset-right, 0px)));
    }
}

/* Prevent text selection */
.bottle,
.control-btn,
.game-over {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Ad Placeholders */
.ad-placeholder {
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    margin: 20px auto;
    max-width: 728px;
}

.ad-top {
    margin-bottom: 20px;
}

.ad-middle {
    margin: 30px 0;
}

.ad-bottom {
    margin-top: 20px;
}

