/* ==========================================================================
   BANGUN PALI — CSS Design System
   Susun Bangunan Ikonik Kabupaten PALI
   ========================================================================== */

/* Google Fonts are loaded in HTML */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');

/* ==========================================================================
   CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   ========================================================================== */
:root {
    /* Primary Colors */
    --color-primary-navy: #002D8C;
    --color-primary-maroon: #8B1A2B;
    --color-accent-gold: #E5A93B;
    --color-accent-blue-light: #E8F4FD;

    /* Background & Panel */
    --color-bg-dark: #0A0E1A;
    --color-panel-bg: rgba(9, 13, 22, 0.85);
    --color-panel-border: rgba(255, 255, 255, 0.08);

    /* Text */
    --color-text-white: #F1F5F9;
    --color-text-gray: #94A3B8;

    /* Grid Tiles */
    --color-tile-even: #1A2332;
    --color-tile-odd: #15202E;

    /* Transitions & Shadows */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-premium: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    --shadow-gold-glow: 0 0 15px rgba(229, 169, 59, 0.3);
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
}

/* ==========================================================================
   LIGHT THEME OVERRIDES
   ========================================================================== */
:root.light-theme {
    --color-bg-dark: #F0F4F8;
    --color-panel-bg: rgba(255, 255, 255, 0.92);
    --color-panel-border: rgba(0, 45, 140, 0.1);
    --color-text-white: #1F2937;
    --color-text-gray: #6B7280;
    --color-tile-even: #D1E3F8;
    --color-tile-odd: #E2ECF5;
    --shadow-premium: 0 8px 32px rgba(0, 45, 140, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* ==========================================================================
   RESET & BASE
   ========================================================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--color-bg-dark);
    color: var(--color-text-white);
    font-family: 'Outfit', sans-serif;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(0, 45, 140, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(139, 26, 43, 0.1) 0%, transparent 45%);
}

.app-container {
    width: 100%;
    max-width: 1100px;
    height: 100%;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
    background: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    backdrop-filter: blur(12px);
    padding: 10px 20px;
    border-radius: var(--border-radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-premium);
    flex-wrap: wrap;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--color-primary-maroon), var(--color-accent-gold));
    border-radius: var(--border-radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: white;
    box-shadow: 0 4px 12px rgba(139, 26, 43, 0.4);
}

.logo-text h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(90deg, var(--color-accent-gold), #FFD700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    font-size: 10px;
    color: var(--color-text-gray);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
}

.header-right-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: rgba(9, 13, 22, 0.6);
    border: 1.5px solid var(--color-panel-border);
    color: var(--color-text-gray);
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-smooth);
}

.icon-btn:hover {
    background: rgba(229, 169, 59, 0.15);
    border-color: var(--color-accent-gold);
    color: var(--color-accent-gold);
}

.light-theme .icon-btn {
    background: white;
    color: var(--color-primary-navy);
    border-color: var(--color-panel-border);
}

.game-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-card {
    background: rgba(9, 13, 22, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius-sm);
    padding: 4px 12px;
    text-align: center;
}

.light-theme .stat-card {
    background: rgba(0, 45, 140, 0.06);
    border-color: rgba(0, 45, 140, 0.08);
}

.stat-label {
    font-size: 9px;
    text-transform: uppercase;
    color: var(--color-text-gray);
    letter-spacing: 0.5px;
    display: block;
}

.stat-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-accent-gold);
}

/* ==========================================================================
   MAIN GAME WORKSPACE
   ========================================================================== */
.game-workspace {
    display: flex;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.reference-panel, .build-panel {
    flex: 1;
    background: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius-lg);
    padding: 8px;
    box-shadow: var(--shadow-premium);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

.panel-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 12px;
    color: var(--color-accent-gold);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.building-name {
    margin-left: auto;
    font-family: 'Fredoka', sans-serif;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--color-primary-maroon), #A0213A);
    padding: 2px 8px;
    border-radius: 10px;
}

.light-theme .building-name {
    color: white;
}

.cmd-progress {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-gray);
    font-family: 'Outfit', sans-serif;
}

.reference-grid-wrapper, .build-grid-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

/* Building Grid */
.building-grid {
    display: grid;
    gap: 3px;
    width: 100%;
    max-width: 280px;
    aspect-ratio: 1 / 1;
}

