/* ==========================================================================
   GENERAL & RESET
   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow: hidden;
    background: #000;
    font-family: Arial, Helvetica, sans-serif;
    color: #eee;
}

/* ==========================================================================
   #CONTROLS - Main controls panel
   ========================================================================== */

#controls {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 260px;
    max-height: 94vh;
    overflow-y: auto;
    padding: 0;
    background: rgba(20, 30, 60, 0.65);
    border-radius: 10px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(100, 150, 255, 0.3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    z-index: 1000;
    transition: all 0.3s ease;
}

#main-controls-toggle {
    background: transparent;
    border: none;
    margin: 0;
    padding: 0;
}

#main-controls-toggle summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    position: relative;
    outline: none;
}

#main-controls-toggle summary h1 {
    margin: 0;
    padding: 12px 18px;
    font-size: 22px;
    font-weight: bold;
    color: #00dfffff;
    text-shadow: 0 0 12px #00dfff99;
    background: rgba(30, 40, 80, 0.6);
    border-radius: 10px 10px 0 0;
    transition: background 0.2s ease;
    text-align: center;
}

#main-controls-toggle summary:hover h1 {
    background: rgba(50, 70, 110, 0.7);
}

/* Custom chevron for main title */
#main-controls-toggle summary h1::after {
    content: '▾';
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: #88ccff;
    transition: transform 0.3s ease;
}

#main-controls-toggle[open] summary h1::after {
    transform: translateY(-50%) rotate(180deg);
}

/* ==========================================================================
   HEADER-INTRO
   ========================================================================== */

/* Hide native marker for main details */
#main-controls-toggle summary::-webkit-details-marker,
#main-controls-toggle summary::marker {
    display: none;
}

.header-intro {
    padding: 10px 16px;
    margin-bottom: 10px;
    font-size: 12px;
    color: #88ccff;
    /* background: rgba(30, 50, 90, 0.4); */
    /* border-bottom: 1px solid rgba(100, 150, 255, 0.25); */
    text-align: center;
    font-weight: 500;
}

/* ==========================================================================
   PANELS (CONTROL-GROUPS)
   ========================================================================== */

.control-group {
    margin: 0;
    background: rgba(30, 40, 60, 0.4);
    border-radius: 0;
    overflow: hidden;
}

.control-group summary {
    list-style: none;
    padding: 8px 40px 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #99ddff;
    background: rgba(40, 60, 90, 0.5);
    cursor: pointer;
    position: relative;
    transition: background 0.2s ease;
    user-select: none;
}

.control-group summary:hover {
    background: rgba(60, 90, 130, 0.6);
}

.control-group summary::-webkit-details-marker,
.control-group summary::marker {
    display: none;
}

.control-group summary::after {
    content: '\25BC';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: #88ccffcc;
    transition: transform 0.3s ease;
}

.control-group[open] summary::after {
    transform: translateY(-50%) rotate(180deg);
}

.group-content {
    padding: 10px 16px;
    background: rgba(20, 30, 50, 0.4);
}

.control-group,
.group-content {
    overflow: visible;
}

/* ==========================================================================
   SUB-PANELS (SUB-CONTROL-GROUPS)
   ========================================================================== */

.sub-control-group {
    margin: 8px 0;
    border-left: 3px solid #444;
    padding-left: 8px;
}

.sub-control-group summary {
    cursor: pointer;
    position: relative;
    font-weight: 600;
    color: #ccc;
    padding: 4px 32px 4px 0;
    user-select: none;
}

.sub-control-group summary::-webkit-details-marker,
.sub-control-group summary::marker {
    display: none;
}

.sub-control-group summary::after {
    content: '▼';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%) !important;
    font-size: 11px;
    color: #77aaff;
    transition: transform 0.3s ease;
}

.sub-control-group[open] summary::after {
    transform: translateY(-50%) rotate(180deg) !important;
}

.sub-group-content {
    padding: 6px 0 10px 8px;
}

/* ==========================================================================
   SPACING & TRANSITIONS
   ========================================================================== */

.main-content-wrapper {
    padding: 0;
    transition: max-height 0.4s ease-out;
    overflow: hidden;
}

/* Intro text spacing */
.main-content-wrapper> :first-child {
    margin-top: 16px !important;
    padding: 0 16px;
}

.main-content-wrapper h4 {
    margin: 0 0 20px 0;
    font-style: italic;
    font-weight: normal;
    color: #88ccffcc;
    text-align: center;
    opacity: 0.9;
}

/* ==========================================================================
   LABELS & LINKS & TEXT
   ========================================================================== */

label {
    display: block;
    margin: 6px 0 4px;
    font-size: 12px;
    color: #aaccff;
}

a {
    color: #eee;
    text-decoration: underline;
    text-decoration-color: rgba(200, 220, 255, 0.4);
    text-decoration-thickness: 1px;
}

