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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #000000;
    color: #ffffff;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.controls {
    width: 320px;
    background-color: #1a1a1a;
    padding: 20px;
    overflow-y: auto;
    border-right: 2px solid #333;
}

h1 {
    font-size: 24px;
    margin-bottom: 25px;
    color: #ffffff;
    text-align: center;
    border-bottom: 2px solid #444;
    padding-bottom: 10px;
}

h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #cccccc;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
}

/* Collapsible sections of the control panel. Native details/summary, so the
   keyboard and screen-reader behaviour comes for free; summary is styled to
   match the h3 headings it replaced. */
details {
    margin-bottom: 18px;
}

details:last-child {
    margin-bottom: 0;
}

summary {
    font-size: 16px;
    color: #cccccc;
    padding-bottom: 8px;
    margin-bottom: 15px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;              /* replaced by the arrow below */
}

summary::-webkit-details-marker {
    display: none;                 /* Safari keeps its own marker otherwise */
}

summary::before {
    content: "▸";
    color: #009EE2;
    font-size: 14px;
    transition: transform 0.15s ease;
}

details[open] > summary::before {
    transform: rotate(90deg);
}

summary:hover {
    color: #ffffff;
}

summary:focus-visible {
    outline: 2px solid #009EE2;
    outline-offset: 2px;
}

/* The panels bring their own bottom margin, which would stack with the one
   on details */
details > .info-panel,
details > .build-panel {
    margin-bottom: 0;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    color: #cccccc;
    font-size: 14px;
}

.control-group input[type="number"] {
    width: 100px;
    padding: 8px;
    background-color: #2a2a2a;
    border: 1px solid #444;
    color: #ffffff;
    border-radius: 4px;
    font-size: 14px;
    margin-right: 10px;
}

.control-group input[type="number"]:focus {
    outline: none;
    border-color: #666;
}

.control-group input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

button {
    padding: 8px 16px;
    background-color: #0066cc;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #0052a3;
}

button:active {
    background-color: #004080;
}

/* Export buttons. The colours used to sit in inline style attributes, which
   outrank any stylesheet rule and so made a disabled state impossible to
   show. */
.export-btn {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}

.export-dxf { background-color: #4CAF50; }
.export-stl { background-color: #2196F3; }
.export-stl-batch { background-color: #FF5722; }

.export-dxf:hover { background-color: #429647; }
.export-stl:hover { background-color: #1c7fd0; }
.export-stl-batch:hover { background-color: #d94a1e; }

button:disabled,
button:disabled:hover {
    background-color: #3a3a3a;
    color: #777777;
    cursor: not-allowed;
}

.export-note {
    color: #888888;
    font-size: 12px;
    line-height: 1.5;
    margin-top: -8px;
}

.info-panel {
    background-color: #2a2a2a;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 5px 0;
}

.info-label {
    color: #aaaaaa;
    font-size: 13px;
}

.info-item span:last-child {
    color: #ffffff;
    font-weight: bold;
    font-size: 14px;
}

.instructions {
    background-color: #2a2a2a;
    padding: 15px;
    border-radius: 6px;
}

.instructions ul {
    list-style: none;
    padding-left: 0;
}

.instructions li {
    padding: 6px 0;
    color: #aaaaaa;
    font-size: 13px;
}

.instructions li:before {
    content: "▸ ";
    color: #009EE2;
    margin-right: 5px;
}

#canvas-container {
    flex: 1;
    position: relative;
    background-color: #000000;
}

#canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    /* Hand touch gestures to the JS handlers instead of letting the browser
       scroll or pinch-zoom the page when a finger lands on the model */
    touch-action: none;
}

/* Scrollbar styling */
.controls::-webkit-scrollbar {
    width: 8px;
}

.controls::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.controls::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.controls::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Build Instructions Panel */
.build-panel {
    background-color: #2a2a2a;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #444;
}

.build-section {
    margin-bottom: 15px;
}

.build-section:last-child {
    margin-bottom: 0;
}

.build-section h4 {
    font-size: 14px;
    color: #aaaaaa;
    margin-bottom: 10px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
    font-weight: normal;
}

.build-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.build-table thead {
    background-color: #1a1a1a;
}

.build-table th {
    padding: 8px;
    text-align: left;
    color: #cccccc;
    border-bottom: 2px solid #444;
    font-weight: normal;
}

.build-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #333;
    color: #ffffff;
}

.build-table tbody tr:hover {
    background-color: #333;
}

.build-table tbody tr:last-child td {
    border-bottom: none;
}

.connector-info {
    padding: 5px 0;
}

.color-box {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #555;
    display: inline-block;
}

/* Stack the canvas above the controls and let the page scroll, whenever side
   by side would not work: on anything narrow (the 320px panel leaves a phone
   in portrait about 70px of canvas — a sliver) and on anything held upright,
   where a column beside the panel leaves the sphere stranded in a tall empty
   strip. The comma is an OR. */
@media (max-width: 820px), (orientation: portrait) {
    /* Let the document scroll rather than the body box, so the sticky canvas
       below has a scrolling ancestor it can pin against */
    body {
        overflow: visible;
    }

    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        width: 100%;
    }

    #canvas-container {
        order: -1;          /* controls come first in the markup */
        flex: none;
        height: 45vh;
        min-height: 260px;
        /* Pin the model to the top: the controls scroll underneath it while
           the sphere stays in view, so a parameter change is visible as it
           happens instead of requiring a scroll back up */
        position: sticky;
        top: 0;
        z-index: 2;
    }

    .controls {
        width: 100%;
        overflow-y: visible;
        border-right: none;
        border-top: 2px solid #333;
        /* Fill whatever height is left. With every section collapsed the panel
           is shorter than a tall screen, and the page background would
           otherwise show through below it as a stray black band. */
        flex: 1 0 auto;
    }
}
