@font-face {
    font-family: "Instrument Sans";
    src: url("/styles/fonts/instrument-sans.woff2") format("woff2");
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
}

:root {
    color-scheme: dark;
    --page: #121212;
    --surface: #1e1e1e;
    --surface-up: #282828;
    --ink: #f3f3f3;
    --ink-dim: #b8b8b8;
    --border: #3a3a3a;
    --border-hover: #828282;
    --signal: #e0e0e0;
    --signal-bg: #343434;
    --accent: #f1f1f1;
    --focus: #efefef;
    --primary-ink: #171717;
    --primary-bg: #dedede;
    --primary-hover: #f4f4f4;
    --alert: #ffc0b4;
    --alert-bg: #482b2b;
    --success: #e7e7e7;
    --success-bg: #323232;
    --brand-bg: #2a2a2a;
    --selection-ink: #171717;
    --selection-bg: #e0e0e0;
    --shadow: #0005;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='m3 5 4 4 4-4' fill='none' stroke='%23b8b8b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    --radius: 10px;
    --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
    --max-width: 1180px;
    --gutter: clamp(18px, 4vw, 48px);
    --bar-height: 64px;
    --ease-out: cubic-bezier(.19, 1, .22, 1);
}

:root[data-theme="light"] {
    color-scheme: light;
    --page: #f4f4f2;
    --surface: #ffffff;
    --surface-up: #ebebe8;
    --ink: #1b1b1b;
    --ink-dim: #5d5d5a;
    --border: #dadad6;
    --border-hover: #8b8b87;
    --signal: #262626;
    --signal-bg: #e0e0dc;
    --accent: #f4f4f2;
    --focus: #262626;
    --primary-ink: #f7f7f5;
    --primary-bg: #2a2a2a;
    --primary-hover: #404040;
    --alert: #a3332b;
    --alert-bg: #f7e3e0;
    --success: #1f1f1f;
    --success-bg: #e3e3df;
    --brand-bg: #2a2a2a;
    --selection-ink: #f7f7f5;
    --selection-bg: #2a2a2a;
    --shadow: #0000001f;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='m3 5 4 4 4-4' fill='none' stroke='%235d5d5a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--bar-height) + 12px); }
body {
    margin: 0;
    min-width: 280px;
    background: var(--page);
    color: var(--ink);
    font: 1rem/1.55 var(--font-body);
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
::selection { color: var(--selection-ink); background: var(--selection-bg); }

.op-skip {
    position: fixed;
    z-index: 20;
    top: 8px;
    left: 8px;
    transform: translateY(-180%);
    padding: .55rem .95rem;
    border-radius: 6px;
    background: var(--primary-bg);
    color: var(--primary-ink);
    font-weight: 600;
    text-decoration: none;
}
.op-skip:focus { transform: none; }

.op-shell { min-height: 100dvh; display: flex; flex-direction: column; }
.op-container, .op-topbar-inner, .op-footer-inner {
    width: min(100%, var(--max-width));
    margin-inline: auto;
    padding-inline: var(--gutter);
}
.op-container { flex: 1; padding-block: clamp(24px, 3.5vw, 44px) 60px; }
.op-container:focus { outline: none; }

/* --- Topbar --- */
.op-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--page);
    box-shadow: 0 1px var(--border);
}
.op-topbar-inner {
    min-height: var(--bar-height);
    display: flex;
    align-items: center;
    gap: 10px;
}
.op-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-right: clamp(8px, 1.8vw, 24px);
    text-decoration: none;
    color: var(--ink);
    white-space: nowrap;
    font-size: 1.15rem;
    letter-spacing: -.045em;
    font-weight: 700;
}
.op-brand-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--brand-bg);
    color: var(--accent);
}
.op-icon { width: 1.12rem; height: 1.12rem; flex: none; vertical-align: -.15em; }
.op-brand-icon .op-icon { width: 19px; height: 19px; }

