:root {
    --color-bg: #111;
    --color-fg: #eee;
    --color-muted: #888;
    --color-surface: #222;
    --color-text-dim: #ddd;
    --color-panel-bg: rgba(30, 30, 30, 0.95);

    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.18);

    --radius-sm: 4px;
    --radius-md: 8px;

    --space-xs: 2px;
    --space-sm: 4px;
    --space-md: 8px;
    --space-lg: 10px;
    --space-xl: 14px;

    --font-family:
        "Maple Mono", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
        "Noto Color Emoji", sans-serif;
}

@font-face {
    font-family: "Maple Mono";
    font-style: normal;
    font-display: swap;
    font-weight: 400;
    src:
        url(https://cdn.jsdelivr.net/fontsource/fonts/maple-mono@latest/latin-400-normal.woff2)
            format("woff2"),
        url(https://cdn.jsdelivr.net/fontsource/fonts/maple-mono@latest/latin-400-normal.woff)
            format("woff");
}

body {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    margin: 0;
    padding-top: 2rem;
    background: var(--color-bg);
    color: var(--color-fg);
    font-family: var(--font-family);
}

button,
select {
    font-family: var(--font-family);
}

/* layout */
.main-content {
    position: relative;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
}

/* render overlay */
.render-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    color: var(--color-fg);
    font-size: 4rem;
    z-index: 10;
    user-select: none;
}

#canvas {
    transform: translateZ(0);
    image-rendering: auto;
    will-change: transform;
}

/* menu bar */
.menubar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;

    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);

    height: auto;
    min-height: 2rem;
    padding: var(--space-sm) var(--space-lg);
    box-sizing: border-box;

    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);

    font-size: clamp(1rem, 1.2vw, 1.8rem);
    user-select: none;
}

.menubar button,
.menubar select {
    background: none;
    border: 1px solid transparent;
    color: var(--color-text-dim);
    font-size: 0.82em;
    white-space: nowrap;
    cursor: pointer;
}

.menubar button:hover,
.menubar select:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-medium);
}

.menubar select option {
    background: var(--color-surface);
    color: var(--color-text-dim);
}

/* menu dropdowns */
.menu-group {
    position: relative;
}

.menu-trigger {
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-trigger.open {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-strong);
}

.menu-panel {
    position: absolute;
    top: 100%;
    left: 0;

    display: flex;
    flex-direction: column;
    gap: var(--space-sm);

    min-width: 180px;
    margin-top: var(--space-sm);
    padding: 6px 0;

    background: var(--color-panel-bg);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.menu-panel.hidden {
    display: none;
}

.menu-item {
    display: block;

    width: calc(100% - 16px);
    margin: 0 var(--space-md);
    padding: var(--space-sm) var(--space-md);

    border-radius: 0;

    font-size: 0.82em;
    text-align: left;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.12);
}

.menu-item:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.menu-label {
    margin: 0 var(--space-md);
    padding: 6px var(--space-md) var(--space-xs);

    color: var(--color-muted);
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.menu-panel select {
    width: calc(100% - 16px);
    margin: 0 var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
}

/* import */
.import-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0;
    margin: 0 var(--space-md);
}

.import-row .menu-item {
    margin: 0;
    width: auto;
}

.import-row .menu-item:not(.clear-btn) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.import-row #import {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.clear-btn {
    width: auto !important;
    padding: var(--space-sm) var(--space-md) !important;
    margin-left: -1px !important;
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    font-size: 0.72em !important;
    text-align: center !important;
}

/* visualizer controls */
#vis-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;

    padding: 0 var(--space-lg);
    border-left: 1px solid var(--border-light);
}

#vis-select {
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    line-height: 1;
}

#vis-params {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;

    padding-left: var(--space-xl);
    border-left: 1px solid var(--border-light);
    line-height: 1;
}

#vis-params input[type="range"] {
    width: 80px;
    accent-color: #aaa;
    vertical-align: middle;
}

#vis-params input[type="number"] {
    width: 52px;
    padding: var(--space-xs) var(--space-sm);

    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--color-text-dim);

    font-family: inherit;
    font-size: 0.75em;
    text-align: center;
    vertical-align: middle;
    appearance: textfield;
}

#vis-params input[type="number"]::-webkit-inner-spin-button,
#vis-params input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
}

#vis-params input[type="color"] {
    width: 24px;
    height: 24px;
    padding: 1px;

    background: var(--color-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);

    cursor: pointer;
    vertical-align: middle;
}

#vis-params .menu-label {
    padding: 0;
    line-height: 1;
}

.hamburger {
    display: none;
    background: none;
    border: 1px solid var(--border-light);
    color: var(--color-text-dim);
    font-size: 1.1rem;
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    line-height: 1;
}

