:root {
    --primary: #5d4037;
    --accent: #ffd700;
    --bg: #3e2723;
    --panel: rgba(43, 29, 26, 0.7);
    --glass: rgba(255, 255, 255, 0.1);
    --text: #ffffff;
    --sidebar-width: 220px;
}

* {
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    touch-action: none; /* Mencegah pull-to-refresh & scroll */
}

#game-scaler {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
    width: 1040px;
    height: 620px;
    margin: 0;
    padding: 0;
    pointer-events: auto;
}

.game-container {
    width: calc(800px + var(--sidebar-width) + 20px);
    height: 600px;
    background: #3e2723;
    border: 10px solid #2b1d1a;
    border-radius: 30px;
    display: flex;
    position: relative;
    overflow: hidden;
    box-sizing: border-box !important;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8), inset 0 0 40px rgba(0,0,0,0.5);
}

canvas {
    width: 800px;
    height: 550px;
    background: #4caf50;
    cursor: crosshair;
    touch-action: none;
}

/* --- HUD & Layout --- */
.hud {
    position: absolute;
    top: 0; left: 0; width: 800px; height: 100px;
    pointer-events: none;
    z-index: 1000;
}

.hud-cluster {
    position: absolute;
    top: 25px;
    display: flex;
    gap: 15px;
    z-index: 1000;
    pointer-events: none;
}

.hud-left { left: 25px; }
.hud-right { 
    right: 25px;
    justify-content: flex-end;
}

.stat-card {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 215, 0, 0.4);
    color: #ffffff;
    font-weight: 800;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    transition: all 0.3s ease;
    pointer-events: auto;
}
.stat-card:hover { transform: translateY(-2px); border-color: #ffd700; }

.hud-btn {
    background: linear-gradient(135deg, #ffd700 0%, #ff8f00 100%);
    color: #1a1a1a;
    border: none;
    padding: 8px 24px;
    border-radius: 12px;
    font-weight: 900;
    font-size: 16px;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.3s ease;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    margin-right: 10px;
}
.hud-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.6);
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex-shrink: 0;
    background: rgba(62, 39, 35, 0.6);
    backdrop-filter: blur(15px);
    padding: 12px 18px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-left: 6px solid #2b1d1a;
    z-index: 500;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Firefox */
}
.sidebar::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.title-panel {
    background: #3e2723;
    padding: 6px;
    border-radius: 12px;
    text-align: center;
    border: 3px solid #ffd700;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.title-panel img {
    max-height: 32px !important;
    margin-bottom: 0px !important;
}

.title-panel h2 {
    color: #ffd700;
    margin: 0;
    font-size: 13px !important;
    letter-spacing: 1px !important;
    line-height: 1.2;
}

.tower-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 6px;
    padding-bottom: 15px;
}

.tower-card {
    width: 100%;
    height: 64px;
    background: rgba(141, 110, 99, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 6px 2px;
    box-shadow: 0 2px 0 #3e2723;
    overflow: hidden;
}

.tower-card .icon {
    font-size: 20px;
    margin-bottom: 2px;
}

.tower-card .name {
    font-size: 8.5px;
    font-weight: 900;
    color: #fff;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.1;
}

.tower-card .price {
    font-size: 9.5px;
    font-weight: 900;
    color: #ffd700;
    background: rgba(0,0,0,0.3);
    padding: 2px 4px;
    border-radius: 4px;
    width: 90%;
    text-align: center;
}
.tower-card.just-unlocked {
    animation: tower-pulse 1.5s infinite alternate;
    background: rgba(255, 215, 0, 0.2) !important;
    border-color: #ffd700;
}
@keyframes tower-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
    100% { transform: scale(1.05); box-shadow: 0 0 15px rgba(255, 215, 0, 0.8); }
}

.tower-card:hover:not(.locked) {
    transform: translateY(-4px);
    background: #fdf5e6;
    border-color: #ffd700;
    box-shadow: 0 10px 0 #3e2723;
}

.tower-card.selected {
    background: #ffffff;
    border-color: #ffd700;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
    transform: scale(1.1) translateY(-5px);
}

.tower-card .icon {
    font-size: 14px;
    margin-bottom: 0px;
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.2));
}

.tower-card .name {
    font-size: 8.5px !important;
    font-weight: 900;
    margin: 1px 0;
}

