:root {
    --bg-darkness: 0;
    --bg-color-1: hsl(240, 40%, calc(18% - var(--bg-darkness) * 8%));
    --bg-color-2: hsl(270, 35%, calc(22% - var(--bg-darkness) * 10%));
    --accent: #f0c040;
    --accent-glow: rgba(240, 192, 64, 0.5);
    --danger: #ff4060;
    --text: #f0f0f0;
    --hud-bg: rgba(0, 0, 0, 0.45);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body {
    display: flex;
    justify-content: center;
    align-items: stretch;
    background: #14141f;
    transition: background 2s ease;
}

#app-frame {
    position: relative;
    width: 100%;
    max-width: 430px;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    background: linear-gradient(170deg, var(--bg-color-1), var(--bg-color-2));
    transition: background 2s ease;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 80px rgba(0, 0, 0, 0.45);
}

/* ---------- Screens ---------- */

.screen, .overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.screen {
    background: linear-gradient(170deg, var(--bg-color-1), var(--bg-color-2));
    animation: fadeIn 0.6s ease;
}

.overlay {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.screen-content {
    text-align: center;
    padding: 2rem;
}

.hidden {
    display: none !important;
}

/* ---------- Intro ---------- */

.intro-title {
    font-size: clamp(2rem, 8vw, 4rem);
    margin-bottom: 0.5rem;
    animation: slideDown 0.7s ease;
}

.intro-subtitle {
    font-size: clamp(1rem, 4vw, 1.6rem);
    opacity: 0.85;
    margin-bottom: 2.5rem;
    animation: slideDown 0.9s ease;
}

/* ---------- Game Over ---------- */

.gameover-panel {
    max-height: min(92vh, 900px);
    overflow-y: auto;
    padding-bottom: 1rem;
}

.gameover-title {
    font-size: clamp(2.5rem, 10vw, 5rem);
    color: var(--danger);
    margin-bottom: 0.75rem;
    animation: shakeText 0.5s ease;
}

.gameover-img {
    display: block;
    width: 100%;
    max-height: min(42vh, 320px);
    margin: 0 auto 1rem;
    object-fit: contain;
    object-position: center bottom;
    border-radius: 16px;

    animation: gameoverImgIn 0.7s ease 0.15s both;
}

.gameover-subtitle {
    font-size: clamp(0.95rem, 3.5vw, 1.4rem);
    opacity: 0.85;
    margin-bottom: 1.25rem;
    animation: fadeIn 1s ease 0.35s both;
}

.gameover-score {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    color: var(--accent);
    margin-bottom: 1.5rem;
    animation: fadeIn 1s ease 0.55s both;
}

@keyframes gameoverImgIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(12px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ---------- Buttons ---------- */

.game-btn {
    font-family: inherit;
    font-size: clamp(1.1rem, 3.5vw, 1.5rem);
    padding: 0.8rem 2.5rem;
    border: none;
    border-radius: 50px;
    background: var(--accent);
    color: #1a1a2e;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.3s ease;
}

.game-btn:hover {
    transform: scale(1.07);
}

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

.glow-btn {
    box-shadow: 0 0 20px var(--accent-glow), 0 0 60px rgba(240, 192, 64, 0.15);
    animation: btnPulse 2.5s ease-in-out infinite;
}

/* ---------- Countdown ---------- */

#countdown-overlay {
    z-index: 200;
}

#countdown-number {
    font-size: clamp(5rem, 20vw, 10rem);
    font-weight: 900;
    color: var(--accent);
    animation: countPop 0.8s ease;
    text-shadow: 0 0 40px var(--accent-glow);
}

/* ---------- HUD ---------- */

#game-area {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

#hud {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 0.4rem 0.6rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
    flex-shrink: 0;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
}

.hud-label {
    font-size: 0.6rem;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hud-item span:last-child {
    font-size: 1.1rem;
    font-weight: 700;
}

#hud-score.pop {
    animation: scorePop 0.3s ease;
}

.hud-buttons {
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 0.5rem;
}

