:root {
    --win95-bg: #c0c0c0;
    --win95-text: #000000;
    --win95-highlight: #ffffff;
    --win95-shadow: #808080;
    --win95-title-bar-bg: #000080;
    --win95-title-bar-text: #ffffff;
    --rect-fill: rgba(0, 0, 255, 0.3);
    --rect-stroke: #000080;
    --rect-hover-stroke: #ff00ff;
}

html, body {
    box-sizing: border-box;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    font-family: 'MS Sans Serif', 'Tahoma', 'Verdana', 'sans-serif';
    background-color: #008080; /* Classic desktop teal */
    color: var(--win95-text);
    display: flex;
    flex-direction: column;
}

.win95-panel {
    background-color: var(--win95-bg);
    padding: 4px;
    border-top: 2px solid var(--win95-highlight);
    border-left: 2px solid var(--win95-highlight);
    border-right: 2px solid #000000;
    border-bottom: 2px solid #000000;
    display: flex;
    align-items: center;
    gap: 16px;
}

header.win95-panel {
    flex-shrink: 0;
    flex-wrap: wrap;
    padding: 8px;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group {
    border: 2px inset var(--win95-bg);
    padding: 4px 8px;
}
.checkbox-group input {
    margin-right: 4px;
}


.win95-button {
    background-color: var(--win95-bg);
    border: 2px outset var(--win95-highlight);
    border-color: var(--win95-highlight) var(--win95-shadow) var(--win95-shadow) var(--win95-highlight);
    box-shadow: 1px 1px 0px 1px #000000;
    padding: 4px 12px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    min-width: 75px;
    text-align: center;
}
.win95-button.active-mode {
    border-style: inset;
    background-color: #e0e0e0;
    box-shadow: none;
    padding: 5px 11px 3px 13px; /* visual push effect */
}

.win95-button:not(:disabled):active {
    border-style: inset;
    box-shadow: none;
    padding: 5px 11px 3px 13px; /* visual push effect */
}

.win95-button:disabled {
    color: var(--win95-shadow);
    text-shadow: 1px 1px 0 var(--win95-highlight);
    cursor: not-allowed;
    box-shadow: none;
}

input[type="file"] {
    display: none;
}

/* Slider Style */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    background: transparent;
}
input[type=range]:focus {
    outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--win95-shadow);
    border: 1px solid #000;
}
input[type=range]::-webkit-slider-thumb {
    border: 2px outset var(--win95-highlight);
    border-color: var(--win95-highlight) #000 #000 var(--win95-highlight);
    height: 20px;
    width: 10px;
    background: var(--win95-bg);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -8px;
}
input[type=range]:disabled::-webkit-slider-runnable-track {
    background: #a0a0a0;
}
input[type=range]:disabled::-webkit-slider-thumb {
    border-color: var(--win95-shadow);
    background: #a0a0a0;
}

.win95-number-input {
    background-color: var(--win95-highlight);
    border: 2px inset var(--win95-bg);
    border-color: var(--win95-shadow) var(--win95-highlight) var(--win95-highlight) var(--win95-shadow);
    padding: 2px 4px;
    font-family: inherit;
    font-size: 1rem;
    width: 70px;
    color: #000000; /* Fix for white-on-white text bug */
}
.win95-number-input:disabled {
    background-color: var(--win95-bg);
    color: var(--win95-shadow);
}

#rectScaleInput {
    width: 60px;
}


main {
    flex-grow: 1;
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* For stacking context of help panel */
    min-height: 0; /* Allow the main area to shrink on short screens */
}

.win95-window {
    width: 100%;
    height: 100%;
    background: var(--win95-bg);
    border: 2px outset var(--win95-highlight);
    box-shadow: 3px 3px 5px rgba(0,0,0,0.5);
    padding: 2px;
    display: flex;
    flex-direction: column;
}

.win95-title-bar {
    background-color: var(--win95-title-bar-bg);
    color: var(--win95-title-bar-text);
    padding: 3px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    user-select: none;
}
.win95-title-bar-buttons {
    display: flex;
}
.win95-title-bar-buttons .win95-button {
    width: 22px;
    height: 20px;
    padding: 0;
    font-weight: bold;
    box-shadow: none;
    margin-left: 2px;
    line-height: 14px;
    min-width: 22px;
}

