/* =========================================
   2. LAYOUT GRID & STRUCTURE
   ========================================= */

* {
    box-sizing: border-box !important;
}

/* Header (Top Navigation) */
header {
    position: fixed;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    border-bottom: 1px solid var(--main-color);
    background: var(--header-bg);
    z-index: 2000;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    transition: background 0.3s;
    user-select: none;
    overflow: hidden;
    /* Prevent vertical breakage */
}

.header-left {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-nav {
    display: flex;
    gap: 8px;
    height: 100%;
    align-items: center;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--main-color);
    color: var(--main-color);
    font-family: var(--font-family);
    font-size: var(--ui-font-size);
    letter-spacing: 1px;
    padding: 6px 14px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

.nav-btn:hover {
    box-shadow: 0 0 8px var(--main-color), inset 0 0 10px rgba(0, 0, 0, 0.2);
    text-shadow: 0 0 5px var(--main-color);
}

.nav-btn.active {
    background: var(--main-color);
    color: var(--header-bg);
    box-shadow: 0 0 15px var(--main-color);
    text-shadow: none;
}

/* Sidebar Removed (Legacy clean up) */
#sidebar {
    display: none !important;
}

/* Screen Wrapper (Centered Content) */
#screen-wrapper {
    margin: 0 !important;
    width: 100% !important;
    height: 100vh;
    padding-top: 48px;
    display: flex;
    justify-content: center;
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0 !important;
    right: 0 !important;
    background: var(--bg-color);
}

/* Settings Panels (Slide from Right) */
#settings-container {
    position: fixed;
    top: 48px !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    width: 340px;
    background: var(--panel-bg);
    border-left: 1px solid var(--main-color);
    border-right: none;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1500;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    height: calc(100vh - 48px);
    overflow-y: auto;
}

#settings-container.open {
    transform: translateX(0);
}

/* Fullscreen behavior: Keep fixed to top */
body.is-fullscreen header {
    top: 0 !important;
}

body.is-fullscreen #editor {
    padding-top: 10px !important;
}

body.is-fullscreen #screen-wrapper {
    padding-top: 48px;
}

body.is-fullscreen #settings-container {
    top: 48px !important;
}

/* Panels inside container */
.panel {
    display: none;
    padding: 20px;
    padding-bottom: 80px;
    width: 100%;
}

.panel.active {
    display: block;
}

.panel-header-title {
    text-align: center;
    margin-bottom: 20px;
    opacity: 0.7;
    font-family: 'Press Start 2P';
    font-size: var(--ui-font-size);
}

/* Accordion Styles */
.accordion {
    width: 100%;
    margin-bottom: 5px;
    border: 1px solid var(--main-color);
}

.accordion-header {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    color: var(--main-color);
    padding: 10px;
    text-align: left;
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
    font-size: calc(var(--ui-font-size) - 2px);
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
    border-bottom: 1px solid var(--main-color);
    border: none;
}

.accordion-header:hover {
    background: rgba(255, 255, 255, 0.1);
}

.accordion-header::after {
    content: '+';
    font-weight: bold;
    margin-left: 10px;
}

.accordion-header.active {
    background: var(--main-color);
    color: var(--bg-color);
}

.accordion-header.active::after {
    content: '-';
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: var(--panel-bg);
}

.accordion-content.open {
    max-height: 2000px;
    padding: 15px;
    border-top: 1px solid var(--main-color);
}

/* Control Groups inside Accordions */
.control-group {
    margin-bottom: 15px;
    border-bottom: 1px dashed var(--main-color);
    padding-bottom: 15px;
}

.control-group:last-child {
    border-bottom: none;
}

.control-group h4 {
    margin: 0 0 10px 0;
    font-size: var(--ui-font-size);
    text-transform: uppercase;
    font-family: var(--cjk-stack);
    opacity: 0.8;
}

/* Helper classes */
label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--ui-font-size);
    margin-bottom: 8px;
    opacity: 0.9;
}

