@font-face {
    font-family: 'Adam';
    src: url('fonts/Adam-Bold.ttf') format('truetype');
    font-weight: bold;
}

body {
    font-family: 'Adam', Arial, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #ebebeb;
}

#canvas {
    display: block;
}

#devtool {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    width: 260px;
    max-height: 90vh;
    overflow-y: auto;
    background: rgba(10,10,10,0.92);
    color: #ccc;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    z-index: 999;
}
#devtool.visible { display: block; }
.dev-title {
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
}
#dev-hint-p {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    color: #555;
    margin-bottom: 10px;
}
#dev-confirm {
    width: 100%;
    margin-top: 10px;
    padding: 6px;
    background: #0af;
    color: #000;
    border: none;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    cursor: pointer;
}
#dev-confirm:hover { background: #3cf; }
#dev-copied {
    font-size: 10px;
    color: #0f8;
    text-align: center;
    margin-top: 5px;
    min-height: 14px;
}
.dev-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0;
    font-size: 10px;
    color: #aaa;
}
.dev-row span:first-child {
    flex: 0 0 82px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dev-row input[type="range"] { flex: 1; min-width: 0; }
.dev-val {
    flex: 0 0 40px;
    text-align: right;
    color: #0f8;
    font-family: monospace;
    font-size: 10px;
}

#canvas {
    cursor: grab;
}

#canvas:active {
    cursor: grabbing;
}

/* ── Snap grid overlay toggle ───────────────────────────────── */
#snap-overlay-toggle {
    display: none;
    position: fixed;
    bottom: 28px;
    left: 28px;
    flex-direction: row;
    align-items: center;
    gap: 7px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.06em;
    color: #bbb;
    cursor: pointer;
    z-index: 100;
    user-select: none;
}
#snap-overlay-toggle input { cursor: pointer; accent-color: #888; }

/* ── Bottom button bar ───────────────────────────────────────── */
#bottom-btns {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 100;
}

#wish-btn {
    display: none;
    background: rgba(255,255,255,0.80);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 20px;
    padding: 9px 22px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.07em;
    color: #555;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0,0,0,0.07);
    transition: background 0.15s, color 0.15s;
}
#wish-btn:hover { background: #fff; color: #222; }

#lang-btn {
    display: none;
    background: rgba(255,255,255,0.80);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 20px;
    padding: 9px 16px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.07em;
    color: #555;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0,0,0,0.07);
    transition: background 0.15s, color 0.15s;
}
#lang-btn:hover { background: #fff; color: #222; }

/* ── Base selector ───────────────────────────────────────────── */
#base-selector {
    position: fixed;
    bottom: 28px;
    right: 28px;
    display: flex;
    gap: 6px;
    z-index: 100;
}
#base-selector.hidden { display: none; }
.base-btn {
    background: rgba(255,255,255,0.75);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 14px;
    padding: 7px 16px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.07em;
    color: #888;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.base-btn:hover  { background: #fff; color: #333; }
.base-btn.active {
    background: rgba(0,0,0,0.07);
    color: #222;
    border-color: rgba(0,0,0,0.18);
}

/* ── Wish overlay ────────────────────────────────────────────── */
#wish-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(245,245,248,0.88);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    z-index: 200;
    opacity: 0;
    transform: scale(0.94);
    transition: opacity 0.28s ease, transform 0.28s ease;
}
#wish-overlay.open {
    opacity: 1;
    transform: scale(1);
}
#wish-cloud {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 48px 32px 32px;
    overflow: hidden;
}
#wish-header {
    display: flex;
    align-items: baseline;
    gap: 28px;
    margin-bottom: 36px;
}
#wish-title {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 14px;
    letter-spacing: 0.10em;
    color: #bbb;
    text-transform: uppercase;
    white-space: nowrap;
}
#wish-search {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 14px;
    border: none;
    border-bottom: 1.5px solid #ccc;
    background: transparent;
    outline: none;
    padding: 3px 6px;
    width: 190px;
    color: #333;
    letter-spacing: 0.05em;
}
#wish-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: 28px 20px;
    overflow-y: auto;
    max-height: calc(100vh - 180px);
    padding: 8px 16px 24px;
    width: 100%;
}
.wish-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    user-select: none;
    will-change: transform;
    transition: filter 0.15s;
}
.wish-card img {
    height: 90px;
    width: auto;
    object-fit: contain;
    display: block;
    pointer-events: none;
}
.wish-card:hover { filter: brightness(0.88); }
.wish-card.highlighted { filter: brightness(0.82); outline: 2px solid rgba(0,0,0,0.12); border-radius: 6px; }
.wish-card.hidden { display: none; }
.wish-card.armed { filter: brightness(0.92) drop-shadow(0 8px 14px rgba(0,0,0,0.35)); }

