* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}
body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    background: #141720;
    font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
}
#webgl-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* Top Header UI */
#top-header {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    background: rgba(20, 24, 34, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    padding: 7px 16px;
    border-radius: 30px;
    backdrop-filter: blur(14px);
    z-index: 100;
    max-width: 95vw;
}
@media (max-width: 820px) {
    #top-header {
        flex-wrap: wrap;
        top: 8px;
        padding: 6px 12px;
        border-radius: 20px;
    }
}
.kopri-brand-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.96);
    padding: 3px 12px;
    border-radius: 16px;
    box-shadow: 0 0 14px rgba(33, 185, 221, 0.5), inset 0 0 4px rgba(0, 74, 147, 0.15);
    border: 1.5px solid #21b9dd;
    height: 32px;
    cursor: default;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.kopri-brand-badge:hover {
    transform: scale(1.04);
    box-shadow: 0 0 20px rgba(33, 185, 221, 0.8);
}
.kopri-header-img {
    height: 20px;
    width: auto;
    object-fit: contain;
    display: block;
}
.modal-kopri-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    padding: 6px 18px;
    border-radius: 14px;
    margin-bottom: 14px;
    border: 2px solid #21b9dd;
    box-shadow: 0 4px 18px rgba(33, 185, 221, 0.4);
}
.kopri-modal-img {
    height: 32px;
    width: auto;
    object-fit: contain;
    display: block;
}
.header-btn {
    background: linear-gradient(135deg, #e53935, #c62828);
    border: none;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    padding: 7px 13px;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(229, 57, 53, 0.4);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.header-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(229, 57, 53, 0.6);
}
.header-btn:active {
    transform: scale(0.96);
}
.header-btn.btn-purple {
    background: linear-gradient(135deg, #7c4dff, #512da8);
    box-shadow: 0 4px 15px rgba(124, 77, 255, 0.4);
}
.header-btn.btn-blue {
    background: linear-gradient(135deg, #00b0ff, #00838f);
    box-shadow: 0 4px 15px rgba(0, 176, 255, 0.4);
}
.header-btn.btn-teal {
    background: linear-gradient(135deg, #26a69a, #00695c);
    box-shadow: 0 4px 15px rgba(38, 166, 154, 0.4);
}
.stat-badge {
    color: #cfd8dc;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.stat-badge b {
    color: #ffd54f;
    font-size: 15px;
    font-weight: 800;
}
#combo-badge {
    background: linear-gradient(135deg, #ff6f00, #ff8f00);
    color: #fff;
    padding: 4px 10px;
    border-radius: 14px;
    box-shadow: 0 0 14px rgba(255, 111, 0, 0.8);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.5px;
    display: none;
    align-items: center;
    gap: 4px;
}
.pulse-combo {
    animation: pulse-combo-anim 0.35s ease-out;
}
@keyframes pulse-combo-anim {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1.0); }
}

/* Top Guide Banner */
#status-guide {
    position: absolute;
    top: 74px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 24, 34, 0.85);
    border: 1px solid rgba(229, 57, 53, 0.4);
    padding: 7px 24px;
    border-radius: 20px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(8px);
    z-index: 99;
    pointer-events: none;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

/* Shortcut Banner */
#shortcut-banner {
    position: absolute;
    top: 112px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    letter-spacing: 0.5px;
    z-index: 99;
    pointer-events: none;
    background: rgba(0,0,0,0.3);
    padding: 3px 12px;
    border-radius: 12px;
}

/* Right Panel (View Mode & Tension) */
#right-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    z-index: 100;
}
.side-btn {
    background: rgba(26, 32, 48, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #b0bec5;
    font-size: 12px;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.15s ease;
    text-align: center;
}
.side-btn:hover {
    background: rgba(45, 55, 80, 0.95);
    color: #fff;
    transform: translateX(-3px);
}
.side-btn.active {
    background: #e53935;
    border-color: #ef5350;
    color: #fff;
    box-shadow: 0 4px 15px rgba(229, 57, 53, 0.5);
}
#btn-lefthand.active {
    background: #00897b;
    border-color: #26a69a;
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 137, 123, 0.45);
}