.tower-card .price {
    background: #3e2723;
    width: 100%;
    text-align: center;
    font-size: 8px;
    font-weight: 900;
    color: #ffd700;
    border-radius: 6px;
    padding: 2px 0;
}

.tower-card.locked-wave {
    opacity: 0.3;
    filter: blur(2px) grayscale(1);
    cursor: not-allowed;
    transform: scale(0.9);
    box-shadow: none;
}

.controls-panel {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.ctrl-btn {
    background: #4caf50;
    border: none;
    border-bottom: 3px solid #2e7d32;
    color: white;
    padding: 6px;
    border-radius: 8px;
    font-weight: 900;
    font-size: 11px;
    cursor: pointer;
    transition: transform 0.1s;
}

.ctrl-btn.speed-on { background: #ff9800; border-bottom-color: #e65100; }
.ctrl-btn.pause-on { background: #f44336; border-bottom-color: #b71c1c; }

.ability-btn {
    background: linear-gradient(135deg, #0288d1, #01579b);
    border: none;
    border-bottom: 3px solid #014a70;
    color: white; 
    padding: 4px;
    border-radius: 10px; 
    cursor: pointer;
    font-weight: 900; 
    font-size: 11px;
    box-shadow: 0 2px 0 #013a5a;
    transition: all 0.1s;
    display: flex; 
    align-items: center; 
    justify-content: center;
    gap: 10px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.cooldown-overlay {
    position: absolute; bottom:0; left:0; width:100%; height:0;
    background: rgba(255,255,255,0.3);
    transition: height 0.1s linear;
    pointer-events: none;
}

/* --- Overlays & Modals --- */
#msg {
    position: absolute; top: 110px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: #ffd700; padding: 15px 40px;
    border-radius: 30px; border: 3px solid #ffd700; font-weight: 900;
    font-size: 28px; letter-spacing: 4px; display: none; z-index: 2000;
}

#intro-txt {
    position: absolute; top:50%; left:50%;
    transform: translate(-50%, -50%);
    font-size: 60px; font-weight: 900;
    color: white; text-shadow: 0 0 30px rgba(76, 175, 80, 0.8);
    letter-spacing: 5px; opacity:0; pointer-events: none;
    z-index: 5000; text-align: center;
}

.intro-active { animation: introIn 3.5s forwards; }
@keyframes introIn {
    0% { opacity:0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity:1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity:1; transform: translate(-50%, -50%) scale(1.1); }
    100% { opacity:0; transform: translate(-50%, -50%) scale(1.5); }
}

#boss-warning {
    position: absolute; top: 40%; left: 0; width: 800px;
    background: linear-gradient(to right, transparent, rgba(244, 67, 54, 0.9), transparent);
    color: white; padding: 25px 0; font-weight: 900; text-align: center;
    font-size: 32px; letter-spacing: 6px; box-shadow: 0 0 40px rgba(244, 67, 54, 0.5);
    display: none; z-index: 3000;
}

.modal {
    position: absolute; top: 0; left: 0; width: 1000px; height: 100%;
    background: rgba(0,0,0,0.85); display: none; backdrop-filter: blur(10px);
    z-index: 9999; flex-direction: column; align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal h1 { font-size: 80px; color: #f44336; margin: 0; text-shadow: 0 0 30px #f44336; }
.modal p { color: white; font-size: 24px; margin: 20px 0; }

#upgradePanel {
    position: absolute; bottom: 20px; left: 20px;
    background: rgba(43, 29, 26, 0.7);
    backdrop-filter: blur(20px);
    padding: 18px; border-radius: 20px;
    border: 2px solid rgba(255, 215, 0, 0.3); display: none; flex-direction: column; gap: 10px; z-index: 2000;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6); width: 230px;
}
#upgradePanel h3 { margin: 0; color: #ff9800; font-size: 16px; }
#upgradeBtn { 
    background: #ff9800; border: none; padding: 10px; border-radius: 8px;
    color: white; font-weight: 900; cursor: pointer;
}

/* --- Tooltips --- */
.tower-tooltip {
    position: absolute;
    width: 160px;
    background: rgba(43, 29, 26, 0.98);
    backdrop-filter: blur(10px);
    border: 2px solid #ffd700;
    border-radius: 12px;
    padding: 12px;
    color: white;
    font-size: 11px;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    box-shadow: -10px 10px 30px rgba(0,0,0,0.8);
    z-index: 10000;
    pointer-events: none;
}
.tower-tooltip.visible {
    opacity: 1;
    visibility: visible;
}



.tower-tooltip h4 { 
    margin: 0 0 6px 0; 
    color: #ffd700; 
    border-bottom: 2px solid rgba(255,255,255,0.2); 
    padding-bottom: 4px; 
    font-size: 14px; 
    text-transform: uppercase;
    text-align: left;
}
.tower-tooltip .stat-line { 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 6px; 
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 2px;
}

/* --- Main Menu & Overlays --- */
.overlay {
    position: absolute;
    top: 0; left: 0; width: 1040px; height: 620px;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    z-index: 5000;
    display: none;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
}
.overlay.active { display: flex; }

.menu-box {
    text-align: center;
    background: linear-gradient(135deg, #1a1a1a 0%, #3d2b1f 100%);
    padding: 50px 80px;
    border-radius: 30px;
    border: 3px solid #ffd700;
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.2);
}

.menu-logo {
    height: 80px;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 10px rgba(255,215,0,0.4));
    animation: floatingLogo 3s ease-in-out infinite;
}

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

