/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    width: 100%;
    height: 100%;
    /* iOS / mobile: stable full-height in portrait (address bar, notch) */
    height: -webkit-fill-available;
}

html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: #0a0e27;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

body {
    min-height: -webkit-fill-available;
    height: -webkit-fill-available;
    margin: 0;
}

/* Yandex i.1.6.2.7 */
img, svg, canvas {
    -webkit-user-drag: none;
}

#game-container {
    width: 100%;
    height: 100%;
    min-height: 100%;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    position: relative;
    overflow: hidden;
    touch-action: none;
    box-sizing: border-box;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    display: flex;
    flex-direction: column;
}

.pw-screens-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.pw-top-bar {
    position: static;
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Sound + language inside main menu block (not a separate top strip). */
.menu-settings-anchor {
    margin-top: 22px;
    display: flex;
    justify-content: center;
    width: 100%;
}

.menu-settings-anchor .pw-top-bar {
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Level select: lang + mute in the top bar, right of pagination (not centered mid-screen). */
.screen-header-end {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

.level-select-settings-anchor {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.level-select-settings-anchor .pw-top-bar {
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 0;
    margin: 0;
    background: none;
    border: none;
    border-radius: 0;
}

.level-select-settings-anchor .lang-btn {
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 6px;
}

.level-select-settings-anchor .btn-mute-top {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-hud .hud-settings-slot {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

#game-hud .pw-top-bar {
    gap: 6px;
    flex-wrap: nowrap;
}

#game-hud .btn-mute-top {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lang-switcher {
    position: static;
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-mute-top {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(0, 0, 0, 0.42);
    color: #fff;
    cursor: pointer;
    line-height: 1;
}

.lang-btn {
    border: 1px solid rgba(255,255,255,0.22);
    background: rgba(0,0,0,0.42);
    color: rgba(255,255,255,0.72);
    font-size: 12px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
}

.lang-btn.active {
    color: #fff;
    border-color: rgba(79,195,247,0.7);
    background: rgba(79,195,247,0.24);
}

/* === Screens === */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

.screen.hidden {
    display: none;
    opacity: 0;
}

.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    height: 100dvh;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    box-sizing: border-box;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.overlay.hidden {
    display: none;
}

/* In-game notices: above gameplay UI */
.overlay-game-message {
    z-index: 350;
}

/* === Main Menu === */
#main-menu {
    background: linear-gradient(135deg, #0a0e27 0%, #1a1e4a 50%, #0d1233 100%);
    align-items: center;
    justify-content: center;
}

.menu-bg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background:
        radial-gradient(circle at 20% 30%, rgba(66, 133, 244, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(138, 43, 226, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(0, 200, 255, 0.08) 0%, transparent 70%);
    animation: bgPulse 6s ease-in-out infinite;
}

@keyframes bgPulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

.menu-content {
    position: relative;
    z-index: 2;
    text-align: center;
    width: min(92vw, 520px);
    margin-top: 18px;
}

.logo-area {
    margin-bottom: 50px;
}

.logo-icon {
    font-size: 80px;
    margin-bottom: 10px;
    animation: dropBounce 2s ease-in-out infinite;
}

@keyframes dropBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.game-title {
    font-size: clamp(34px, 8vw, 48px);
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: none;
    background: linear-gradient(135deg, #4fc3f7, #7c4dff, #ff6ec7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}

.subtitle {
    font-size: clamp(13px, 3.2vw, 16px);
    color: rgba(255,255,255,0.5);
    letter-spacing: 4px;
    margin-top: 8px;
    text-transform: uppercase;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

/* === Buttons === */
.btn {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
    background: linear-gradient(135deg, #4fc3f7, #7c4dff);
    color: #fff;
    font-size: 18px;
    padding: 16px 60px;
    border-radius: 50px;
    min-width: min(240px, 82vw);
    box-shadow: 0 4px 20px rgba(79, 195, 247, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 30px rgba(79, 195, 247, 0.5);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 15px;
    padding: 14px 50px;
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,0.2);
    min-width: min(240px, 82vw);
}

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

.btn-back {
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 14px;
    padding: 10px 20px;
    border-radius: 25px;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-icon {
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.15);
    /* Emoji HUD labels: .btn letter-spacing/uppercase breaks 🧪+ into two lines in a circle */
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    line-height: 1;
}

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

/* Yandex 4.5.1: RV entry shows visible text that an ad plays for a reward. */
.btn-hud-rv {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    min-height: 44px;
    max-width: min(160px, 46vw);
    padding: 6px 12px 6px 10px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-weight: 700;
    flex-shrink: 1;
    min-width: 0;
    letter-spacing: normal;
    text-transform: none;
    white-space: normal;
    line-height: 1.2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-hud-rv-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.btn-hud-rv-icon {
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
}

.btn-hud-rv-label {
    font-size: 10px;
    font-weight: 800;
    text-align: left;
    min-width: 0;
}

/* === Level Select === */
#level-select {
    background:
        radial-gradient(circle at 15% 15%, rgba(70, 132, 255, 0.16), transparent 30%),
        radial-gradient(circle at 85% 18%, rgba(138, 91, 255, 0.14), transparent 28%),
        radial-gradient(circle at 50% 85%, rgba(58, 206, 255, 0.08), transparent 38%),
        linear-gradient(155deg, #090e2a 0%, #101846 48%, #0a1235 100%);
    min-height: 0;
}

.screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    margin: 12px 12px 0;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.08);
    background: linear-gradient(160deg, rgba(17, 29, 78, 0.86), rgba(10, 18, 52, 0.8));
    box-shadow: 0 10px 30px rgba(4, 8, 26, 0.45);
    backdrop-filter: blur(8px);
    flex-wrap: wrap;
}

#level-select .screen-header h2 {
    text-align: center;
}

.screen-header h2 {
    font-size: clamp(16px, 3.2vw, 21px);
    letter-spacing: 2px;
    flex: 1;
    min-width: 0;
    font-weight: 800;
    text-transform: uppercase;
    color: rgba(241, 246, 255, 0.96);
    text-shadow: 0 4px 16px rgba(49, 138, 255, 0.35);
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-nav span {
    font-size: 13px;
    color: rgba(224, 233, 255, 0.84);
    min-width: 56px;
    text-align: center;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
}

.btn-page {
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: 14px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-page:hover {
    background: rgba(99, 169, 255, 0.25);
    border-color: rgba(141, 196, 255, 0.5);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    padding: 14px 12px 16px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    align-content: start;
    grid-auto-rows: minmax(64px, 1fr);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.level-btn {
    min-height: 64px;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.level-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(145deg, rgba(255,255,255,0.2), transparent 35%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.level-btn.unlocked {
    background: linear-gradient(160deg, rgba(43, 75, 176, 0.32), rgba(44, 35, 112, 0.42));
    color: #f4f7ff;
    border: 1px solid rgba(116, 166, 255, 0.22);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.09);
}

.level-btn.unlocked:hover {
    background: linear-gradient(160deg, rgba(59, 102, 226, 0.5), rgba(65, 47, 165, 0.52));
    border-color: rgba(142, 196, 255, 0.46);
    box-shadow: 0 10px 26px rgba(35, 73, 180, 0.35);
    transform: translateY(-2px);
}

.level-btn.unlocked:hover::before {
    opacity: 1;
}

.level-btn.locked {
    background: linear-gradient(160deg, rgba(255,255,255,0.035), rgba(255,255,255,0.02));
    color: rgba(196, 204, 230, 0.45);
    border: 1px solid rgba(255,255,255,0.06);
    cursor: not-allowed;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.level-btn.current {
    background: linear-gradient(152deg, #66c5ff, #6f82ff 42%, #8f62ff);
    color: #fff;
    border: 1px solid rgba(188, 224, 255, 0.62);
    box-shadow: 0 0 0 1px rgba(143, 206, 255, 0.4), 0 0 22px rgba(96, 182, 255, 0.5);
    animation: currentPulse 2s ease-in-out infinite;
}

@keyframes currentPulse {
    0%, 100% { box-shadow: 0 0 0 1px rgba(143, 206, 255, 0.4), 0 0 20px rgba(90, 180, 255, 0.48); }
    50% { box-shadow: 0 0 0 2px rgba(173, 223, 255, 0.7), 0 0 30px rgba(120, 196, 255, 0.74); }
}

.level-num {
    position: relative;
    z-index: 1;
    font-size: 18px;
    line-height: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.level-head {
    width: 100%;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.level-state {
    font-size: 9px;
    letter-spacing: 0.8px;
    padding: 2px 6px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(242, 249, 255, 0.86);
    background: rgba(255,255,255,0.08);
    line-height: 1.2;
}

.level-state-locked {
    color: rgba(194, 200, 226, 0.58);
    border-color: rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.03);
}

.level-stars {
    position: relative;
    z-index: 1;
    font-size: 10px;
    letter-spacing: 1px;
    color: rgba(255, 232, 136, 0.92);
    text-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

.level-btn.current .level-stars {
    color: #ffe88e;
}

.level-dots {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.level-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}

.level-dot.filled {
    background: #ffe88e;
    box-shadow: 0 0 8px rgba(255, 232, 142, 0.7);
}

.level-lock {
    font-size: 20px;
    opacity: 0.55;
    filter: grayscale(0.3);
}

/* === Game Screen === */
#game-screen {
    background: linear-gradient(180deg, #0a0e27 0%, #141842 50%, #0d1233 100%);
}

#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 10px max(12px, env(safe-area-inset-right, 0px)) 10px max(12px, env(safe-area-inset-left, 0px));
    background: rgba(0,0,0,0.3);
    z-index: 10;
    flex-shrink: 0;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: 100%;
}

#hud-level {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    max-width: min(42vw, 200px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Tubes Container === */
.tubes-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    /* 横屏桌面与竖屏手机：多行试管在 HUD 下方剩余高度里垂直居中，避免贴顶、底下大片空 */
    align-content: center;
    gap: 12px;
    padding: 20px max(10px, env(safe-area-inset-right, 0px)) 20px max(10px, env(safe-area-inset-left, 0px));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* === Tube === */
.tube {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.tube:hover {
    transform: translateY(-4px);
}

.tube.selected {
    transform: translateY(-12px);
    filter: brightness(1.2);
}

.tube.selected .tube-body {
    box-shadow: 0 0 20px rgba(79, 195, 247, 0.6);
}

.tube.shake {
    animation: tubeShake 0.4s ease;
}

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

.tube-body {
    width: 52px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top: none;
    border-radius: 0 0 16px 16px;
    background: rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column-reverse;
    overflow: hidden;
    position: relative;
    transition: box-shadow 0.2s ease;
}

.tube-top {
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 4px 4px 0 0;
    margin: 0 auto;
    border: 2px solid rgba(255,255,255,0.3);
    border-bottom: none;
    margin-left: -1px;
}

.water-layer {
    width: 100%;
    transition: all 0.3s ease;
    position: relative;
}

.water-layer::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

.tube.completed .tube-body {
    border-color: rgba(76, 175, 80, 0.6);
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.3);
}

.tube.completed::after {
    content: '✓';
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    color: #4caf50;
}

/* === Pour Animation === */
.water-pour {
    position: fixed;
    border-radius: 4px;
    z-index: 50;
    pointer-events: none;
}

/* Tube tilt animation during pour */
.tube.pouring-from {
    transform-origin: bottom center;
    z-index: 20;
}

.tube.pouring-to {
    z-index: 19;
}

/* Flying water blob */
.water-blob {
    position: fixed;
    border-radius: 6px 6px 4px 4px;
    z-index: 60;
    pointer-events: none;
    filter: brightness(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: none;
}

.water-blob::after {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    width: 30%;
    height: 40%;
    background: rgba(255,255,255,0.35);
    border-radius: 50%;
    filter: blur(1px);
}

/* Splash particles */
.splash-particle {
    position: fixed;
    border-radius: 50%;
    z-index: 61;
    pointer-events: none;
    opacity: 1;
}

/* Water stream from tube mouth */
.water-stream {
    position: fixed;
    z-index: 59;
    pointer-events: none;
    border-radius: 0 0 3px 3px;
    opacity: 0.85;
}

/* Landing ripple effect */
.water-ripple {
    position: fixed;
    border-radius: 50%;
    z-index: 58;
    pointer-events: none;
    border: 2px solid;
    opacity: 0;
    animation: rippleExpand 0.5s ease-out forwards;
}

@keyframes rippleExpand {
    0% {
        transform: scale(0.3);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Droplet trail */
.water-droplet {
    position: fixed;
    border-radius: 50%;
    z-index: 55;
    pointer-events: none;
    opacity: 0.6;
    animation: dropletFade 0.4s ease-out forwards;
}

@keyframes dropletFade {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(0) translateY(8px);
        opacity: 0;
    }
}

/* Tube bounce on receive */
.tube.receiving {
    animation: tubeReceive 0.3s ease;
}

@keyframes tubeReceive {
    0% { transform: translateY(0); }
    40% { transform: translateY(3px); }
    70% { transform: translateY(-2px); }
    100% { transform: translateY(0); }
}

/* Source tube spring back */
.tube.pour-done {
    animation: tubePourDone 0.25s ease;
}

@keyframes tubePourDone {
    0% { transform: translateY(-8px); }
    60% { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

/* === Overlay === */
.overlay-box {
    background: linear-gradient(135deg, #1a1e4a, #252966);
    border-radius: 24px;
    padding: 40px 32px;
    text-align: center;
    min-width: 300px;
    max-width: 90vw;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.overlay-box h2 {
    font-size: 28px;
    margin-bottom: 16px;
    letter-spacing: 3px;
}

.complete-icon {
    font-size: 60px;
    margin-bottom: 10px;
}

.stars-display {
    font-size: 36px;
    margin: 12px 0;
    letter-spacing: 8px;
}

.moves-info {
    color: rgba(255,255,255,0.6);
    font-size: 14px;
    margin-bottom: 20px;
}

.message-text {
    color: rgba(255,255,255,0.9);
    font-size: 15px;
    line-height: 1.45;
    margin-bottom: 16px;
    white-space: pre-line;
}

.overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.overlay-buttons .btn {
    min-width: 220px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

/* === Responsive === */
@media (max-width: 400px) {
    .game-title { font-size: 36px; }
    .logo-icon { font-size: 60px; }
    .tubes-container { gap: 6px; padding: 10px 4px; }
    .level-grid { grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 10px 10px 12px; }
    .level-btn { min-height: 58px; border-radius: 12px; }
    .level-num { font-size: 16px; }
    .level-stars { font-size: 9px; }
    .level-state { font-size: 8px; padding: 1px 5px; }
    .level-dot { width: 5px; height: 5px; }
    .page-nav span { font-size: 12px; }
    .lang-btn {
        font-size: 11px;
        padding: 3px 7px;
    }
}

/* Narrow phone portrait: larger level cells, compact HUD */
@media (max-width: 420px) and (orientation: portrait) {
    .screen-header-end {
        flex-basis: 100%;
        justify-content: flex-end;
        margin-left: 0;
        padding-top: 4px;
    }
    .level-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    #game-hud {
        padding-left: 8px;
        padding-right: 8px;
    }
    #game-hud .btn-icon {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }
    .hud-left, .hud-right {
        gap: 6px;
    }
    #hud-level {
        font-size: 12px;
        letter-spacing: 1px;
        max-width: 34vw;
    }
}

/* === Orientation support (mobile) === */
@media (max-width: 700px) and (orientation: portrait) {
    .screen-header {
        margin: 10px 10px 0;
        padding: 12px 14px;
    }

    .level-grid {
        gap: 10px;
        padding: 12px 10px 14px;
        grid-template-columns: repeat(5, 1fr);
    }

    .tubes-container {
        gap: 10px;
        padding: 16px max(6px, env(safe-area-inset-right, 0px)) 16px max(6px, env(safe-area-inset-left, 0px));
    }
}

@media (max-width: 700px) and (orientation: landscape) {
    .screen-header {
        margin: 8px 10px 0;
        padding: 12px 14px;
    }

    .level-grid {
        gap: 10px;
        padding: 12px 10px 14px;
        /* Override min-width breakpoints to avoid too many tiny cards */
        grid-template-columns: repeat(8, 1fr);
    }

    .tubes-container {
        gap: 12px;
        padding: 18px max(8px, env(safe-area-inset-right, 0px)) 18px max(8px, env(safe-area-inset-left, 0px));
    }
}

/* Tablet+: keep portrait readable (avoid 10 tiny columns when holding phone upright) */
@media (min-width: 600px) and (orientation: portrait) {
    .tubes-container { gap: 14px; }
    .level-grid {
        grid-template-columns: repeat(6, 1fr);
        padding: 14px 14px 18px;
    }
    .level-btn { min-height: 68px; }
}

@media (min-width: 600px) and (orientation: landscape) {
    .tubes-container { gap: 14px; }
    .level-grid { grid-template-columns: repeat(10, 1fr); padding: 14px 16px 18px; }
    .level-btn { min-height: 70px; }
}

@media (min-width: 800px) and (orientation: portrait) {
    .tubes-container { gap: 18px; padding: 24px 16px; }
    .level-grid { grid-template-columns: repeat(6, 1fr); gap: 14px; padding: 16px 18px 20px; }
    .level-btn { min-height: 74px; border-radius: 16px; }
}

@media (min-width: 800px) and (orientation: landscape) {
    .tubes-container { gap: 18px; padding: 30px; }
    .level-grid { grid-template-columns: repeat(10, 1fr); gap: 14px; padding: 16px 20px 20px; }
    .level-btn { min-height: 76px; border-radius: 16px; }
}
