:root {
    --ui-font: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --ui-bg: rgba(0, 0, 0, 0.4);
    --ui-text: #ffffff;
    --ui-accent: #a865b5;
    /* Light Indigo to match grass/theme */
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #000;
    font-family: var(--ui-font);
    font-size: 18px;
    /* Boost base font size */
    user-select: none;
}

#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

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

/* UI Hidden State */
#ui-layer.ui-hidden> :not(#start-screen):not(#world-select-screen):not(#pause-screen) {
    display: none !important;
}

#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    transform: translate(-50%, -50%);
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

#crosshair::before {
    top: 11px;
    left: 0;
    width: 24px;
    height: 2px;
}

#crosshair::after {
    top: 0;
    left: 11px;
    width: 2px;
    height: 24px;
}

#dev-info {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 14px;
    font-weight: bold;
    color: var(--ui-accent);
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
    z-index: 100;
}

#debug-overlay {
    position: absolute;
    top: 35px;
    left: 10px;
    background: var(--ui-bg);
    padding: 10px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    color: var(--ui-text);
    text-shadow: 1px 1px 0 #000;
}

#debug-overlay>div {
    margin-bottom: 4px;
}

#block-name-popup {
    position: fixed;
    bottom: 155px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.45);
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 5px 18px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(6px);
    white-space: nowrap;
    z-index: 200;
}

#block-name-popup.visible {
    opacity: 1;
}

.hotbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: var(--ui-bg);
    padding: 10px;
    border-radius: 8px;
    backdrop-filter: blur(4px);
}

.hotbar-slot {
    width: 64px;
    height: 64px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

.hotbar-slot.active {
    border-color: var(--ui-accent);
    transform: scale(1.1);
    box-shadow: 0 0 12px var(--ui-accent);
}

.slot-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: bold;
    pointer-events: none;
}

#height-bar-container {
    position: absolute;
    bottom: 104px;
    /* Just above the hotbar (20px bottom + 84px height) */
    left: 50%;
    transform: translateX(-50%);
    width: 730px;
    /* Matching inner hotbar width: 10*64 + 9*10 */
    height: 6px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 3px;
    overflow: hidden;
    z-index: 100;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#height-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #7620a2, #ff5555);
    /* Indigo to Saturated Red */
    box-shadow: 0 0 8px rgba(255, 85, 85, 0.6);
    transition: width 0.2s ease-out;
}

.hotbar-slot-inner {
    width: 40px;
    height: 40px;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, #1e2746 0%, #0a0e17 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    /* Catch clicks for pointer lock */
    color: white;
    text-align: center;
}

.overlay-screen h1 {
    font-size: 5rem;
    margin-bottom: 0.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: -webkit-linear-gradient(#ff5555, #7620a2);
    /* Saturated Red to Deep Indigo gradient */
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 4px 10px rgba(255, 85, 85, 0.3);
}

.overlay-screen.hidden {
    display: none !important;
}

.ws-sub-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.ws-sub-menu.hidden {
    display: none !important;
}

.settings-panel {
    background: rgba(255, 255, 255, 0.05);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 700px;
    max-width: 90%;
    max-height: 70vh;
    overflow-y: auto;
    margin-top: 20px;
    text-align: left;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-row label {
    font-size: 1.1em;
    font-weight: bold;
}

.setting-row input[type="range"] {
    width: 100%;
    accent-color: var(--ui-accent);
}

.pause-tabs {
    display: flex;
    gap: 10px;
}

.pause-tab {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1.1em;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.pause-tab:hover {
    background: rgba(255, 255, 255, 0.2);
}

.pause-tab.active {
    background: var(--ui-accent);
    color: black;
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Settings Sub-tabs */
.sub-tab {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    padding: 5px 10px;
    font-size: 0.9em;
    cursor: pointer;
    transition: color 0.2s, border-bottom 0.2s;
    border-bottom: 2px solid transparent;
}

.sub-tab:hover {
    color: rgba(255, 255, 255, 0.8);
}

.sub-tab.active {
    color: var(--ui-accent);
    border-bottom-color: var(--ui-accent);
    font-weight: bold;
}

.sub-tab-content {
    display: none;
}

.sub-tab-content.active {
    display: block;
}

#loading-container {
    width: 300px;
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#loading-bar-border {
    width: 100%;
    height: 10px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 5px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.5);
}

#loading-bar-fill {
    width: 0%;
    height: 100%;
    background: var(--ui-accent);
    transition: width 0.2s ease-out;
}

#start-hint {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--ui-accent);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

/* ─── World Select Menu ─── */

.world-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 14px 18px;
    margin-bottom: 10px;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.world-entry:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.world-info {
    text-align: left;
}

.world-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.world-meta {
    font-size: 0.8rem;
    opacity: 0.5;
}

.world-actions {
    display: flex;
    gap: 8px;
}

.world-play-btn {
    padding: 8px 20px;
    background: linear-gradient(135deg, #7620a2, #a865b5);
    /* Deep Indigo to Light Indigo */
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform 0.1s;
}

.world-play-btn:hover {
    transform: scale(1.05);
}

.world-delete-btn {
    padding: 8px 14px;
    background: rgba(255, 100, 100, 0.15);
    border: 1px solid rgba(255, 100, 100, 0.3);
    color: #ff6b6b;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.world-delete-btn:hover {
    background: rgba(255, 100, 100, 0.3);
}

/* ─── Modern Global UI Classes ─── */

.btn-pill {
    padding: 10px 28px;
    border-radius: 30px;
    border: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
    backdrop-filter: blur(4px);
}

.btn-primary {
    background: linear-gradient(135deg, #ff5555, #7620a2);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 85, 85, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(255, 85, 85, 0.5);
    filter: brightness(1.1);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.btn-outline-red {
    background: rgba(255, 100, 100, 0.05);
    border: 1px solid rgba(255, 100, 100, 0.3);
    color: #ff6b6b;
}

.btn-outline-red:hover {
    background: rgba(255, 100, 100, 0.15);
    border-color: #ff6b6b;
    transform: translateY(-2px);
}

.btn-outline-blue {
    background: rgba(100, 200, 255, 0.05);
    border: 1px solid rgba(100, 200, 255, 0.3);
    color: #64c8ff;
}

.btn-outline-blue:hover {
    background: rgba(100, 200, 255, 0.15);
    border-color: #64c8ff;
    transform: translateY(-2px);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Modern Inputs */
.modern-input-group {
    margin-bottom: 20px;
    text-align: left;
}

.modern-input-label {
    display: block;
    margin-bottom: 6px;
    opacity: 0.6;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modern-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}

.modern-input:focus {
    outline: none;
    border-color: var(--ui-accent);
    background: rgba(0, 0, 0, 0.7);
    box-shadow: 0 0 10px rgba(168, 101, 181, 0.3);
}

/* ─── Controls Toast ─── */
#controls-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    /* top-right corner */
    left: auto;
    transform: translateX(120%);
    background: rgba(10, 15, 25, 0.55);
    border: 1px solid rgba(168, 101, 181, 0.35);
    /* Light Indigo border */
    border-radius: 12px;
    padding: 14px 22px;
    color: rgba(255, 255, 255, 0.92);
    text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    z-index: 1000;
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.35s;
    pointer-events: none;
}

#controls-toast .toast-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: #a865b5;
    /* Light Indigo */
    letter-spacing: 0.5px;
}

#controls-toast .toast-body {
    font-size: 0.9rem;
    line-height: 1.6;
    opacity: 0.9;
}

#controls-toast.show {
    transform: translateX(0);
    opacity: 1;
}

#controls-toast .toast-body span {
    display: inline-block;
    transition: color 0.3s, transform 0.2s, text-shadow 0.3s;
}

