/* =========================
   LAYOUT
   ========================= */
body {
    margin: 0;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background: #202020;
}

#canvas-container {
    width: 100vw;
    height: 100vh;
}

/* Legacy keybind-table — overridden by .keybind-props in builder */
#keybind-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 4px;
}
#keybind-table td {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.keybind-key {
    font-size: 13px;
    text-align: center;
    width: 44px;
    color: #4ecca3;
    font-family: monospace;
}


/* =========================
   UI - EFFECTS
   ========================= */
#fade {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: black;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1s;
}


/* =========================
   UI - TOOLBAR
   ========================= */
#toolbar {
    position: fixed;
    bottom: 8px;
    left: 8px;
    right: 8px;
    height: 52px;
    background: rgba(0, 0, 0, 0.78);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 6px;
    z-index: 500;
    pointer-events: all;
}

.toolbar-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 6px;
    padding: 5px 14px;
    cursor: pointer;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 52px;
    transition: background 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.toolbar-btn.active {
    background: rgba(135, 206, 235, 0.22);
    border-color: rgba(135, 206, 235, 0.55);
}

.toolbar-icon { font-size: 18px; line-height: 1; }
.toolbar-label { font-size: 10px; color: rgba(255, 255, 255, 0.65); }

#msg-log-panel {
    position: fixed;
    bottom: 68px;
    left: 8px;
    width: 480px;
    max-height: 260px;
    background: rgba(0, 0, 0, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 8px;
    z-index: 490;
    pointer-events: all;
}

.log-line {
    font-family: monospace;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    white-space: pre;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.log-line:last-child {
    color: rgba(255, 255, 255, 0.9);
}

/* =========================
   UI - CATALOG PANEL
   ========================= */
#catalog-panel {
    position: fixed;
    top: 8px;
    right: -300px;
    width: 280px;
    height: calc(100vh - 76px);
    background: rgba(12, 18, 12, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px 0 0 8px;
    display: flex;
    flex-direction: column;
    z-index: 600;
    transition: right 0.2s ease;
    pointer-events: all;
}

#catalog-panel.open { right: 8px; }

.catalog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.catalog-title {
    color: #87CEEB;
    font-size: 15px;
    font-weight: bold;
    font-family: Arial, sans-serif;
}

.catalog-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.45);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s;
}

.catalog-close:hover { color: white; }

.catalog-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.catalog-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: rgba(255, 255, 255, 0.45);
    padding: 10px 6px;
    cursor: pointer;
    font-size: 12px;
    font-family: Arial, sans-serif;
    transition: color 0.15s;
}

.catalog-tab:hover { color: white; }
.catalog-tab.active { color: #87CEEB; border-bottom-color: #87CEEB; }

.catalog-grid {
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
}

.catalog-card {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.82);
    border-radius: 5px;
    padding: 6px;
    font-size: 11px;
    font-family: Arial, sans-serif;
    cursor: pointer;
    text-align: center;
    width: calc(50% - 3px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.catalog-card:hover {
    background: rgba(135, 206, 235, 0.15);
    border-color: rgba(135, 206, 235, 0.4);
    color: white;
}

.catalog-thumb {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.04);
    display: block;
    object-fit: contain;
}

.catalog-card-name {
    font-size: 10px;
    margin-top: 4px;
    line-height: 1.2;
    word-break: break-word;
}


/* =========================
   UI - DISPLAY CHECKBOXES
   All checkboxes in the Display tab share one style.
   ========================= */
.display-checkbox-row {
    margin: 10px 0;
}

.display-checkbox-row label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
}

.display-checkbox-row input[type="checkbox"] {
    margin-right: 10px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

/* =========================
   UI - INFO PANELS (game-info / env-info)
   ========================= */
#game-info,
#env-info {
    position: fixed;
    top: 10px;
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 11px;
    pointer-events: none;
    z-index: 400;
    display: none;
}

#game-info { left: 10px; }
#env-info  { left: 160px; }

#load-status {
    position: fixed;
    bottom: 72px;   /* above 52px toolbar + 8px gap + a bit of breathing room */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.82);
    color: #ccc;
    font-family: monospace;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 600;
    display: none;
    max-width: 480px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-table {
    border-collapse: collapse;
}

.info-label {
    color: rgba(255, 255, 255, 0.45);
    padding: 1px 8px 1px 0;
    white-space: nowrap;
    vertical-align: middle;
}

.info-value {
    color: #87CEEB;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 3px;
    padding: 1px 5px;
    text-align: right;
    white-space: nowrap;
    vertical-align: middle;
    min-width: 70px;
}


/* =========================
   UI - SLIDER TOOLTIP
   ========================= */
#slider-tooltip {
    position: fixed;
    display: none;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 11px;
    font-family: monospace;
    padding: 3px 8px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 9999;
    transform: translateX(-50%);
    white-space: nowrap;
}

#slider-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.85);
}


#fps-display {
    position: fixed;
    top: 8px;
    right: 12px;
    color: #7ecfff;
    font-family: monospace;
    font-size: 12px;
    pointer-events: none;
    z-index: 500;
}

#pos-display {
    position: fixed;
    top: 24px;
    right: 12px;
    color: #7ecfff;
    font-family: monospace;
    font-size: 12px;
    pointer-events: none;
    z-index: 500;
}

#open-builder {
    position: fixed;
    bottom: 12px;
    right: 110px;
    background: rgba(30,30,60,0.8);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    font-size: 18px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 500;
    line-height: 1;
}
#open-builder:hover { background: rgba(60,60,120,0.9); }

