/* ===== Reset & Base ===== */
* {
    margin: 0; padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* iOS Safari (i.1.6.1.8): must block text selection / callout on all in-game UI */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
/* Host shell: avoid drag-select on media */
img, svg, canvas {
    -webkit-user-drag: none;
}
html {
    overflow: hidden;
    overscroll-behavior: none;
    height: 100%;
}
html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #87CEEB;
}
/* i.1.10.2 — host scroll / pull-to-refresh; inner regions use touch-action pan-* */
body.yx-host-scroll-lock {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    max-height: 100dvh;
    touch-action: auto;
    overscroll-behavior: none;
}
#game-container {
    width: 100%;
    height: 100%;
    max-height: 100%;
    max-height: 100dvh;
    max-width: 450px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    /* iOS: treat whole WebApp as non-text; prevents long-press selection on labels */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: auto;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    background: linear-gradient(180deg, #98D8F0 0%, #B8E8F8 40%, #CBF0FF 100%);
}

#game-screen {
    touch-action: none;
}

#game-screen * {
    touch-action: none;
}

#level-select,
#gallery-screen,
#settings-panel {
    touch-action: pan-y;
}

/* Board area: subtle grid/pattern background */
.board-area {
    flex: 1; position: relative;
    margin: 2px 6px 4px;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    background: radial-gradient(ellipse at 30% 40%, rgba(255,255,255,0.18) 0%, transparent 60%),
                radial-gradient(ellipse at 70% 70%, rgba(200,230,255,0.15) 0%, transparent 50%);
    border-radius: 12px;
}
.hidden { display: none !important; }
.screen {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
}

/* ===== HOME SCREEN ===== */
#home-screen { align-items: center; justify-content: flex-start; }
.home-bg {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 30%, rgba(255,255,255,0.3) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}
.home-content {
    position: relative; z-index: 1;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    gap: 8px;
    padding: 50px 16px 20px;
    min-height: 0;
}
.settings-btn {
    position: absolute; top: 10px; left: 14px;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.8);
    border: 2px solid rgba(255,255,255,0.9);
    font-size: 20px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 10;
}

/* Art Carousel */
.art-carousel-wrap {
    width: 100%; flex-shrink: 0;
    display: flex; flex-direction: column; align-items: center;
    gap: 6px;
}
.art-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: none;
    width: 100%;
    padding: 12px 0;
    gap: 0;
}
.art-carousel::-webkit-scrollbar { display: none; }

.art-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}

/* Art Frame (reused inside slides) */
.art-frame {
    width: min(240px, 62vw); height: min(240px, 62vw);
    flex-shrink: 0;
    background: #F5E6CC;
    border: 8px solid #8B6914;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25), inset 0 0 20px rgba(0,0,0,0.05);
    display: flex; align-items: center; justify-content: center;
}
.art-frame-corner {
    position: absolute;
    width: 24px; height: 24px;
    background: #C0A050;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: #5a3800; font-weight: bold;
    border: 2px solid #8B6914;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.art-frame-corner.tl { top: -12px; left: -12px; }
.art-frame-corner.tr { top: -12px; right: -12px; }
.art-frame-corner.bl { bottom: -12px; left: -12px; }
.art-frame-corner.br { bottom: -12px; right: -12px; }
.art-slide canvas { border-radius: 2px; width: 100%; height: 100%; display: block; }

.art-slide-name {
    font-size: 13px; font-weight: 800; color: #5a3800;
    letter-spacing: 0.5px;
}

/* Art Progress (inside slide) */
.art-progress-bar {
    width: min(240px, 62vw); height: 22px;
    background: rgba(0,0,0,0.15);
    border-radius: 13px;
    position: relative; overflow: hidden;
}
.art-progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #F39C12, #E67E22);
    border-radius: 13px;
    transition: width 0.8s ease;
}
.art-progress-text {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Carousel dots */
.art-carousel-dots {
    display: flex; gap: 6px; justify-content: center;
}
.art-carousel-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: rgba(0,0,0,0.15);
    transition: all 0.25s;
    cursor: pointer;
}
.art-carousel-dot.active {
    background: #E67E22;
    transform: scale(1.3);
}

