/* Digiverse Styles */
/* Discord Activity Viewport Handling */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevent pull-to-refresh and overscroll */
    overscroll-behavior: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    width: 100%;
    height: 100%;
    /* Prevent text selection during gameplay */
    user-select: none;
    -webkit-user-select: none;
    /* Prevent touch callouts on mobile */
    -webkit-touch-callout: none;
    /* Prevent tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
    /* Fixed position to handle Discord iframe resize */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Canvas - fill entire viewport */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    /* Prevent canvas from being dragged */
    -webkit-user-drag: none;
    touch-action: none;
}

/* Loading Screen */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-content h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.loading-bar {
    width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto 1rem;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.3s ease;
}

#loadingText {
    font-size: 1.2rem;
    opacity: 0.8;
}

/* UI Overlay */
#ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
}

#ui > * {
    pointer-events: auto;
}

/* Top Bar */
.ui-top {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
}

.top-left, .top-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

.top-left span, .top-right span {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
}

#playerName {
    color: #4CAF50;
    font-weight: bold;
}

#playerHealth {
    color: #ff6b6b;
}

#playerDimension {
    color: #64B5F6;
}

#fps {
    color: #4CAF50;
}

#playerCoords {
    color: #FFD54F;
}

#chunkCoords {
    color: #BA68C8;
}

/* Dev Console */
.dev-console {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(var(--ui-scale));
    width: 700px;
    max-height: 500px;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #4CAF50;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    font-family: 'Courier New', monospace;
    z-index: 100;
}

.dev-console.active {
    display: flex;
}

.console-header {
    background: rgba(76, 175, 80, 0.2);
    padding: 10px 15px;
    border-bottom: 1px solid #4CAF50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    color: #4CAF50;
}

.console-close {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
}

.console-close:hover {
    color: #ff4444;
}

.console-output {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-size: 13px;
    line-height: 1.5;
}

.console-line {
    margin: 2px 0;
}

.console-line.command {
    color: #8BC34A;
}

.console-line.success {
    color: #4CAF50;
}

.console-line.error {
    color: #ff6b6b;
}

.console-line.info {
    color: #64B5F6;
}

.console-line.warning {
    color: #FFB74D;
}

.console-input-container {
    display: flex;
    align-items: center;
    padding: 10px;
    border-top: 1px solid #4CAF50;
    background: rgba(76, 175, 80, 0.05);
}

.console-prompt {
    color: #4CAF50;
    margin-right: 10px;
    font-weight: bold;
}

.console-input {
    flex: 1;
    background: none;
    border: none;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    outline: none;
}

/* Crosshair - base styles only, elements created by Crosshair.js */
/* Container is 0x0 — arms use negative offsets from the exact screen-center anchor.
   translate(-50%, -50%) on a non-zero container would shift the anchor off-center. */
.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 50;
}

/* Legacy crosshair-dot style (not currently used) */
.crosshair-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

/* NOTE: Pseudo-element crosshair removed - Crosshair.js creates its own elements */