/* ── Port editor ─────────────────────────────────────────────────────────── */
#port-editor {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    z-index: 400;
    align-items: center;
    justify-content: center;
}
#port-editor.open { display: flex; }
#port-editor-box {
    background: #1a1a1a;
    display: flex;
    flex-direction: row;
    max-height: 92vh;
    overflow: hidden;
    clip-path: polygon(
        0 10px, 10px 0,
        calc(100% - 10px) 0, 100% 10px,
        100% calc(100% - 28px), calc(100% - 28px) 100%,
        10px 100%, 0 calc(100% - 10px)
    );
}
#port-editor-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid #2a2a2a;
    overflow-y: auto;
    overscroll-behavior: contain;
    min-height: 0;
}
#port-editor-sidebar::-webkit-scrollbar { width: 4px; }
#port-editor-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}
#port-editor-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }
#port-editor-sidebar::-webkit-scrollbar-track { background: transparent; }
#port-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
#port-editor-heading {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 20px;
    letter-spacing: 0.12em;
    color: #ccc;
}
.pe-nav-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 6px;
}
.pe-nav-row #port-editor-sel {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}
.pe-nav-row button {
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
    padding: 2px 7px;
}
#port-editor-sel {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 17px;
    background: #2a2a2a;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 6px;
    width: 100%;
    margin-bottom: 6px;
}
.pe-section-label {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 15px;
    letter-spacing: 0.12em;
    color: #555;
    margin-top: 6px;
}
.pe-tool-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
#port-editor-sidebar button {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 15px;
    background: #2a2a2a;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    white-space: nowrap;
}
#port-editor-sidebar button:hover { background: #3a3a3a; color: #fff; border-color: #666; }
#port-editor-count, #port-editor-knob-count {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 15px;
    color: #555;
    flex: 1;
}
#port-editor-sidebar #port-editor-x {
    font-size: 18px;
    background: transparent;
    color: #666;
    border: none;
    padding: 0 2px;
    line-height: 1;
}
#port-editor-sidebar #port-editor-x:hover { background: transparent; color: #fff; border: none; }
#port-editor-detect, #port-editor-copy,
#port-editor-knob-add, #port-editor-knob-clear {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 15px;
    background: #2a2a2a;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    white-space: nowrap;
}
#port-editor-detect:hover    { background: #fa0; color: #000; border-color: #fa0; }
#port-editor-copy-all:hover  { background: #0af; color: #000; border-color: #0af; }
#port-editor-knob-add:hover    { background: #a0f; color: #fff; border-color: #a0f; }
#port-editor-knob-clear:hover  { background: #a00; color: #fff; border-color: #a00; }
.pe-hint {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    color: #444;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}
#port-editor-desc {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.02em;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #ccc;
    padding: 7px 9px;
    outline: none;
    resize: none;
    min-height: 64px;
    width: 100%;
    box-sizing: border-box;
    margin-top: 4px;
    margin-bottom: 4px;
}
#port-editor-desc:focus { border-color: #666; }
#port-editor-copy-all {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 15px;
    background: #2a2a2a;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 8px 10px;
    cursor: pointer;
    width: 100%;
    margin-top: 8px;
}
.pe-tool-btn {
    width: 36px;
    height: 36px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
}
.pe-tool-btn img {
    width: 24px;
    height: 24px;
    display: block;
    image-rendering: pixelated;
    pointer-events: none;
}
.pe-port-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255,220,60,0.9);
    border: 2px solid #000;
    box-shadow: 0 0 4px rgba(255,200,0,0.7);
    display: block;
    flex-shrink: 0;
}
.pe-zone-icon {
    width: 20px;
    height: 13px;
    border-radius: 50%;
    background: rgba(255,160,0,0.12);
    border: 1px dashed rgba(255,160,0,0.9);
    display: block;
    flex-shrink: 0;
}
.pe-tool-btn.active {
    background: #444 !important;
    border-color: #aaa !important;
    box-shadow: 0 0 6px rgba(255,255,255,0.15);
}
.pe-tool-btn:hover { background: #383838; border-color: #888; }

#port-editor-link-toggle.active {
    background: #443a2a !important;
    border-color: rgba(255,232,196,0.8) !important;
    color: #ffe8c4;
    box-shadow: 0 0 6px rgba(255,232,196,0.3);
}
.pe-placement-row button:disabled,
.pe-placement-row .pe-tool-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#port-editor-wrap {
    position: relative;
    display: inline-block;
    align-self: center;
    cursor: crosshair;
    margin: 16px;
}
#port-editor-wrap.tool-active { cursor: cell; }
#port-editor-wrap.link-mode-active { cursor: default; }
#port-editor-link-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: none;
}
#port-editor-wrap.link-mode-active #port-editor-link-svg { display: block; }
#port-editor-img {
    display: block;
    max-height: 88vh;
    max-width: 75vw;
    width: auto;
    pointer-events: none;
    user-select: none;
}
.port-marker {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255,220,60,0.85);
    border: 2px solid #000;
    box-shadow: 0 0 6px rgba(255,200,0,0.7);
    transform: translate(-50%, -50%);
    cursor: move;
    box-sizing: border-box;
}
.port-marker:hover { background: #fff; }
.port-marker.preview { background: rgba(255,220,60,0.35); box-shadow: none; border-color: rgba(255,220,60,0.6); cursor: default; pointer-events: none; }
.knob-marker {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,0,255,0.18);
    border: 2px solid rgba(255,0,255,0.9);
    box-shadow: 0 0 8px rgba(255,0,255,0.5);
    transform: translate(-50%, -50%);
    cursor: move;
    box-sizing: border-box;
}
.knob-marker::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255,0,255,0.9);
}
.knob-marker:hover { background: rgba(255,0,255,0.35); border-color: #fff; }
.microknob-marker {
    position: absolute;
    border-radius: 50%;
    background: rgba(0,220,255,0.15);
    border: 2px solid rgba(0,220,255,0.85);
    box-shadow: 0 0 7px rgba(0,220,255,0.45);
    transform: translate(-50%, -50%);
    cursor: move;
    box-sizing: border-box;
}
.microknob-marker:hover { background: rgba(0,220,255,0.3); border-color: #fff; }
.hint-section {
    color: #666;
    letter-spacing: 0.06em;
}

/* ── Bottom bar buttons ──────────────────────────────────────────── */
#place-all-btn {
    display: none;
    position: fixed;
    bottom: 28px;
    left: 28px;
    background: rgba(255,255,255,0.65);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 20px;
    padding: 7px 18px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.07em;
    color: #888;
    cursor: pointer;
    box-shadow: 0 1px 8px rgba(0,0,0,0.05);
    z-index: 100;
    transition: background 0.15s, color 0.15s, opacity 0.4s;
}
#place-all-btn:hover { background: rgba(255,255,255,0.9); color: #333; }
#place-all-btn.hidden { display: none !important; }
#place-all-btn.overlay-open { display: none !important; }

#kit-btn {
    display: none;
    background: rgba(255,255,255,0.80);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 20px;
    padding: 9px 22px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.07em;
    color: #555;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0,0,0,0.07);
    transition: background 0.15s, color 0.15s;
}
#kit-btn:hover { background: #fff; color: #222; }