/* Arcade Tension Meter Card */
.tension-card {
    background: rgba(18, 24, 38, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 9px 11px;
    text-align: center;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    min-width: 136px;
}
.tension-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 8px;
    letter-spacing: 0.3px;
    transition: all 0.3s ease;
}
.tension-badge.standard {
    background: rgba(255, 179, 0, 0.18);
    border: 1px solid #ffb300;
    color: #ffd54f;
    text-shadow: 0 0 8px rgba(255, 179, 0, 0.4);
}
.tension-badge.generous {
    background: rgba(76, 175, 80, 0.25);
    border: 1px solid #4caf50;
    color: #81c784;
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.6);
    animation: lucky-glow 1s infinite alternate;
}
.tension-badge.hard {
    background: rgba(244, 67, 54, 0.2);
    border: 1px solid #f44336;
    color: #ef5350;
    text-shadow: 0 0 8px rgba(244, 67, 54, 0.4);
}
.tension-badge.fever {
    background: linear-gradient(135deg, rgba(255, 61, 0, 0.4), rgba(255, 214, 0, 0.4));
    border: 1px solid #ffd600;
    color: #fff9c4;
    text-shadow: 0 0 12px rgba(255, 214, 0, 0.9);
    animation: fever-pulse 0.45s infinite alternate;
}
@keyframes fever-pulse {
    from { box-shadow: 0 0 6px rgba(255, 61, 0, 0.5), 0 0 16px rgba(255, 214, 0, 0.7); transform: scale(1.0); }
    to { box-shadow: 0 0 14px rgba(255, 61, 0, 0.9), 0 0 28px rgba(255, 214, 0, 1.0); transform: scale(1.06); }
}
@keyframes lucky-glow {
    from { box-shadow: 0 0 4px rgba(76, 175, 80, 0.3); }
    to { box-shadow: 0 0 14px rgba(76, 175, 80, 0.8); }
}
#tension-desc {
    font-size: 10px;
    color: #b0bec5;
    margin-top: 5px;
    line-height: 1.35;
}
.tension-meta {
    font-size: 9px;
    color: #78909c;
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    letter-spacing: 0.3px;
}

/* Virtual Joystick */
#joystick-container {
    position: absolute;
    bottom: calc(35px + env(safe-area-inset-bottom, 0px));
    left: 35px;
    width: 130px;
    height: 130px;
    background: radial-gradient(circle, rgba(40, 48, 68, 0.7) 0%, rgba(18, 22, 32, 0.9) 100%);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    touch-action: none;
    z-index: 100;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}
#joystick-handle {
    width: 54px;
    height: 54px;
    background: radial-gradient(circle at 35% 35%, #ff5252, #c62828);
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    transition: transform 0.05s ease-out;
}

/* Grab Button */
#grab-btn {
    position: absolute;
    bottom: calc(35px + env(safe-area-inset-bottom, 0px));
    right: 35px;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle at 35% 35%, #ff5252, #b71c1c);
    border: 4px solid #ffffff;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    font-weight: 900;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 8px 25px rgba(229, 57, 53, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: all 0.1s ease;
}
body.left-handed #joystick-container {
    left: auto;
    right: 35px;
}
body.left-handed #grab-btn {
    right: auto;
    left: 35px;
}
#grab-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(229, 57, 53, 0.8);
}
#grab-btn:active {
    transform: scale(0.94);
    box-shadow: 0 4px 15px rgba(229, 57, 53, 0.5);
}
#grab-btn.second-tap {
    background: radial-gradient(circle at 35% 35%, #ffd54f, #f57f17) !important;
    box-shadow: 0 8px 25px rgba(245, 127, 23, 0.7) !important;
    animation: pulse-ring 0.6s infinite alternate;
}
@keyframes pulse-ring {
    0% { transform: scale(1.0); }
    100% { transform: scale(1.08); }
}
#grab-btn sub {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 2px;
}

/* Win Notification Modal */
#win-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(20, 24, 34, 0.96);
    border: 2px solid #ffd54f;
    padding: 30px 48px;
    border-radius: 24px;
    text-align: center;
    color: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 213, 79, 0.4);
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#win-modal.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}
#win-modal h1 {
    font-size: 30px;
    color: #ffd54f;
    margin-bottom: 8px;
    text-shadow: 0 2px 10px rgba(255, 213, 79, 0.6);
}
#win-modal p {
    font-size: 16px;
    color: #cfd8dc;
    margin-bottom: 20px;
}
#win-modal button {
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    border: none;
    color: #212121;
    font-weight: 800;
    font-size: 15px;
    padding: 10px 28px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 179, 0, 0.4);
}