#settings-toggle {
    position: fixed;
    bottom: 12px;
    left: 12px;
    background: rgba(30,30,60,0.8);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    font-size: 18px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 500;
    line-height: 1;
    transition: background 0.15s, border-color 0.15s;
}
#settings-toggle:hover  { background: rgba(60,60,120,0.9); }
#settings-toggle.active {
    background: rgba(78,204,163,0.18);
    border-color: rgba(78,204,163,0.55);
}

#settings-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 56px;
    width: 310px;
    background: #1a1a2e;
    border-right: 1px solid rgba(78,204,163,0.25);
    overflow-y: auto;
    z-index: 490;
    font-family: Arial, sans-serif;
    font-size: 11px;
    color: white;
    padding: 6px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.25) rgba(0,0,0,0.2);
}

/* =========================
   BUILDER — TREEVIEW LAYOUT
   ========================= */
#builder-main {
    padding: 6px 8px 68px;   /* bottom clears toolbar */
    font-family: Arial, sans-serif;
    color: white;
    font-size: 11px;
}

/* Top-level collapsible sections (Settings, Room) */
.tree-section {
    margin-bottom: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    overflow: hidden;
}

.tree-section-title {
    cursor: pointer;
    list-style: none;
    padding: 6px 10px;
    background: rgba(135,206,235,0.1);
    color: #87CEEB;
    font-weight: bold;
    font-size: 11px;
    user-select: none;
}
.tree-section-title::-webkit-details-marker { display: none; }
.tree-section-title::before { content: '▼ '; font-size: 10px; }
details.tree-section:not([open]) .tree-section-title::before { content: '▶ '; }

/* Second-level collapsible groups (Camera, Keyboard, …) */
.tree-group {
    border-top: 1px solid rgba(255,255,255,0.07);
}

.tree-group > summary {
    cursor: pointer;
    list-style: none;
    padding: 4px 12px;
    color: rgba(255,255,255,0.65);
    font-size: 10px;
    font-weight: bold;
    user-select: none;
    background: rgba(255,255,255,0.03);
}
.tree-group > summary::-webkit-details-marker { display: none; }
.tree-group > summary::before { content: '▼ '; font-size: 9px; opacity: 0.6; }
details.tree-group:not([open]) > summary::before { content: '▶ '; }
.tree-group > summary:hover { color: rgba(255,255,255,0.9); }

/* Properties table used in every group */
.props-table {
    width: calc(100% - 24px);
    margin: 2px 0 6px 12px;
    border-collapse: collapse;
    table-layout: fixed;
}
.props-table td {
    padding: 3px 4px;
    vertical-align: middle;
}
.props-table th {
    padding: 6px 4px 3px;
    text-align: left;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #4ecca3;
    border-bottom: 1px solid rgba(78,204,163,0.25);
}
.props-table td:first-child {
    width: 110px;
    color: rgba(255,255,255,0.5);
    font-size: 10px;
    white-space: nowrap;
}
/* Slider cells: flex so value badge sits left, slider fills remaining space */
.props-table td:last-child:has(input[type="range"]) {
    display: flex;
    align-items: center;
    gap: 4px;
}
.props-table td:last-child input[type="range"] {
    flex: 1;
    min-width: 0;
    accent-color: #4ecca3;
    cursor: pointer;
    height: 3px;
}
.props-table input[type="checkbox"] {
    width: 13px;
    height: 13px;
    cursor: pointer;
    vertical-align: middle;
    accent-color: #4ecca3;
}

/* Unified number input — used in both Settings (.prop-num) and Room inspector (.inspector-input).
   Both classes share identical styles so the UI is visually consistent throughout. */
.prop-num, .inspector-input {
    width: 46px;
    background: #0f3460;
    border: 1px solid #1f4068;
    color: white;
    font-size: 10px;
    font-family: Arial, sans-serif;
    padding: 2px 3px;
    border-radius: 3px;
    text-align: right;
    flex-shrink: 0;
}
.prop-num:focus, .inspector-input:focus { border-color: #4ecca3; outline: none; }

/* Inline value display — kept for legacy spans (season, time-of-day) */
.prop-val {
    display: inline-block;
    min-width: 36px;
    max-width: 56px;
    text-align: right;
    color: white;
    font-family: monospace;
    font-size: 10px;
    padding: 1px 4px;
    border: 1px solid rgba(78,204,163,0.25);
    border-radius: 3px;
    background: rgba(15,52,96,0.85);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Read-only text value */
.prop-value-display {
    color: #87CEEB;
    font-family: monospace;
    font-size: 11px;
}

/* Keybindings inside a tree-group */
.keybind-props { margin-top: 4px; }
.keybind-props td { padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.keybind-props .keybind-key { color: #4ecca3; font-size: 13px; text-align: center; width: 44px; cursor: pointer; font-family: monospace; }
.keybind-props .keybind-key:hover { color: #7effd4; }

/* Room entity rows */
.entity-row {
    border-top: 1px solid rgba(255,255,255,0.06);
}
.entity-row > summary {
    cursor: pointer;
    list-style: none;
    padding: 4px 14px;
    color: rgba(255,255,255,0.75);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}
.entity-row > summary::-webkit-details-marker { display: none; }
.entity-row > summary::before { content: '▶ '; font-size: 9px; opacity: 0.5; }
details.entity-row[open] > summary::before { content: '▼ '; }
.entity-row > summary:hover { color: white; }

.entity-props {
    width: calc(100% - 48px);
    margin: 0 0 6px 28px;
}
.entity-props td:first-child { width: 44px; }