.menu-box .title {
    font-size: 64px;
    font-weight: 900;
    line-height: 0.9;
    letter-spacing: -2px;
    margin-bottom: 10px;
    color: white;
    text-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.menu-box .subtitle {
    font-size: 18px;
    letter-spacing: 5px;
    color: #ffd700;
    text-transform: uppercase;
    margin-bottom: 40px;
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.btn-menu {
    padding: 18px 40px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-menu.primary {
    background: #ffd700;
    color: #1a1a1a;
    box-shadow: 0 10px 0 #b8860b;
}

.btn-menu.primary:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 0 #b8860b;
}

.btn-menu.secondary {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 2px solid white;
}

.btn-menu.secondary:hover {
    background: white;
    color: #1a1a1a;
}

/* --- Map Selection Modal --- */
.modal-box.large {
    width: 920px;
    max-height: 560px;
    height: 560px;
    background: #1a1a1a;
    border-radius: 20px;
    padding: 25px 30px;
    border: 2px solid #5d4037;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 2px solid #3e2723;
    padding-bottom: 12px;
    flex-shrink: 0;
}

.close-x {
    background: none; border: none; color: white; font-size: 32px; cursor: pointer;
}

.map-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    overflow-y: auto;
    padding-right: 10px;
}

.map-card {
    background: #2b1d1a;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.map-card:hover {
    transform: scale(1.05);
    border-color: #ffd700;
}

.map-thumb {
    width: 100%;
    height: 100px;
    position: relative;
    background: #1a1a1a;
}
.map-preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.map-info {
    padding: 10px;
    text-align: center;
}

.map-info h3 {
    font-size: 12px;
    margin: 0;
    color: #fff;
    line-height: 1.2;
    text-transform: uppercase;
}

.map-info p {
    font-size: 10px;
    color: #ffd700;
    margin-top: 5px;
}

/* --- Responsive & Orientation Overlay --- */
#orientation-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #2b1d1a;
    z-index: 10000;
    color: white;
    justify-content: center;
    align-items: center;
    text-align: center;
}

#orientation-overlay .phone-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
}

@keyframes rotatePhone {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

/* Tampilkan overlay HANYA pada layar kecil berorientasi portrait */
@media screen and (max-width: 900px) and (orientation: portrait) {
    #orientation-overlay {
        display: flex;
        flex-direction: column;
    }
}

/* Penyesuaian untuk iPad/Tablets atau Layar Medium */
@media screen and (max-width: 1100px) {
    :root { --sidebar-width: 200px; }
    .stat-card { padding: 8px 12px; font-size: 18px; }
}

@media screen and (max-height: 600px) {
    .game-container { border-radius: 0; border: none; }
}

