* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    align-items: start;
    background: #15191e;
    color: #f0f0f0;
    font-family: Arial, sans-serif;
}

.site-sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
    height: 100vh;
    padding: 24px 16px;
    background: #242a31;
    border-right: 1px solid #414952;
}

.site-title {
    color: #f0f0f0;
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
}

.panel {
    width: 100%;
    max-width: 1000px;
    margin: 24px auto;
    padding: 30px 20px;
    text-align: center;
    background: #242a31;
    border: 1px solid #414952;
    border-radius: 16px;
    box-shadow: 0 12px 35px #0005;
}

h1 {
    margin: 0 0 20px;
    font-size: 1.5rem;
    font-weight: 500;
    text-align: center;
}

.site-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.site-nav a,
button,
.button-link {
    padding: 8px 14px;
    color: #f0f0f0;
    background: #323a43;
    border: 1px solid #414952;
    border-radius: 6px;
    font: inherit;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
}

.site-nav a {
    display: block;
    text-align: left;
}

.site-nav a[aria-current="page"] {
    background: #43504a;
    border-color: #25f078;
}

button:hover:not(:disabled),
.button-link:hover,
.site-nav a:hover {
    background: #3f4953;
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

button.danger:hover:not(:disabled) {
    background: #7a2b2b;
}

input,
select {
    min-width: 0;
    padding: 8px;
    color: #f0f0f0;
    background: #111519;
    border: 1px solid #414952;
    border-radius: 6px;
    font: inherit;
    font-size: 0.9rem;
}

.clock {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(5px, 2vw, 16px);
}

.digit {
    position: relative;
    flex: 0 1 124px;
    width: 124px;
    height: 222px;
    aspect-ratio: 0.5585;
    max-width: 124px;
}

.segment {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 3px;
    background: #111519;
    border: 1px solid #353c43;
    border-radius: 5px;
}

.segment.a,
.segment.d,
.segment.g {
    width: 72px;
    height: 26px;
}

.segment.b,
.segment.c,
.segment.e,
.segment.f {
    width: 26px;
    height: 72px;
    flex-direction: column;
}

.segment.a { top: 0;     left: 26px; }
.segment.b { top: 26px;  left: 98px; }
.segment.c { top: 124px; left: 98px; }
.segment.d { top: 196px; left: 26px; }
.segment.e { top: 124px; left: 0px;  }
.segment.f { top: 26px;  left: 0px;  }
.segment.g { top: 98px;  left: 26px; }

.light {
    appearance: none;
    -webkit-appearance: none;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.18;
    transition: opacity 0.12s, box-shadow 0.12s;
}

.light.red {
    background: #ff3038;
    color: #ff3038;
}

.light.yellow {
    background: #ffd52a;
    color: #ffd52a;
}

.light.green {
    background: #25f078;
    color: #25f078;
}

.light.on {
    opacity: 1;
    box-shadow: 0 0 7px currentColor, 0 0 14px currentColor;
}

.light:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
    z-index: 2;
}

.colon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 0 2px;
}

.colon-dot {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #ffd52a;
    color: #ffd52a;
    opacity: 0.18;
    cursor: pointer;
}

.colon-dot.on {
    opacity: 1;
    box-shadow: 0 0 7px currentColor, 0 0 14px currentColor;
}

.instructions {
    margin: 28px 0 18px;
    color: #bdc5ce;
    font-size: 0.95rem;
}

.legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 22px;
    font-size: 0.85rem;
}

.legend span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-light {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.legend-light.red { background: #ff3038; }
.legend-light.yellow { background: #ffd52a; }
.legend-light.green { background: #25f078; }

#api-status {
    min-height: 1.2em;
    margin: 24px 0 0;
    color: #aab4bf;
    font-size: 0.8rem;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.toolbar .button-link {
    margin-right: auto;
}

.status {
    min-height: 1.4em;
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: #aab3bc;
}

.status.error,
#status.error {
    color: #ff7b7b;
}

.file-table {
    width: 100%;
    border-collapse: collapse;
}

.file-table th,
.file-table td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #414952;
}

.file-table td.actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.file-table .empty {
    text-align: center;
    color: #aab3bc;
}

.file-table td.name {
    word-break: break-all;
}

.editor-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 0 16px;
}

.editor-row label,
.hex-form label {
    font-size: 0.9rem;
}

#name-input,
#load-select {
    flex: 1 1 180px;
}

#rate-input {
    width: 80px;
}

.editor-row button.primary,
.frame-strip button.selected {
    background: #2b6a46;
}

.frame-tools {
    margin-top: 24px;
}

.frame-label {
    margin: 0 0 8px;
    color: #bdc5ce;
    font-size: 0.9rem;
}

.frame-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    max-height: 180px;
    margin-bottom: 20px;
    overflow-y: auto;
}

.frame-strip button {
    min-width: 44px;
    font-family: monospace;
}

.frame-strip button.selected {
    border-color: #25f078;
}

#status {
    min-height: 1.2em;
    margin: 0;
    color: #aab4bf;
    font-size: 0.85rem;
}

.hex-form {
    margin-top: 20px;
}

.hex-form label {
    display: block;
    margin-bottom: 8px;
}

.hex-row {
    display: flex;
    gap: 8px;
}

.hex-row input {
    flex: 1;
    font-family: monospace;
}

.hex-row input.invalid {
    border-color: #e04848;
}

.setup-form {
    text-align: left;
}

.setup-section {
    min-width: 0;
    margin: 24px 0 0;
    padding: 18px 0 0;
    border: 0;
    border-top: 1px solid #414952;
}

.setup-section legend {
    padding-right: 12px;
    font-size: 1.05rem;
    font-weight: 600;
}

.setup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.setup-field,
.setup-secret {
    display: grid;
    align-content: start;
    gap: 8px;
    min-width: 0;
}

.setup-field {
    color: #d5dce2;
    font-size: 0.9rem;
}

.setup-field input,
.setup-field select {
    width: 100%;
}

.setup-field small {
    color: #aab4bf;
    font-size: 0.8rem;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #25f078;
}

input:disabled {
    opacity: 0.55;
}

.setup-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

#setup-status {
    min-height: 1.4em;
    margin: 20px 0 0;
    color: #aab4bf;
    font-size: 0.9rem;
}

#setup-status.error {
    color: #ff7b7b;
}

@media (max-width: 720px) {
    body {
        display: flex;
        flex-direction: column;
    }

    .site-sidebar {
        position: static;
        width: 100%;
        height: auto;
        gap: 16px;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid #414952;
    }

    .site-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .site-nav a {
        padding: 8px 10px;
    }

    .panel {
        margin: 16px auto;
    }

    .setup-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 420px) {
    .panel {
        padding: 24px 10px;
    }

    .clock {
        gap: 5px;
    }

    .digit {
        min-width: 0;
    }

    .segment {
        gap: 2px;
        padding: 2px;
    }

    .colon {
        gap: 18px;
    }
}