@import url('https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@400;700&family=Merriweather:wght@400;700&display=swap');

:root {
    /* Encarta 97 Palette - Kept for reference, but UI is now image-based */
    --encarta-cream: #F4F1EA;
    --encarta-text: #4E483F;
    --encarta-blue: #788F9C;
    --encarta-tan: #C6BD98;
    --text-color: #4E483F;
}

body {
    font-family: 'Merriweather Sans', 'Helvetica', sans-serif;
    color: var(--text-color);

    /* Hide Scrollbars */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body::-webkit-scrollbar {
    display: none;
}

/* --- Common Glass/Menu Utilities --- */
.glass-panel {
    background: rgba(244, 241, 234, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(78, 72, 63, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
    color: var(--text-color);
    transition: all 0.3s ease;
}

/* --- Bottom Center Menu "Paper Scroll" (Img based) --- */

#bottom-ui-wrapper {
    position: absolute;
    /* 
       Dynamic positioning: -20vh (User confirmed sweet spot).
    */
    bottom: -20vh;
    left: 50%;
    transform: translateX(-50%);

    /* Wrapper fits the content (the image) */
    width: auto;
    height: auto;

    display: flex;
    justify-content: center;
    align-items: center;

    z-index: 1000;
    pointer-events: none;

    /* NO SHADOWS */
    filter: none;
    box-shadow: none;

    /* Animation transition for sliding - Slower as requested */
    transition: transform 1.5s cubic-bezier(0.22, 1, 0.36, 1);
}

#bottom-ui-wrapper.minimized {
    /* 
       Dynamic Calculation maintained with Centering:
       Target: Leave ~15vh visible as a handle.
       Current Offset: -20vh.
       Formula: visible = (Height - offset) - translate.
       15vh = (100% - 20vh) - translate.
       translate = 100% - 35vh.
    */
    transform: translateX(-50%) translateY(calc(100% - 35vh));
}

.bottom-menu-bg-img {
    display: block;
    /* 
       "Normal height and width (fit)"
       Scaled down 10% further (640px -> 580px)
    */
    max-width: 580px;
    width: 85vw;
    /* Responsive on mobile */
    height: auto;
    /* Preserve Aspect Ratio */

    pointer-events: auto;
    cursor: pointer;

    /* Smooth rendering */
    image-rendering: -webkit-optimize-contrast;
}

/* Clear the old class if it exists in DOM memory */
.bottom-menu-bg {
    display: none;
}

/* Clear any pseudo-elements that might add borders */
.bottom-menu-bg::before,
.bottom-menu-bg::after {
    display: none;
    content: none;
}

/* Content Container - NOW ABSOLUTE OVERLAY */
.bottom-menu-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    display: flex;
    justify-content: center;

    /* 
       DEBUG: Force items to the TOP of the container so they are visible 
       even if the bottom 170px is hidden.
    */
    align-items: center;

    /* 
       Lowered elements by reducing padding-bottom (120px -> 90px)
       This pushes the flex-centered/aligned items further down relative to the image
    */
    padding-bottom: 90px;

    gap: 32px;

    /* 
       CRITICAL: set to none so clicks on empty space fall through to the image 
       allowing the double-click handler to work.
    */
    pointer-events: none;

    z-index: 1001;
    /* Ensure on top */
    flex-direction: column;
    /* Stack the main controls and the hide button vertically */
}


/* Row for the main controls (Select + Buttons) */
.menu-main-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;

    /* Ensure content inside this row captures clicks */
    pointer-events: auto;
}

/* 1. Location Stack */
.menu-controls-stack {
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: center;
}

/* Hide button must also be clickable */
.ancient-hide-button {
    pointer-events: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--encarta-text);
    padding: 8px;
    transition: transform 0.2s;
}

.ancient-hide-button:hover {
    transform: scale(1.1);
    color: var(--text-color);
}

.modern-button {
    width: 72px;
    height: 72px;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 6px;
    border: none;
    background: transparent;
    transition: all 0.2s;
}

/* Hover effect - Only affects the icon */
.modern-button:hover {
    background: transparent;
    transform: none;
}

.modern-button img {
    transition: all 0.2s;
}

.modern-button:hover img,
.menu-controls-stack:hover .modern-button img {
    filter: brightness(0.7);
    transform: translateY(-2px);
}

/* Click Animation (Resizing) */
.modern-button:active {
    transform: scale(0.9) translateY(0);
}

.modern-button span {
    font-size: 12px;
    /* Increased size */
    text-transform: uppercase;
    font-weight: 800;
    margin-top: 4px;
    color: #4E483F;
    /* Brownish text */
}