#export-btn {
    display: none;
    background: rgba(255,255,255,0.80);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 20px;
    padding: 9px 22px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.07em;
    color: #555;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0,0,0,0.07);
    transition: background 0.15s, color 0.15s;
}
#export-btn:hover { background: #fff; color: #222; }

/* ── Export overlay ──────────────────────────────────────────────── */
#export-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(8,8,8,0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 350;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
}
#export-overlay.open { display: flex; opacity: 1; }

#export-box {
    display: flex;
    gap: 32px;
    align-items: flex-start;
    padding: 32px;
    max-width: 94vw;
}

/* Holder for the canvas that patch-preview.js draws — sized by its contents, not
   by a stored image. */
#export-preview {
    display: block;
    flex-shrink: 0;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0,0,0,0.7);
}
#export-preview canvas { display: block; }

#export-sidebar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 210px;
    flex-shrink: 0;
    padding-top: 4px;
}

.ex-label {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    letter-spacing: 0.10em;
    color: #555;
    text-transform: uppercase;
    margin-top: 6px;
}

#ex-title, #ex-author {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.06em;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 4px;
    color: #ddd;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
    box-sizing: border-box;
}
#ex-title { font-size: 15px; letter-spacing: 0.10em; text-transform: uppercase; }
#ex-title:focus, #ex-author:focus, #ex-desc:focus { border-color: rgba(255,255,255,0.32); }

