:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1d1f23;
    --muted: #6b7079;
    --border: #dfe2e7;
    --accent: #6c5ce7;
    --accent-text: #ffffff;
    --on: #1f9d55;
    --error-bg: #fdecec;
    --error-text: #b42318;
    --screen: #1d1f23;
    --screen-text: #c9ccd2;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14161a;
        --surface: #1e2127;
        --text: #e8eaed;
        --muted: #9aa0a9;
        --border: #30343c;
        --accent: #8c7ff0;
        --on: #3ccf7c;
        --error-bg: #3a1d1d;
        --error-text: #ff9b91;
        --screen: #0b0c0e;
        --screen-text: #7d828b;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

/*************** Navigation *******************************************************************/
.navbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 16px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.navbar .brand {
    font-weight: 700;
}

.navbar a {
    color: var(--muted);
    text-decoration: none;
    padding: 16px 0;
    border-bottom: 2px solid transparent;
}

.navbar a:hover,
.navbar a.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/*************** Layout ***********************************************************************/
main {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.2;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; margin-bottom: 16px; }
h3 { font-size: 0.95rem; margin: 24px 0 12px; color: var(--muted); font-weight: 600; }

/*************** Power Switch *****************************************************************/
.power {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.status {
    margin: 4px 0 0;
    color: var(--muted);
}

.status.on {
    color: var(--on);
}

.switch {
    position: relative;
    flex-shrink: 0;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: inherit;
}

.switch .track {
    display: block;
    width: 64px;
    height: 36px;
    border-radius: 18px;
    background: var(--border);
    transition: background 0.2s;
}

.switch .thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.switch input:checked + .track {
    background: var(--on);
}

.switch input:checked + .track .thumb {
    transform: translateX(28px);
}

.switch input:focus-visible + .track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.switch input:disabled + .track {
    opacity: 0.5;
}

/*************** Sliders **********************************************************************/
.range {
    display: grid;
    grid-template-columns: 120px 1fr 56px;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.range input {
    width: 100%;
    accent-color: var(--accent);
}

.range output {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/*************** Number Fields ****************************************************************/
.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field label {
    font-size: 0.9rem;
    color: var(--muted);
}

.field input {
    width: 100%;
    max-width: 120px;
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.field input:invalid {
    border-color: var(--error-text);
}

/* distance fields arranged around a screen */
.screen-layout {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-areas:
        ".    top    ."
        "left screen right"
        ".    bottom .";
    gap: 12px;
    align-items: center;
    justify-items: center;
}

.distance {
    align-items: center;
    text-align: center;
}

.distance input {
    max-width: 80px;
    text-align: center;
}

.distance.top { grid-area: top; }
.distance.left { grid-area: left; }
.distance.right { grid-area: right; }
.distance.bottom { grid-area: bottom; }

.screen {
    grid-area: screen;
    width: 100%;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--screen);
    color: var(--screen-text);
    border-radius: 6px;
    box-shadow: 0 0 0 4px var(--border), 0 0 24px 4px color-mix(in srgb, var(--accent) 45%, transparent);
    font-size: 0.9rem;
}

/*************** Error ************************************************************************/
.error {
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--error-bg);
    color: var(--error-text);
    white-space: pre-line;
}

@media (max-width: 480px) {
    .range {
        grid-template-columns: 1fr 56px;
    }

    .range label {
        grid-column: 1 / -1;
        margin-bottom: -8px;
    }

    .range input {
        grid-column: 1;
    }
}