.hud-clock-wrap {
    position: absolute;
    left: 0.45rem;
    bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(200px, 42vh, 300px));
    z-index: 12;
    padding: 0.35rem 0.55rem;
    background: var(--hud-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 12px;
    direction: rtl;
}

.hud-clock-wrap .hud-item {
    align-items: flex-start;
}

.hud-clock-wrap .hud-item span:last-child {
    font-size: clamp(1.15rem, 4vw, 1.45rem);
    font-variant-numeric: tabular-nums;
}

.hud-btn {
    font-size: 1.3rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text);
    width: 2.4rem;
    height: 2.4rem;
    cursor: pointer;
    display: flex;
    box-shadow: none !important;
}

.hud-btn {
    font-size: 1.3rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text);
    width: 2.4rem;
    height: 2.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ---------- Bottle Zone ---------- */

#bottle-zone {
    flex: 1;
    position: relative;
    overflow: hidden;
    direction: ltr;
    height: 80vh;
    top: 0px;
      z-index: 6;
    position: fixed;
    left: 0px;
    right: 0px;
}

/* ---------- Bottles ---------- */

.bottle {
    position: absolute;
    left: 0;
    top: 0;
    width: 80px;
    height: 144px;
    cursor: pointer;
    z-index: 5;
    transition: filter 0.1s;
    will-change: transform;
}

.bottle:hover {
    filter: brightness(1.2);
}

.bottle.bottle-chaser {
    width: 48px;
    height: 86px;
    z-index: 6;
}

.bottle img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.bottle-fallback {
    border-radius: 8px 8px 12px 12px;
    overflow: hidden;
}

.bottle-fallback::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    height: 22%;
    border-radius: 4px 4px 0 0;
    background: inherit;
    filter: brightness(0.8);
}

.bottle-fallback::after {
    content: '';
    position: absolute;
    top: 25%;
    left: 15%;
    width: 30%;
    height: 50%;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    transform: rotate(-15deg);
}

.bottle.exploding {
    animation: explode 0.35s ease forwards;
    pointer-events: none;
}

/* ---------- Particles ---------- */

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    animation: particleFly 0.5s ease-out forwards;
}

/* ---------- Meir Zone ---------- */

#meir-zone {
     position: fixed;
    bottom: 0;
    left: 0px;
    right: 0px;
    min-height: clamp(115px, 26vh, 200px);
    padding: 0.15rem 0.5rem 0.25rem;
    display: flex;
    align-items: flex-end;
    justify-content: center;

    flex-shrink: 0;
    z-index: 5;
}

#meir-img {
    height: 300px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    object-position: bottom center;
    border-radius: 0;
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
    pointer-events: none;
    display: none;
}

#meir-img.loaded {
    display: block;
}

#meir-img.loaded ~ #meir-placeholder {
    display: none;
}

#meir-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    font-size: 3rem;
    line-height: 1;
}

#meir-placeholder span {
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.8;
}

/* ---------- Screen Shake ---------- */

#game-area.shake {
    animation: screenShake 0.35s ease;
}

/* ---------- Keyframes ---------- */

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

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

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow), 0 0 60px rgba(240, 192, 64, 0.15); }
    50%      { box-shadow: 0 0 30px var(--accent-glow), 0 0 80px rgba(240, 192, 64, 0.25); }
}

@keyframes countPop {
    0%   { transform: scale(0.3); opacity: 0; }
    50%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes scorePop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.4); color: var(--accent); }
    100% { transform: scale(1); }
}

@keyframes explode {
    0%   { scale: 1; opacity: 1; }
    50%  { scale: 1.5; opacity: 0.6; }
    100% { scale: 0.2; opacity: 0; }
}

@keyframes particleFly {
    0%   { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--px), var(--py)) scale(0.3); }
}

@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-6px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

@keyframes shakeText {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-8px); }
    50%      { transform: translateX(8px); }
    75%      { transform: translateX(-4px); }
}

/* מסכים צרים מאוד (מתחת למסגרת המובייל) */
@media (max-width: 360px) {
    #app-frame {
        max-width: 100%;
        box-shadow: none;
    }
}