#ex-desc {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.04em;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 4px;
    color: #ccc;
    padding: 7px 10px;
    outline: none;
    resize: none;
    min-height: 72px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

#ex-copy {
    width: 100%;
    padding: 11px;
    background: #0af;
    color: #000;
    border: none;
    border-radius: 5px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.08em;
    cursor: pointer;
    margin-top: 8px;
}
#ex-copy:hover { background: #3cf; }

#ex-status {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    color: #666;
    min-height: 14px;
    text-align: center;
}

#ex-hint {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    letter-spacing: 0.05em;
    line-height: 1.6;
    color: #4a4a4a;
    text-align: center;
}

#ex-close {
    width: 100%;
    padding: 8px;
    background: none;
    color: #444;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 5px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: color 0.15s;
}
#ex-close:hover { color: #aaa; }

/* ── Kit overlay ─────────────────────────────────────────────────────────── */
#kit-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(8,8,8,0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 350;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
}
#kit-overlay.open { display: flex; opacity: 1; }

#kit-box {
    padding: 32px;
}

#kit-sidebar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 280px;
}

.kx-label {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    letter-spacing: 0.10em;
    color: #555;
    text-transform: uppercase;
    margin-top: 6px;
}

#kx-name, #kx-author {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.06em;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 4px;
    color: #ddd;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
    box-sizing: border-box;
}
#kx-name { font-size: 15px; letter-spacing: 0.10em; text-transform: uppercase; }
#kx-name:focus, #kx-author:focus, #kx-comment:focus { border-color: rgba(255,255,255,0.32); }

#kx-comment {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.04em;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 4px;
    color: #ccc;
    padding: 7px 10px;
    outline: none;
    resize: none;
    min-height: 52px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

#kx-modules {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: #555;
    line-height: 1.8;
    word-break: break-word;
    min-height: 18px;
}

#kx-copy {
    width: 100%;
    padding: 11px;
    background: #0af;
    color: #000;
    border: none;
    border-radius: 5px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.08em;
    cursor: pointer;
    margin-top: 8px;
}
#kx-copy:hover { background: #3cf; }

#kx-status {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    color: #666;
    min-height: 14px;
    text-align: center;
}

#kx-close {
    width: 100%;
    padding: 8px;
    background: none;
    color: #444;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 5px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: color 0.15s;
}
#kx-close:hover { color: #aaa; }

/* ── Kit library strip ───────────────────────────────────────────────────── */
#kit-library {
    display: none;
    flex-direction: row;
    gap: 14px;
    overflow-x: auto;
    padding: 18px 32px 24px;
    align-items: flex-start;
    max-width: 94vw;
}
#kit-library::-webkit-scrollbar { height: 4px; }
#kit-library::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.kx-card {
    position: relative;
    flex-shrink: 0;
    width: 200px;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    padding: 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.kx-card:hover { background: rgba(255,255,255,0.10); }
