/* digitaljs bundles a jQuery UI theme that injects `body { font-family: verdana }`
   as a runtime <style> tag, which always lands after our stylesheets in the head
   and wins the cascade. !important is needed to reclaim the site font. */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif !important;
}

.diagram-container {
    height: 300px;
    background-color: #eeeeee;
    margin-top: 10px;
    margin-bottom: 10px;
}

/* Horizontal scroll for circuits too wide to fit */
.d-flex.justify-content-center:has([id^="circuit-"]) {
    overflow-x: auto;
    justify-content: flex-start !important;
}
.d-flex.justify-content-center:has([id^="circuit-"]) > [id^="circuit-"] {
    flex-shrink: 0;
    margin: 0 auto;
}

.bd-callout {
    padding-left: 1.25rem;
    padding-top: 1.25rem;
    margin-top: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid #eee;
    border-left-color: red;
    border-left-width: .25rem;
    border-radius: .25rem;
    overflow: hidden;
    transform: rotate(0);
}

.cursor-pointer {
    cursor: pointer;
}

.green {
    color: green;
}

.red {
    color: red;
}

.tree {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px 16px;
    overflow: auto;
    max-height: 600px;
}

.tree ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.tree li {
    position: relative;
    padding: 0;
    margin: 0;
}

.tree .key {
    font-weight: 600;
    color: #0550ae;
}