.op-nav {
    display: flex;
    align-items: center;
    gap: clamp(12px, 2vw, 24px);
    flex-shrink: 0;
}
.op-nav .op-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    color: var(--ink-dim);
    text-decoration: none;
    font-size: .91rem;
    font-weight: 600;
    white-space: nowrap;
}
.op-nav .op-link::after {
    content: "";
    position: absolute;
    inset: auto 0 1px;
    height: 2px;
    background: var(--signal);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .24s var(--ease-out);
}
.op-nav .op-link:hover, .op-nav .op-link.is-active { color: var(--ink); }
.op-nav .op-link:hover::after, .op-nav .op-link.is-active::after { transform: scaleX(1); }

.op-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}
.op-icon-button {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface-up);
    transition: color .18s, background .18s, transform .22s var(--ease-out);
}
.op-icon-button:hover { color: var(--signal); background: var(--signal-bg); }
.op-icon-button:active { transform: scale(.92); }
.op-theme-moon, [data-theme="light"] .op-theme-sun { display: none; }
[data-theme="light"] .op-theme-moon { display: block; }
.op-menu-toggle { display: none; }

/* --- Page head --- */
.op-page-head { margin-bottom: clamp(20px, 3vw, 28px); }
.op-eyebrow {
    font-family: var(--font-mono);
    font-size: .78rem;
    color: var(--ink-dim);
    letter-spacing: .05em;
    text-transform: uppercase;
    margin: 0 0 6px;
    font-weight: 600;
}
.op-page-head h1 {
    margin: 0 0 8px;
    font-size: clamp(1.9rem, 4.2vw, 2.85rem);
    line-height: 1.1;
    letter-spacing: -.04em;
    font-weight: 700;
}
.op-sub {
    margin: 0;
    color: var(--ink-dim);
    font-size: .95rem;
    max-width: 68ch;
}

/* --- Controls bar --- */
.op-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px 22px;
    padding: 18px 20px;
    margin-bottom: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.op-field { display: grid; gap: 6px; }
.op-field-label {
    font-family: var(--font-mono);
    font-size: .74rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-dim);
    font-weight: 600;
}
.op-field select, .op-field input[type="text"] {
    min-height: 40px;
    padding: 7px 11px;
    border: 0;
    border-bottom: 1px solid var(--border-hover);
    border-radius: 6px 6px 2px 2px;
    background: var(--surface-up);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: .88rem;
}
.op-field select {
    appearance: none;
    min-width: 170px;
    padding-right: 32px;
    background-image: var(--select-chevron);
    background-position: right 10px center;
    background-repeat: no-repeat;
}
#base-addr { width: 175px; text-transform: uppercase; }

.op-toggle {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    cursor: pointer;
    font-size: .9rem;
    color: var(--ink);
}
.op-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.op-toggle-track {
    position: relative;
    width: 36px;
    height: 21px;
    border-radius: 999px;
    background: var(--border-hover);
    flex: none;
    transition: background .2s;
}
.op-toggle-thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--surface);
    transition: transform .22s var(--ease-out), background .2s;
}
.op-toggle input:checked + .op-toggle-track { background: var(--primary-bg); }
.op-toggle input:checked + .op-toggle-track .op-toggle-thumb {
    transform: translateX(15px);
    background: var(--primary-ink);
}
.op-toggle input:focus-visible + .op-toggle-track {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

/* --- Editor windows --- */
.op-windows { display: flex; gap: 16px; margin-bottom: 18px; }
.op-window {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.op-window-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-up);
}
.op-window-title { display: inline-flex; align-items: center; gap: 10px; }
.op-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 5px;
    background: var(--signal-bg);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .04em;
}
.op-meta-count {
    font-family: var(--font-mono);
    font-size: .78rem;
    color: var(--ink-dim);
}
.op-editor { position: relative; display: flex; height: 340px; }
.op-gutter {
    flex-shrink: 0;
    min-width: 84px;
    overflow: hidden;
    padding: 12px 10px 12px 8px;
    font-family: var(--font-mono);
    font-size: .84rem;
    line-height: 1.6;
    color: var(--ink-dim);
    text-align: right;
    user-select: none;
    border-right: 1px solid var(--border);
    background: var(--surface-up);
    white-space: pre;
}
.op-textarea {
    flex: 1;
    min-width: 0;
    padding: 12px 14px;
    background: transparent;
    border: 0;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: .84rem;
    line-height: 1.6;
    white-space: pre;
    overflow: auto;
    resize: none;
}
.op-textarea:focus { outline: none; }
.op-textarea::placeholder { color: var(--ink-dim); opacity: .85; }
.op-window:focus-within { border-color: var(--border-hover); }