.kx-card-builtin { border: 1px solid rgba(255,255,255,0.08); }

.kx-card-name {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.10em;
    color: #ccc;
    margin-bottom: 8px;
}

.kx-card-modules {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    letter-spacing: 0.04em;
    color: #555;
    line-height: 1.7;
    word-break: break-word;
}

.kx-card-meta {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    letter-spacing: 0.04em;
    color: #3a3a3a;
    margin-top: 8px;
}

.kx-card-del {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    background: rgba(0,0,0,0.55);
    color: #888;
    border: none;
    border-radius: 50%;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}
.kx-card:hover .kx-card-del { opacity: 1; }
.kx-card-del:hover { color: #fff; }

/* ── module importer ─────────────────────────────────────────────────────── */
#importer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    z-index: 500;
    align-items: center;
    justify-content: center;
}
#importer-overlay.open { display: flex; }

#importer-box {
    display: flex;
    background: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
    max-width: 95vw;
    max-height: 92vh;
    padding: 12px;
    gap: 12px;
}

#importer-drop-zone {
    width: 480px;
    min-height: 340px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #444;
    border-radius: 6px;
    margin: 18px;
    cursor: default;
}

#importer-instructions {
    color: #888;
    font-size: 11px;
    line-height: 1.9;
    text-align: left;
    padding: 24px;
}
#importer-instructions .imp-step-title {
    color: #bbb;
    font-size: 12px;
    margin-bottom: 6px;
    letter-spacing: 0.06em;
}
#importer-instructions ol {
    margin: 0 0 16px 18px;
    padding: 0;
}
#imp-read-clipboard {
    margin-top: 8px;
    padding: 7px 22px;
    background: #333;
    color: #eee;
    border: none;
    border-radius: 4px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 11px;
    cursor: pointer;
    letter-spacing: 0.08em;
}
#imp-read-clipboard:hover { background: #444; }
#imp-clip-hint {
    margin-top: 8px;
    color: #555;
    font-size: 10px;
}

#importer-canvas {
    display: none;
    max-width: 65vw;
    max-height: 88vh;
    object-fit: contain;
    image-rendering: pixelated;
}

#importer-sidebar {
    width: 220px;
    min-width: 220px;
    background: #111;
    padding: 12px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 10px;
    color: #ccc;
}

.imp-label {
    font-size: 9px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: #666;
    margin-top: 6px;
}
.imp-section {
    font-size: 8px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: #ff9900;
    margin: 8px 0 2px;
    border-top: 1px solid #333;
    padding-top: 6px;
}
.imp-slider-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
}
.imp-slider-row label { flex: 1; color: #999; }
.imp-slider-row input[type=range] { width: 80px; }
.imp-slider-row span { width: 28px; text-align: right; color: #ccc; }

#imp-module-display {
    font-size: 13px;
    letter-spacing: 0.12em;
    color: #eee;
    min-height: 18px;
    margin-bottom: 4px;
}
#imp-instructions {
    font-size: 11px;
    line-height: 1.7;
    color: #888;
    margin-bottom: 6px;
}
.imp-inst-head {
    color: #bbb;
}

/* name modal */
#imp-name-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 600;
    align-items: center;
    justify-content: center;
}
#imp-name-modal.open { display: flex; }
#imp-name-modal-box {
    background: #1e1e1e;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 240px;
}
#imp-name-input {
    background: #111;
    border: 1px solid #444;
    border-radius: 3px;
    color: #eee;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    padding: 6px 8px;
    letter-spacing: 0.08em;
    width: 100%;
    box-sizing: border-box;
    text-transform: uppercase;
}
#imp-name-modal-btns {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
#imp-name-cancel, #imp-name-confirm {
    padding: 5px 14px;
    border-radius: 3px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    letter-spacing: 0.06em;
    cursor: pointer;
    border: 1px solid #444;
}
#imp-name-cancel  { background: #222; color: #888; }
#imp-name-confirm { background: #1a3a1a; color: #88ee88; border-color: #2a6a2a; }
#imp-name-cancel:hover  { color: #ccc; }
#imp-name-confirm:hover { background: #224422; }