/* Small Button Variant for Top Actions */
/* Small Button Variant for Top Actions */
.modern-button.small-btn {
    width: 50px;
    height: 50px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    /* Circular look usually fits icons well */
    background: rgba(30, 25, 20, 0.66);
    /* Darker background */
    border: 2px solid #8D8368;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    position: relative;
    /* For tooltip positioning */
    overflow: visible;
    /* Allow large icon to exceed button bounds */
}

.modern-button.small-btn:hover {
    background: rgba(50, 45, 40, 0.8);
    transform: scale(1.1);
    border-color: #F4F1EA;
}

.modern-button.small-btn img {
    /* Ensure icon fits well */
    height: 64px;
    width: auto;
    filter: none;
    /* Keep original colors */
}

/* Tooltip implementation */
.modern-button.small-btn::after {
    content: attr(title);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #F4F1EA;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    border: 1px solid #8D8368;
}

.modern-button.small-btn:hover::after {
    opacity: 1;
}

.modern-button.small-btn:hover img {
    transform: none;
    /* Reset since we scale the button itself */
}

/* Top Actions Logic - Absolute Positioning to avoid layout shifts */
.menu-top-actions {
    position: absolute;
    top: -15px;
    /* Anchored nicely on top of the scroll */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 1005;
    pointer-events: auto;
}

.modern-select {
    font-size: 16px;
    padding: 12px;
    border: 1px solid rgba(78, 72, 63, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-color);
    font-family: inherit;
    cursor: pointer;
}

/* --- Level Maker (Redesign) --- */
#level-maker-toggle {
    display: none;
}

#level-maker-ui {
    position: absolute;
    bottom: 22vh;
    /* Just above the scroll handle */
    left: 50%;
    transform: translateX(-50%);

    /* Parchment / Glass Style */
    background: rgba(244, 241, 234, 0.95);
    border: 2px solid #8D8368;
    /* Antique Brass */
    border-radius: 16px;
    padding: 10px 16px;

    display: flex;
    flex-direction: row;
    gap: 16px;
    /* Space between sections */
    align-items: center;

    z-index: 2000;
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Tools Row */
.editor-tools-row {
    display: flex;
    gap: 8px;
}

.tool-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background-size: 70%;
    background-repeat: no-repeat;
    background-position: center;

    /* Engraved/Stamped Look */
    border: 1px solid rgba(78, 72, 63, 0.2);
    background-color: transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background-color: rgba(78, 72, 63, 0.1);
    transform: translateY(-1px);
}

.tool-btn.active {
    background-color: rgba(78, 72, 63, 0.15);
    border-color: #8D8368;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Pressed in look */
}

/* Eraser specific */
.eraser-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.eraser-btn span {
    font-size: 18px;
    filter: sepia(0.5);
    /* Antique emoji */
}

/* Divider */
.editor-divider {
    width: 2px;
    height: 24px;
    background: rgba(78, 72, 63, 0.15);
    border-radius: 2px;
}

/* Actions */
.editor-actions-row {
    display: flex;
    gap: 8px;
}

.editor-action-btn {
    padding: 0 12px;
    height: 36px;
    border: 1px solid rgba(78, 72, 63, 0.3);
    border-radius: 8px;
    font-family: inherit;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    color: #F4F1EA;
    /* Cream text */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.reset-btn {
    background: linear-gradient(to bottom, #C62828, #B71C1C);
    border-color: #8E1616;
}

.reset-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.export-btn {
    background: linear-gradient(to bottom, #78909C, #546E7A);
    border-color: #455A64;
}

.export-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* Toggle Row */
.editor-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(78, 72, 63, 0.05);
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid rgba(78, 72, 63, 0.1);
}

.editor-label {
    font-size: 10px;
    font-weight: 800;
    color: #8D8368;
    text-transform: uppercase;
}

/* Compact Switch Override */
.switch.compact {
    width: 32px;
    height: 18px;
}

.switch.compact .slider {
    border-radius: 18px;
}

.switch.compact .slider:before {
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
}

.switch.compact input:checked+.slider:before {
    transform: translateX(14px);
}

/* Feedback */
.auto-save-text {
    position: absolute;
    top: -20px;
    right: 16px;
    font-size: 10px;
    font-weight: 700;
    font-style: italic;
    color: #4E483F;
    opacity: 0.6;
}

/* --- Settings Modal --- */
#settings-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 340px;
    padding: 0;
    z-index: 2001;
    pointer-events: auto;
    background: #F4F1EA;
    border: 2px solid #8D8368;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    font-family: 'Merriweather', serif;
    overflow: hidden;
}

.modal-header {
    background: #EBE8E1;
    border-bottom: 2px solid #D8D0C0;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: #4E483F;
    font-weight: 900;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #8D8368;
}

.modal-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 20px;
}