/* --- Actions & status --- */
.op-actions-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.op-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    min-height: 40px;
    padding: .45rem .95rem;
    border: 0;
    border-radius: 7px;
    background: var(--surface-up);
    color: var(--ink);
    font-size: .89rem;
    font-weight: 640;
    text-decoration: none;
    transition: background .18s, color .18s, transform .2s var(--ease-out);
}
.op-btn:hover { background: var(--signal-bg); color: var(--ink); }
.op-btn:active { transform: scale(.96); }
.op-btn-primary { background: var(--primary-bg); color: var(--primary-ink); }
.op-btn-primary:hover { background: var(--primary-hover); color: var(--primary-ink); }
.op-btn-sm { min-height: 32px; padding: .28rem .68rem; font-size: .81rem; }

.op-status {
    min-height: 22px;
    margin-top: 6px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: .84rem;
    white-space: pre-wrap;
    color: var(--ink-dim);
}
.op-status.is-error {
    color: var(--alert);
    background: var(--alert-bg);
    padding: 10px 14px;
    border-radius: 7px;
}
.op-status.is-ok {
    color: var(--success);
    background: var(--success-bg);
    padding: 10px 14px;
    border-radius: 7px;
}

/* --- Snippets & animations --- */
.op-snippets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    margin-bottom: 16px;
}
.op-snippets-label {
    font-family: var(--font-mono);
    font-size: .76rem;
    color: var(--ink-dim);
    margin-right: 4px;
}
.op-snippet-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink-dim);
    font-family: var(--font-mono);
    font-size: .78rem;
    font-weight: 600;
    transition: color .16s, border-color .16s, background .16s, transform .18s var(--ease-out);
}
.op-snippet-btn:hover { color: var(--ink); border-color: var(--border-hover); background: var(--surface-up); }
.op-snippet-btn:active { transform: scale(.96); }

@keyframes op-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: no-preference) {
    [data-motion="page"] > .op-page-head { animation: op-in .36s var(--ease-out) both; }
    [data-motion="page"] > .op-controls { animation: op-in .38s var(--ease-out) .04s both; }
    [data-motion="page"] > .op-snippets { animation: op-in .38s var(--ease-out) .07s both; }
    [data-motion="page"] > .op-windows { animation: op-in .4s var(--ease-out) .1s both; }
}

/* --- Footer --- */
.op-footer { border-top: 1px solid var(--border); }
.op-footer-inner {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 18px;
    font-size: .85rem;
    color: var(--ink-dim);
}
.op-footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.op-footer-links a { color: var(--ink-dim); text-decoration: none; }
.op-footer-links a:hover { color: var(--ink); text-decoration: underline; }

@media (max-width: 820px) {
    .op-menu-toggle { display: inline-grid; }
    .op-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        display: none;
        padding: 10px var(--gutter) 16px;
        background: var(--page);
        box-shadow: 0 12px 24px var(--shadow);
        border-bottom: 1px solid var(--border);
    }
    .op-nav.is-open { display: grid; gap: 4px; }
    .op-nav .op-link { width: fit-content; }
}

@media (max-width: 680px) {
    .op-windows { flex-direction: column; }
    .op-editor { height: 240px; }
    .op-controls { gap: 12px; }
}