.tree .value { font-weight: normal; }
.tree .value-string { color: #b91c1c; }
.tree .value-number { color: #7c3aed; }
.tree .value-other  { color: #374151; }

.tree .caret {
    cursor: pointer;
    user-select: none;
    display: inline-block;
    width: 14px;
    color: #9ca3af;
    font-size: 10px;
    vertical-align: middle;
    transition: color 0.1s;
}

.tree .caret:hover { color: #0550ae; }
.tree .caret::before { content: '▶'; }
.tree .caret.open::before { content: '▼'; }

.tree .nested {
    display: none;
    padding-left: 16px;
    border-left: 2px solid #dee2e6;
    margin-left: 5px;
}

.tree .nested.show { display: block; }

/* Disable old .line / .show-line system */
.tree .line { display: none !important; }
.tree .show-line { padding-left: 0 !important; }

.bi-caret-right-fill { display: inline; }
.bi-caret-down-fill { display: none; }

.svg-line-green { stroke-width: 1px; stroke: green; }
.svg-line-red { stroke-width: 1px; stroke: red; }
.svg-line-black { stroke-width: 1px; stroke: black; }

.bg-lightgreen { background: lightgreen; }
.bg-gray { background: gray; }
.bg-lightblue { background: lightblue; }
.bg-lightsalmon { background: lightsalmon; }
.bg-lightcoral { background: lightcoral; }

/* Tetris / emulator step-loop diagrams (cytoscape) */
.tf-wrap { margin-top: 1.1rem; margin-bottom: 0.5rem; position: relative; }
.tf-canvas {
  /* height is set by *-flowchart.js to match the laid-out content, so the
     diagram renders at ~1:1 instead of being shrunk to fit a fixed box */
  width: 100%;
  border-radius: 12px; border: 1px solid #e3e7ee;
  background-color: #fbfcfe;
  background-image: radial-gradient(circle, #d7dee6 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
}

.tf-zoom-controls {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  display: flex; gap: 4px; background: rgba(255,255,255,.85);
  border: 1px solid #e3e7ee; border-radius: 8px; padding: 3px;
}
.tf-zoom-controls .btn { line-height: 1; padding: 2px 8px; }

.tf-card {
  font: 12.5px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #24292f; background: #fff;
  width: 100%; height: 100%; box-sizing: border-box;
  padding: 8px 12px 8px 11px;
  border-radius: 10px; border: 1px solid #e3e7ee; border-left-width: 3px;
  box-shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 10px rgba(16,24,40,.06);
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  overflow: hidden;
}
.tf-card.tf-process { border-left-color: #b57a10; }
.tf-card.tf-anchor { border-left-color: #b57a10; background: #fffaf0; }
.tf-card.tf-branch { border-left-color: #5f6b7d; background: #f8f9fb; }
.tf-card.tf-halt { border-left-color: #c0453e; background: #fdf4f3; }

.tf-title { font-weight: 700; font-size: 12.5px; }
.tf-card.tf-branch .tf-title { color: #414c63; }
.tf-card.tf-halt .tf-title { color: #a83731; }
.tf-body { font-size: 11.5px; line-height: 1.5; }
.tf-small { font-size: 11px; line-height: 1.5; }
.tf-body .tf-small { display: block; margin-top: 3px; color: #6a7382; }
.tf-code { font-family:'Consolas','Monaco','Courier New',monospace; font-size:11px; background:#f6f8fa; border:1px solid #e2e8f0; border-radius:3px; padding:0 4px; color:#0550ae; }
.tf-swatches { display:flex; gap:4px; margin-top:2px; }
.tf-swatch { width:17px; height:17px; border-radius:3px; display:flex; align-items:center; justify-content:center; color:#fff; font-size:9px; font-weight:700; text-shadow:0 1px 1px rgba(0,0,0,.35); }

.editor-container { height: 300px; width: 100%; }
.w-fit-content { width: fit-content; }
.code-pink { color: #d63384; }

.terminal-frame {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 10px;
    padding: 12px 12px 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
    border: 1px solid #333;
}

.terminal-titlebar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a2a2a;
}

.terminal-title {
    flex: 1;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
    color: #666;
    letter-spacing: 1px;
    margin-right: 0;
}

.terminal {
    position: relative;
    background-color: #0a0f0a;
    color: #00e838;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    padding: 14px 16px;
    border-radius: 4px;
    overflow: auto;
    line-height: 1.45;
    min-height: calc(5 * 1.45em + 28px);
    border: 1px solid #0d1f0d;
    white-space: pre;
    text-shadow: 0 0 6px rgba(0, 232, 56, 0.7);
    box-shadow: inset 0 0 60px rgba(0,0,0,0.5), 0 0 1px #00e838;
}

/* CRT scanlines overlay */
.terminal::before {
    content: '';
    pointer-events: none;
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.12) 2px,
        rgba(0, 0, 0, 0.12) 4px
    );
    border-radius: 4px;
    z-index: 1;
}

.terminal-cursor {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    background-color: #00e838;
    vertical-align: text-bottom;
    animation: terminal-blink 1s step-end infinite;
    box-shadow: 0 0 6px rgba(0, 232, 56, 0.9);
}

@keyframes terminal-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* Keyboard Memory Unit */
.kbd-memory-frame {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 1px solid #333;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.kbd-memory-titlebar {
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
    color: #666;
    letter-spacing: 1px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a2a2a;
}
.kbd-memory-body { display: flex; flex-direction: column; gap: 6px; }
.kbd-register-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    padding: 6px 8px;
    background: #0a0f0a;
    border-radius: 4px;
    border: 1px solid #0d1f0d;
}
.kbd-reg-addr  { color: #888; min-width: 52px; }
.kbd-reg-name  { color: #aaa; min-width: 120px; }
.kbd-reg-bits  { color: #00e838; letter-spacing: 1px; flex: 1; text-shadow: 0 0 6px rgba(0,232,56,0.5); }
.kbd-reg-hex   { color: #5cc8ff; min-width: 60px; }
.kbd-reg-char  { color: #ffcc44; min-width: 20px; text-align: center; }
.kbd-reg-char-active { color: #ff6b6b; text-shadow: 0 0 6px rgba(255,107,107,0.8); }

/* Keyboard Log */
.kbd-log-frame {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 1px solid #333;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.kbd-log-titlebar {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a2a2a;
}
.kbd-log-title {
    flex: 1;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
    color: #666;
    letter-spacing: 1px;
}
.kbd-log-clear-btn {
    font-size: 11px;
    color: #555;
    border-color: #444;
    padding: 1px 8px;
    background: transparent;
}
.kbd-log-clear-btn:hover { color: #999; border-color: #666; background: transparent; }
.kbd-log {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    background: #0a0f0a;
    border: 1px solid #0d1f0d;
    border-radius: 4px;
    padding: 10px 12px;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
}
.kbd-log-empty { color: #444; font-style: italic; }
.kbd-log-entry {
    display: flex;
    gap: 16px;
    padding: 2px 0;
    border-bottom: 1px solid #0d1f0d;
    animation: kbd-log-flash 0.3s ease-out;
}
.kbd-log-entry:last-child { border-bottom: none; }
.kbd-log-key  { color: #00e838; min-width: 80px; text-shadow: 0 0 6px rgba(0,232,56,0.5); }
.kbd-log-hex  { color: #5cc8ff; min-width: 60px; }
.kbd-log-dec  { color: #888; }
@keyframes kbd-log-flash {
    from { background: rgba(0, 232, 56, 0.1); }
    to   { background: transparent; }
}

/* Assembly editor - current-instruction line highlight (Monaco decoration) */
.asm-current-line {
    background: rgba(0, 232, 56, 0.13) !important;
    border-left: 2px solid #00e838;
}

/* Instruction Trace Panel */
.instr-trace-frame {
    background: linear-gradient(145deg, #1a1a2e, #16213e);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 8px 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
}
.instr-trace-titlebar {
    text-align: center;
    font-size: 10px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    padding-bottom: 5px;
    border-bottom: 1px solid #222;
}
.instr-trace-body { display: flex; align-items: center; gap: 12px; }
.instr-trace-pc-label { color: #666; font-size: 11px; }
.instr-trace-pc { color: #5cc8ff; }
.instr-trace-sep { color: #444; }
.instr-trace-text { color: #00e838; text-shadow: 0 0 5px rgba(0,232,56,0.25); }

/* QWERTY Keyboard Layout */
.kbd-layout-frame {
    background: linear-gradient(145deg, #f7f8fa, #e9ecf1);
    border: 1px solid #d5d9e0;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.kbd-layout-titlebar {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #d5d9e0;
}
.kbd-layout-title {
    flex: 1;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    color: #555;
}
.kbd-capture-btn {
    font-size: 11px;
    color: #666;
    border: 1px solid #bbb;
    padding: 2px 10px;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.kbd-capture-btn:hover { color: #222; border-color: #888; }
.kbd-capture-btn.capturing {
    color: #1a8a34;
    border-color: #1a8a34;
    box-shadow: 0 0 6px rgba(26,138,52,0.25);
}
.kbd-layout-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: fit-content;
    margin: 0 auto;
}
.kbd-row { display: flex; gap: 4px; }
.kbd-key {
    flex: 0 0 34px;
    width: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    background: #fff;
    border: 1px solid #d0d3d8;
    border-bottom: 3px solid #b8bcc4;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 11px;
    color: #555;
    cursor: default;
    user-select: none;
    transition: color 0.1s, border-color 0.1s, box-shadow 0.1s, background 0.1s, text-shadow 0.1s;
}
.kbd-key-1h  { flex: 0 0 53px; }
.kbd-key-175 { flex: 0 0 62.5px; }
.kbd-key-2   { flex: 0 0 72px; }
.kbd-key-225 { flex: 0 0 81.5px; }
.kbd-key-275 { flex: 0 0 100.5px; }
.kbd-key-9   { flex: 0 0 338px; }
.kbd-spacer-1  { flex: 0 0 34px; }
.kbd-spacer-12 { flex: 0 0 452px; }
.kbd-spacer-13 { flex: 0 0 490px; }
.kbd-key.kbd-key-lit {
    color: #147a2c;
    border-color: #1a8a34;
    background: #e3f7e8;
    box-shadow: 0 0 10px rgba(26,138,52,0.35);
    text-shadow: none;
}
@keyframes kbd-key-flash {
    from { color: #147a2c; border-color: #1a8a34; background: #e3f7e8; box-shadow: 0 0 10px rgba(26,138,52,0.35); text-shadow: none; }
    to   { color: #555; border-color: #d0d3d8; background: #fff; box-shadow: none; text-shadow: none; }
}

/* Page chrome - hero, numbered build modules, panel typography */

#card-body {
    counter-reset: module;
    padding: 2rem 2.25rem 2.5rem;
}

/* Section toggles: one system replacing the Bootstrap rainbow */
#card-body .btn.col-sm-12[data-toggle="collapse"] {
    --sec: #3563c9;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--sec);
    border-radius: 6px !important;
    color: #1a202c;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.55rem 0.9rem;
    margin-top: 0.45rem !important;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
#card-body .btn.col-sm-12[data-toggle="collapse"]:hover {
    background: color-mix(in srgb, var(--sec) 5%, #fff);
    border-color: color-mix(in srgb, var(--sec) 30%, #e2e8f0);
    border-left-color: var(--sec);
    color: #1a202c;
}
#card-body .btn.col-sm-12[data-toggle="collapse"][aria-expanded="true"] {
    background: color-mix(in srgb, var(--sec) 7%, #fff);
    border-color: color-mix(in srgb, var(--sec) 35%, #e2e8f0);
    border-left-color: var(--sec);
    color: #1a202c;
}
#card-body .btn.col-sm-12[data-toggle="collapse"]:focus-visible {
    outline: 2px solid var(--sec);
    outline-offset: 2px;
}
#card-body .btn.col-sm-12[data-toggle="collapse"] svg {
    color: var(--sec);
    flex-shrink: 0;
    width: 13px;
    height: 13px;
}

/* Module numbering - top-level sections are the build sequence */
#card-body > .btn.col-sm-12[data-toggle="collapse"] {
    counter-increment: module;
}
#card-body > .btn.col-sm-12[data-toggle="collapse"]::before {
    content: counter(module, decimal-leading-zero);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.72rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    color: var(--sec);
    min-width: 1.5rem;
}

/* Nested sub-sections read as subordinate */
#card-body .collapse .btn.col-sm-12[data-toggle="collapse"],
#card-body .collapsing .btn.col-sm-12[data-toggle="collapse"] {
    background: #f8f9fa;
    font-size: 0.875rem;
    border-left-width: 2px;
    border-left-color: color-mix(in srgb, var(--sec) 55%, #fff);
}

/* Per-group accents (button + its collapse panel) */
#card-body .btn.btn-danger.col-sm-12,    #card-body .btn.btn-danger.col-sm-12 + div    { --sec: #c0453e; }
#card-body .btn.btn-primary.col-sm-12,   #card-body .btn.btn-primary.col-sm-12 + div   { --sec: #3563c9; }
#card-body .btn.btn-success.col-sm-12,   #card-body .btn.btn-success.col-sm-12 + div   { --sec: #2f8f5b; }
#card-body .btn.btn-dark.col-sm-12,      #card-body .btn.btn-dark.col-sm-12 + div      { --sec: #414c63; }
#card-body .btn.btn-warning.col-sm-12,   #card-body .btn.btn-warning.col-sm-12 + div   { --sec: #b57a10; }
#card-body .btn.btn-secondary.col-sm-12, #card-body .btn.btn-secondary.col-sm-12 + div { --sec: #5f6b7d; }
#card-body .btn.btn-info.col-sm-12,      #card-body .btn.btn-info.col-sm-12 + div      { --sec: #1f8a99; }

/* Collapse panels connect to their toggle */
#card-body .btn.col-sm-12[data-toggle="collapse"] + div > .card {
    border: 1px solid #e6e9ef;
    border-left: 3px solid color-mix(in srgb, var(--sec, #3563c9) 40%, #fff);
    border-radius: 0 0 6px 6px;
    background: #fdfdfe;
    padding: 1.25rem 1.4rem;
    margin-top: 2px;
}

#card-body .card pre {
    background: #f6f8fa;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.8rem 1rem;
    font-size: 0.83rem;
    line-height: 1.55;
    color: #24292f;
    overflow-x: auto;
}

@media (prefers-reduced-motion: reduce) {
    #card-body .btn.col-sm-12[data-toggle="collapse"] { transition: none; }
}

/* Restore list indentation stripped by the global reset in style.css
   (Bootstrap relies on the browser default ul/ol padding) */
#card-body ul:not([class]),
#card-body ol:not([class]) {
    padding-left: 1.6rem;
    margin-bottom: 1rem;
}
#card-body .tree ul { padding-left: 0; margin: 0; }
#card-body .tree .nested { padding-left: 16px; }
