:root {
    --bg-main: #22272f;
    --bg-panel: #1b2028;
    --bg-tool: #2d3542;
    --bg-tool-hover: #374455;
    --text: #e8edf3;
    --muted: #9aa7b2;
    --accent: #67e8f9;
    --accent-2: #a78bfa;
    --border: rgba(255,255,255,0.12);
    --shadow: 0 12px 30px rgba(0,0,0,0.28);
}

html,
body {
    min-height: 100%;
    width: 100%;
    margin: 0;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font-family: "Segoe UI", sans-serif;
    background: linear-gradient(135deg, #1a1f27 0%, #2a3140 100%);
    color: var(--text);
    padding: 24px;
}

* {
    box-sizing: border-box;
}


/* ---------- layout ---------- */

#set {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

#editor,
#run {
    display: flex;
    flex-direction: row;

    background: var(--bg-panel);
    padding: 15px;
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

#saveload {
    width: auto;
    height: auto;

    display: flex;
    flex-direction: row;

    background: var(--bg-panel);
    padding: 15px;
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);

    overflow: hidden;
}

#loadTool {
    flex: 0 0 120px;
}


/* ---------- tool panel ---------- */

.toolPanel {
    width: 120px;

    display: flex;
    flex-direction: column;
    gap: 5px;

    padding: 6px;
    margin-right: 10px;

    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.toolPanel button {
    width: 100%;
}


/* ---------- menu ---------- */

#rectSelectMenu,
#jointSelectMenu {
    position: absolute;

    display: none;
    flex-direction: column;

    background: rgba(27, 32, 40, 0.96);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);

    padding: 10px;
    gap: 8px;
}


/* ---------- group ---------- */

.groupRow {
    display: flex;
    gap: 4px;
}

.groupBtn {
    width: 24px;
    height: 24px;

    border: 1px solid black;

    display: flex;
}

.groupBtn:nth-child(1) {
    background: blue;
}

.groupBtn:nth-child(2) {
    background: red;
}

.groupBtn:nth-child(3) {
    background: green;
}

.groupBtn:nth-child(4) {
    background: yellow;
}

.groupBtn:nth-child(5) {
    background: purple;
}

.groupBtn:nth-child(6) {
    background: orange;
}

.groupBtn:nth-child(7) {
    background: cyan;
}


/* ---------- slider ---------- */

#sliders {
    display: flex;
    flex-direction: column;

    font-size: 10px;
    color: var(--text);
    gap: 2px;
}

.sliderBox {
    display: flex;
    flex-direction: column;

    margin-bottom: 8px;

    padding: 6px;

    background: #333;
    border-radius: 6px;
}

.sliderLine {
    display: flex;
    align-items: center;

    gap: 8px;
}

.sliderLine input[type="range"] {
    flex: 1;
    width: 100%;
    min-width: 0;
}

.sliderLine span {
    width: 40px;
    text-align: right;
}


/* ---------- canvas ---------- */

#canvasWrap {
    position: relative;
}

#sideBtn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    border-radius: 999px;
    padding: 8px 12px;
    box-shadow: var(--shadow);
}

canvas {
    width: min(100%,800px);
    height: auto;

    touch-action: none;
    border-radius: 0;
    border: 1px solid var(--border);
    background: #111;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}


/* ---------- save ---------- */

#saveData {
    width: 800px;
    height: 600px;

    resize: none;

    font-family: Consolas, monospace;
    background: #0d1117;
    color: #7efc7e;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}


/* ---------- button ---------- */

button {
    background: var(--bg-tool);
    color: white;
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 5px 8px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow:
        0 3px 6px rgba(0,0,0,0.25),
        inset 0 1px 0 rgba(255,255,255,0.08);
}

button:hover {
    background: var(--bg-tool-hover);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

input:not([type="range"]),
textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: var(--text);
    padding: 6px 8px;
}

input[type="range"] {
    padding: 0;
    border: none;
    background: transparent;
}

/* ---------- icons ---------- */

.jointIcon {
    display: inline-block;

    width: 10px;
    height: 10px;

    border-radius: 50%;

    background: transparent;

    border: 2px solid;

    margin-right: 6px;
}

.runIcon {
    display: inline-block;

    width: 10px;
    height: 10px;

    border: none;
    background: transparent;

    position: relative;

    margin-right: 6px;
}

.objectIcon {
    display: inline-block;

    width: 10px;
    height: 8px;

    margin-right: 6px;

    background: rgba(0,120,255,0.4);
    border: 2px solid rgb(0,120,255);
}

.fixIcon {
    border-color:red;
}

.hingeIcon {
    border-color:blue;
}

.motorIcon {
    border-color:green;
}


.startIcon::before {
    content:"";

    position:absolute;

    top:1px;
    left:2px;

    width:0;
    height:0;

    border-top:4px solid transparent;
    border-bottom:4px solid transparent;
    border-left:7px solid white;
}


.stopIcon::before,
.stopIcon::after {
    content:"";

    position:absolute;

    top:1px;

    width:3px;
    height:8px;

    background:white;
}

.stopIcon::before {
    left:1px;
}

.stopIcon::after {
    left:6px;
}


/* ---------- credit ---------- */

#credit {
    color: var(--muted);
    text-align: center;
    margin-top: 14px;
}


/* ---------- mobile ---------- */

@media (max-width:600px) {

    html,
    body {
        width:100%;
        justify-content:flex-start;
        padding:0;
        align-items:stretch;
    }

    main {
        width:100%;
        max-width:100%;
    }

    #editor,
    #run {
        flex-direction:column;
        width:100%;
    }

    #canvasWrap {
        width:100%;
    }

    canvas {
        width:100%;
    }

    .toolPanel {
        width:100%;

        order:2;

        margin-right:0;
        margin-top:10px;

        display:grid;
        grid-template-columns:repeat(3,1fr);
    }


    .toolPanel button {
        width:auto;
    }


    #editScene,
    #runScene{
        order:1;
    }


    #saveload {
        margin-top:10px;

        width:100%;
        max-width:100%;

        display:flex;
        flex-direction:row;
        align-items:stretch;
    }

    #loadTool {
        display:flex;
        flex-direction:column;
        width:max-content;
        flex:0 0 auto;
        order:1;
    }


    #saveData {
        width:auto !important;
        max-width:none !important;
        flex:1;
        min-width:0;
        order:2;

        min-height:300px !important;
        height:60vh !important;
    }


    #loaderBtn {
        width:max-content;
        height:max-content;
    }
}