a:hover,
a:focus {
    color: #fff;
    text-decoration-color: #88f;
    text-decoration-thickness: 2px;
}

a:visited {
    color: #eee;
}

.text-field {
    margin: 6px 0;
}

.text-field input {
    width: 100%;
    padding: 4px;
    background: #222;
    border: 1px solid #444;
    color: #eee;
    border-radius: 4px;
}

.read-only-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 6px 0;
    gap: 3px !important;
    margin: 2px 0 !important;
}

.read-only-field label {
    flex: 1;
    margin-right: 3px !important;
}

.read-only-value {
    font-family: monospace;
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 4px;
    color: #0f9;
    padding: 1px 4px !important;
    margin: 0 2px !important;
    min-width: 38px !important;
}

.unit {
    color: #88ccff;
    opacity: 0.85;
    font-size: 11px;
    font-weight: 400;
    margin-left: 3px;
    margin-right: 14px;
    vertical-align: baseline;
    letter-spacing: 0.3px;
    margin: 0 2px 0 0 !important;
    font-size: 8.8px !important;
}

/* ==========================================================================
   SLIDERS & INPUTS
   ========================================================================== */

/* Range slider full width */
.slider-wrapper input[type="range"] {
    width: 100%;
    margin: 0;
    accent-color: #00dfff;
}

/* Top row: label + editable value on same line */
.slider-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    flex-wrap: nowrap;
}

.slider-top-row label {
    flex: 1;
    margin-right: 10px;
    font-weight: 500;
    color: #ddd;
}

.slider-top-row input[type="number"] {
    width: 80px;
    text-align: right;
    background: rgba(40, 60, 90, 0.7);
    border: 1px solid #00aaff88;
    color: #fff;
    padding: 4px 4px 4px 4px;
    border-radius: 4px;
    font-size: 12px;
}

/* ==========================================================================
   CHECKBOXES
   ========================================================================== */

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.checkbox-wrapper input[type="checkbox"] {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: #00dfff;
}

.checkbox-wrapper label {
    margin: 0;
    font-size: 12px;
    color: #aaccff;
    cursor: pointer;
    flex: 1;
    white-space: nowrap;
}

/* ==========================================================================
   CUSTOM SELECT
   ========================================================================== */

.custom-select-wrapper {
    display: flex;
    flex-direction: column;
    margin: 0 0 20px 0;
}

.custom-select-label-before {
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 500;
    color: #aaccff;
}

.custom-select-box {
    position: relative;
    overflow: visible;
}

.custom-select-selected {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(40, 60, 90, 0.7);
    border: 1px solid #00aaff88;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

.custom-select-arrow {
    margin-left: 8px;
    color: #88ccff;
}

.custom-select-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: rgba(20, 30, 50, 0.95);
    border: 1px solid #00aaff88;
    border-radius: 4px;
    max-height: 180px;
    overflow-y: auto;
    display: none;
    z-index: 5000;
}

.custom-select-list.open {
    display: block;
}

.custom-select-item {
    padding: 6px 8px;
    font-size: 12px;
    color: #fff;
    cursor: pointer;
}

.custom-select-item:hover {
    background: rgba(0, 180, 255, 0.25);
}

.custom-select-label-after {
    margin-top: 4px;
    font-size: 11px;
    color: #88ccffcc;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

button {
    padding: 6px 14px;
    margin: 8px 0;
    background: rgba(0, 200, 255, 0.3);
    border: 1px solid #00dfff;
    color: #00dfff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
}

button:hover {
    background: rgba(0, 220, 255, 0.5);
}

/* Time control button */
.time-button {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: bold;
    margin: 8px 0;
    background: rgba(100, 180, 255, 0.4);
    border: 1px solid #88ccff;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.time-button:hover {
    background: rgba(100, 180, 255, 0.6);
}

/* Fire cannonball button */
.fire-button {
    display: block;
    width: 100%;
    margin: 16px auto;
    padding: 12px;
    font-size: 16px;
    font-weight: bold;
    background: linear-gradient(135deg, #ff4444, #ff8800);
    border: none;
    color: white;
    border-radius: 6px;
    box-shadow: 0 0 15px #ff4444aa;
    cursor: pointer;
    transition: all 0.3s ease;
}

.fire-button:hover {
    transform: scale(1.04);
    box-shadow: 0 0 30px #ff4444ff;
}

/* Spaceshipt engine button */
button.thrust-active {
    background-color: #ffeb3b !important;
    color: #000 !important;
    font-weight: bold;
    box-shadow: 0 0 8px rgba(255, 235, 59, 0.7);
}

/* ==========================================================================
   TEMPORARY MESSAGES
   ========================================================================== */

#temporary-message {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

#temporary-message.hidden {
    opacity: 0;
}

/* ==========================================================================
   STATUS BAR
   ========================================================================== */

#status-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    min-width: 300px;
    max-width: 95%;
    height: 50px;
    background: rgba(20, 30, 60, 0.82);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(100, 150, 255, 0.35);
    border-radius: 12px;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    gap: 30px;
    font-size: 13.2px;
    color: #aaddff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    white-space: nowrap;
}