.hamburger:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-medium);
}

/* mobile */
@media (max-width: 768px) {
    body {
        padding-top: 3rem;
    }

    /* top bar */
    .hamburger {
        display: block;
        flex-shrink: 0;
        font-size: 1.25rem;
        padding: 6px 12px;
    }

    .menubar {
        flex-wrap: nowrap;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
        min-height: 3rem;
    }

    .menubar > .menu-group:not(#vis-group) {
        display: none;
    }

    #vis-params {
        display: none;
    }

    #vis-group {
        border-left: none;
        padding: 0;
        gap: 0;
        margin-left: auto;
    }

    #vis-select {
        font-size: 1rem;
        padding: 6px 12px;
    }

    .mobile-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 997;
    }

    .mobile-backdrop.hidden {
        display: none;
    }

    .mobile-drawer {
        position: fixed;
        top: 3rem;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 998;

        display: flex;
        flex-direction: column;
        gap: var(--space-md);

        background: var(--color-panel-bg);
        border-top: 1px solid var(--border-medium);
        overflow-y: auto;
        padding: var(--space-lg);
    }

    .mobile-drawer.hidden {
        display: none;
    }

    .drawer-section-label {
        display: block;
        padding: var(--space-sm) 0 var(--space-xs);
        margin-top: var(--space-sm);
        color: var(--color-muted);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        border-bottom: 1px solid var(--border-subtle);
    }

    .drawer-section-label:first-child {
        margin-top: 0;
    }

    .mobile-drawer .menu-group {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .mobile-drawer .menu-trigger {
        width: 100%;
        text-align: left;
        font-size: 0.95rem;
        padding: 12px var(--space-md);
        border: 1px solid var(--border-light);
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.04);
        color: var(--color-text-dim);
    }

    .mobile-drawer .menu-trigger.open {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--border-medium);
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-bottom-color: transparent;
    }

    .mobile-drawer .menu-panel {
        position: static;
        border: 1px solid var(--border-light);
        border-top: none;
        border-radius: 0 0 var(--radius-sm) var(--radius-sm);
        box-shadow: none;
        background: rgba(255, 255, 255, 0.03);
        padding: var(--space-sm) 0;
        margin: 0;
        min-width: unset;
        width: 100%;
    }

    .mobile-drawer .menu-panel.hidden {
        display: none;
    }

    /* panel internals */
    .mobile-drawer .menu-label {
        font-size: 0.7rem;
        margin: 0 var(--space-md);
        padding: 8px var(--space-md) 2px;
    }

    .mobile-drawer .menu-item {
        font-size: 0.95rem;
        padding: 10px var(--space-md);
        width: calc(100% - 16px);
        margin: 0 var(--space-md);
    }

    .mobile-drawer select {
        font-size: 0.95rem;
        padding: 8px var(--space-md);
        width: calc(100% - 16px);
        margin: 0 var(--space-md);
        min-height: 40px;
    }

    .mobile-drawer .import-row {
        margin: 0 var(--space-md);
    }

    .mobile-drawer .clear-btn {
        font-size: 0.9rem !important;
        padding: 10px 14px !important;
    }

    .mobile-drawer #vis-params {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-sm);
        align-items: center;
    }

    .mobile-drawer #vis-params .menu-label {
        font-size: 0.7rem;
        padding: 0;
        margin: 0;
        min-width: 100%;
        margin-top: var(--space-xs);
    }

    .mobile-drawer #vis-params input[type="range"] {
        width: 100px;
        height: 36px;
        accent-color: #aaa;
    }

    .mobile-drawer #vis-params input[type="number"] {
        width: 56px;
        height: 36px;
        font-size: 0.9rem;
        padding: var(--space-xs) var(--space-sm);
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border-light);
        border-radius: var(--radius-sm);
        color: var(--color-text-dim);
        font-family: inherit;
        text-align: center;
        appearance: textfield;
    }

    .mobile-drawer #vis-params input[type="color"] {
        width: 36px;
        height: 36px;
        padding: 2px;
        background: var(--color-surface);
        border: 1px solid var(--border-medium);
        border-radius: var(--radius-sm);
        cursor: pointer;
    }

    .mobile-drawer #vis-params select {
        font-size: 0.9rem;
        padding: 6px 10px;
        min-height: 36px;
        width: auto;
        margin: 0;
    }

    .mobile-drawer #vis-params input[type="text"] {
        font-size: 0.9rem;
        padding: 6px 8px;
        height: 36px;
        width: 52px;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border-light);
        border-radius: var(--radius-sm);
        color: var(--color-text-dim);
        font-family: inherit;
        text-align: center;
    }

    .main-content {
        padding: var(--space-sm);
    }
}
