* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    overflow: hidden;
    background-color: #000;
    position: fixed;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/* Desain Teks Status di Kiri Atas */
#status {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    z-index: 25;
    color: #ffffff;
    padding: 8px 14px;
    border-radius: 10px;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 13px;
    line-height: 1.3;
    max-width: 220px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* --- Screen layout --- */
.screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: none;
    background: linear-gradient(180deg, #f6fbff 0%, #fff 60%);
    overflow: hidden;
}
.screen.active { display: block; }

/* Home screen */
.home-header { display:flex; align-items:center; gap:16px; padding: calc(20px + env(safe-area-inset-top)) 20px 0 20px; }
.avatar { width:88px; height:88px; background:#fff; border-radius:24px; display:flex; align-items:center; justify-content:center; font-size:44px; box-shadow:0 6px 16px rgba(0,0,0,0.12); }
.greeting h2 { font-size:20px; color:#0b6; margin-bottom:6px; }
.greeting p { font-size:13px; color:#666; }

.home-main { display:flex; flex-direction:column; gap:18px; padding:28px 20px; }
.big-btn { display:flex; flex-direction:column; align-items:flex-start; gap:6px; padding:18px 22px; border-radius:28px; color:#fff; font-size:18px; font-weight:700; border:none; box-shadow:0 8px 18px rgba(0,0,0,0.12); cursor: pointer; }
.big-btn .sub { display:block; font-size:13px; font-weight:500; opacity:0.9; }
.big-btn.yellow { background:#FFD24D; color:#4b3b00 }
.big-btn.green { background:#3EC77B; }
.big-btn.blue { background:#48A9FF; }

.home-bottomnav, .builder-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    padding: 8px 40px;
    z-index: 30;
}
.nav-item { width:58px; height:58px; border-radius:14px; background:#fff; border:none; box-shadow:0 8px 18px rgba(0,0,0,0.12); font-size:20px; cursor: pointer; }
.nav-item.active { background:#00a8ff; color:#fff; }

/* Builder/AR overlays */
#webcam { position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; height: 100dvh; object-fit: cover; z-index: 1; transform: scaleX(-1); }
#tracking_canvas { position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; height: 100dvh; z-index: 3000; pointer-events: none; transform: scaleX(-1); }
#output_canvas { position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; height: 100dvh; z-index: 3; pointer-events: none; }

#btn-tracking { display: none !important; }

.right-controls {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    top: max(80px, calc(16px + env(safe-area-inset-top)));
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 25;
}
.rc-btn { width:52px; height:52px; border-radius:12px; border:none; background:linear-gradient(180deg,#fff,#f0f0f0); box-shadow:0 8px 20px rgba(0,0,0,0.12); font-size:20px; cursor: pointer; transition: 0.2s; }
.rc-btn:active { transform: scale(0.95); }
.rc-btn.delete {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.rc-btn.delete.active {
    background: linear-gradient(135deg, #ff4b4b, #ff2a2a) !important;
    color: white !important;
    box-shadow: 0 8px 25px rgba(255, 75, 75, 0.5);
    transform: scale(1.1);
}
.rc-btn.webxr-ar {
    background: linear-gradient(135deg, #00c6ff, #0072ff) !important;
    color: white !important;
    box-shadow: 0 6px 16px rgba(0, 114, 255, 0.4);
}
.rc-btn.webxr-ar.hidden {
    display: none !important;
}

/* Top Center Controls (Undo & Redo) */
.top-center-controls {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 25;
}
.tc-btn {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(180deg, #fff, #f0f0f0);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.tc-btn:active {
    transform: scale(0.95);
}

/* Color Picker & Palette */
.color-picker-container {
    position: relative;
    display: flex;
    align-items: center;
}
.color-palette {
    position: absolute;
    right: 64px;
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 26;
}
.color-palette.hidden {
    opacity: 0;
    transform: translateX(15px);
    pointer-events: none;
}
.color-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}
.color-dot:active {
    transform: scale(0.9);
}
.color-dot.red { background: #FF6B6B; }
.color-dot.green { background: #39C07A; }
.color-dot.blue { background: #2B9CFF; }
.color-dot.yellow { background: #FFD24D; }
.color-dot.orange { background: #FF9D00; }
.color-dot.purple { background: #9b59b6; }
.color-dot.active {
    border: 3px solid #000 !important;
    transform: scale(1.15);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.bottom-fab {
    position: absolute;
    left: max(12px, env(safe-area-inset-left));
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 25;
    max-height: calc(100dvh - 160px);
}

/* Scrollable Carousel Wrapper */
.carousel-wrapper {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
    min-height: 0;
}
.carousel-wrapper::-webkit-scrollbar { display: none; }

.carousel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 8px;
    background: rgba(255,255,255,0.95);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    align-items: center;
    height: max-content;
}
.carousel .block {
    width: 62px;
    height: 72px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.6);
    font-size: 12px;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
    padding: 6px 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.carousel .block:active { transform: scale(0.92); }
.carousel .block.selected {
    border: 2px solid #000;
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}
.carousel .block svg {
    width: 28px;
    height: 28px;
}
.carousel .block span {
    font-size: 9px;
    font-weight: 600;
    line-height: 1;
    opacity: 0.9;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.carousel .blue { background: linear-gradient(135deg, #2B9CFF, #1a7de0); }
.carousel .yellow { background: linear-gradient(135deg, #FFD24D, #f0b800); color:#3b2b00; }
.carousel .green { background: linear-gradient(135deg, #39C07A, #28a866); }
.carousel .red { background: linear-gradient(135deg, #FF6B6B, #e04545); }
.carousel .orange { background: linear-gradient(135deg, #FF9D00, #e08800); }
.carousel .purple { background: linear-gradient(135deg, #9b59b6, #8344a0); }

.camera-btn { width:78px; height:78px; background:#fff; border-radius:50%; border:none; box-shadow:0 12px 28px rgba(0,0,0,0.18); font-size:26px; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); flex-shrink: 0; cursor: pointer; }
.camera-btn.active {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    color: white;
    box-shadow: 0 8px 25px rgba(0, 114, 255, 0.4);
    transform: scale(1.05);
}

/* Floating Scale/Size Indicator Overlay */
.scale-badge {
    position: absolute;
    transform: translate(-50%, -130%) scale(0.9);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    padding: 8px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 999;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: opacity 0.15s ease-out, transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0;
    font-family: system-ui, -apple-system, sans-serif;
    color: #333;
}

.scale-badge.visible {
    opacity: 1;
    transform: translate(-50%, -140%) scale(1);
}

.scale-badge.hidden {
    display: none !important;
}

.scale-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #888;
}

.scale-value {
    font-size: 18px;
    font-weight: 800;
    color: #ff4b4b;
    text-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.scale-dims {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 6px;
    white-space: nowrap;
}

/* Scroll buttons for vertical carousel */
.scroll-btn {
    width: 62px;
    height: 62px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 25;
    flex-shrink: 0;
}
.scroll-btn:active {
    transform: scale(0.92);
}
.scroll-btn:hover {
    background: #f0f0f0;
}

/* Level Overlay and Modals */
.level-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}
.level-overlay.hidden {
    display: none !important;
}
.level-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.4);
    transform: scale(0.9);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes popIn {
    to { transform: scale(1); }
}
.level-card h2 {
    font-size: 22px;
    margin-bottom: 10px;
    color: #1e293b;
    font-weight: 800;
}
.level-card p {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 20px;
}
.level-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}
.lvl-btn {
    padding: 12px 18px;
    border-radius: 14px;
    border: none;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    align-items: center;
}
.lvl-btn.easy {
    background: #f0fdf4;
    color: #166534;
    border: 1.5px solid #bbf7d0;
}
.lvl-btn.easy:hover { background: #dcfce7; transform: translateY(-2px); }
.lvl-btn.medium {
    background: #fefbeb;
    color: #854d0e;
    border: 1.5px solid #fef08a;
}
.lvl-btn.medium:hover { background: #fef9c3; transform: translateY(-2px); }
.lvl-btn.hard {
    background: #fef2f2;
    color: #991b1b;
    border: 1.5px solid #fecaca;
}
.lvl-btn.hard:hover { background: #fee2e2; transform: translateY(-2px); }

.lvl-btn-back {
    background: #e2e8f0;
    color: #475569;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}
.lvl-btn-back:hover { background: #cbd5e1; }

/* Success Card customization */
.success-card {
    background: rgba(255, 255, 255, 0.45) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 2px solid rgba(74, 222, 128, 0.6) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
.success-card h2 {
    color: #15803d !important;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}
.success-card p {
    color: #0f172a !important;
    font-weight: 700;
}

/* HUD styles */
.game-hud {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1.5px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    padding: 10px 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.12);
    z-index: 100;
    font-family: system-ui, sans-serif;
    max-width: 280px;
    width: calc(100% - 140px);
}
.game-hud.hidden {
    display: none !important;
}
.hud-title {
    font-size: 13px;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 3px;
    text-align: center;
}
.hud-title span {
    color: #2b9cff;
}
.hud-status {
    font-size: 10px;
    color: #64748b;
    margin-bottom: 8px;
    text-align: center;
}
.hud-buttons {
    display: flex;
    gap: 8px;
}
.hud-btn {
    flex: 1;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.hud-btn.reset {
    background: #f1f5f9;
    color: #475569;
}
.hud-btn.reset:hover { background: #e2e8f0; }
.hud-btn.exit {
    background: #fee2e2;
    color: #991b1b;
}
.hud-btn.exit:hover { background: #fecaca; }

/* Komprehensif Mobile Responsiveness (UI & UX Portrait & Landscape) */
@media (max-width: 768px) {
    /* Home Screen Tweaks */
    .avatar {
        width: 68px;
        height: 68px;
        font-size: 32px;
    }
    .greeting h2 {
        font-size: 18px;
    }
    .greeting p {
        font-size: 12px;
    }
    .home-main {
        padding: 15px;
        gap: 12px;
    }
    .big-btn {
        padding: 14px 18px;
        font-size: 16px;
        border-radius: 20px;
    }
    .big-btn .sub {
        font-size: 11px;
    }

    /* Status Text */
    #status {
        font-size: 11px !important;
        top: max(10px, env(safe-area-inset-top)) !important;
        left: max(10px, env(safe-area-inset-left)) !important;
        padding: 6px 10px !important;
        max-width: 140px !important;
    }

    /* Builder Screen Layout & Button Sizes */
    .tc-btn {
        width: 44px;
        height: 44px;
        font-size: 16px;
        border-radius: 10px;
    }
    .top-center-controls {
        top: max(10px, env(safe-area-inset-top));
        gap: 8px;
    }

    .rc-btn {
        width: 44px;
        height: 44px;
        font-size: 16px;
        border-radius: 10px;
    }
    .right-controls {
        right: max(8px, env(safe-area-inset-right));
        top: max(70px, calc(10px + env(safe-area-inset-top)));
        gap: 8px;
    }

    /* Vertical Carousel Left Panel */
    .bottom-fab {
        left: max(8px, env(safe-area-inset-left));
        gap: 6px;
        max-height: calc(100dvh - 140px);
    }
    .scroll-btn {
        width: 46px;
        height: 46px;
        font-size: 18px;
        border-radius: 10px;
    }
    .carousel {
        padding: 8px 5px;
        border-radius: 12px;
        gap: 6px;
    }
    .carousel .block {
        width: 46px;
        height: 56px;
        border-radius: 10px;
        font-size: 9px;
        padding: 4px 2px;
    }
    .carousel .block svg {
        width: 20px;
        height: 20px;
    }
    .carousel .block span {
        font-size: 8px;
    }
    .camera-btn {
        width: 58px;
        height: 58px;
        font-size: 20px;
        border-radius: 50%;
    }

    /* Color Palette */
    .color-palette {
        right: 52px;
        padding: 6px 10px;
        gap: 6px;
    }
    .color-dot {
        width: 26px;
        height: 26px;
    }

    /* Game HUD */
    .game-hud {
        top: max(65px, calc(50px + env(safe-area-inset-top)));
        left: 50%;
        transform: translateX(-50%);
        max-width: 240px;
        width: calc(100% - 120px);
        padding: 8px 12px;
        border-radius: 12px;
    }

    /* Bottom Navigation Bar */
    .home-bottomnav, .builder-bottomnav {
        bottom: max(6px, env(safe-area-inset-bottom));
        padding: 4px 16px;
    }
    .nav-item {
        width: 46px;
        height: 46px;
        font-size: 18px;
        border-radius: 10px;
    }

    /* Overlays */
    .level-card {
        padding: 18px;
        width: 88%;
        border-radius: 18px;
    }
    .level-card h2 {
        font-size: 18px;
        margin-bottom: 6px;
    }
    .level-card p {
        font-size: 11px;
        margin-bottom: 14px;
    }
    .level-buttons {
        gap: 8px;
        margin-bottom: 12px;
    }
    .lvl-btn {
        padding: 10px 14px;
        font-size: 12px;
        border-radius: 10px;
    }
    .lvl-btn-back {
        padding: 10px 16px;
        font-size: 12px;
        border-radius: 10px;
    }
}

/* Optimasi Landscape HP (max-height: 500px) */
@media (max-height: 500px) {
    .home-header {
        padding-top: 10px;
    }
    .avatar {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
    .home-main {
        padding: 10px 20px;
        gap: 8px;
        flex-direction: row;
    }
    .big-btn {
        flex: 1;
        padding: 10px 14px;
        font-size: 14px;
    }

    #status {
        font-size: 10px !important;
        max-width: 120px !important;
        padding: 4px 8px !important;
    }

    .top-center-controls {
        top: 6px;
        gap: 6px;
    }
    .tc-btn, .rc-btn, .scroll-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
        border-radius: 8px;
    }
    .right-controls {
        top: 6px;
        gap: 6px;
    }
    .bottom-fab {
        max-height: calc(100dvh - 70px);
        gap: 4px;
    }
    .carousel {
        padding: 4px;
        gap: 4px;
    }
    .carousel .block {
        width: 38px;
        height: 44px;
        font-size: 8px;
        padding: 2px;
    }
    .carousel .block svg {
        width: 16px;
        height: 16px;
    }
    .camera-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }
    .nav-item {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
    .home-bottomnav, .builder-bottomnav {
        bottom: 4px;
        padding: 2px 10px;
    }
}