#controls-toast .toast-body span.completed {
    color: #00e676;
    /* Bright green */
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 230, 118, 0.4);
    transform: scale(1.05);
}

/* ─── Touch Controls ─── */
.touch-device {
    touch-action: none; /* Prevent iOS Safari from intercepting drags for scrolling */
}

.touch-device #dev-info {
    font-size: 8px;
    top: 5px;
}

.touch-device #debug-overlay {
    font-size: 7px;
    padding: 3px;
    top: 20px;
    width: 45%;
    overflow-wrap: break-word;
}

.touch-device #touch-controls {
    display: block !important;
}

#touch-controls {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 50; 
}

#tc-joystick-zone {
    position: absolute;
    bottom: 0; left: 0;
    width: 40vw; height: 50vh;
    pointer-events: auto;
}

#tc-joystick-base {
    position: absolute;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s;
    backdrop-filter: blur(4px);
    pointer-events: none;
}

#tc-joystick-knob {
    position: absolute;
    top: 50%; left: 50%;
    width: 50px; height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    pointer-events: none;
}

#tc-look-zone {
    position: absolute;
    top: 0; right: 0;
    width: 60vw; height: 100vh;
    pointer-events: auto;
}

#tc-actions {
    position: absolute;
    bottom: 30px; right: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    pointer-events: auto;
}

.tc-btn {
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 24px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    transition: background 0.1s, transform 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.tc-btn:active, .tc-btn.active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.tc-btn-large {
    width: 70px; height: 70px;
    font-size: 32px;
}

.tc-btn-small {
    width: 55px; height: 55px;
    font-size: 24px;
}

.tc-top-right {
    position: absolute;
    top: 20px; right: 20px;
    pointer-events: auto;
}

/* Adjust hotbar on touch so it doesn't overlap action buttons */
.touch-device .hotbar {
    bottom: unset;
    top: 5px;
    gap: 4px;
    padding: 6px;
    /* Scale down the entire hotbar layout cleanly */
    transform: translateX(-50%) scale(0.65);
    transform-origin: top center;
    /* Ensure it receives touches ABOVE the look-zone */
    z-index: 100;
    pointer-events: auto;
}
.touch-device #height-bar-container {
    bottom: unset;
    top: 60px;
    transform: translateX(-50%) scale(0.65);
    transform-origin: top center;
}

/* ─── E-Menu / Pause Screen Mobile Landscape Optimizations ─── */
@media (max-height: 500px) and (orientation: landscape) {
    .touch-device .overlay-screen h1 {
        font-size: 2.2rem;
        margin-bottom: 0px;
        margin-top: 5px;
    }
    
    .touch-device .settings-panel {
        width: 95%;
        max-height: 85vh;
        padding: 15px 20px;
        margin-top: 5px;
    }

    .touch-device .pause-tabs {
        margin-top: 5px !important;
    }

    .touch-device .pause-tab {
        padding: 6px 12px;
        font-size: 0.9em;
    }

    .touch-device .setting-row {
        gap: 5px;
        margin-top: 10px !important;
    }

    .touch-device .btn-pill {
        padding: 6px 16px;
        font-size: 0.85rem;
    }
}