/* Collection Shelf Modal */
#collection-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    background: rgba(16, 20, 30, 0.97);
    border: 2px solid #7c4dff;
    border-radius: 24px;
    padding: 24px 30px;
    color: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85), 0 0 40px rgba(124, 77, 255, 0.3);
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 660px;
    width: 92vw;
    max-height: 86vh;
    overflow-y: auto;
    backdrop-filter: blur(16px);
}
#collection-modal.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 10px;
}
.modal-header h2 {
    font-size: 21px;
    color: #ffd54f;
    display: flex;
    align-items: center;
    gap: 8px;
}
.rank-tag {
    background: linear-gradient(135deg, #7c4dff, #512da8);
    padding: 5px 12px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 2px 10px rgba(124, 77, 255, 0.4);
}
.modal-summary {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: #b0bec5;
    margin-bottom: 16px;
}
.modal-summary b {
    color: #69f0ae;
    font-size: 16px;
}
.shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(95px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}
.shelf-card {
    background: rgba(30, 36, 52, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 12px 6px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: transform 0.2s, background 0.2s;
}
.shelf-card:hover {
    transform: translateY(-3px);
    background: rgba(45, 55, 80, 0.9);
}
.shelf-card.golden-card {
    border: 2px solid #ffd700;
    background: linear-gradient(145deg, rgba(70, 52, 10, 0.7), rgba(35, 28, 10, 0.85));
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.4);
}
.toy-icon {
    font-size: 30px;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}
.toy-name {
    font-size: 12px;
    font-weight: 700;
    color: #cfd8dc;
}
.toy-count {
    font-size: 11px;
    color: #90a4ae;
}
.toy-count b {
    color: #ffd54f;
    font-size: 14px;
}
.modal-close-btn {
    display: block;
    margin: 0 auto;
    background: linear-gradient(135deg, #7c4dff, #512da8);
    border: none;
    color: #fff;
    font-weight: 800;
    font-size: 15px;
    padding: 9px 36px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(124, 77, 255, 0.4);
    transition: transform 0.15s;
}
.modal-close-btn:hover {
    transform: scale(1.05);
}

/* Achievements Section & Toast */
.achievements-section {
    margin-bottom: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.achievements-title {
    font-size: 14px;
    font-weight: 800;
    color: #ffd54f;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 8px;
}
.ach-badge {
    background: rgba(24, 29, 44, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.45;
    filter: grayscale(0.8);
    transition: all 0.2s ease;
}
.ach-badge.unlocked {
    opacity: 1;
    filter: none;
    background: linear-gradient(135deg, rgba(33, 185, 221, 0.18), rgba(124, 77, 255, 0.22));
    border-color: #21b9dd;
    box-shadow: 0 2px 12px rgba(33, 185, 221, 0.25);
}
.ach-icon {
    font-size: 22px;
    flex-shrink: 0;
}
.ach-info {
    text-align: left;
    min-width: 0;
}
.ach-name {
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ach-desc {
    font-size: 10.5px;
    color: #b0bec5;
    margin-top: 2px;
    line-height: 1.25;
}
#achievement-toast {
    position: fixed;
    top: 118px;
    left: 50%;
    transform: translate(-50%, -18px) scale(0.92);
    background: linear-gradient(135deg, rgba(16, 22, 36, 0.96), rgba(30, 42, 70, 0.96));
    border: 2px solid #21b9dd;
    color: #fff;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65), 0 0 20px rgba(33, 185, 221, 0.5);
    z-index: 300;
    pointer-events: none;
    opacity: 0;
    transition: all 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
}
#achievement-toast.active {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

/* Mobile & Tablet Responsive Overrides */
@media (max-width: 820px) {
    #shortcut-banner {
        display: none;
    }
    #status-guide {
        top: 108px;
        max-width: 92vw;
        font-size: 12px;
        padding: 6px 14px;
        line-height: 1.35;
    }
    #right-panel {
        top: auto;
        bottom: calc(165px + env(safe-area-inset-bottom, 0px));
        right: 12px;
        gap: 6px;
    }
    .side-btn {
        font-size: 11.5px;
        padding: 7px 11px;
    }
    #achievement-toast {
        top: 152px;
    }
}
@media (max-width: 540px) {
    #top-header {
        top: calc(6px + env(safe-area-inset-top, 0px));
        gap: 5px;
        padding: 5px 10px;
        border-radius: 16px;
    }
    .kopri-brand-badge {
        height: 26px;
        padding: 2px 8px;
        border-radius: 12px;
    }
    .kopri-header-img {
        height: 16px;
    }
    .header-btn {
        font-size: 11px;
        padding: 5px 9px;
        border-radius: 12px;
    }
    .stat-badge {
        font-size: 11.5px;
        gap: 3px;
    }
    .stat-badge b {
        font-size: 13px;
    }
    #status-guide {
        top: calc(86px + env(safe-area-inset-top, 0px));
        font-size: 11.5px;
        padding: 5px 12px;
    }
    #right-panel {
        bottom: calc(130px + env(safe-area-inset-bottom, 0px));
        right: 10px;
        gap: 5px;
    }
    #right-panel > div:first-child {
        display: none;
    }
    .side-btn {
        font-size: 11px;
        padding: 6px 10px;
        border-radius: 9px;
    }
    #joystick-container {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        left: 16px;
        width: 104px;
        height: 104px;
    }
    #joystick-handle {
        width: 44px;
        height: 44px;
    }
    #grab-btn {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        right: 16px;
        width: 96px;
        height: 96px;
        font-size: 17px;
        border-width: 3px;
    }
    #grab-btn sub {
        font-size: 9.5px;
    }
    body.left-handed #joystick-container {
        left: auto;
        right: 16px;
    }
    body.left-handed #grab-btn {
        right: auto;
        left: 16px;
    }
    #win-modal {
        width: 88vw;
        padding: 22px 20px;
    }
    #win-modal h1 {
        font-size: 24px;
    }
    #collection-modal {
        padding: 18px 16px;
        border-radius: 18px;
    }
    .modal-header h2 {
        font-size: 17px;
    }
}
