:root {
    color-scheme: dark;

    /* Strict monochrome palette. No accents, no gradients. */
    --panel-bg: #0a0a0a;
    --panel-border: #1f1f1f;
    --panel-divider: #161616;

    --text: #d4d4d4;
    --text-strong: #f0f0f0;
    --text-muted: #6e6e6e;
    --text-dim: #4a4a4a;

    --surface: #111111;
    --surface-hover: #181818;
    --surface-active: #1f1f1f;

    --track: #1c1c1c;
    --thumb: #d4d4d4;

    --mono:
        ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas,
        "Liberation Mono", monospace;
}

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

body {
    overflow: hidden;
    background: #000;
    color: var(--text);
    font-family:
        ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
}

canvas#bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    display: block;
}

/* ---------------------------------------------------------- Control panel */

.dbg-panel {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: min(18rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    color: var(--text);
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.4;
    user-select: none;
}

.dbg-panel::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.dbg-panel::-webkit-scrollbar-track {
    background: transparent;
}

.dbg-panel::-webkit-scrollbar-thumb {
    background: #2a2a2a;
    border-radius: 0;
}

.dbg-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.dbg-panel__title {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.dbg-panel__title h2 {
    color: var(--text-strong);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.12em;
    line-height: 1;
    text-transform: uppercase;
}

.dbg-panel__subtitle {
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.04em;
}

.dbg-panel__actions {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.dbg-panel__fps {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    min-width: 56px;
    padding: 0 0.5rem;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    background: transparent;
    user-select: none;
}

.dbg-panel__reset {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    padding: 0 0.6rem;
    color: var(--text-strong);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    background: var(--surface);
    cursor: pointer;
    transition:
        background 100ms linear,
        border-color 100ms linear,
        color 100ms linear;
}

.dbg-panel__reset:hover,
.dbg-panel__reset:focus-visible {
    color: #000;
    border-color: var(--text-strong);
    background: var(--text-strong);
    outline: none;
}

.dbg-panel__reset:active {
    background: var(--text);
}

/* ---------------------------------------------------------------- Presets */

.dbg-panel__presets {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.dbg-panel__presets-label {
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.dbg-panel__presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.dbg-preset {
    appearance: none;
    flex: 0 1 auto;
    height: 22px;
    padding: 0 0.55rem;
    color: var(--text);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    background: var(--surface);
    cursor: pointer;
    transition:
        background 100ms linear,
        border-color 100ms linear,
        color 100ms linear;
}

.dbg-preset:hover,
.dbg-preset:focus-visible {
    color: var(--text-strong);
    border-color: var(--text-muted);
    background: var(--surface-hover);
    outline: none;
}

.dbg-preset--active,
.dbg-preset--active:hover,
.dbg-preset--active:focus-visible {
    color: #000;
    border-color: var(--text-strong);
    background: var(--text-strong);
}

.dbg-preset:active {
    background: var(--surface-active);
}

.dbg-panel__body {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1 1 auto;
}

/* ----------------------------------------------------- Sections (details) */

.dbg-section {
    border-bottom: 1px solid var(--panel-divider);
    background: transparent;
}

.dbg-section:last-child {
    border-bottom: 0;
}

.dbg-section__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    color: var(--text);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    list-style: none;
    transition: background 80ms linear;
}

.dbg-section__summary::-webkit-details-marker {
    display: none;
}

.dbg-section__summary:hover {
    background: var(--surface);
}

.dbg-section__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dbg-section__chevron {
    display: grid;
    place-items: center;
    width: 12px;
    height: 12px;
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1;
    border: 0;
    background: transparent;
    transition: color 80ms linear;
}

.dbg-section__chevron::after {
    content: "+";
    font-family: var(--mono);
    font-size: 12px;
}

.dbg-section[open] > .dbg-section__summary .dbg-section__chevron {
    color: var(--text);
}

.dbg-section[open] > .dbg-section__summary .dbg-section__chevron::after {
    content: "−";
}

.dbg-section__content {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    border-top: 1px solid var(--panel-divider);
}

.dbg-section__content--grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
}

/* --------------------------------------------------------------- Controls */

.dbg-control {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.55rem 0.75rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    min-width: 0;
}

.dbg-section__content > .dbg-control + .dbg-control {
    border-top: 1px solid var(--panel-divider);
}

.dbg-section__content--grid > .dbg-control {
    border-right: 1px solid var(--panel-divider);
    border-top: 1px solid var(--panel-divider);
}

.dbg-section__content--grid > .dbg-control:nth-child(2n) {
    border-right: 0;
}

.dbg-section__content--grid > .dbg-control:nth-child(-n + 2) {
    border-top: 0;
}

.dbg-section__content--grid .dbg-control--switch {
    grid-column: 1 / -1;
    border-right: 0;
}

.dbg-control--switch {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.dbg-control__label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.6rem;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.04em;
    line-height: 1.2;
    min-width: 0;
}

.dbg-control--switch .dbg-control__label {
    flex: 1 1 auto;
}

.dbg-control__label-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.dbg-control__label-text > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.dbg-control__hint {
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 400;
    letter-spacing: 0.02em;
}

.dbg-control__value {
    min-width: 0;
    padding: 0;
    color: var(--text-strong);
    text-align: right;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}

/* Range */

input[type="range"].dbg-control__range {
    width: 100%;
    height: 2px;
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    border-radius: 0;
    outline: none;
    cursor: pointer;
    background: var(--track);
}

input[type="range"].dbg-control__range::-webkit-slider-runnable-track {
    height: 2px;
    background: var(--track);
    border-radius: 0;
}

input[type="range"].dbg-control__range::-moz-range-track {
    height: 2px;
    background: var(--track);
    border-radius: 0;
}

input[type="range"].dbg-control__range::-webkit-slider-thumb {
    width: 10px;
    height: 10px;
    margin-top: -4px;
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    border-radius: 0;
    background: var(--thumb);
    box-shadow: none;
    cursor: pointer;
    transition: background 80ms linear;
}

input[type="range"].dbg-control__range::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border: 0;
    border-radius: 0;
    background: var(--thumb);
    box-shadow: none;
    cursor: pointer;
    transition: background 80ms linear;
}

input[type="range"].dbg-control__range:hover::-webkit-slider-thumb,
input[type="range"].dbg-control__range:focus-visible::-webkit-slider-thumb {
    background: var(--text-strong);
}

input[type="range"].dbg-control__range:hover::-moz-range-thumb,
input[type="range"].dbg-control__range:focus-visible::-moz-range-thumb {
    background: var(--text-strong);
}

/* Color */

input[type="color"].dbg-control__color {
    width: 100%;
    height: 24px;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--panel-border);
    border-radius: 0;
    background: var(--surface);
    cursor: pointer;
    overflow: hidden;
}

input[type="color"].dbg-control__color::-webkit-color-swatch-wrapper {
    padding: 2px;
}

input[type="color"].dbg-control__color::-webkit-color-swatch {
    border: 0;
    border-radius: 0;
}

input[type="color"].dbg-control__color::-moz-color-swatch {
    border: 0;
    border-radius: 0;
}

/* Text */

textarea.dbg-control__text {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 0.4rem 0.5rem;
    color: var(--text-strong);
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.45;
    letter-spacing: 0.01em;
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    background: var(--surface);
    resize: vertical;
    outline: none;
    box-sizing: border-box;
    word-break: break-all;
    overflow-y: auto;
    transition:
        background 100ms linear,
        border-color 100ms linear;
}

textarea.dbg-control__text:hover {
    background: var(--surface-hover);
}

textarea.dbg-control__text:focus-visible {
    border-color: var(--text);
    background: var(--surface-hover);
}

textarea.dbg-control__text::-webkit-scrollbar {
    width: 6px;
}

textarea.dbg-control__text::-webkit-scrollbar-thumb {
    background: #2a2a2a;
}

/* Switch */
input[type="checkbox"].dbg-control__switch {
    position: relative;
    flex: 0 0 auto;
    width: 28px;
    height: 14px;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--panel-border);
    border-radius: 0;
    background: var(--surface);
    cursor: pointer;
    transition:
        background 100ms linear,
        border-color 100ms linear;
}

