:root {
    color-scheme: dark;
    --page: #111018;
    --panel: #191622;
    --chrome: #201b2b;
    --border: #3b304b;
    --muted: #b0a2be;
    --text: #ebe3f3;
    --accent: #c6a7f8;
    --mono: 'Ubuntu Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
    --row: 26px;
    --editor-padding: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); font: 14px/1.5 system-ui, sans-serif; }
.ide-header {
    min-height: 58px;
    padding: 0 clamp(16px, 3vw, 40px);
    display: flex;
    gap: 8px 16px;
    justify-content: space-between;
    flex-wrap: wrap;
    align-items: center;
}
.ide-brand { display: flex; align-items: center; gap: clamp(8px, 1.4vw, 16px); }
.ide-brand img { display: block; width: clamp(42px, 5vw, 76px); height: auto; }
.ide-brand h1 { margin: 0; border-left: 1px solid #393242; padding-inline-start: clamp(8px, 1.4vw, 16px); font: 500 clamp(15px, 2vw, 20px)/1.2 'Space Grotesk', sans-serif; letter-spacing: -.04em; white-space: nowrap; }
.ide-header .engine-version { min-height: 0; padding: 4px 7px; color: #b499fa; background: #262035; border: 1px solid #393242; border-radius: 4px; font: 11px var(--mono); }
.ide-header .engine-version:hover:enabled { background: #35284a; border-color: #775ba1; }
.site-links { display: flex; align-items: center; gap: clamp(10px, 1.5vw, 18px); font-size: 13px; white-space: nowrap; }
.site-links a { color: var(--muted); text-decoration: none; }
.site-links a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 4px; }
.version-details { position: fixed; inset: 58px auto auto clamp(12px, 3vw, 40px); width: min(390px, calc(100% - 24px)); margin: 0; padding: 0; border: 1px solid #63507b; border-radius: 8px; background: var(--panel); color: var(--text); box-shadow: 0 16px 45px #05030aa0; }
.version-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 13px; border-bottom: 1px solid var(--border); background: var(--chrome); }
.version-heading h2 { margin: 0; font-size: 14px; font-weight: 600; }
.version-details dl { margin: 0; padding: 5px 13px; }
.version-details dl > div { display: grid; grid-template-columns: minmax(85px, 1fr) minmax(0, 1.55fr); gap: 8px; padding-block: 8px; }
.version-details dl > div + div { border-top: 1px solid var(--border); }
.version-details dt { color: var(--muted); font-size: 12px; }
.version-details dd { margin: 0; color: var(--text); font: 13px/1.4 var(--mono); text-align: end; overflow-wrap: anywhere; }
.workbench { display: flex; flex-direction: column; min-width: 0; }
.toolbar, .toolbar-group { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.toolbar { background: var(--chrome); padding: 6px 12px; gap: 6px 12px; }
.debug-controls { gap: 2px; }
button, select { border: 1px solid #514161; border-radius: 5px; padding: 6px 10px; min-height: 34px; background: #292135; color: var(--text); font: inherit; }
.toolbar button { min-height: 38px; border: 0; }
.toolbar button:not(.primary, .context-trigger) { background: transparent; }
.toolbar button:not(.primary):hover:enabled { background: #362a47; }
button { cursor: pointer; }
button:hover:enabled { background: #3b2d4f; }
button:disabled { opacity: .48; cursor: default; }
button.primary { background: #453259; border-color: #795aa0; color: #f2e7ff; }
button.primary:hover:enabled { background: #543b71; }
:where(a, textarea, button, select):focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(230px, 29%); background: var(--panel); }
.editor-pane, .stack-pane { min-width: 0; }
.stack-pane { border-left: 1px solid var(--border); }
.stack-section + .stack-section { border-top: 1px solid var(--border); }
.pane-title { min-height: 36px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 13px; }
.pane-title h2 { margin: 0; font-size: 13px; font-weight: 600; }
.pane-title span { color: var(--muted); font: 12px var(--mono); }
.current-instruction { color: var(--muted); font: 12px var(--mono); min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.editor { display: grid; grid-template-columns: 48px minmax(0, 1fr); height: clamp(330px, 59dvh, 760px); background: #13101b; }
.gutter { position: relative; overflow: hidden; background: #181421; }
.gutter pre { position: absolute; top: var(--editor-padding); width: 100%; margin: 0; color: #92839e; text-align: right; }
.gutter span { display: block; padding-inline-end: 10px; }
.gutter .active-line { color: #f1ddff; background: #35264b; }
.source { position: relative; min-width: 0; overflow: hidden; }
.gutter pre, textarea { font: 14px/var(--row) var(--mono); }
textarea { display: block; position: relative; width: 100%; height: 100%; padding: var(--editor-padding) 14px; resize: none; border: 0; border-radius: 0; background: transparent; color: var(--text); tab-size: 4; }
#script-source:focus-visible { outline: none; }
.editor:has(#script-source:focus-visible) .gutter { background: #211a2e; }
#script-highlight { position: absolute; inset-inline: 0; height: var(--row); background: #35264b; border-left: 2px solid var(--accent); pointer-events: none; }
.stack-empty { padding: 0 14px; color: var(--muted); font-size: 12px; }
.script-stack { margin: 0; padding: 0; list-style: none; max-height: clamp(280px, 52dvh, 680px); overflow: auto; font: 13px/1.5 var(--mono); }
.script-stack li { display: grid; grid-template-columns: 3ch minmax(0, 1fr); gap: 10px; padding: 7px 14px; border-top: 1px solid #30263c; overflow-wrap: anywhere; }
.script-stack li:first-child { background: #261d33; color: #e6ccff; }
.stack-index { color: var(--muted); }
.vm-panel { border-top: 1px solid var(--border); }
.vm-metrics {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 8px;
    margin: 0;
    padding: 8px 13px 4px;
    font-size: 12px;
}
.vm-metrics dd { margin: 0; font: 12px/18px var(--mono); text-align: right; }
.vm-metrics dd[data-exceeded] { color: #ffe0eb; font-weight: 700; }
#script-vm-note { margin: 0; padding: 0 13px 8px; color: var(--muted); font-size: 12px; }
.statusbar { padding: 6px 12px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 20px; background: var(--chrome); }
.script-error:not([hidden]) {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    padding: 9px 12px;
    background: #251a2b;
    color: var(--text);
    border-inline-start: 3px solid #bb7daa;
    border-block-end: 1px solid #49334c;
    overflow-wrap: anywhere;
}
.script-error strong { color: #efc0db; font-size: 12px; font-weight: 600; }
.script-error code { border: 1px solid #5e3d5c; border-radius: 4px; padding: 2px 6px; background: #32203a; color: #efc6e1; font: 12px var(--mono); }
.script-error span { min-width: 0; }
.script-error span::first-letter { text-transform: uppercase; }
.context-controls {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 8px;
    flex: 1 1 0;
    min-width: min(220px, 100%);
    max-width: 460px;
    margin-inline-start: auto;
}
.context-trigger { min-width: 0; padding-block: 4px; }
.context-trigger > span { display: grid; min-width: 0; }
.context-label { color: var(--muted); font-size: 11px; line-height: 1.15; }
.context-trigger strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; line-height: 1.15; }
.context-note, .context-error { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
.context-note { color: var(--muted); }
.context-error { color: #ffe0eb; }
.transaction-fields { align-content: start; gap: 8px; padding: 14px 16px; }
.transaction-fields label { font-size: 12px; font-weight: 600; }
.transaction-fields textarea, #script-spent-value {
    height: auto;
    padding: 8px 10px;
    border: 1px solid #514161;
    border-radius: 5px;
    background: #13101b;
    color: var(--text);
    font: 13px/1.5 var(--mono);
}
.transaction-fields textarea { resize: vertical; min-height: 72px; max-height: 30dvh; }
#script-parse-tx { justify-self: start; }
#script-transaction-details:not([hidden]) { display: grid; gap: 12px; }
.transaction-facts {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px 12px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--chrome);
}
.transaction-facts dt { color: var(--muted); font-size: 12px; }
.transaction-facts dd { margin: 2px 0 0; overflow-wrap: anywhere; font: 13px var(--mono); }
.transaction-id { grid-column: 1 / -1; }
.transaction-input-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.transaction-input-fields > div { display: grid; gap: 4px; min-width: 0; }
.transaction-input-fields :is(select, input) { min-width: 0; }
#script-spent-value:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#script-transaction-dialog .picker-footer { gap: 6px; padding-inline: 10px; }
#script-transaction-clear { margin-inline-end: auto; }
.picker-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-inline: 11px 14px;
    text-align: start;
}
.picker-trigger::after {
    content: '';
    flex: 0 0 7px;
    height: 7px;
    border: solid var(--accent);
    border-width: 0 1.5px 1.5px 0;
    transform: translateY(-2px) rotate(45deg);
}
.statusbar p { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
#script-status { color: #e6ccff; }
#script-hint { color: var(--muted); }

@media (min-width: 671px) {
    body {
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        height: 100dvh;
        min-height: 420px;
    }
    .workbench { min-height: 0; }
    .workspace { flex: 1; min-height: 0; }
    .editor-pane, .stack-section {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    .stack-pane {
        display: grid;
        grid-template-rows: minmax(0, 3fr) minmax(0, 2fr) auto;
        min-height: 0;
    }
    .stack-section { overflow: hidden; }
    .editor { flex: 1; height: auto; min-height: 0; }
    .script-stack { max-height: none; min-height: 0; }
}

@media (max-width: 670px) {
    .ide-header { padding-block: 8px; }
    .version-details { top: 54px; }
    .workspace { order: 1; grid-template-columns: minmax(0, 1fr); }
    .stack-pane { border-left: 0; border-top: 1px solid var(--border); }
    .editor { grid-template-columns: 36px minmax(0, 1fr); height: clamp(230px, 42dvh, 400px); }
    .toolbar { column-gap: 6px; }
    .debug-controls button, #script-example { padding-inline: 8px; }
    .context-controls {
        flex-basis: 100%;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: none;
        margin-inline-start: 0;
    }
    .context-trigger { gap: 8px; padding-inline: 8px 10px; }
    .script-stack { max-height: 220px; }
}

@media (max-width: 380px) {
    .ide-header { padding-inline: 12px; gap: 6px; }
    .ide-brand, .site-links { gap: 8px; }
    .site-links { font-size: 11px; }
}

#opcode-popover, .ide-picker {
    position: fixed;
    inset: 0;
    max-height: calc(100dvh - 24px);
    margin: auto;
    padding: 0;
    border: 1px solid #70538f;
    border-radius: 9px;
    background: var(--chrome);
    color: var(--text);
    box-shadow: 0 16px 44px #060409a6;
}
#opcode-popover { width: min(410px, calc(100vw - 24px)); overflow: auto; }
#opcode-popover[data-anchored] { inset: 0 auto auto 0; margin: 0; }
#opcode-popover::backdrop { background: #0a07134d; }
.opcode-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: #2a2038;
    border-bottom: 1px solid var(--border);
}
.opcode-header h2 { margin: 0; color: #ecdfff; font: 600 16px/1.5 var(--mono); overflow-wrap: anywhere; }
#opcode-byte { color: var(--muted); font: 12px var(--mono); }
.opcode-close { min-width: 30px; min-height: 30px; padding: 0 7px; font-size: 20px; line-height: 1; }
.opcode-description { margin: 0; padding: 12px 14px; }
.opcode-description div + div { margin-top: 10px; }
.opcode-description dt { color: var(--accent); font-size: 12px; font-weight: 600; }
.opcode-description dd { margin: 2px 0 0; overflow-wrap: anywhere; }

.ide-picker {
    width: min(var(--picker-width), calc(100vw - 24px));
    max-width: none;
    max-height: min(740px, calc(100dvh - 24px));
    overflow: hidden;
}
.ide-picker[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.ide-picker::backdrop { background: #0a0713a3; }
#script-rules-picker { --picker-width: 710px; }
#script-examples-picker { --picker-width: 610px; }
#script-transaction-dialog { --picker-width: 720px; }
.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: #2a2038;
}
.picker-header h2 { margin: 0; font-size: 17px; font-weight: 600; }
.picker-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.picker-form { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.picker-list {
    display: grid;
    gap: 6px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 10px 12px;
    background: var(--panel);
}
.examples-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 12px;
}
.examples-list section { display: grid; align-content: start; gap: 5px; }
.examples-list h3 { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.examples-list button { background: #201b2b; border-color: var(--border); text-align: start; min-height: 38px; }
.examples-list button:hover, .examples-list button:focus-visible { background: #30233f; border-color: #8363a5; }
@media (max-width: 480px) {
    .examples-list { grid-template-columns: minmax(0, 1fr); }
}
.rules-choice {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}
.rules-choice:hover { background: #261d33; }
.rules-choice:has(input:checked) { border-color: #8363a5; background: #30233f; }
.rules-choice input { width: 15px; height: 15px; margin: 3px 0 0; accent-color: var(--accent); }
.rules-choice-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 10px; }
.rules-choice-edition { color: var(--muted); font: 12px var(--mono); }
.rules-choice-edition:empty { display: none; }
.rules-choice-description { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.rules-choice-unchanged { color: var(--accent); font-weight: 600; }
.picker-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    border-top: 1px solid var(--border);
}