.setting-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-group label {
    font-size: 15px;
    font-weight: 700;
    color: #5D5346;
}

/* Existing Switch/Slider styles preserved */
.switch {
    display: inline-block;
    position: relative;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #D8D0C0;
    border: 2px solid #8D8368;
    transition: .3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: #FFF;
    border-radius: 50%;
    transition: .3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

input:checked+.slider {
    background-color: #788F9C;
    border-color: #546E7A;
}

input:checked+.slider:before {
    transform: translateX(22px);
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    max-width: 120px;
    background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: #D8D0C0;
    border-radius: 4px;
    border: 1px solid #8D8368;
}

input[type=range]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #FFF;
    border: 2px solid #788F9C;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
}

/* --- Travel Modal & Search --- */
#travel-modal {
    /* Inherits glass-panel styling via class, but needs overrides for size */
    width: 400px;
    /* Bigger than settings */
    height: auto;
    max-height: 80vh;

    /* Centering Logic */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    z-index: 2002;
    /* Above settings if needed */
    pointer-events: auto;
}

.modern-input {
    width: 100%;
    padding: 12px;
    border: 2px solid rgba(141, 131, 104, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 14px;
    color: #4E483F;
    margin-bottom: 16px;
    transition: all 0.2s;
    box-sizing: border-box;
}

.modern-input:focus {
    outline: none;
    border-color: #8D8368;
    background: #fff;
}

.city-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;

    /* Scrollbar styling */
    /* Scrollbar styling - Hidden/Transparent */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.city-list::-webkit-scrollbar {
    display: none;
}

.city-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(78, 72, 63, 0.1);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    color: #4E483F;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.city-item:hover {
    background: #fff;
    transform: translateX(4px);
    border-color: #8D8368;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.city-item span.coords {
    font-size: 10px;
    color: #788F9C;
    font-weight: 400;
}

.city-flag {
    width: 32px;
    height: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    mix-blend-mode: multiply;
}

/* --- Chat Interface --- */
.chat-panel {
    width: 500px;
    height: 230px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    pointer-events: none; /* Default to none when hidden */
    padding: 10px;
    box-sizing: border-box;
    /* Extra specific overrides if needed */
    border-radius: 12px;
    border: 2px solid rgba(141, 131, 104, 0.3);

    /* Hidden State Defaults */
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.chat-panel.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto; /* Enable interaction when visible */
}

.chat-input-field {
    width: 480px;
    /* Inherits .modern-input styles */
    border-radius: 20px;
    /* Rounder for chat input */
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chat-message {
    width: 100%;
    padding-bottom: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: baseline;
    font-size: 14px;
    line-height: 1.4;
    font-family: 'Merriweather Sans', sans-serif;
}

.chat-timestamp {
    color: #788F9C;
    font-size: 11px;
    margin-right: 8px;
    font-weight: 400;
}

.chat-author {
    font-weight: 800;
    margin-right: 4px;
    text-transform: uppercase;
    font-size: 12px;
}

.chat-author.player {
    color: #2E7D32;
    /* Greenish for Nasir */
}

.chat-author.system {
    color: #E65100;
    /* Orange/Gold for System */
}

.chat-author.other {
    color: #1565C0;
    /* Blue for others */
}

/* --- Contact Section --- */
.setting-divider {
    height: 1px;
    background: rgba(141, 131, 104, 0.3);
    margin: 16px 0;
    width: 100%;
}

.contact-section {
    text-align: center;
}

.contact-section h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    text-transform: uppercase;
    color: #8D8368;
    letter-spacing: 1px;
    font-weight: 800;
}

.contact-card {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(141, 131, 104, 0.2);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.contact-name {
    margin: 0;
    font-weight: 700;
    color: #4E483F;
    line-height: 1.4;
}

.contact-name.arabic {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    font-size: 18px;
    color: #2E7D32;
    /* Slight Green tint for Arabic */
}

.contact-name.chinese {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 14px;
    color: #E65100;
    /* Slight Orange tint */
}

.contact-name.english {
    font-size: 14px;
    color: #5D5346;
}

.contact-email {
    margin-top: 8px;
    font-size: 12px;
    color: #78909C;
    text-decoration: none;
    transition: color 0.2s;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.contact-email:hover {
    color: #B71C1C;
    text-decoration: underline;
}

.contact-flag {
    width: 32px;
    height: auto;
    margin: 12px auto 0 auto;
    display: block;
    image-rendering: pixelated;
    mix-blend-mode: multiply;
    opacity: 0.9;
}

.reset-game-button {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid rgba(78, 72, 63, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.5);
    color: #4E483F;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.reset-game-button:hover {
    background: rgba(255, 255, 255, 0.8);
    border-color: #8D8368;
    transform: translateY(-1px);
}