.status-section {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.status-label {
    font-weight: 600;
    opacity: 0.8;
    white-space: nowrap;
    margin-right: 4px;
}

.status-value {
    font-family: monospace;
    color: #0ff;
    min-width: 20px;
    text-align: right;
    display: inline-block;
    margin-right: 2px;
}

.unit {
    margin-top: 4px;
}

.status-section .custom-select-box {
    margin-top: 20px;
}

#status-bar .custom-select-selected {
    min-width: 200px;
    padding: 4px 12px;
}

#status-bar .custom-select-selected-text {
    white-space: nowrap;
}

#status-bar .custom-select-list {
    top: auto;
    bottom: 100%;
    margin-bottom: 4px;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
}

#status-bar .custom-select-wrapper {
    margin-right: 12px;
}

#fps {
    position: fixed !important;
    bottom: 8px !important; 
    left: auto !important; 
    right: 8px !important;
    transform: none !important;
    z-index: 1190 !important; 
    color: #0ff !important;
    font-family: monospace !important;
    font-size: 11px !important;
    padding: 3px 8px !important;
    min-width: 60px;
    text-align: center;
}

/* ==========================================================================
   RESPONSIVE - Mobile & small screens (≤ 768px)
   ========================================================================== */
   
@media (max-width: 768px) {

    /* Main controls panel */
    #controls {
        width: calc(100% - 12px);
        left: 6px;
        right: 6px;
        top: 6px;
        padding: 0;
        max-height: 85vh;
    }

    /* Hide intro elements */
    .header-intro,
    .main-content-wrapper>h4 {
        display: none !important;
    }

    /* Group titles - more compact */
    .control-group summary {
        padding: 9px 48px 9px 18px;
        font-size: 15px;
        min-height: 36px;
        line-height: 1.3;
    }

    /* Main title */
    #main-controls-toggle summary h1 {
        font-size: 22px;
        padding: 14px 20px;
    }

    /* Content padding inside opened groups */
    .group-content {
        padding: 12px 18px;
    }

    /* Very small vertical spacing between groups */
    .control-group {
        margin: 3px 0;
    }

    .control-group+.control-group {
        margin-top: 0;
    }

    /* Sliders & number inputs - smaller */
    .slider-top-row {
        margin-bottom: 8px;
    }

    #status-bar {
        position: fixed !important;
        inset: auto 0 0 0 !important; 
        width: auto !important;    
        max-width: calc(100% - 12px) !important;  
        min-width: 0 !important;
        left: 6px !important;  
        right: 6px !important;
        bottom: 6px !important;
        box-sizing: border-box !important;
        height: auto !important;
        min-height: 52px !important;
        padding: 6px 8px !important;  
        margin: 0 !important;
        border: 1px solid rgba(100, 150, 255, 0.32) !important;
        border-radius: 12px !important;
        background: rgba(18, 28, 58, 0.93) !important;
        box-shadow: 0 -5px 18px rgba(0,0,0,0.72) !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 5px !important;
        align-items: stretch !important;
        justify-content: center !important;
        font-size: 10.8px !important;
        z-index: 1200 !important;
        transform: none !important;
    }

    .status-line {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        width: 100% !important;
    }

    .status-line:first-child {
        gap: 4px !important;
        justify-content: flex-start !important;
    }

    .status-line:last-child {
        gap: 4px !important; 
        justify-content: space-between !important;
    }

    .read-only-field {
        flex: 1 1 32% !important;
        min-width: 0 !important;
        font-size: 10.2px !important;
        gap: 2px !important;
        justify-content: flex-start !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }

    .read-only-field label {
        font-size: 9.6px !important;
        opacity: 0.84 !important;
        flex: none !important;
        margin-right: 3px !important;
    }

    .read-only-value {
        flex: 1 1 auto !important;
        min-width: 36px !important;
        font-size: 10.9px !important;
        padding: 1px 3px !important;
        margin: 0 1px !important;
        background: rgba(0,0,0,0.48) !important;
        border-radius: 3px !important;
    }

    .unit {
        font-size: 8.4px !important;
        opacity: 0.72 !important;
        flex: none !important;
        margin-left: 2px !important;
        margin-right: 0 !important;
    }

    .status-line:first-child .custom-select-wrapper {
        flex: 1 !important;
        max-width: 65% !important; 
        min-width: 110px !important;
        margin: 0 !important;
    }

    .custom-select-selected {
        min-width: 100px !important; 
        padding: 4px 8px !important;
        font-size: 11px !important;
        min-height: 26px !important;
        line-height: 1.1 !important;
    }

    #fps {
        bottom: 80px !important;
        left: auto !important;
        right: 6px !important;
        width: auto !important;
        font-size: 10.5px !important;
        padding: 3px 6px !important;
    }
}