.building-grid.grid-3x3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.building-grid.grid-4x4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.grid-cell {
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: var(--transition-smooth);
    overflow: hidden;
}

.grid-cell.even { background-color: var(--color-tile-even); }
.grid-cell.odd { background-color: var(--color-tile-odd); }

.grid-cell svg {
    width: 85%;
    height: 85%;
}

/* Build grid cell states */
.grid-cell.filled {
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.grid-cell.correct-cell {
    border: 2px solid #10B981 !important;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.grid-cell.wrong-cell {
    border: 2px solid #DC2626 !important;
    box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
    animation: shake 0.4s ease;
}

.grid-cell.active-fill {
    border: 2px solid var(--color-accent-gold) !important;
    box-shadow: 0 0 14px var(--color-accent-gold);
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

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

/* ==========================================================================
   BOTTOM PANEL (Materials + Commands + Actions)
   ========================================================================== */
.bottom-panel {
    background: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius-lg);
    padding: 8px 12px;
    box-shadow: var(--shadow-premium);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.section-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 11px;
    color: var(--color-accent-gold);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-bottom: 2px;
}

/* Materials Palette */
.materials-section {
    display: flex;
    flex-direction: column;
}

.materials-palette {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.material-btn {
    width: 48px;
    height: 48px;
    background: rgba(9, 13, 22, 0.5);
    border: 2px solid var(--color-panel-border);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-smooth);
    padding: 4px;
    position: relative;
}

.material-btn:hover {
    background: rgba(0, 45, 140, 0.15);
    border-color: var(--color-primary-maroon);
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 45, 140, 0.3);
}

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

.material-btn svg {
    width: 80%;
    height: 80%;
}

.material-btn .material-label {
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 7px;
    font-family: 'Fredoka', sans-serif;
    color: var(--color-text-gray);
    white-space: nowrap;
    pointer-events: none;
}

.light-theme .material-btn {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
}

/* Command Bar */
.command-section {
    display: flex;
    flex-direction: column;
}

.command-bar {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 4px 0;
    min-height: 44px;
    align-items: center;
}

.command-bar::-webkit-scrollbar {
    height: 4px;
}

.command-bar::-webkit-scrollbar-thumb {
    background: var(--color-accent-gold);
    border-radius: 10px;
}

.cmd-slot {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: rgba(255, 255, 255, 0.03);
    border: 2px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-smooth);
}

.cmd-slot.filled {
    border-style: solid;
    border-color: var(--color-accent-gold);
    background: rgba(229, 169, 59, 0.08);
}

.cmd-slot.active-exec {
    transform: scale(1.15);
    box-shadow: 0 0 12px var(--color-accent-gold);
    z-index: 5;
}

.cmd-slot.completed-exec {
    opacity: 0.5;
}

.cmd-slot svg {
    width: 75%;
    height: 75%;
}

.light-theme .cmd-slot {
    background: rgba(0, 45, 140, 0.03);
    border-color: rgba(0, 45, 140, 0.12);
}

.light-theme .cmd-slot.filled {
    border-color: var(--color-accent-gold);
    background: rgba(229, 169, 59, 0.1);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.action-right {
    display: flex;
    gap: 8px;
}

.action-btn {
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition-smooth);
    white-space: nowrap;
}

.primary-btn {
    background: linear-gradient(135deg, var(--color-primary-maroon), #A0213A);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 26, 43, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 26, 43, 0.5);
}

.secondary-btn {
    background: rgba(9, 13, 22, 0.6);
    color: var(--color-text-gray);
    border: 1px solid var(--color-panel-border);
}

.secondary-btn:hover {
    background: rgba(229, 169, 59, 0.1);
    color: var(--color-accent-gold);
    border-color: var(--color-accent-gold);
}

.light-theme .secondary-btn {
    background: white;
    color: var(--color-primary-navy);
    border-color: rgba(0, 0, 0, 0.08);
}

.action-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Copyright Bar */
.copyright-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    flex: 1;
    text-align: center;
}

.copyright-bar span {
    font-size: 8px;
    color: var(--color-text-gray);
    opacity: 0.45;
    font-family: 'Outfit', sans-serif;
}

.copyright-bar a {
    color: var(--color-accent-gold);
    text-decoration: none;
    opacity: 1;
}

.copyright-bar a:hover {
    text-decoration: underline;
}

.light-theme .copyright-bar a {
    color: var(--color-primary-maroon);
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    backdrop-filter: blur(20px);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    max-width: 480px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
}

