/* Visual refresh, on top of style.css (same palette). Experimental: open
   diii with ?classic to compare with the current look. */

:root {
    --ui-font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    /* Consolas on Windows (as before), SF Mono / Menlo on macOS */
    --mono-font: 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', monospace;
    --hover: #2a2d2e;
    --pressed: #37373d;
    --radius: 6px;
    --header-h: 44px;

    /* icons (stroke icons, drawn with currentColor through a mask) */
    --icon-plug: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22v-5M9 8V2M15 8V2M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8z'/%3E%3C/svg%3E");
    --icon-chip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='5' width='14' height='14' rx='2'/%3E%3Crect x='9' y='9' width='6' height='6'/%3E%3Cpath d='M9 2v3M15 2v3M9 19v3M15 19v3M2 9h3M2 15h3M19 9h3M19 15h3'/%3E%3C/svg%3E");
    --icon-upload: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3M7 8l5-5 5 5M4 15v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4'/%3E%3C/svg%3E");
    --icon-help: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3M12 17h.01'/%3E%3C/svg%3E");
    --icon-branch: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='6' cy='5' r='2.5'/%3E%3Ccircle cx='6' cy='19' r='2.5'/%3E%3Ccircle cx='18' cy='7' r='2.5'/%3E%3Cpath d='M6 7.5v9M18 9.5c0 4-6 3.5-11 7.5'/%3E%3C/svg%3E");
    --icon-nodes: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='3' width='7' height='6' rx='1.5'/%3E%3Crect x='15' y='15' width='7' height='6' rx='1.5'/%3E%3Cpath d='M9 6c6 0 0 12 6 12'/%3E%3C/svg%3E");
    --icon-book: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4h6a4 4 0 0 1 4 4v13a3 3 0 0 0-3-3H2zM22 4h-6a4 4 0 0 0-4 4v13a3 3 0 0 1 3-3h7z'/%3E%3C/svg%3E");
}

body {
    font-family: var(--ui-font);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

/* code and device output stay monospaced */
.repl-output,
.repl-input,
.repl-input-prompt,
.midi-list,
.file-label,
.editor-title,
.title-pill h1,
.api-sig,
.reference-entry code,
.reference-search,
.editor-host > .prism-code-editor {
    font-family: var(--mono-font);
}

button,
input,
select,
.repl-action-btn,
.repl-connection-btn,
.file-menu-item,
.modal-btn {
    font-family: var(--ui-font);
}

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

/* text fields show their own focus (the editor its cursor, inputs a border) */
.prism-code-editor textarea:focus-visible,
.repl-input:focus-visible,
.reference-search:focus-visible {
    outline: none;
}

/* --- header: a real bar --------------------------------------------------- */

.app-header {
    height: var(--header-h);
    border-top: 2px solid var(--accent-hover);
    border-bottom: 1px solid var(--neutral-trim);
    background-color: var(--bg-surface);
    padding: 0 10px;
    position: relative;
    z-index: 40;
}

.header-left,
.header-right {
    position: static;
    gap: 4px;
}

.workspace {
    padding-top: 0;
}

.title-pill {
    background: transparent;
    padding: 0 10px 0 4px;
    border-radius: 0;
}

.title-pill h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--interactive-selected);
    letter-spacing: 0.02em;
}

.repl-status-pill {
    background: transparent;
    border: 1px solid var(--neutral-trim);
    padding: 4px 10px;
    margin-right: 4px;
    font-size: 12px;
}

.repl-status-text {
    font-size: 12px;
}

.header-left .repl-connection-btn,
.header-right .repl-connection-btn,
.editor-header .repl-action-btn,
.output-cleanup-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    background-color: transparent;
    color: var(--neutral-heavy);
    font-size: 13px;
    padding: 5px 9px;
    border-radius: var(--radius);
    transition:
        background-color 120ms ease,
        color 120ms ease;
}

.header-left .repl-connection-btn:hover,
.header-right .repl-connection-btn:hover,
.editor-header .repl-action-btn:hover,
.output-cleanup-btn:hover {
    background-color: var(--hover);
    border-color: transparent;
    color: var(--interactive-selected);
}

/* not connected yet: connect is the thing to do */
.header-left:has(.repl-status-indicator:not(.connected)) #replConnectionBtn {
    background-color: var(--accent);
    color: #fff;
}

.header-left:has(.repl-status-indicator:not(.connected)) #replConnectionBtn:hover {
    background-color: var(--accent-hover);
}

#replConnectionBtn::before,
#deviceMenuBtn::before,
#uploadBtn::before,
#patchOpenBtn::before,
#helpBtn::before,
#repoLink::before,
#scriptReferenceBtn::before {
    content: '';
    width: 15px;
    height: 15px;
    flex: none;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

#replConnectionBtn {
    --icon: var(--icon-plug);
}

#deviceMenuBtn {
    --icon: var(--icon-chip);
}

#uploadBtn {
    --icon: var(--icon-upload);
}

#patchOpenBtn {
    --icon: var(--icon-nodes);
}

#helpBtn {
    --icon: var(--icon-help);
}

#scriptReferenceBtn {
    --icon: var(--icon-book);
}

#repoLink {
    --icon: var(--icon-branch);
}

/* --- menus and dialogs ------------------------------------------------------ */

.file-menu {
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 8px 24px #0009;
}

.device-menu {
    top: 38px;
    min-width: 170px;
}

.file-menu-item {
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 4px;
}

.file-menu-item:hover {
    background-color: var(--hover);
}