/* LED marker in port editor */
.led-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid rgba(0,200,255,0.7);
    background-size: 100% 100%;
    background-position: center;
    cursor: move;
    box-sizing: border-box;
    pointer-events: all;
    overflow: hidden;
}
.led-marker:hover { border-color: #fff; }

/* Switch marker in port editor */
.switch-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    background: #000 url('images/stamps/toggle.png') center / 100% 100% no-repeat;
    border: 2px solid rgba(0,255,160,0.8);
    box-shadow: 0 0 6px rgba(0,255,160,0.4);
    cursor: move;
    box-sizing: border-box;
}
.switch-marker:hover { border-color: #fff; }

/* Zone-of-interest marker in port editor — ellipse, independent width/height,
   own amber color so it reads as a distinct kind from the circular markers */
.zone-marker {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,160,0,0.12);
    border: 2px dashed rgba(255,160,0,0.85);
    cursor: move;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
}
.zone-marker:hover { background: rgba(255,160,0,0.25); border-color: #fff; }

/* LED colour swatch buttons — reused inside #port-props-popup's COLOR row */
.pe-led-pick-btn {
    padding: 4px;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pe-led-pick-btn:hover  { border-color: #fff; }
.pe-led-pick-btn.active { border-color: #00ccff; box-shadow: 0 0 6px #00ccff; }

/* Unified element/port properties popup (port editor, right-click any marker) */
#port-props-popup {
    display: none;
    position: fixed;
    z-index: 700;
    width: 230px;
    background: #1e1e1e;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 10px;
    font-family: 'Adam', Arial, sans-serif;
    color: #ccc;
}
#port-props-popup .pp-label {
    font-size: 10px;
    letter-spacing: 0.08em;
    color: #777;
    margin: 6px 0 3px;
}
#port-props-popup .pp-label:first-child { margin-top: 0; }
#port-props-popup input[type="text"] {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #ccc;
    padding: 5px 7px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}
#port-props-popup input[type="text"]:focus { border-color: #666; }
#port-props-popup textarea {
    font-family: 'Adam', Arial, sans-serif;
    font-size: 13px;
    letter-spacing: 0.02em;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #ccc;
    padding: 7px 9px;
    outline: none;
    resize: none;
    min-height: 56px;
    width: 100%;
    box-sizing: border-box;
}
#port-props-popup textarea:focus { border-color: #666; }
.pp-row { display: flex; gap: 4px; }
.pp-type-btn, .pp-dir-btn {
    flex: 1;
    padding: 5px;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pp-type-btn img { width: 16px; height: 16px; display: block; pointer-events: none; }
.pp-type-btn:hover, .pp-dir-btn:hover { border-color: #888; }
.pp-type-btn.active, .pp-dir-btn.active { border-color: #0af; box-shadow: 0 0 6px rgba(0,170,255,0.5); }
.pp-warn {
    font-size: 10px;
    color: #f84;
    margin-top: 3px;
    min-height: 12px;
}
.pp-slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: #777;
    margin-top: 4px;
}
.pp-slider-row input[type="range"] { flex: 1; }
.pp-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 10px;
}
.pp-actions button {
    flex: 1;
    font-size: 11px;
    padding: 6px 4px;
}
#pp-delete:hover { background: #a00; color: #fff; border-color: #a00; }
.pp-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 5px 0;
    border-top: 1px solid #333;
    font-size: 11px;
    color: #ccc;
}
.pp-link-row:first-of-type { border-top: none; }
.pp-link-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pp-link-row button {
    font-size: 10px;
    padding: 4px 8px;
    flex-shrink: 0;
}
.pp-link-del:hover { background: #a00; color: #fff; border-color: #a00; }
.pp-link-add:hover { background: #0af; color: #000; border-color: #0af; }
.pp-link-empty { font-size: 11px; color: #666; padding: 4px 0; }

#imp-stats {
    color: #00ccff;
    font-size: 10px;
    margin: 4px 0;
    letter-spacing: 0.06em;
}


#imp-brush-toggle {
    padding: 5px 10px;
    background: #222;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 3px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 9px;
    cursor: pointer;
    letter-spacing: 0.06em;
    width: 100%;
}
#imp-brush-toggle.active { background: #003344; color: #00ccff; border-color: #00ccff; }

#imp-save {
    margin-top: 10px;
    padding: 8px;
    background: #1a3a1a;
    color: #88ee88;
    border: 1px solid #2a6a2a;
    border-radius: 4px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    cursor: pointer;
    letter-spacing: 0.08em;
    width: 100%;
}
#imp-save:hover { background: #224422; }