.light-theme .modal-content {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 25px 60px rgba(0, 45, 140, 0.15);
}

.animate-zoom {
    animation: zoomIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 24px;
    color: var(--color-text-gray);
    cursor: pointer;
    transition: var(--transition-smooth);
    line-height: 1;
}

.close-btn:hover {
    color: var(--color-accent-gold);
    transform: rotate(90deg);
}

.modal-header {
    text-align: center;
    margin-bottom: 16px;
}

.badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--color-primary-navy), var(--color-primary-maroon));
    color: white;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.badge-wrong {
    background: linear-gradient(135deg, #DC2626, #B91C1C);
}

.badge-gold {
    background: linear-gradient(135deg, var(--color-accent-gold), #D4941F);
}

.modal-header h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text-white);
}

.modal-description {
    font-size: 14px;
    color: var(--color-text-gray);
    line-height: 1.6;
    text-align: center;
}

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

.modal-footer {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

/* Success Stars */
.success-stars {
    display: flex;
    gap: 8px;
    font-size: 28px;
}

.success-stars .star {
    color: rgba(255, 255, 255, 0.15);
    transition: var(--transition-smooth);
}

.success-stars .star.earned {
    color: var(--color-accent-gold);
    filter: drop-shadow(0 0 6px rgba(229, 169, 59, 0.6));
    animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.success-icon {
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.success-icon svg {
    width: 100%;
    height: 100%;
}

/* Levels Grid */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 4px;
}

.level-card {
    background: rgba(9, 13, 22, 0.5);
    border: 2px solid var(--color-panel-border);
    border-radius: var(--border-radius-md);
    padding: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

.level-card:hover {
    background: rgba(0, 45, 140, 0.15);
    border-color: var(--color-primary-maroon);
    transform: translateY(-3px);
}

.level-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.level-card.locked:hover {
    transform: none;
    border-color: var(--color-panel-border);
}

.level-card.completed {
    border-color: #10B981;
}

.level-card-icon {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.level-card-icon svg {
    width: 100%;
    height: 100%;
}

.level-card-name {
    font-size: 11px;
    font-weight: 600;
    color: white;
    font-family: 'Fredoka', sans-serif;
}

.level-card-num {
    font-size: 9px;
    color: var(--color-text-gray);
}

.light-theme .level-card {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.06);
}

.light-theme .level-card-name {
    color: #1F2937;
}

/* Final Score */
.final-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 32px;
    font-weight: 700;
    color: var(--color-accent-gold);
    text-align: center;
}

/* ==========================================================================
   CONFETTI
   ========================================================================== */
.confetti-particle {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 9999;
    animation: confettiFall 2.5s ease-in forwards;
}

@keyframes confettiFall {
    0% { opacity: 1; transform: translateY(0) rotate(0deg); }
    100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* ==========================================================================
   RESPONSIVE — Mobile (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding: 6px;
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .app-container {
        height: auto;
        max-height: none;
        gap: 5px;
        padding-bottom: 24px;
    }

    .app-header {
        padding: 6px 12px;
        gap: 6px;
    }

    .logo-text h1 { font-size: 16px; }
    .logo-text p { font-size: 7px; }
    .logo-icon { width: 32px; height: 32px; font-size: 15px; }

    .stat-value { font-size: 14px; }
    .stat-label { font-size: 7px; }
    .stat-card { padding: 2px 8px; }

    .game-workspace {
        gap: 5px;
    }

    .reference-panel, .build-panel {
        padding: 5px;
        gap: 3px;
    }

    .panel-label { font-size: 10px; }

    .building-grid { max-width: 200px; }

    .bottom-panel {
        padding: 6px 8px;
        gap: 4px;
    }

    .material-btn {
        width: 38px;
        height: 38px;
    }

    .cmd-slot {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .section-label { font-size: 9px; }

    .copyright-bar span { font-size: 6px; }
}

/* ==========================================================================
   LIGHT THEME EXTRA OVERRIDES
   ========================================================================== */
:root.light-theme .logo-text h1 {
    background: linear-gradient(90deg, var(--color-primary-maroon), var(--color-accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

:root.light-theme .panel-label,
:root.light-theme .section-label {
    color: var(--color-primary-maroon);
}

:root.light-theme .code-panel-header {
    border-color: rgba(0, 0, 0, 0.08);
}