.modal {
    background: #0008;
    backdrop-filter: blur(2px);
}

.modal-content {
    border-radius: 10px;
    box-shadow: 0 20px 60px #000a;
}

/* --- file explorer -------------------------------------------------------- */

.file-explorer-header {
    padding: 6px 8px;
    min-height: 40px;
}

.file-explorer-toggle {
    min-width: 0;
    gap: 6px;
}

/* a "files" label next to the folder icon */
.file-explorer-pane:not(.collapsed) .file-explorer-toggle::after {
    content: 'files';
    font-family: var(--ui-font);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--neutral-medium);
}

.file-explorer-chevron {
    font-size: 1.2rem;
}

.file-explorer-refresh {
    border-radius: var(--radius);
}

.file-explorer-refresh:hover {
    background-color: var(--hover);
}

.file-list {
    padding: 4px 6px;
}

.file-row {
    padding: 3px 6px;
    border-radius: var(--radius);
    min-height: 30px;
}

.file-row:hover {
    background-color: var(--hover);
}

.file-label {
    font-size: 12.5px;
}

.file-play-btn {
    border: 0;
    width: 20px;
    height: 20px;
    color: var(--neutral-medium);
    font-size: 0.65rem;
}

.file-play-btn:hover {
    color: var(--accent-hover);
    background-color: var(--pressed);
}

/* the ⋯ menu appears on hover (and stays while its menu is open) */
.file-menu-btn {
    border: 0;
    background: transparent;
    opacity: 0;
    transition: opacity 120ms ease;
}

.file-row:hover .file-menu-btn,
.file-row:focus-within .file-menu-btn,
.file-menu-btn:focus-visible {
    opacity: 1;
}

.file-menu-btn:hover {
    background-color: var(--pressed);
}

.file-first-pill {
    background-color: #0a84ff26;
    color: var(--accent-hover);
    font-family: var(--ui-font);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 3px 6px;
}

/* a script made in the patch editor */
.file-patch-pill {
    background-color: #c48bff26;
    color: #d7a6ff;
}

.file-space-footer {
    font-size: 11px;
    line-height: 1.5;
}

/* --- console --------------------------------------------------------------- */

/* the console keeps its lighter gray: device output vs. code at a glance */
.repl-pane,
.repl-output,
.repl-input-container {
    background-color: var(--bg-subdued);
}

.repl-input {
    background-color: var(--bg-default);
}

.repl-output {
    font-size: 12.5px;
    line-height: 1.55;
    padding: 12px 14px;
}

.output-cleanup-btn {
    font-size: 12px;
    padding: 3px 8px;
    color: var(--neutral-medium);
}

.repl-input-container {
    border-top: 1px solid var(--neutral-trim);
    padding: 8px 10px 10px;
}

.repl-input {
    min-height: 40px;
    border-radius: 8px;
    font-size: 12.5px;
    padding: 10px 10px 10px 34px;
}

.repl-input-prompt {
    top: 11px;
    font-size: 12.5px;
    color: var(--accent-hover);
}

/* --- drawers (grid, midi) -------------------------------------------------- */

.midi-drawer-bar {
    min-height: 30px;
    padding: 2px 12px;
    background-color: var(--bg-surface);
}

.midi-toggle {
    font-family: var(--ui-font);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--neutral-heavy);
}

.midi-status {
    font-size: 11px;
}

.midi-controls {
    font-size: 12px;
}

.midi-controls .repl-action-btn {
    border-color: transparent;
    background: transparent;
    color: var(--neutral-heavy);
}

.midi-controls .repl-action-btn:hover {
    background-color: var(--hover);
}

.midi-list {
    font-size: 12px;
}

.midi-row:nth-child(even) {
    background-color: #ffffff05;
}

.grid-cells {
    gap: clamp(2px, 1.6cqh, 5px);
}

.grid-cell {
    border: 0;
    border-radius: 4px;
    background-color: #2b2b2e;
    transition: box-shadow 80ms ease;
}

/* lit keys (diii sets their color inline) glow a little */
.grid-cell[style*='background'] {
    box-shadow: 0 0 6px #ffbe6438;
}

/* a press shows as a lighter key, no outline */
.grid-cell.pressed {
    border-color: transparent;
    filter: brightness(1.6);
}

/* --- editor panel ---------------------------------------------------------- */

.editor-header {
    min-height: 40px;
    padding: 4px 8px 4px 12px;
    background-color: var(--bg-surface);
}

.editor-title {
    font-size: 12.5px;
}

.editor-close-btn {
    border-radius: var(--radius);
}

.editor-close-btn:hover {
    background-color: var(--hover);
}

.editor-pane.collapsed .editor-expand {
    font-family: var(--mono-font);
    font-size: 12px;
}

/* --- dividers and scrollbars ------------------------------------------------ */

.explorer-resizer {
    width: 5px;
    flex-basis: 5px;
    background-color: transparent;
}

.explorer-resizer:hover,
.explorer-resizer.dragging {
    background-color: #0a84ff66;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #45454a transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background-color: #3a3a3e;
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #4a4a50;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* --- narrow windows: header buttons become icons ---------------------------- */

@media (max-width: 900px) {
    .header-left .repl-connection-btn,
    .header-right .repl-connection-btn {
        font-size: 0;
        gap: 0;
        padding: 6px 7px;
    }

    .header-left .repl-connection-btn::before,
    .header-right .repl-connection-btn::before {
        width: 16px;
        height: 16px;
    }

    #deviceMenuBtn.has-update::after {
        font-size: 13px;
    }
}
