:root {
    --bg-dark: #0a0a0a;
    --text-light: #f4ecd8;
    --gold: #d4af37;
    --gold-dim: #997a00;
    --curse-purple: #4a0e4e;
    --danger: #cf1c1c;
    --success: #2e8b57;
    --panel-bg: rgba(20, 15, 10, 0.85);

    --font-title: 'Cinzel', serif;
    --font-ui: 'Merienda', cursive;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: var(--font-ui);
    overflow: hidden;
    touch-action: none;
    /* Prevent scroll on mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    /* Limit width for browser testing, but mobile will be full width */
    height: 100%;
    aspect-ratio: 9/16;
    background-color: #000;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

@media (min-aspect-ratio: 1/1) {
    #game-container {
        height: 100%;
        width: auto;
    }
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas when UI is not active */
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--panel-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 10;
    padding: 20px;
    text-align: center;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

/* Typography */
h1,
h2 {
    font-family: var(--font-title);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 10px;
}

.title {
    font-size: 2.5rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.subtitle {
    font-size: 1.2rem;
    color: #ccc;
    margin-bottom: 40px;
}

.text-danger {
    color: var(--danger);
    text-shadow: 0 0 10px rgba(207, 28, 28, 0.5);
}

.text-success {
    color: var(--gold);
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 300px;
}

.btn {
    font-family: var(--font-title);
    font-size: 1.1rem;
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
}

.btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.btn.primary {
    background: linear-gradient(to bottom, var(--gold), var(--gold-dim));
    color: #111;
    border: 1px solid #fff;
}

.btn.secondary {
    background: rgba(40, 30, 20, 0.8);
    color: var(--text-light);
    border: 1px solid var(--gold-dim);
}

.btn-icon {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--gold-dim);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mt-4 {
    margin-top: 30px;
}

/* Ad Placeholders */
.ad-placeholder {
    margin-top: auto;
    width: 100%;
    height: 50px;
    background: #333;
    color: #888;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed #666;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

/* HUD System */
#screen-hud {
    background: none;
    justify-content: space-between;
    padding: 15px;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

#hud-health {
    display: flex;
    gap: 5px;
    font-size: 1.2rem;
}

#hud-temple-name {
    font-family: var(--font-title);
    color: var(--gold);
    text-shadow: 1px 1px 3px #000;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 20px;
    border: 1px solid var(--gold-dim);
}

#minimap-canvas {
    border-radius: 50%;
    border: 2px solid var(--gold);
    background-color: rgba(0, 0, 0, 0.7);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    image-rendering: pixelated;
    cursor: pointer;
    pointer-events: auto;
    /* Required to intercept touch events over absolute siblings or fallback */
    position: relative;
    z-index: 10;
}

.hud-inventory {
    width: 100%;
    background: rgba(20, 15, 10, 0.8);
    border-top: 2px solid var(--gold-dim);
    padding: 10px;
    border-radius: 10px 10px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.inventory-label {
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 5px;
    text-transform: uppercase;
}

#inventory-slots {
    display: flex;
    gap: 10px;
}

.item-slot {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #555;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    opacity: 0.3;
    /* Uncollected */
}

.item-slot.collected {
    opacity: 1;
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

/* Temple Map Grid */
#temple-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    width: 90%;
    max-width: 350px;
    margin: 20px 0;
}

.temple-btn {
    background: rgba(40, 30, 20, 0.8);
    border: 1px solid var(--gold-dim);
    color: var(--text-light);
    padding: 15px;
    border-radius: 8px;
    font-family: var(--font-title);
    font-size: 1.1rem;
    cursor: pointer;
    position: relative;
    text-align: left;
}

.temple-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(20, 20, 20, 0.8);
    border-color: #444;
}

.temple-btn.locked::after {
    content: "🔒";
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

/* Level 4 Puzzle */
#puzzle-grid {
    display: grid;
    grid-template-columns: repeat(2, 80px);
    grid-template-rows: repeat(2, 80px);
    gap: 10px;
    margin: 30px 0;
}

.puzzle-tile {
    background: var(--bg-dark);
    border: 2px solid var(--gold-dim);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    cursor: pointer;
}

.puzzle-tile.selected {
    border-color: var(--gold);
    box-shadow: 0 0 15px var(--gold);
}

/* Custom Modal */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    pointer-events: auto;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-box {
    background: var(--panel-bg);
    border: 2px solid var(--gold-dim);
    border-radius: 10px;
    padding: 20px;
    width: 80%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

#ui-alert-text {
    font-size: 1.2rem;
    line-height: 1.5;
    margin-bottom: 20px;
    font-family: var(--font-title);
    color: var(--text-light);
}

/* Mobile Controls Overlay */
.mobile-controls {
    display: none;
    /* Hidden by default, toggled via JS or media query */
    position: absolute;
    bottom: 90px;
    /* Shifted up to avoid overlapping inventory */
    left: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    /* Let clicks pass through empty space */
    z-index: 50;
    /* Ensure it stays above other elements but below modals */
}

/* Show on devices with coarse pointers (touch screens) */
@media (pointer: coarse) {
    .mobile-controls {
        display: flex;
    }
}

.d-pad,
.action-pad {
    pointer-events: auto;
    /* Re-enable clicks for the buttons */
    display: flex;
}

.d-pad {
    position: relative;
    width: 120px;
    height: 120px;
}

.d-btn {
    position: absolute;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(212, 175, 55, 0.5);
    border-radius: 5px;
    color: white;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.d-btn:active {
    background: rgba(212, 175, 55, 0.6);
}

.d-btn.top {
    top: 0;
    left: 40px;
}

.d-btn.bottom {
    bottom: 0;
    left: 40px;
}

.d-btn.left {
    top: 40px;
    left: 0;
}

.d-btn.right {
    top: 40px;
    right: 0;
}

.action-pad {
    flex-direction: row;
    gap: 15px;
}

.a-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(212, 175, 55, 0.5);
    color: white;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.a-btn:active {
    background: rgba(212, 175, 55, 0.6);
}