#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    flex-grow: 1;
    border: 2px inset var(--win95-highlight);
    border-color: var(--win95-shadow) var(--win95-highlight) var(--win95-highlight) var(--win95-shadow);
    overflow: hidden;
    background-color: var(--win95-shadow);
}

canvas {
    background-color: #ffffff;
    cursor: default;
    display: block; /* remove bottom space */
}

#instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--win95-text);
    font-size: 1.1rem;
    line-height: 1.6;
    padding: 1rem;
    background: var(--win95-bg);
    border: 2px outset var(--win95-highlight);
    pointer-events: none;
}

.win95-status-bar {
    display: flex;
    gap: 2px;
    padding: 2px;
    flex-shrink: 0;
}

.win95-status-field {
    flex-grow: 1;
    padding: 2px 4px;
    border: 1px inset #fff;
    border-color: var(--win95-shadow) var(--win95-highlight) var(--win95-highlight) var(--win95-shadow);
    font-size: 0.9rem;
    min-width: 150px;
    white-space: nowrap;
}

footer.win95-panel {
    justify-content: space-between;
    flex-wrap: wrap;
    flex-shrink: 0; /* Prevent footer from shrinking */
}

.footer-credits {
    font-size: 0.9rem;
    color: var(--win95-text);
    padding: 0 4px;
    white-space: nowrap;
}

.footer-credits a {
    color: blue;
    text-decoration: underline;
}

.footer-credits a:hover,
.footer-credits a:active {
    color: red;
}

.footer-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Help Panel */
.help-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 350px;
    max-width: 90vw;
    background: var(--win95-bg);
    border-left: 2px outset var(--win95-highlight);
    box-shadow: -3px 0 5px rgba(0,0,0,0.5);
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-in-out;
}
.help-panel.hidden {
    transform: translateX(100%);
}
.help-content {
    padding: 10px 15px;
    overflow-y: auto;
    flex-grow: 1;
}
.help-content h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
}
.help-content ul {
    padding-left: 20px;
    margin: 0;
    list-style-type: square;
}
.help-content li {
    margin-bottom: 0.5em;
}

/* Custom Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-overlay.hidden {
    display: none;
}

.modal-overlay .win95-window {
    width: 400px;
    max-width: 90vw;
    height: auto;
}

.modal-content {
    padding: 20px;
    text-align: center;
}

.modal-content p {
    margin: 0 0 20px 0;
    line-height: 1.4;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    /* Make header and footer controls stack vertically */
    header.win95-panel, footer.win95-panel {
        flex-direction: column;
        align-items: stretch; /* Stretch groups to full width */
        gap: 8px;
    }

    .controls-group {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-start;
    }

    /* Reduce font size for smaller screens to fit more */
    body {
        font-size: 0.9rem;
    }
    .win95-button, .win95-number-input {
        font-size: 0.9rem;
    }

    /* Reduce padding to save space */
    header.win95-panel, footer.win95-panel {
        padding: 6px;
    }
    
    main {
        padding: 8px;
    }

    /* Make footer credits and controls stack */
    .footer-credits {
        order: 2; /* Move credits to the bottom */
        width: 100%;
        text-align: center;
        white-space: normal; /* Allow credits to wrap */
        padding-top: 8px;
    }

    .footer-controls {
        order: 1;
        width: 100%;
        justify-content: center;
    }

    /* Make status bar fields wrap */
    .win95-status-bar {
        flex-wrap: wrap;
    }

    .win95-status-field {
        min-width: 120px; /* Allow fields to be smaller */
    }
    
    /* Adjust initial instructions text size */
    #instructions {
        font-size: 1rem;
        width: 90%;
    }
    
    /* Prevent title text from overflowing */
    .win95-title-bar span#app-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px; /* Use px for more control on mobile */
    }
    .win95-button, .win95-number-input, .win95-status-field {
        font-size: 14px;
    }
    .win95-button {
        padding: 4px 8px;
        min-width: unset; /* Let button size be natural */
    }
     .win95-title-bar-buttons .win95-button {
        width: 22px;
        height: 20px;
        min-width: 22px;
    }
    
    /* Stack status bar fields on very small screens */
    .win95-status-bar {
        flex-direction: column;
        gap: 1px;
    }

    .win95-status-field {
        min-width: 0; /* Allow it to shrink */
    }
}