/* Game Specific Styles */
:root {
    --game-font-heading: 'Cinzel', serif;
    --game-font-body: 'Roboto', sans-serif;
    --panel-bg: rgba(20, 20, 30, 0.85);
    /* Dark semi-transparent */
    --text-gold: #FFD700;
    --text-light: #F0F0F0;
    --accent-red: #D32F2F;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #2c3e50;
    /* Fallback color */
    font-family: var(--game-font-body);
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
    /* Critical for mobile touch interaction */
    background: #1a1a2e;
}

canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

#game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to canvas */
}

/* Enable pointer events for UI elements */
.game-top-bar,
.game-info-panel,
.neighbors-panel {
    pointer-events: auto;
}

/* Top Bar */
.game-top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 24px;
    box-sizing: border-box;
    z-index: 100;
}

.topbar-section-left {
    display: flex;
    justify-content: flex-start;
}

.topbar-section-center {
    display: flex;
    justify-content: center;
    text-align: center;
}

.topbar-section-right {
    display: flex;
    justify-content: flex-end;
}

#region-title {
    margin: 0;
    color: white;
    font-family: var(--game-font-heading);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    font-size: 1.5rem;
    white-space: nowrap;
}

.game-btn-medieval {
    background: linear-gradient(135deg, #2c3e50, #1a252f);
    color: white;
    border: 1px solid #444;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--game-font-heading);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, background 0.2s;
    pointer-events: auto;
}

.game-btn-medieval:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #34495e, #2c3e50);
}

.btn-text-mobile {
    display: none;
}

.resource-container {
    display: flex;
    gap: 24px;
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.resource-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.resource-item span {
    color: var(--text-gold);
    font-weight: bold;
    font-size: 1.1rem;
    font-family: var(--game-font-body);
}

#close-game-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

#close-game-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Info Panel */
.game-info-panel {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: var(--panel-bg);
    padding: 16px 24px;
    border-radius: 12px;
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
}

.game-info-panel h2 {
    margin: 0;
    font-family: var(--game-font-heading);
    color: var(--text-gold);
    font-size: 1.5rem;
    letter-spacing: 1px;
}

.game-info-panel p {
    margin: 4px 0 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Neighbors Panel */
.neighbors-panel {
    position: absolute;
    top: 100px;
    right: 0;
    width: 300px;
    background: var(--panel-bg);
    border-radius: 12px 0 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-right: none;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
}

.neighbors-panel.collapsed {
    transform: translateX(260px);
    /* Keep tab visible */
}

.panel-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    font-family: var(--game-font-heading);
}

.neighbors-list {
    overflow-y: auto;
    padding: 8px;
}

.neighbor-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: background 0.2s;
}

.neighbor-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.neighbor-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-family: var(--game-font-heading);
}

.neighbor-info {
    flex: 1;
}

.neighbor-name {
    display: block;
    color: var(--text-light);
    font-weight: bold;
    font-size: 0.9rem;
}

.neighbor-level {
    font-size: 0.8rem;
    color: var(--text-gold);
}

/* Responsive Mobile Fixes */
@media (max-width: 600px) {
    .game-top-bar {
        padding: 0 12px;
        height: 64px;
        grid-template-columns: auto 1fr auto;
        /* Tighter layout */
        gap: 8px;
    }

    #region-title {
        font-size: 1rem;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .game-btn-medieval {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .btn-text-desktop {
        display: none;
    }

    .btn-text-mobile {
        display: inline;
    }

    .nav-icon-btn {
        width: 40px;
        height: 40px;
    }

    /* Smaller Labels for Mobile */
    .island-label {
        padding: 4px 10px;
        font-size: 0.7rem;
        gap: 2px;
    }

    .label-title {
        font-size: 0.8rem;
    }

    .label-progress {
        font-size: 0.65rem;
        padding: 1px 6px;
    }
}

/* Island Floating Labels (Minimalist & Interactive) */
.island-label {
    position: absolute;
    transform: translate(-50%, -100%) scale(0.9);
    background: rgba(20, 20, 30, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 215, 0, 0.4);
    padding: 6px 12px;
    border-radius: 40px;
    color: white;
    font-family: var(--game-font-heading);
    white-space: nowrap;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0.9;
    cursor: pointer;
    overflow: hidden;
    max-width: 150px;
}

.label-content-collapsed {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    /* Reduced from 8px */
}

.label-content-expanded {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    /* Reduced from 6px */
}

.island-label:hover {
    transform: translate(-50%, -105%) scale(1.1);
    background: rgba(20, 20, 30, 0.95);
    border: 1px solid rgba(255, 215, 0, 0.8);
    padding: 12px 24px;
    max-width: 400px;
    opacity: 1;
    z-index: 1000;
}

.island-label:hover .label-content-collapsed {
    display: none;
}

.island-label:hover .label-content-expanded {
    display: flex;
}

.label-title-first,
.label-title-full {
    color: var(--text-gold);
    font-weight: 700;
    font-size: 0.65rem;
    /* Reduced from 0.75rem */
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.label-title-full {
    font-size: 0.85rem;
    /* Reduced from 1rem */
}

.label-progress {
    font-family: var(--game-font-body);
    font-size: 0.55rem;
    /* Reduced from 0.65rem */
    background: rgba(46, 204, 113, 0.2);
    padding: 1px 5px;
    border-radius: 8px;
    color: #4CAF50;
    font-weight: bold;
}

.label-locked,
.label-mastered {
    color: #ff5252;
    font-size: 0.7rem;
    opacity: 0.8;
}

.label-mastered {
    color: var(--text-gold);
    font-weight: bold;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

/* Material Icons Override */
.material-symbols-outlined {
    font-variation-settings:
        'FILL' 1,
        'wght' 400,
        'GRAD' 0,
        'opsz' 24
}