#imp-save-status { color: #88ee88; font-size: 9px; text-align: center; }

#imp-close {
    margin-top: 4px;
    padding: 6px;
    background: none;
    color: #555;
    border: 1px solid #333;
    border-radius: 4px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 10px;
    cursor: pointer;
    width: 100%;
}

/* ── Gallery button ─────────────────────────────────────────── */
#gallery-btn {
    display: none;
    background: rgba(255,255,255,0.80);
    border: 1.5px solid rgba(0,0,0,0.10);
    border-radius: 20px;
    padding: 9px 22px;
    font-family: 'Adam', Arial, sans-serif;
    font-size: 12px;
    letter-spacing: 0.07em;
    color: #555;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0,0,0,0.07);
    transition: background 0.15s, color 0.15s;
}
#gallery-btn:hover { background: #fff; color: #222; }

/* ── Gallery overlay ───────────────────────────────────────── */
#gallery-overlay {
    display: none; opacity: 0;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.88);
    justify-content: center; align-items: flex-start;
    overflow-y: auto;
    z-index: 300;
    transition: opacity 0.22s ease;
}
#gallery-overlay.open { opacity: 1; }

#gallery-box { width: min(860px, 94vw); margin: 48px auto 64px; }

#gallery-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
#gallery-title { font-family: 'Adam', Arial, sans-serif; font-size: 13px; letter-spacing: 0.12em; color: #888; }
#gallery-close { background: none; border: none; color: #555; font-size: 22px; cursor: pointer; padding: 0; }
#gallery-close:hover { color: #ccc; }

/* One wide card per patch: the preview is the content of the gallery, not a
   thumbnail beside it. At ~400px a base slot lands around 40px, which is where the
   stylised panels stay legible. */
#gallery-list { display: flex; flex-direction: column; gap: 26px; }