/* --- Katalog (Arsip Nusantara) --- */
.catalog-box {
    width: 920px !important;
    height: 560px !important;
    max-height: 560px !important;
    background: linear-gradient(135deg, #1a1a1a 0%, #2b1d1a 100%) !important;
    border: 2px solid #ffd700 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.catalog-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    border-bottom: 2px solid rgba(255, 215, 0, 0.2);
    padding-bottom: 8px;
    flex-shrink: 0;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: rgba(255, 255, 255, 0.5);
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.25s;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.tab-btn:hover {
    color: white;
}

.tab-btn.active {
    color: #ffd700;
    background: rgba(255, 215, 0, 0.08);
    border-bottom: 3px solid #ffd700;
    border-radius: 6px 6px 0 0;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding: 4px 8px 4px 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,215,0,0.3) transparent;
}

.catalog-grid::-webkit-scrollbar {
    width: 6px;
}
.catalog-grid::-webkit-scrollbar-track {
    background: transparent;
}
.catalog-grid::-webkit-scrollbar-thumb {
    background: rgba(255,215,0,0.3);
    border-radius: 3px;
}

.catalog-card {
    background: rgba(255, 215, 0, 0.03);
    border: 1px solid rgba(255, 215, 0, 0.12);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    transition: all 0.25s ease;
    position: relative;
    min-height: 100px;
}

.catalog-card:hover:not(.locked) {
    background: rgba(255, 215, 0, 0.07);
    border-color: rgba(255, 215, 0, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.catalog-card.locked {
    filter: grayscale(1) brightness(0.5);
    background: rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.05);
}

.card-icon-big {
    font-size: 32px;
    background: rgba(0,0,0,0.4);
    width: 60px;
    height: 60px;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    line-height: 1;
}

.card-info {
    flex: 1;
    min-width: 0;
    padding-right: 70px;
}

.card-info h3 {
    margin: 0 0 4px 0;
    color: #ffd700;
    font-size: 15px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-info .desc {
    font-size: 10.5px;
    color: rgba(255,255,255,0.65);
    line-height: 1.5;
    margin-bottom: 8px;
}

.card-info .stats {
    display: flex;
    gap: 12px;
    font-size: 10px;
    font-weight: 800;
    color: #80cbc4;
}

.unlock-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 9px;
    background: rgba(93,64,55,0.9);
    color: #ffd700;
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid rgba(255,215,0,0.4);
    white-space: nowrap;
    font-weight: 700;
}

@media screen and (max-width: 800px) {
    .catalog-grid { grid-template-columns: 1fr; }
    .catalog-box { width: 95vw !important; }
}
/* --- Fullscreen Buttons --- */
.fs-btn-main {
    position: absolute;
    top: 25px;
    right: 25px;
    background: rgba(255, 215, 0, 0.05);
    border: 2px solid rgba(255, 215, 0, 0.2);
    color: #ffd700;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.fs-btn-main:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: #ffd700;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

.fs-toggle-btn {
    font-size: 18px !important;
    background: rgba(43, 29, 26, 0.6) !important;
    border: 2px solid rgba(255, 215, 0, 0.3) !important;
    color: #ffd700 !important;
    min-width: 44px !important;
    margin-right: 5px;
}

.fs-toggle-btn:hover {
    background: #ffd700 !important;
    color: #3e2723 !important;
    border-color: #fff !important;
    transform: translateY(-2px) scale(1.05);
}

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

/* --- QRIS Modal Animations --- */
@keyframes modalPop {
    0% { transform: scale(0.8) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

#qrisModal .qris-container {
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#qrisModal {
    transition: opacity 0.3s ease;
}

/* --- Splash Screen Animations --- */
.splash-logo {
    animation: splashPulse 2s ease-in-out infinite;
}

@keyframes splashPulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 20px rgba(255,215,0,0.5)); }
    50% { transform: scale(1.05); filter: drop-shadow(0 0 40px rgba(255,215,0,0.8)); }
}

#splash-screen {
    background: linear-gradient(rgba(0,0,0,0.65) 0%, rgba(0,0,0,0.85) 100%), url('bg_splash.png');
    background-size: cover;
    background-position: center;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.8s ease, visibility 0.8s;
}

#splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* --- Tactical Radar Scan Effect --- */
.tactical-scan {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 229, 255, 0.05) 50.2%, 
        rgba(18, 16, 16, 0) 50.4%
    );
    background-size: 100% 4px;
    z-index: 5;
    pointer-events: none;
}

.tactical-scan::after {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(
        rgba(255, 215, 0, 0.03) 0%, 
        rgba(255, 215, 0, 0) 10%, 
        rgba(255, 215, 0, 0) 90%, 
        rgba(255, 215, 0, 0.03) 100%
    );
    pointer-events: none;
}

#splash-tips {
    transition: opacity 0.4s ease-in-out;
}

#splash-tips.fade-out-text {
    opacity: 0;
}