/* Hotbar Container */
.hotbar-container {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Row indicator dots */
.hotbar-row-indicator {
    display: flex;
    gap: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
}

.hotbar-row-indicator .row-dot {
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.hotbar-row-indicator .row-dot:hover {
    color: rgba(255, 255, 255, 0.7);
}

.hotbar-row-indicator .row-dot.active {
    color: #4CAF50;
    text-shadow: 0 0 6px rgba(76, 175, 80, 0.8);
}

/* Hotbar */
.hotbar {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.8);
    padding: 8px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.hotbar-slot {
    width: 60px;
    height: 70px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.hotbar-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.hotbar-slot.active {
    background: rgba(76, 175, 80, 0.2);
    border-color: #4CAF50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.slot-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: bold;
}

.slot-icon {
    font-size: 24px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Rendered item icon images */
.item-icon-img {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.slot-name {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
}

/* Hotbar hint text */
.hotbar-hint {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    text-align: center;
}

/* Stack count badge */
.slot-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 10px;
    color: #fff;
    font-weight: bold;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.8);
}

/* Drag element (follows cursor during drag) */
.drag-element,
.drag-item {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    width: 50px;
    height: 50px;
    background: rgba(76, 175, 80, 0.3);
    border: 2px solid #4CAF50;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.drag-element .slot-icon,
.drag-item .slot-icon {
    font-size: 20px;
}

.drag-element .item-icon-img,
.drag-item .item-icon-img {
    width: 36px;
    height: 36px;
}

.drag-element .slot-count,
.drag-item .slot-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
}

/* Inventory */
.inventory {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%) scale(var(--ui-scale));
    display: none;
    z-index: 100;
}

.inventory.active {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

/* Creative mode wrapper - puts creative browser left of inventory */
.inventory-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

/* Main inventory panel */
.inventory-panel {
    width: 560px;
    max-height: 80vh;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
}

.inventory-header {
    background: rgba(76, 175, 80, 0.2);
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.inventory-header h3 {
    margin: 0;
    color: #4CAF50;
}

.inventory-close {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
}

.inventory-close:hover {
    color: #ff4444;
}

.inventory-grid {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

/* Storage section (rows 0-5) */
.inventory-storage {
    display: grid;
    grid-template-columns: repeat(9, 54px);
    gap: 6px;
    justify-content: center;
}

/* Divider between storage and hotbar */
.inventory-divider {
    height: 2px;
    background: linear-gradient(to right, transparent, rgba(76, 175, 80, 0.5), transparent);
    margin: 4px 0;
}

/* Hotbar section in inventory (rows 6-8) */
.inventory-hotbars {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inventory-hotbar-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    justify-content: center;
};
}

.inventory-hotbar-row.active-row {
    background: rgba(76, 175, 80, 0.1);
    box-shadow: inset 0 0 10px rgba(76, 175, 80, 0.2);
}

.inventory-hotbar-row .row-indicator {
    width: 16px;
    text-align: center;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
}

.inventory-hotbar-row.active-row .row-indicator {
    color: #4CAF50;
}

.inventory-slot {
    width: 54px;
    height: 54px;
    min-width: 54px;
    min-height: 54px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.inventory-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.inventory-slot .slot-icon {
    font-size: 28px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 3D icon canvas in inventory slots */
.inventory-slot .icon-3d-canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: auto;
}

/* 3D hover effect canvas */
.icon-3d-hover-canvas {
    image-rendering: auto;
}

/* Slightly larger hover area for 3D icons */
.inventory-slot:hover .icon-3d-canvas {
    filter: brightness(1.1);
}

/* Creative menu slot icon positioning for hover effect */
.creative-slot {
    position: relative;
}

.creative-slot .slot-icon {
    position: relative;
}

.inventory-slot .item-icon-img,
.creative-slot .item-icon-img {
    width: 44px;
    height: 44px;
    transition: opacity 0.15s ease;
}

.inventory-slot .slot-name {
    font-size: 9px;
    margin-top: 4px;
}

/* Inventory sections */
.inventory-section-label {
    grid-column: 1 / -1;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 0 4px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 8px;
}

.inventory-section-label:first-child {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

/* Hotbar row in inventory (slightly different styling) */
.inventory-slot.hotbar-row {
    border-color: rgba(76, 175, 80, 0.3);
}

.inventory-slot.hotbar-row.active-row {
    background: rgba(76, 175, 80, 0.15);
    border-color: rgba(76, 175, 80, 0.5);
}

/* Drag target highlight */
.inventory-slot.drag-over {
    background: rgba(76, 175, 80, 0.3);
    border-color: #4CAF50;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

/* Slot being dragged from */
.inventory-slot.dragging {
    opacity: 0.5;
}

/* Chat (Future) */
.ui-chat {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 400px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.chat-messages {
    height: 200px;
    overflow-y: auto;
    padding: 10px;
    font-size: 13px;
}

.chat-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 10px;
    color: #fff;
    font-size: 13px;
    border-radius: 0 0 8px 8px;
    outline: none;
}

/* Error Screen */
#error {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.error-content {
    text-align: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    border: 2px solid #ff6b6b;
}

.error-content h2 {
    color: #ff6b6b;
    margin-bottom: 20px;
}

.error-content button {
    margin-top: 20px;
    padding: 10px 30px;
    background: #4CAF50;
    border: none;
    color: white;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.error-content button:hover {
    background: #45a049;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* ==================== CREATIVE MODE BROWSER ==================== */

.creative-browser {
    width: 480px;
    max-height: 80vh;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid rgba(76, 175, 80, 0.4);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Match height with inventory panel via align-items: stretch on parent */
    align-self: stretch;
}

.creative-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: rgba(76, 175, 80, 0.15);
    border-bottom: 1px solid rgba(76, 175, 80, 0.3);
}

.creative-title {
    color: #4CAF50;
    font-weight: bold;
    font-size: 14px;
    margin: 0;
    white-space: nowrap;
}

.creative-search {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 6px 10px;
    color: #fff;
    font-size: 12px;
    flex: 1;
    min-width: 0;
}

.creative-search:focus {
    outline: none;
    border-color: #4CAF50;
}

.creative-search::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* Main content area - 20/80 split */
.creative-content {
    display: flex;
    flex: 1;
    min-height: 0;
    height: calc(100% - 50px); /* Account for header */
    overflow: hidden;
}

/* Left side - Category tabs (20%) */
.creative-tabs {
    width: 20%;
    min-width: 80px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.creative-tab {
    padding: 10px 8px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    text-align: center;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.creative-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.8);
}

.creative-tab.active {
    background: rgba(76, 175, 80, 0.15);
    color: #4CAF50;
    border-left-color: #4CAF50;
}

.creative-tab-icon {
    font-size: 18px;
}

.creative-tab-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Right side - Items content (80%) */
.creative-items-panel {
    width: 80%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.creative-items-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    max-height: calc(100% - 10px);
}

/* Item family groups */
.creative-family {
    margin-bottom: 12px;
}

.creative-family-header {
    color: rgba(255, 255, 255, 0.5);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 4px 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.creative-family-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, 48px);
    gap: 4px;
    padding: 0 4px;
}

.creative-slot {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.creative-slot:hover {
    background: rgba(76, 175, 80, 0.25);
    border-color: #4CAF50;
    transform: scale(1.08);
}

.creative-slot .slot-icon {
    font-size: 22px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 3D icon canvas in creative slots */
.creative-slot .icon-3d-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.creative-slot:hover .icon-3d-canvas {
    filter: brightness(1.1);
}

.creative-slot .item-icon-img {
    width: 36px;
    height: 36px;
}

/* No results message */
.creative-no-results {
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    text-align: center;
    padding: 40px 20px;
}

/* ============================================
   RESPONSIVE UI SCALING
   Scales entire UI windows/panels using transform
   ============================================ */

:root {
    /* Base UI scale factor - applied via transform to whole windows */
    --ui-scale: 1;
}

/* Large screens (default - 1080p+) */
@media screen and (min-width: 1200px) and (min-height: 800px) {
    :root {
        --ui-scale: 1;
    }
}

/* Medium screens (720p - 1080p) */
@media screen and (max-width: 1199px), screen and (max-height: 799px) {
    :root {
        --ui-scale: 0.9;
    }
}

/* Small screens (typical Discord Activity window) */
@media screen and (max-width: 900px), screen and (max-height: 600px) {
    :root {
        --ui-scale: 0.8;
    }
}

/* Very small screens (mobile or small Discord window) */
@media screen and (max-width: 700px), screen and (max-height: 500px) {
    :root {
        --ui-scale: 0.7;
    }
}

/* Tiny screens (phone portrait or very small window) */
@media screen and (max-width: 500px), screen and (max-height: 400px) {
    :root {
        --ui-scale: 0.6;
    }
}

/* Discord Activity specific - when embedded in small window */
@media screen and (max-width: 800px) and (max-height: 600px) {
    :root {
        --ui-scale: 0.75;
    }
}

/* ============================================
   Apply transform scaling to UI panels/windows
   This scales the ENTIRE window as a unit
   ============================================ */

/* Scalable UI class - apply to any panel that should scale as a whole */
.scalable-ui {
    transform: scale(var(--ui-scale));
    transform-origin: center center;
}

/* Pause Menu / Main Menu - scale the content inside */
.menu-content {
    transform: scale(var(--ui-scale));
    transform-origin: center center;
}

/* Dimension Selector - scale entire window */
.dimension-selector {
    transform: scale(var(--ui-scale));
    transform-origin: center center;
}

/* Chat Container - scale entire window */
.chat-container {
    transform: scale(var(--ui-scale));
    transform-origin: bottom left;
}

/* Hotbar Container - scale entire area including row indicators */
.hotbar-container {
    transform: translateX(-50%) scale(var(--ui-scale));
    transform-origin: bottom center;
}

/* HUD / Top bar - scale entire bar */
.ui-top {
    transform: scale(var(--ui-scale));
    transform-origin: top center;
}

/* Tooltip - scale */
.tooltip,
.item-tooltip {
    transform: scale(var(--ui-scale));
    transform-origin: top left;
}

/* Health bars container */
.health-container,
.status-bars {
    transform: scale(var(--ui-scale));
    transform-origin: bottom left;
}

/* ============================================
   Crosshair - special case, always centered
   ============================================ */
.crosshair {
    /* Crosshair stays 1:1, doesn't scale with UI.
       No transform override needed — 0x0 container is already anchored at (top:50%, left:50%). */
}

/* ============================================
   Loading screen - scales nicely
   ============================================ */
.loading-content {
    transform: scale(var(--ui-scale));
    transform-origin: center center;
}

/* ============================================
   Mobile-specific adjustments
   ============================================ */

@media screen and (max-width: 600px) {
    /* Hide some HUD elements on very small screens */
    #chunkCoords {
        display: none;
    }
}

/* Landscape mobile - adjust hotbar position */
@media screen and (max-height: 400px) and (orientation: landscape) {
    .hotbar {
        bottom: 8px;
    }
}