.gallery-import-card {
    display: block; width: 100%;
    padding: 18px; background: none;
    border: 1px dashed rgba(255,255,255,0.16); border-radius: 6px;
    font-family: 'Adam', Arial, sans-serif; font-size: 11px; letter-spacing: 0.10em;
    color: #666; cursor: pointer; text-align: center;
    transition: border-color 0.15s, color 0.15s;
}
.gallery-import-card:hover { border-color: rgba(255,255,255,0.4); color: #ddd; }

.gallery-card {
    border: 1px solid rgba(255,255,255,0.07); border-radius: 6px;
    padding: 18px; background: rgba(255,255,255,0.015);
}
.gallery-card-head { margin-bottom: 14px; }

.gallery-name {
    font-family: 'Adam', Arial, sans-serif; font-size: 13px;
    letter-spacing: 0.10em; color: #ddd; margin-bottom: 5px;
}
.gallery-author { font-family: 'Adam', Arial, sans-serif; font-size: 10px; letter-spacing: 0.07em; color: #555; margin-bottom: 6px; }
.gallery-desc {
    font-family: 'Adam', Arial, sans-serif; font-size: 10px; letter-spacing: 0.06em;
    color: #4a4a4a; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}

.gallery-preview {
    display: block; width: 100%; border-radius: 4px; overflow: hidden;
    cursor: zoom-in; transition: filter 0.15s;
}
.gallery-preview:hover { filter: brightness(1.12); }
.gallery-preview canvas { display: block; width: 100%; }

.gallery-load {
    margin-top: 14px; width: 100%; padding: 9px;
    background: none; border: 1px solid rgba(255,255,255,0.14); border-radius: 4px;
    font-family: 'Adam', Arial, sans-serif; font-size: 11px; letter-spacing: 0.10em;
    color: #888; cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.gallery-load:hover { border-color: #fff; color: #fff; }

.gallery-empty {
    font-family: 'Adam', Arial, sans-serif; font-size: 11px;
    color: #444; letter-spacing: 0.08em; padding: 40px 0; text-align: center;
}

#gallery-lightbox {
    display: none; opacity: 0;
    position: fixed; inset: 0; background: rgba(0,0,0,0.94);
    justify-content: center; align-items: center;
    z-index: 400; transition: opacity 0.22s ease; cursor: zoom-out;
}
#gallery-lightbox.open { opacity: 1; }
#gallery-lightbox-inner {
    position: absolute; inset: 14px; cursor: default;
}
#gallery-lightbox-preview {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
}
#gallery-lightbox-preview canvas { display: block; max-width: 100%; max-height: 100%; }
#gallery-lightbox-load {
    position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
    font-family: 'Adam', Arial, sans-serif; font-size: 11px; letter-spacing: 0.12em;
    background: rgba(0,0,0,0.55); border: 1px solid rgba(255,255,255,0.18); color: #aaa;
    padding: 7px 22px; border-radius: 3px; cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
#gallery-lightbox-load:hover { border-color: #fff; color: #fff; }

/* ── Import overlay ─────────────────────────────────────────────────────────── */
/* Three ways in — paste into the box, ask for the clipboard, or pick a file. The
   textarea is first because it is the only one that works in every browser without
   a permission prompt. */
#import-overlay {
    display: none; opacity: 0;
    position: fixed; inset: 0;
    background: rgba(8,8,8,0.94);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    justify-content: center; align-items: center;
    z-index: 420; transition: opacity 0.22s ease;
}
#import-overlay.open { opacity: 1; }

#import-box {
    width: min(560px, 92vw);
    display: flex; flex-direction: column; gap: 10px;
    padding: 28px;
}

.imp-patch-title {
    font-family: 'Adam', Arial, sans-serif; font-size: 13px;
    letter-spacing: 0.12em; color: #ccc; text-transform: uppercase;
}
.imp-patch-sub {
    font-family: 'Adam', Arial, sans-serif; font-size: 10px;
    letter-spacing: 0.06em; color: #555; margin-bottom: 4px;
}

#imp-patch-text {
    font-family: 'Courier New', monospace; font-size: 11px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.13); border-radius: 4px;
    color: #bbb; padding: 10px; outline: none; resize: none;
    min-height: 130px; width: 100%; box-sizing: border-box;
    word-break: break-all;
}
#imp-patch-text:focus { border-color: rgba(255,255,255,0.32); }

#imp-patch-status {
    font-family: 'Adam', Arial, sans-serif; font-size: 10px;
    color: #666; min-height: 14px;
}

#imp-patch-row { display: flex; gap: 8px; }
#imp-patch-row > * { flex: 1; }

#imp-patch-go, #imp-patch-clip, #imp-patch-file-lbl {
    padding: 9px; border-radius: 4px; box-sizing: border-box;
    font-family: 'Adam', Arial, sans-serif; font-size: 11px; letter-spacing: 0.07em;
    cursor: pointer; text-align: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#imp-patch-go { background: #0af; color: #000; border: none; }
#imp-patch-go:hover { background: #3cf; }

#imp-patch-clip, #imp-patch-file-lbl {
    background: none; color: #777;
    border: 1px solid rgba(255,255,255,0.13);
}
#imp-patch-clip:hover, #imp-patch-file-lbl:hover { border-color: rgba(255,255,255,0.35); color: #ccc; }
#imp-patch-file { display: none; }

#imp-patch-close {
    width: 100%; padding: 8px; margin-top: 4px;
    background: none; color: #444;
    border: 1px solid rgba(255,255,255,0.07); border-radius: 5px;
    font-family: 'Adam', Arial, sans-serif; font-size: 11px; letter-spacing: 0.06em;
    cursor: pointer; transition: color 0.15s;
}
#imp-patch-close:hover { color: #aaa; }
#imp-close:hover { color: #aaa; }