input[type="checkbox"].dbg-control__switch::after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    width: 10px;
    height: 10px;
    border-radius: 0;
    background: var(--text-muted);
    transition:
        transform 100ms linear,
        background 100ms linear;
}

input[type="checkbox"].dbg-control__switch:checked {
    border-color: var(--text-strong);
    background: var(--surface-active);
}

input[type="checkbox"].dbg-control__switch:checked::after {
    transform: translateX(14px);
    background: var(--text-strong);
}

input[type="checkbox"].dbg-control__switch:focus-visible {
    border-color: var(--text);
    outline: none;
}

/* ---------------------------------------------------- Mobile adjustments */

@media (max-width: 520px) {
    .dbg-panel {
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
        width: auto;
    }

    .dbg-section__content--grid {
        grid-template-columns: 1fr;
    }

    .dbg-section__content--grid > .dbg-control {
        border-right: 0;
    }

    .dbg-section__content--grid > .dbg-control:nth-child(-n + 2) {
        border-top: 1px solid var(--panel-divider);
    }

    .dbg-section__content--grid > .dbg-control:first-child {
        border-top: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dbg-panel__reset,
    .dbg-preset,
    .dbg-section__summary,
    .dbg-section__chevron,
    input[type="range"].dbg-control__range::-webkit-slider-thumb,
    input[type="range"].dbg-control__range::-moz-range-thumb,
    input[type="checkbox"].dbg-control__switch,
    input[type="checkbox"].dbg-control__switch::after {
        transition: none;
    }
}