/* Taunt line above main menu (home nav) */
.home-taunt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    max-width: 320px;
    margin: 10px auto 6px;
    padding: 0 12px;
    text-align: center;
    pointer-events: none;
}
.home-taunt-emoji {
    font-size: clamp(2.5rem, 10vw, 3.25rem);
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}
.home-taunt-text {
    font-size: clamp(18px, 5.2vw, 28px);
    font-weight: 900;
    color: #ffffff;
    background: linear-gradient(180deg, #3f2b96 0%, #2b4fb4 52%, #1f3f8f 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow:
        0 1px 0 rgba(255,255,255,0.35),
        0 5px 12px rgba(36,54,120,0.35),
        0 0 12px rgba(74,48,170,0.25);
    line-height: 1.35;
    letter-spacing: 0.03em;
    transform-origin: center center;
    animation: homeTauntTextPulse 2s ease-in-out infinite;
    will-change: transform;
}
@keyframes homeTauntTextPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
    .home-taunt-text {
        animation: none;
        will-change: auto;
    }
}

/* Home Nav */
.home-nav {
    display: flex; gap: 12px; align-items: flex-start;
    margin-top: 4px;
}
.nav-btn-wrap {
    display: flex; flex-direction: column; align-items: center;
    position: relative;
}

/* Bouncing hint + arrow under My Art button */
.bounce-arrow {
    display: none;
    flex-direction: column; align-items: center;
    margin-top: 4px;
    animation: arrowBounce 1.2s ease-in-out infinite;
    pointer-events: none;
}
.bounce-arrow.visible { display: flex; }
.arrow-hint {
    background: linear-gradient(135deg, #FF8C00, #FF6B00);
    color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 3px 10px;
    border-radius: 10px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(255,140,0,0.4);
    letter-spacing: 0.3px;
}
.arrow-icon {
    font-size: 14px; color: #FF8C00;
    line-height: 1;
    margin-bottom: -2px;
    filter: drop-shadow(0 1px 2px rgba(255,140,0,0.5));
}
@keyframes arrowBounce {
    0%, 100% { transform: translateY(0); opacity: 0.75; }
    50% { transform: translateY(-5px); opacity: 1; }
}

.home-nav-btn {
    display: flex; flex-direction: column;
    align-items: center; gap: 4px;
    background: rgba(255,255,255,0.85);
    border: 2px solid rgba(255,255,255,0.95);
    border-radius: 16px;
    padding: 10px 16px; cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.1s;
}
.home-nav-btn:active { transform: scale(0.93); }
.home-nav-btn.primary {
    background: linear-gradient(135deg, #FF8C00, #FF6B00);
    border-color: #FF9500;
    padding: 12px 28px;
    box-shadow: 0 4px 16px rgba(255,140,0,0.45);
}
.home-nav-btn .nav-icon { font-size: 26px; }
.home-nav-btn .nav-label {
    font-size: 12px; font-weight: 700; color: #444;
    letter-spacing: 0.5px;
}
.home-nav-btn.primary .nav-label { color: #fff; font-size: 14px; }

/* ===== LEVEL SELECT ===== */
#level-select { background: linear-gradient(180deg, #87CEEB, #B0E0FF); }
.screen-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    color: #fff;
}
.screen-header h2 { font-size: 17px; letter-spacing: 1px; text-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.back-btn {
    background: rgba(255,255,255,0.8); border: none;
    border-radius: 10px; padding: 7px 14px;
    font-size: 14px; font-weight: 600; cursor: pointer; color: #444;
}
.page-nav { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #fff; }
.page-btn {
    background: rgba(255,255,255,0.7); border: none;
    border-radius: 8px; padding: 5px 10px; cursor: pointer; color: #444;
}
.level-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 10px; padding: 12px; overflow-y: auto; flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
    overscroll-behavior-y: contain;
}
.level-btn {
    background: rgba(255,255,255,0.85);
    border: 3px solid rgba(255,255,255,0.95);
    border-radius: 16px; padding: 12px 6px;
    cursor: pointer; display: flex;
    flex-direction: column; align-items: center; gap: 5px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
    transition: transform 0.12s;
}
.level-btn:hover:not(.locked) { transform: scale(1.06); }
.level-btn.locked { opacity: 0.5; cursor: default; }
.level-btn.ad-unlock {
    border-color: #FF8C00;
    background: linear-gradient(135deg, rgba(255,140,0,0.15), rgba(255,107,0,0.08));
    cursor: pointer;
    animation: adPulse 2s ease-in-out infinite;
}
@keyframes adPulse {
    0%, 100% { box-shadow: 0 3px 10px rgba(255,140,0,0.2); }
    50% { box-shadow: 0 3px 16px rgba(255,140,0,0.5); }
}
.level-btn.ad-unlock.dim {
    opacity: 0.55;
    animation: none;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
}
.level-btn.completed { border-color: #FFD700; background: rgba(255,215,0,0.15); }
.level-num { font-size: 20px; font-weight: 800; color: #333; }
.level-stars { font-size: 13px; color: #F39C12; letter-spacing: 1px; }

/* ===== GAME SCREEN ===== */
#game-screen {
    background: linear-gradient(180deg, #87CEEB 0%, #A8D8EA 100%);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* HUD */
.game-hud {
    display: flex; align-items: center;
    padding: 8px 14px; gap: 10px;
    z-index: 100;
}
.hud-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(255,255,255,0.85);
    border: 2px solid rgba(255,255,255,0.95);
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.level-badge {
    background: rgba(0,0,0,0.25);
    color: #fff; font-size: 15px; font-weight: 700;
    padding: 6px 16px; border-radius: 16px;
    letter-spacing: 0.5px;
}
.hud-spacer { flex: 1; }
.hud-shop {
    display: flex;
    gap: 6px;
}
.hud-shop-btn {
    border: 2px solid rgba(255,255,255,0.55);
    border-radius: 10px;
    background: rgba(0,0,0,0.18);
    color: #fff;
    min-width: 68px;
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.05;
    cursor: pointer;
}
.hud-shop-btn:active { transform: scale(0.96); }
.hud-shop-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}
.hud-shop-emoji { font-size: 14px; }
.hud-shop-price { font-size: 10px; font-weight: 800; }
.hud-shop-btn.is-maxed {
    border-color: rgba(255, 255, 255, 0.9);
    background: rgba(70, 70, 70, 0.35);
}

/* ===== Boxes Area ===== */
.boxes-area {
    padding: 6px 8px 2px;
    display: flex; flex-direction: column; align-items: center;
    gap: 4px; z-index: 50; flex-shrink: 0;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.boxes-scroll {
    display: flex; gap: 7px;
    width: 100%; justify-content: center;
}
.box-dots {
    display: flex; gap: 5px; justify-content: center; min-height: 10px;
}
.box-dot {
    width: 8px; height: 8px; border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.5);
    transition: all 0.2s;
}

/* ─── All 4 box slots ─── */
.screw-box {
    width: 82px; height: 92px;
    border-radius: 16px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 6px 5px 7px;
    flex-shrink: 0;
    position: relative;
    transition: transform 0.12s;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Active slot: colored box */
.screw-box.slot-active {
    box-shadow:
        0 5px 16px rgba(0,0,0,0.25),
        inset 0 2px 4px rgba(255,255,255,0.4),
        inset 0 -3px 5px rgba(0,0,0,0.2);
}

/* Locked slot: shows ad icon + "Unlock Box" text (matches screenshot) */
.screw-box.slot-locked {
    background: rgba(200,215,240,0.55);
    border: 3px dashed rgba(180,180,220,0.7);
    cursor: pointer;
    gap: 5px;
}
.screw-box.slot-locked:active { transform: scale(0.92); }
.slot-lock-icon { font-size: 26px; }
.slot-lock-label {
    font-size: 10px; font-weight: 700;
    color: rgba(80,80,120,0.75);
    text-align: center; line-height: 1.2;
    letter-spacing: 0.2px;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Empty unlocked slot (queue loading) */
.screw-box.slot-empty {
    background: rgba(255,255,255,0.2);
    border: 2px dashed rgba(255,255,255,0.5);
}
.slot-empty-dots { color: rgba(255,255,255,0.45); font-size: 20px; letter-spacing: 4px; }

/* Holes inside active box */
.box-holes {
    display: flex; gap: 6px; justify-content: center;
    flex-wrap: wrap; width: 100%; margin-bottom: 3px;
}
.box-hole {
    width: 23px; height: 23px; border-radius: 50%;
    background: rgba(0,0,0,0.22);
    border: 2px solid rgba(0,0,0,0.1);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.22s;
    flex-shrink: 0;
}
.box-hole.filled {
    background: var(--sc, #aaa);
    border-color: rgba(255,255,255,0.3);
    box-shadow: 0 2px 5px rgba(0,0,0,0.28), inset 0 1px 2px rgba(255,255,255,0.25);
    animation: holePop 0.28s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes holePop {
    0% { transform: scale(0); }
    70% { transform: scale(1.25); }
    100% { transform: scale(1); }
}
.box-hole.filled::after { content:'+'; color:rgba(0,0,0,0.28); font-size:13px; font-weight:900; }
.box-label {
    font-size: 11px; font-weight: 700; color: rgba(255,255,255,0.92);
    text-shadow: 0 1px 2px rgba(0,0,0,0.35); letter-spacing: 0.5px;
}

/* Collect animation */
@keyframes collectAnim {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2) translateY(-10px); }
    100% { transform: scale(0.1) translateY(-70px); opacity: 0; }
}
.screw-box.collecting { animation: collectAnim 0.4s ease-in forwards; pointer-events: none; }

/* ===== Buffer Area ===== */
.buffer-area {
    display: flex; justify-content: center; align-items: center;
    padding: 3px 14px 2px; flex-shrink: 0; gap: 8px;
}
.buffer-slots {
    display: flex; gap: 10px;
    background: rgba(0,0,0,0.12);
    border-radius: 20px;
    padding: 5px 16px;
    border: 2px solid rgba(255,255,255,0.35);
}
/* +1 buffer ad button */
.buffer-add-btn {
    display: flex; flex-direction: column; align-items: center;
    gap: 2px;
    background: linear-gradient(135deg, #FF8C00, #FF6B00);
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 12px;
    padding: 5px 10px;
    cursor: pointer; color: #fff;
    font-size: 13px; font-weight: 800;
    box-shadow: 0 3px 8px rgba(255,140,0,0.4);
    transition: transform 0.1s, box-shadow 0.1s;
    line-height: 1;
}
.buffer-add-btn:active { transform: scale(0.9); }
.buffer-add-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
    box-shadow: none;
}
.buffer-add-btn span:first-child { font-size: 16px; }
.buffer-slot {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 2.5px dashed rgba(255,255,255,0.45);
    display: flex; align-items: center; justify-content: center;
    position: relative; flex-shrink: 0;
    transition: all 0.2s;
}
.buffer-slot.occupied {
    border-style: solid;
    border-color: rgba(255,255,255,0.7);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    cursor: pointer;
    animation: slotFill 0.28s cubic-bezier(0.34,1.56,0.64,1);
}
.buffer-slot.occupied:active { transform: scale(0.88); }
@keyframes slotFill {
    0% { transform: scale(0); }
    70% { transform: scale(1.18); }
    100% { transform: scale(1); }
}
.buffer-slot .slot-cross { color:rgba(0,0,0,0.3); font-size:14px; font-weight:900; pointer-events:none; }

/* Progress + basket */
.gray-screws { display: none; }
.progress-area {
    display: flex; align-items: center; gap: 6px;
    padding: 0 14px 3px; justify-content: flex-end; flex-shrink: 0;
}
.progress-box-icon { font-size: 18px; }
.progress-text { font-size: 12px; font-weight: 600; color: rgba(0,0,60,0.42); }


#game-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Tools Bar */
.tools-bar {
    display: flex; gap: 10px;
    padding: 6px 14px 10px;
    justify-content: center; z-index: 50;
}
.tool-btn {
    background: linear-gradient(135deg, #4A90E2, #3478C8);
    border: 3px solid rgba(255,255,255,0.4);
    border-radius: 16px;
    padding: 8px 14px;
    cursor: pointer; color: #fff;
    display: flex; flex-direction: column;
    align-items: center; gap: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: 90px;
    position: relative; transition: transform 0.1s;
}
.tool-btn:active { transform: scale(0.93); }
.tool-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
    filter: grayscale(0.35);
}
.tool-icon { font-size: 22px; }
.tool-badge {
    position: absolute; top: -6px; right: -6px;
    background: #FF5252; color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 2px 5px; border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.5);
}
.tool-label { font-size: 10px; font-weight: 700; letter-spacing: 0.3px; }

/* ===== SETTINGS ===== */
.settings-box { max-width: 340px; }
.settings-list { display: flex; flex-direction: column; gap: 14px; margin: 16px 0; }
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.setting-label { font-size: 14px; font-weight: 600; color: #444; }
.setting-slider {
    -webkit-appearance: none; appearance: none;
    width: 120px; height: 6px;
    background: rgba(0,0,0,0.15); border-radius: 3px; outline: none;
}
.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 18px; height: 18px; border-radius: 50%;
    background: #E67E22; border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25); cursor: pointer;
}
.toggle-switch {
    position: relative; width: 48px; height: 26px; display: inline-block;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0; background: #ccc; border-radius: 13px;
    transition: 0.3s; cursor: pointer;
}
.toggle-slider::before {
    content: ''; position: absolute; width: 20px; height: 20px;
    left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: #E67E22; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }
.setting-reset { width: 100%; font-size: 13px; padding: 10px; color: #E74C3C; border-color: #E74C3C; }
.mobile-only { display: none; }
@media (pointer: coarse) { .mobile-only { display: flex; } }

/* ===== OVERLAYS ===== */
.overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-box {
    background: linear-gradient(135deg, #fff 0%, #f0f8ff 100%);
    border-radius: 24px;
    padding: 28px 24px;
    text-align: center; color: #333;
    max-width: 330px; width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    animation: popIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.overlay-box h2 { font-size: 22px; margin-bottom: 12px; color: #222; }

.victory-box { border-top: 6px solid #4CAF50; }
.gameover-box { border-top: 6px solid #FF5252; }

.victory-icon { font-size: 52px; margin-bottom: 6px; }
.gameover-icon { font-size: 52px; margin-bottom: 6px; }
.unlock-icon { font-size: 48px; margin-bottom: 6px; }

.screws-earned {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin: 10px 0;
    background: rgba(255,193,7,0.15);
    border-radius: 12px; padding: 8px 20px;
}
.earned-icon { font-size: 26px; }
#earned-count { font-size: 28px; font-weight: 900; color: #F39C12; }
.victory-sub { color: #666; font-size: 13px; margin-bottom: 4px; }

.stuck-msg { color: #FF5252; font-size: 14px; margin: 6px 0 10px; }
.revive-reward-hint {
    color: #555;
    font-size: 12px;
    line-height: 1.35;
    margin: -2px 0 2px;
    text-align: center;
}
.unlock-msg { color: #555; font-size: 13px; margin: 6px 0 10px; line-height: 1.4; }

.overlay-buttons {
    display: flex; flex-direction: column; gap: 10px; margin-top: 16px;
}

/* Buttons */
.btn {
    border: none; border-radius: 14px;
    cursor: pointer; font-family: inherit;
    font-weight: 700; font-size: 15px;
    padding: 13px 24px;
    transition: transform 0.1s, box-shadow 0.1s;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
    background: linear-gradient(135deg, #FF8C00, #FF6B00);
    color: #fff;
    box-shadow: 0 4px 14px rgba(255,140,0,0.4);
}
.btn-outline {
    background: rgba(255,255,255,0.7);
    border: 2px solid #ddd; color: #444;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.btn-text {
    background: transparent; color: #888;
    font-size: 13px; padding: 8px;
}
.btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

/* ===== GALLERY ===== */
#gallery-screen {
    background: linear-gradient(180deg, #87CEEB, #B0E0FF);
    min-height: 0;
}
.gallery-grid {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) + 132px);
    overflow-y: auto; flex: 1;
    min-height: 0;
    max-height: 100%;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
}
.gallery-item {
    display: flex; flex-direction: column;
    position: relative;
    overflow: visible;
    cursor: pointer; transition: transform 0.12s;
    gap: 8px;
}
.gallery-item:active { transform: scale(0.97); }
.gallery-item-frame {
    position: relative;
    background: #F5E6CC;
    border: 6px solid #8B6914;
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22), inset 0 0 16px rgba(0,0,0,0.05);
    padding: 8px;
}
.gallery-item-frame .art-frame-corner {
    width: 18px;
    height: 18px;
    font-size: 10px;
}
.gallery-item-frame .art-frame-corner.tl { top: -9px; left: -9px; }
.gallery-item-frame .art-frame-corner.tr { top: -9px; right: -9px; }
.gallery-item-frame .art-frame-corner.bl { bottom: -9px; left: -9px; }
.gallery-item-frame .art-frame-corner.br { bottom: -9px; right: -9px; }
.gallery-item-canvas-wrap {
    position: relative;
    background: #F5E6CC;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}
.gallery-item canvas {
    width: 100%;
    height: 100%;
    display: block;
}
.gallery-item-hidden-locked canvas {
    filter: blur(0.45px) saturate(0.88) brightness(0.98);
    opacity: 1;
}
.gallery-hidden-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 8px;
    background: rgba(30, 42, 60, 0.04);
    color: #fff;
    text-align: left;
    pointer-events: none;
}
.gallery-hidden-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.4px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.45);
    background: rgba(0, 0, 0, 0.38);
    border-radius: 10px;
    padding: 2px 8px;
}
.gallery-hidden-sub {
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.95;
    background: rgba(0, 0, 0, 0.32);
    border-radius: 10px;
    padding: 2px 8px;
}
.gallery-footer {
    background: rgba(0,0,0,0.35);
    padding: 5px 8px 6px;
    display: flex; align-items: center; gap: 6px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.16);
}
.gallery-bar {
    flex: 1; height: 6px; background: rgba(255,255,255,0.25);
    border-radius: 3px; overflow: hidden;
}
.gallery-bar-fill {
    height: 100%; background: #F5A623;
    border-radius: 3px; transition: width 0.5s;
}
.gallery-pct {
    font-size: 12px; font-weight: 700;
    color: #fff; min-width: 30px; text-align: right;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ===== SCREW ELEMENT ON CANVAS (for hit areas) ===== */
.screw-hit {
    position: absolute; cursor: pointer;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}
.screw-hit.blocked { cursor: default; }

/* ===== Animations ===== */
@keyframes screwPop {
    0% { transform: translate(-50%,-50%) scale(1); }
    40% { transform: translate(-50%,-50%) scale(1.4) rotate(180deg); }
    100% { transform: translate(-50%,-50%) scale(0) rotate(540deg); opacity: 0; }
}
.screw-hit.removing {
    animation: screwPop 0.3s ease-in forwards;
    pointer-events: none;
}

@keyframes platePhysics {
    0% { transform: rotate(0deg) translateY(0); opacity: 1; }
    20% { transform: rotate(var(--fall-rot, 8deg)) translateY(10px); }
    100% { transform: rotate(var(--fall-rot, 15deg)) translateY(500px); opacity: 0; }
}
.plate-falling {
    animation: platePhysics 0.8s ease-in forwards;
    pointer-events: none;
}

@keyframes screwFloat {
    0% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
    60% { transform: translate(-50%, calc(-50% - 40px)) scale(0.8); opacity: 0.8; }
    100% { transform: translate(-50%, calc(-50% - 80px)) scale(0.5); opacity: 0; }
}

@keyframes shake {
    0%,100% { transform: translateX(0); }
    15% { transform: translateX(-8px); }
    30% { transform: translateX(8px); }
    45% { transform: translateX(-6px); }
    60% { transform: translateX(6px); }
    75% { transform: translateX(-3px); }
    90% { transform: translateX(3px); }
}
.shake { animation: shake 0.4s ease-out; }

@keyframes sparkle {
    0% { opacity: 1; transform: scale(0) rotate(0deg); }
    50% { opacity: 1; transform: scale(1.5) rotate(180deg); }
    100% { opacity: 0; transform: scale(0) rotate(360deg); }
}

/* Language switcher */
.lang-switcher {
    position: absolute; top: 10px; right: 14px;
    display: flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.75);
    border-radius: 14px; padding: 4px 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    z-index: 10;
}
.lang-btn {
    background: none; border: none; cursor: pointer;
    font-size: 13px; font-weight: 700; color: #888;
    padding: 2px 4px; border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.lang-btn.active { color: #E67E22; background: rgba(230,126,34,0.12); }
.lang-sep { color: #ccc; font-size: 12px; }
.home-screw-balance {
    display: flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,0.75);
    border-radius: 20px; padding: 6px 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    margin-top: 4px;
}
.balance-icon { font-size: 18px; }
.balance-num { font-size: 20px; font-weight: 900; color: #D4830A; }
.balance-label { font-size: 12px; color: #888; font-weight: 600; }

/* Art Detail Screen */
#art-detail-screen { align-items: center; gap: 10px; padding-bottom: 16px; position: relative; }
/* Block all taps/clicks while screw-fill animation runs (buttons re-enabled in JS after). */
#art-detail-screen.art-fill-busy {
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.art-detail-header {
    width: 100%; position: relative;
    display: flex; align-items: center; justify-content: center;
    padding: 10px 14px;
    flex-shrink: 0;
}
.art-detail-header .back-btn {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
}
.art-detail-name {
    font-size: 28px; font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.25), 0 1px 0 rgba(0,0,0,0.15);
    letter-spacing: 1px;
}
.art-detail-frame {
    width: min(300px, 80vw); height: min(300px, 80vw);
    background: #F5E6CC;
    border: 8px solid #8B6914;
    border-radius: 8px;
    position: relative; flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    display: flex; align-items: center; justify-content: center;
}
#art-detail-canvas { width: 100%; height: 100%; display: block; border-radius: 2px; }

.art-detail-progress-wrap {
    display: flex; align-items: center; gap: 8px;
    width: min(300px, 80vw);
}
.art-detail-progress-bar {
    flex: 1; height: 10px; background: rgba(0,0,0,0.15);
    border-radius: 5px; overflow: hidden;
}
.art-detail-progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #F39C12, #E67E22);
    border-radius: 5px; transition: width 0.05s linear;
}
.art-detail-pct {
    font-size: 13px; font-weight: 700; color: #555; min-width: 36px;
}

.art-detail-reserve {
    display: flex; align-items: center; gap: 12px;
    background: rgba(255,255,255,0.85);
    border-radius: 16px; padding: 10px 18px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    width: min(320px, 88vw);
}
.reserve-basket {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    flex: 1;
}
.basket-icon { font-size: 32px; line-height: 1; }
.basket-screws {
    display: flex; align-items: center; gap: 4px;
}
.basket-screw-icon { font-size: 16px; }
.reserve-count { font-size: 20px; font-weight: 900; color: #D4830A; }
.reserve-controls { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.slider-row { display: flex; align-items: center; width: 100%; }
.fill-slider {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 8px;
    background: linear-gradient(90deg, #F39C12, #E67E22);
    border-radius: 4px; outline: none;
    cursor: pointer;
}
.fill-slider:disabled {
    background: rgba(0,0,0,0.15);
    cursor: default;
}
.fill-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid #E67E22;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    cursor: pointer;
}
.fill-slider:disabled::-webkit-slider-thumb {
    border-color: #aaa;
    cursor: default;
}
.slider-label {
    font-size: 12px; font-weight: 700; color: #888;
    text-align: center;
}
.reserve-fill-btn { padding: 10px 18px; font-size: 14px; white-space: nowrap; }
.reserve-fill-btn:disabled { opacity: 0.4; cursor: default; }

/* Flying screw animation */
.flying-screw {
    position: fixed;
    width: 24px; height: 24px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
    z-index: 9999;
    transition: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.8);
}
.flying-screw::after {
    content: '+';
    color: rgba(0,0,0,0.3);
    font-size: 12px; font-weight: 900;
}

/* Responsive */
@media (max-width: 380px) {
    .art-frame { width: min(200px, 60vw); height: min(200px, 60vw); }
    .art-progress-bar { width: min(200px, 60vw); }
    .screw-box { width: 72px; }
    .tool-btn { min-width: 78px; padding: 7px 10px; }
}
@media (max-height: 680px) {
    .art-frame { width: 160px; height: 160px; }
    .art-progress-bar { width: 160px; }
    .home-content { gap: 4px; padding-top: 45px; padding-bottom: 12px; }
    .home-nav-btn { padding: 7px 12px; }
    .home-nav-btn .nav-icon { font-size: 20px; }
}