.accordion-content input[type=range] {
    width: 120px;
    /* Fixed length for all sliders in panels */
}

.ctl-row label {
    margin-bottom: 0;
}

/* Status Overlay */
#status-overlay {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--main-color);
    color: var(--bg-color);
    padding: 10px 20px;
    font-family: var(--font-family);
    font-weight: bold;
    text-transform: uppercase;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 15px var(--main-color);
    border: 2px solid var(--bg-color);
}

/* Init Overlay */
#init-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.init-content-wrapper {
    width: 800px;
    max-width: 90%;
    text-align: center;
    border: 2px solid var(--main-color);
    padding: 40px;
    background: #050505;
    box-shadow: 0 0 50px rgba(0, 255, 0, 0.1);
    max-height: 90vh;
    overflow-y: auto;
}

.init-warning {
    color: var(--warning-color);
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Config IO */
.config-io-area {
    width: 100%;
    height: 100px;
    background: #000 !important;
    border: 1px solid var(--main-color);
    color: var(--main-color);
    font-family: 'Courier New', monospace;
    font-size: 10px;
    padding: 8px;
    margin-bottom: 10px;
    resize: none;
    display: block;
    overflow-y: auto;
}

.config-button-row {
    display: flex;
    gap: 8px;
}

.config-button-row .sys-btn {
    flex: 1;
    font-size: 11px;
    padding: 6px 0;
}

/* Responsive Mobile View */
@media (max-width: 700px) {
    header {
        height: 80px;
        flex-direction: column;
        padding: 5px;
        justify-content: center;
        gap: 5px;
    }

    .header-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    #screen-wrapper {
        padding-top: 80px;
    }

    #settings-container {
        top: 80px !important;
        width: 100%;
        transform: translateY(100%);
        height: calc(100vh - 80px);
    }

    #settings-container.open {
        transform: translateY(0);
    }
}

/* =========================================
   WORLD BUILDER STYLES
   ========================================= */
#world-builder-root {
    display: flex;
    flex-direction: column;
    height: 400px;
    border: 1px solid var(--main-color);
    padding: 5px;
    background: rgba(0, 0, 0, 0.2);
}

.acc-wrapper {
    margin-top: 5px;
}

.acc-header {
    display: flex;
    align-items: center;
}

.acc-btn {
    background: rgba(0, 0, 0, 0.3);
    color: var(--main-color);
    border: 1px solid var(--main-color);
    flex-grow: 1;
    text-align: left;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    text-transform: uppercase;
    transition: all 0.2s;
}

.acc-btn:hover,
.acc-btn.active {
    background: var(--main-color);
    color: var(--bg-color);
}

.acc-panel {
    max-height: 0;
    overflow-y: auto;
    transition: max-height 0.3s ease-out;
    border-left: 1px dashed var(--main-color);
    border-right: 1px dashed var(--main-color);
    margin-bottom: 5px;
    background: rgba(0, 0, 0, 0.2);
}

.acc-panel.open {
    border-bottom: 1px solid var(--main-color);
}

.note-row {
    display: flex;
    border-bottom: 1px dashed #333;
}

.note-item {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--main-color);
    padding: 4px 8px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    opacity: 0.8;
}

.note-item:hover {
    opacity: 1;
    text-decoration: underline;
    background: rgba(51, 255, 0, 0.1);
}

.note-add-btn {
    width: 100%;
    background: transparent;
    border: none;
    border-top: 1px dashed var(--main-color);
    color: var(--main-color);
    padding: 6px;
    cursor: pointer;
    opacity: 0.6;
    font-size: 12px;
}

.note-add-btn:hover {
    opacity: 1;
    font-weight: bold;
}

/* FIXES */
#btn-add-category {
    flex-grow: 0 !important;
    width: 40px !important;
    padding: 0 !important;
    font-size: 18px !important;
    line-height: normal;
}

@media (max-width: 700px) {
    #underdeck {
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        transform: none !important;
        bottom: 0 !important;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    #underdeck-toggle {
        right: 0 !important;
        border-right: none;
    }
}