:root {
    --app-width: 100vw;
    --app-height: 100vh;
    --safe-bottom-inset: 0px;
    --bg-base: #050b1b;
    --bg-panel-top: rgba(9, 16, 36, 0.88);
    --bg-panel-bottom: rgba(5, 10, 24, 0.94);
    --border-subtle: rgba(126, 156, 230, 0.28);
    --border-strong: rgba(126, 156, 230, 0.44);
    --text-main: #f2f6ff;
    --text-muted: rgba(214, 224, 247, 0.82);
    --text-dim: rgba(173, 186, 215, 0.56);
    --accent-blue: #7ab5ff;
    --accent-blue-soft: rgba(122, 181, 255, 0.16);
    --accent-green: #16dd78;
    --accent-green-strong: #0dc766;
    --shadow-panel: 0 22px 48px rgba(0, 0, 0, 0.42);
    --shadow-button: 0 12px 28px rgba(6, 201, 103, 0.2);
    --radius-panel: 26px;
    --radius-pill: 999px;
    --hud-blur: blur(14px) saturate(140%);
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: var(--app-width);
    height: var(--app-height);
    overflow: hidden;
    position: fixed;
    inset: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Arial, sans-serif;
    background: var(--bg-base);
    color: var(--text-main);
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

html[lang="he"] .game-message,
html[lang="he"] .loading-content,
html[lang="he"] .offline-banner,
html[lang="he"] .score-panel {
    direction: rtl;
}

html[lang="he"] .score-panel {
    text-align: right;
}

body {
    background:
        radial-gradient(circle at top, rgba(24, 58, 120, 0.18), transparent 44%),
        linear-gradient(180deg, #060d1f 0%, #081326 50%, #071224 100%);
}

.game-container {
    position: relative;
    width: var(--app-width);
    height: var(--app-height);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#gameCanvas {
    position: absolute;
    inset: 0;
    width: var(--app-width);
    height: var(--app-height);
    display: block;
    background: linear-gradient(180deg, #081125 0%, #101b36 65%, #162745 100%);
    cursor: none;
    touch-action: none;
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.safe-area-probe {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 0;
    height: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    visibility: hidden;
    pointer-events: none;
}

.ui-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

.ui-overlay.hidden {
    opacity: 0;
}

.score-panel,
.controls,
.game-message,
.loading-screen {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.score-panel {
    position: absolute;
    top: max(14px, env(safe-area-inset-top, 14px));
    left: max(14px, env(safe-area-inset-left, 14px));
    min-width: 132px;
    padding: 8px 12px;
    border-radius: 16px;
    pointer-events: auto;
    background: rgba(7, 14, 35, 0.64);
    backdrop-filter: var(--hud-blur);
    -webkit-backdrop-filter: var(--hud-blur);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    transition: opacity 0.24s ease, transform 0.24s ease;
}

.score-panel.auto-hide {
    opacity: 0.58;
    transform: translateY(-3px);
}

.score-panel div {
    margin: 2px 0;
    font-size: clamp(11px, 2.7vw, 14px);
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    letter-spacing: 0.01em;
    color: rgba(235, 242, 255, 0.94);
}

.score-panel div.score {
    font-size: clamp(13px, 3vw, 16px);
}

.score-panel span {
    color: var(--accent-blue);
}

@keyframes scorePop {
    0% { transform: scale(1); }
    40% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.score-pop {
    animation: scorePop 0.28s ease-out;
}

.controls {
    position: absolute;
    top: max(14px, env(safe-area-inset-top, 14px));
    right: max(14px, env(safe-area-inset-right, 14px));
    display: flex;
    gap: 8px;
    transition: opacity 0.24s ease, transform 0.24s ease;
}

.controls.auto-hide {
    opacity: 0.62;
    transform: translateY(-3px);
}

button {
    border: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    transition:
        transform 0.18s ease,
        background-color 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
    -webkit-font-smoothing: antialiased;
}

button:active {
    transform: scale(0.97);
}

.control-btn {
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(7, 15, 36, 0.52);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(126, 156, 230, 0.28);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    font-size: 18px;
}

.control-btn:active {
    background: rgba(18, 31, 74, 0.7);
}

.game-message {
    position: absolute;
    left: max(20px, env(safe-area-inset-left, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    max-height: min(60vh, 460px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: 24px 20px 18px;
    border-radius: var(--radius-panel);
    text-align: center;
    pointer-events: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background:
        linear-gradient(180deg, rgba(16, 27, 58, 0.2), transparent 22%),
        linear-gradient(180deg, var(--bg-panel-top), var(--bg-panel-bottom));
    backdrop-filter: blur(20px) saturate(135%);
    -webkit-backdrop-filter: blur(20px) saturate(135%);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-panel);
    animation: messageIn 0.28s ease both;
}

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

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

.game-message::before {
    content: "";
    display: block;
    width: 48px;
    height: 2px;
    margin: 0 auto;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, rgba(122, 181, 255, 0.92), transparent);
}

.game-message h2 {
    color: var(--text-main);
    font-weight: 800;
    line-height: 0.98;
    letter-spacing: -0.04em;
}

.game-message[data-message-style="menu"] h2 {
    font-size: clamp(2rem, 9vw, 3.2rem);
    color: var(--accent-blue);
    text-shadow: 0 10px 28px rgba(28, 88, 182, 0.24);
}

.game-message[data-message-style="status"] h2 {
    font-size: clamp(1.8rem, 7.5vw, 2.5rem);
    text-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.game-title-subtitle {
    display: block;
    margin-top: 10px;
    font-size: 0.34em;
    font-weight: 700;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: rgba(152, 191, 255, 0.82);
    text-shadow: none;
}

html[lang="he"] .game-title-subtitle {
    letter-spacing: 0.12em;
    text-transform: none;
}

.game-message p {
    font-size: clamp(14px, 3.6vw, 18px);
    line-height: 1.52;
    color: var(--text-muted);
}

.game-message p strong {
    color: var(--text-main);
}

.city-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.game-message[data-message-style="menu"] .city-selector {
    margin-bottom: auto;
}

.city-selector.hidden {
    display: none;
}

.city-selector-label {
    font-size: clamp(11px, 2.9vw, 13px);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(186, 201, 231, 0.76);
}

html[lang="he"] .city-selector-label {
    letter-spacing: 0.04em;
}

.city-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

html[lang="he"] .city-options {
    direction: rtl;
}

.city-option-btn {
    width: 100%;
    min-height: 46px;
    margin: 0;
    padding: 11px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(126, 156, 230, 0.25);
    background: rgba(41, 60, 104, 0.34);
    color: rgba(227, 235, 255, 0.82);
    font-size: clamp(13px, 3vw, 15px);
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.city-option-btn.selected {
    border-color: rgba(67, 237, 148, 0.48);
    background: linear-gradient(180deg, rgba(18, 109, 69, 0.82), rgba(10, 74, 48, 0.94));
    color: #ffffff;
    box-shadow:
        0 0 0 1px rgba(67, 237, 148, 0.12),
        0 10px 18px rgba(7, 42, 26, 0.28);
}

.start-button {
    width: 100%;
    min-height: 56px;
    margin: 2px 0 0;
    padding: 16px 20px;
    border-radius: 18px;
    background: linear-gradient(180deg, var(--accent-green), var(--accent-green-strong));
    color: #071b12;
    font-size: clamp(17px, 4.5vw, 21px);
    font-weight: 800;
    letter-spacing: 0.06em;
    box-shadow: var(--shadow-button);
}

html[lang="he"] .start-button {
    letter-spacing: 0.02em;
}

.start-button:active {
    background: linear-gradient(180deg, #15d772, #0eb85f);
}

.share-button {
    width: 100%;
    min-height: 50px;
    margin: 4px 0 0;
    padding: 14px 18px;
    border-radius: 18px;
    background: rgba(33, 173, 92, 0.16);
    color: #e9fff2;
    border: 1px solid rgba(62, 225, 132, 0.3);
    box-shadow: 0 10px 22px rgba(18, 80, 46, 0.16);
    font-size: clamp(15px, 4vw, 18px);
    font-weight: 700;
}

.share-button:active {
    background: rgba(33, 173, 92, 0.28);
}

.credits {
    margin-top: 2px;
    color: var(--text-dim);
    font-size: clamp(11px, 2.7vw, 13px);
    font-style: italic;
}

html[lang="he"] .credits {
    font-style: normal;
}

.touch-feedback {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(22, 221, 120, 0.82);
    box-shadow: 0 0 16px rgba(22, 221, 120, 0.26);
    opacity: 0;
    transform: scale(0.4);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 100;
}

.touch-feedback.active {
    opacity: 0.86;
    transform: scale(1.1);
}

.loading-screen {
    position: absolute;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at top, rgba(52, 106, 196, 0.18), transparent 38%),
        linear-gradient(180deg, #050913 0%, #081426 52%, #0c2240 100%);
    transition: opacity 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    padding: 0 24px;
    text-align: center;
}

.loading-content h2 {
    margin-bottom: 26px;
    color: var(--accent-blue);
    font-size: clamp(2.1rem, 9vw, 4.4rem);
    font-weight: 900;
    letter-spacing: -0.04em;
    text-shadow: 0 14px 40px rgba(24, 86, 180, 0.28);
}

.loading-spinner {
    width: 58px;
    height: 58px;
    margin: 0 auto 20px;
    border-radius: 50%;
    border: 4px solid rgba(122, 181, 255, 0.14);
    border-top-color: rgba(122, 181, 255, 0.9);
    border-right-color: rgba(122, 181, 255, 0.48);
    box-shadow: 0 0 24px rgba(24, 86, 180, 0.18);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-content p {
    color: rgba(182, 211, 255, 0.78);
    font-size: clamp(14px, 3.4vw, 18px);
    letter-spacing: 0.04em;
}

.ios-prompt {
    position: absolute;
    left: 50%;
    bottom: max(24px, env(safe-area-inset-bottom, 24px));
    transform: translateX(-50%);
    width: min(calc(100vw - 32px), 360px);
    padding: 14px 18px;
    border-radius: 20px;
    background: rgba(6, 14, 34, 0.92);
    border: 1px solid var(--border-subtle);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: rgba(212, 226, 255, 0.88);
    font-size: clamp(13px, 3vw, 15px);
    line-height: 1.35;
    text-align: center;
    pointer-events: auto;
    z-index: 100;
    animation: slideUp 0.45s ease, fadeOut 0.45s ease 4.5s forwards;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        pointer-events: none;
    }
}

.offline-banner {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    padding: 10px 14px;
    background: rgba(184, 95, 24, 0.88);
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    backdrop-filter: blur(8px);
}

.game-container[data-ui-mode="loading"] .score-panel,
.game-container[data-ui-mode="loading"] .controls,
.game-container[data-ui-mode="menu"] .score-panel,
.game-container[data-ui-mode="menu"] .controls,
.game-container[data-ui-mode="result"] .score-panel,
.game-container[data-ui-mode="result"] .controls {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
}

.game-container[data-ui-mode="paused"] .score-panel {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
}

.game-container[data-ui-mode="paused"] #restartBtn {
    display: none;
}

.game-container[data-ui-mode="paused"] .game-message,
.game-container[data-ui-mode="result"] .game-message {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(calc(100vw - 40px), 400px);
    max-height: min(78vh, 520px);
    transform: translate(-50%, -50%);
}

@media screen and (max-width: 768px) and (orientation: portrait) {
    .game-container[data-ui-mode="menu"] .game-message {
        bottom: calc(env(safe-area-inset-bottom, 20px) + 108px);
        max-height: min(56vh, 420px);
    }
}

@media (min-width: 900px) and (min-height: 620px) {
    .game-container[data-ui-mode="menu"] .game-message {
        top: 50%;
        right: auto;
        bottom: auto;
        left: 50%;
        width: min(420px, calc(100vw - 80px));
        max-height: 76vh;
        padding: 30px 28px 22px;
        transform: translate(-50%, -50%);
    }

    .game-message[data-message-style="menu"] h2 {
        font-size: clamp(2.2rem, 3.8vw, 3.4rem);
    }
}

@media screen and (orientation: landscape) and (max-height: 500px) {
    .score-panel {
        min-width: 118px;
        padding: 7px 10px;
        border-radius: 14px;
    }

    .controls {
        top: max(10px, env(safe-area-inset-top, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
    }

    .control-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }

    .game-container[data-ui-mode="menu"] .game-message {
        top: max(16px, env(safe-area-inset-top, 16px));
        right: auto;
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        left: max(16px, env(safe-area-inset-left, 16px));
        width: min(320px, calc(100vw - 136px));
        max-height: none;
        padding: 18px 18px 16px;
        gap: 10px;
        overflow: hidden;
        transform: none;
    }

    .game-container[data-ui-mode="paused"] .game-message,
    .game-container[data-ui-mode="result"] .game-message {
        width: min(320px, calc(100vw - 32px));
        max-height: min(90vh, 360px);
        padding: 18px 18px 16px;
    }

    .game-message::before {
        width: 40px;
    }

    .game-message[data-message-style="menu"] h2 {
        font-size: clamp(1.8rem, 4vw, 2.4rem);
    }

    .game-message[data-message-style="status"] h2 {
        font-size: clamp(1.5rem, 3.8vw, 2rem);
    }

    .game-message p {
        font-size: 14px;
        line-height: 1.42;
    }

    .city-selector {
        gap: 8px;
    }

    .city-option-btn {
        min-height: 40px;
        padding: 9px 10px;
        font-size: 13px;
    }

    .start-button,
    .share-button {
        min-height: 46px;
        padding: 12px 14px;
        font-size: 15px;
    }

    .credits {
        font-size: 11px;
    }
}

@media screen and (max-width: 360px) {
    .score-panel {
        min-width: 124px;
        padding: 7px 10px;
    }

    .game-message {
        left: max(16px, env(safe-area-inset-left, 16px));
        right: max(16px, env(safe-area-inset-right, 16px));
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        padding: 20px 16px 16px;
        gap: 12px;
    }

    .city-options {
        gap: 8px;
    }

    .city-option-btn {
        padding: 10px 8px;
        font-size: 12px;
    }
}

@media (hover: hover) and (pointer: fine) {
    .city-option-btn:hover {
        background: rgba(58, 82, 138, 0.46);
        border-color: rgba(126, 156, 230, 0.38);
    }

    .start-button:hover {
        transform: translateY(-1px);
        box-shadow: 0 16px 30px rgba(6, 201, 103, 0.26);
    }

    .share-button:hover {
        background: rgba(33, 173, 92, 0.24);
    }

    .control-btn:hover {
        background: rgba(13, 24, 54, 0.74);
        border-color: rgba(126, 156, 230, 0.38);
    }
}
