/*
 * Simulador Superescalar RISC-V
 * Tema claro e tema escuro definidos por variáveis; o tema é escolhido em <html data-theme="light|dark">.
 * Cores de etiquetas (estações, ROB, instruções) chegam pela variável --tag e são misturadas com o fundo.
 */

:root,
[data-theme='light'] {
    --bg: #f8fafc;
    --panel: #ffffff;
    --panel-2: #f2f4f8;
    --line: #b4bfcf;
    --line-strong: #8796ad;
    --ink: #111827;
    --muted: #475266;
    --faint: #667085;
    --accent: #1650ff;
    --accent-ink: #ffffff;
    --accent-soft: #e3ebff;
    --focus: #d99700;
    --focus-soft: #fff3cf;
    --warn: #b23a12;
    --ok: #1d6e42;
    --ok-soft: #d6f0e0;
    --bad-soft: #f8d9d0;
    --wire: #8f9bb0;
    --c-issue: #e3e7fb;
    --c-id: #e7ebf2;
    --c-exec: #d7f0e3;
    --c-mem: #d6eaf6;
    --c-write: #efe0f6;
    --c-commit: #f8ebcc;
    --c-squash: #f6d6d2;
    --c-stall: #fbe5cc;
    --tag-bg: 18%;
    --tag-fg: 75%;
    --shadow: 0 4px 16px rgba(17, 24, 39, 0.10);
    color-scheme: light;
}

[data-theme='dark'] {
    --bg: #000000;
    --panel: #0d0f14;
    --panel-2: #1a1e27;
    --line: #6b7486;
    --line-strong: #9aa3b5;
    --ink: #ffffff;
    --muted: #dde2ea;
    --faint: #b4bccb;
    --accent: #5294ff;
    --accent-ink: #000000;
    --accent-soft: #0f2a5e;
    --focus: #ffd23f;
    --focus-soft: #3d3200;
    --warn: #ff9e7a;
    --ok: #7ef0ad;
    --ok-soft: #0f3a24;
    --bad-soft: #4a1d1d;
    --wire: #7c869a;
    --c-issue: #22306e;
    --c-id: #2a3140;
    --c-exec: #11452c;
    --c-mem: #0f3c57;
    --c-write: #44255a;
    --c-commit: #574300;
    --c-squash: #5c1f22;
    --c-stall: #5a3410;
    --tag-bg: 40%;
    --tag-fg: 75%;
    --shadow: 0 0 0 1px #6b7486;
    color-scheme: dark;
}

:root {
    --sans: 'IBM Plex Sans', system-ui, 'Segoe UI', Roboto, sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
    --radius: 6px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.4;
}

a {
    color: var(--accent);
}

code {
    font-family: var(--mono);
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.screen {
    position: fixed;
    inset: 0;
}

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

/* Ícones: SVG usados como máscara, para seguirem a cor do texto */

.icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    background: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
    flex: none;
}

.i-cpu { --icon: url('../svg/cpu.svg'); }
.i-new { --icon: url('../svg/new.svg'); }
.i-close { --icon: url('../svg/close.svg'); }
.i-moon { --icon: url('../svg/moon.svg'); }
.i-sun { --icon: url('../svg/sun.svg'); }
.i-skip-back { --icon: url('../svg/skipBack.svg'); }
.i-skip-fwd { --icon: url('../svg/skipFwd.svg'); }
.i-step-back { --icon: url('../svg/stepBack.svg'); }
.i-step-fwd { --icon: url('../svg/stepFwd.svg'); }

/* Botões */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-size: 0.875rem;
    color: var(--ink);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 5px 10px;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    background: var(--panel-2);
    border-color: var(--line);
}

.btn.primary {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

.btn.primary:hover {
    background: color-mix(in srgb, var(--accent) 88%, var(--ink));
    border-color: transparent;
}

.btn.small {
    font-size: 0.8rem;
    padding: 2px 8px;
    border-color: var(--line);
}

.icon-btn {
    padding: 6px;
}

/* Estrutura ----------------------------------------------------------------------------------------------- */

#workspace {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    z-index: 30;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 10px;
    border-right: 1px solid var(--line);
}

.brand-mark {
    width: 26px;
    height: 26px;
    color: var(--accent);
}

.brand-name {
    font-weight: 500;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.brand-name b {
    font-weight: 600;
    color: var(--accent);
}

.actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.tools {
    display: flex;
    align-items: center;
    gap: 6px;
}

.lang select {
    font: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 6px;
}

.menu {
    position: relative;
}

.menu .menu-items {
    display: none;
    position: fixed;
    z-index: 60;
    margin-top: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 4px;
    min-width: 260px;
}

.menu.open .menu-items {
    display: flex;
    flex-direction: column;
}

.menu .menu-items button {
    font: inherit;
    font-size: 0.875rem;
    text-align: left;
    color: var(--ink);
    background: none;
    border: 0;
    border-radius: 4px;
    padding: 7px 10px;
    cursor: pointer;
}

.menu .menu-items button:hover {
    background: var(--panel-2);
}

/* Abas */

#tab-names {
    flex: 0 0 auto;
    display: flex;
    gap: 2px;
    padding: 6px 12px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    user-select: none;
}

#tab-names .tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px 5px 12px;
    font-size: 0.85rem;
    color: var(--muted);
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    white-space: nowrap;
    cursor: pointer;
}

#tab-names .tab.active {
    color: var(--ink);
    background: var(--panel);
    border-color: var(--line);
    margin-bottom: -1px;
    box-shadow: inset 0 2px 0 var(--accent);
}

#tab-names .close-tab {
    display: inline-flex;
    padding: 2px;
    color: var(--faint);
    background: none;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

#tab-names .close-tab .icon {
    width: 14px;
    height: 14px;
}

#tab-names .close-tab:hover {
    color: var(--ink);
    background: var(--panel-2);
}

#tab-filler {
    flex: 1;
}

#tab-visual {
    flex: 1 1 400px;
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

/* Ajuda */

#readme {
    position: absolute;
    inset: 0;
    overflow: auto;
    z-index: 15;
    background: var(--bg);
    scroll-behavior: smooth;
}

#readme.overlay {
    display: block !important;
    z-index: 40;
}

.help {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 40px;
    max-width: 1180px;
    padding: 24px 32px 80px;
}

.help-toc {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: calc(100vh - 140px);
    overflow: auto;
    padding-top: 4px;
}

.help-search {
    width: 100%;
    font: inherit;
    font-size: 0.875rem;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px 10px;
}

.help-toc-title {
    margin: 18px 0 6px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--faint);
}

.help-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: toc;
}

.help-toc li {
    counter-increment: toc;
}

.help-toc a {
    display: block;
    padding: 5px 10px;
    border-left: 2px solid var(--line);
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.help-toc a::before {
    content: counter(toc) '.';
    display: inline-block;
    width: 2em;
    color: var(--faint);
    font-family: var(--mono);
    font-size: 0.85em;
}

.help-toc a:hover {
    color: var(--ink);
    background: var(--panel-2);
}

.help-toc a.current {
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}

.help-body {
    max-width: 78ch;
    font-size: 0.95rem;
    line-height: 1.6;
}

.help-head {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    justify-content: space-between;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.help-head h1 {
    font-size: 1.7rem;
    font-weight: 600;
    margin: 0 0 6px;
}

.help-lead {
    margin: 0;
    color: var(--muted);
}

.help-close {
    display: none;
    border-color: var(--line);
}

#readme.overlay .help-close {
    display: inline-flex;
    width: 100%;
    justify-content: center;
    margin-bottom: 10px;
}

body.help-open #tab-timeline {
    display: none;
}

.help-section {
    padding-top: 10px;
}

.help-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 30px 0 8px;
    color: var(--ink);
}

.help-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 22px 0 6px;
    color: var(--accent);
}

.help-section ul,
.help-section ol {
    padding-left: 22px;
}

.help-section li {
    margin: 4px 0;
}

.help-section dt {
    font-weight: 600;
    margin-top: 12px;
}

.help-section dd {
    margin: 2px 0 0 0;
    color: var(--ink);
}

.help-section table {
    border-collapse: collapse;
    margin: 10px 0 14px;
    font-size: 0.9rem;
    width: 100%;
}

.help-section th,
.help-section td {
    border-bottom: 1px solid var(--line);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}

.help-section th {
    background: var(--panel-2);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
}

.help-section pre {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    overflow: auto;
    font-size: 0.85rem;
    line-height: 1.5;
}

.help-section pre code {
    background: none;
    border: 0;
    padding: 0;
}

.help-section p.tip {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 8px 12px;
}

.help-empty {
    margin-top: 30px;
    color: var(--muted);
}

kbd {
    font-family: var(--mono);
    font-size: 0.82em;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 5px;
    white-space: nowrap;
}

#readme code,
.dialog code,
.errors code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 0 4px;
}

@media (max-width: 860px) {
    .help {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }

    .help-toc {
        position: static;
        max-height: none;
    }
}

/* Diagrama ------------------------------------------------------------------------------------------------ */

#viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    cursor: grab;
    display: none;
}

#viewport.visible {
    display: block;
}

#viewport.dragging {
    cursor: grabbing;
}

#diagram {
    position: relative;
    display: inline-flex;
    align-items: flex-start;
    gap: 40px;
    padding: 8px 8px 110px;
    transform-origin: 0 0;
    font-size: 14px;
    user-select: none;
}

#diagram .col {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 1;
}

/* Painéis e tabelas */

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px 10px;
}

.panel.focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 2px var(--focus);
}

.panel h3 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
}

.panel .sub {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85em;
    margin-left: 6px;
}

.panel.stations .sub {
    display: inline-block;
    max-width: 380px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

.panel .note {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.note.warn,
.warn {
    color: var(--warn);
    font-weight: 600;
}

.panel table {
    border-collapse: collapse;
}

.panel th,
.panel td {
    border-bottom: 1px solid var(--line);
    padding: 3px 8px;
    height: 26px;
    text-align: left;
    white-space: nowrap;
}

.panel tr:first-child th {
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--panel-2);
    border-bottom-color: var(--line-strong);
}

.panel tr:last-child td,
.panel tr:last-child th {
    border-bottom: 0;
}

.panel td.num {
    text-align: right;
    font-family: var(--mono);
    font-size: 0.95em;
}

.dim,
.panel td.dim {
    color: var(--faint);
}

.panel td.tag,
.cdb-item {
    font-family: var(--mono);
    font-weight: 600;
    text-align: center;
    background: color-mix(in srgb, var(--tag) var(--tag-bg), var(--panel));
    color: color-mix(in srgb, var(--tag) var(--tag-fg), var(--ink));
}

.panel th.tagname {
    color: color-mix(in srgb, var(--tag) var(--tag-fg), var(--ink));
    font-weight: 600;
}

.panel code {
    font-family: var(--mono);
    font-size: 0.95em;
}

.panel tr.busy td {
    background: color-mix(in srgb, var(--tag) 8%, var(--panel));
}

.panel tr.busy td.tag {
    background: color-mix(in srgb, var(--tag) var(--tag-bg), var(--panel));
}

.panel tr.focus th,
.panel tr.focus td {
    background: var(--focus-soft) !important;
}

.panel tr.mispredict td {
    color: var(--warn);
}

.panel .imm {
    font-style: italic;
    color: var(--muted);
}

.panel .abi {
    color: var(--faint);
    font-size: 0.8em;
    margin-left: 5px;
    font-weight: 400;
}

.panel table.regs {
    min-width: 220px;
}

.panel td.stage {
    min-width: 150px;
    font-size: 0.9em;
    color: var(--muted);
}

.bar {
    display: inline-block;
    width: 44px;
    height: 6px;
    margin-left: 6px;
    border-radius: 3px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    vertical-align: middle;
    overflow: hidden;
}

.bar span {
    display: block;
    height: 100%;
    background: var(--accent);
}

ol.queue {
    margin: 0;
    padding: 0;
    list-style: none;
    min-width: 260px;
}

ol.queue li {
    padding: 3px 6px;
    border-bottom: 1px solid var(--line);
}

ol.queue li:last-child {
    border-bottom: 0;
}

ol.queue li.next {
    background: var(--accent-soft);
    border-radius: 4px;
    font-weight: 600;
}

.pc {
    font-family: var(--mono);
    color: var(--faint);
    font-size: 0.85em;
    margin-right: 8px;
    font-weight: 400;
}

.panel.cdb {
    min-height: 34px;
}

.panel.cdb.active {
    border-color: var(--accent);
}

.cdb-item {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    margin: 2px 4px 2px 0;
}

.ptr {
    display: inline-block;
    font-size: 0.72rem;
    padding: 0 6px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-ink);
    margin-right: 3px;
}

.ptr.tail {
    background: var(--muted);
    color: var(--panel);
}

/* Controle ------------------------------------------------------------------------------------------------ */

#control {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 10px;
    display: flex;
    align-items: stretch;
    gap: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 20;
}

#control.visible {
    pointer-events: auto;
    opacity: 1;
}

.ctl-buttons,
#control-msg {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.ctl-buttons {
    display: flex;
    align-items: center;
    padding: 4px;
    flex: none;
}

.control-button {
    display: inline-flex;
    padding: 8px;
    color: var(--faint);
    background: none;
    border: 0;
    border-radius: 8px;
    cursor: default;
}

.control-button .icon {
    width: 20px;
    height: 20px;
}

.control-button.active {
    color: var(--ink);
    cursor: pointer;
}

.control-button.active:hover {
    background: var(--panel-2);
}

#control-counter {
    min-width: 84px;
    text-align: center;
    font-family: var(--mono);
    font-size: 0.95rem;
}

#control-msg {
    flex: 1;
    padding: 8px 14px;
    font-size: 0.95rem;
    line-height: 1.45;
    max-height: 120px;
    overflow: auto;
    opacity: 0;
    transition: opacity 0.15s;
}

#control-msg.active {
    opacity: 1;
}

#control-msg .bold {
    font-weight: 600;
}

#control-msg .italic {
    font-style: italic;
    font-family: var(--mono);
    font-size: 0.92em;
}

#control-msg .mono {
    font-family: var(--mono);
    font-weight: 500;
    background: var(--panel-2);
    border-radius: 4px;
    padding: 0 3px;
}

/* Linha do tempo ------------------------------------------------------------------------------------------ */

#tab-timeline {
    flex: 0 2 230px;
    overflow: auto;
    background: var(--panel);
    border-top: 1px solid var(--line);
}

table.timeline {
    border-collapse: separate;
    border-spacing: 0;
    user-select: none;
    font-size: 0.8rem;
}

table.timeline th,
table.timeline td {
    min-width: 50px;
    padding: 3px 5px;
    text-align: center;
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
}

table.timeline tr:first-child th {
    position: sticky;
    top: 0;
    background: var(--panel-2);
    color: var(--muted);
    font-weight: 500;
    z-index: 2;
}

table.timeline th.cur,
table.timeline td.cur {
    box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent);
}

table.timeline tr:first-child th.cur {
    color: var(--accent);
    font-weight: 600;
}

table.timeline .inst {
    position: sticky;
    left: 0;
    background: var(--panel);
    font-family: var(--mono);
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    z-index: 1;
}

table.timeline tr:first-child th.inst {
    z-index: 3;
    background: var(--panel-2);
    font-family: var(--sans);
}

table.timeline td.issue { background: var(--c-issue); }
table.timeline td.id { background: var(--c-id); }
table.timeline td.exec { background: var(--c-exec); }
table.timeline td.mem { background: var(--c-mem); }
table.timeline td.write { background: var(--c-write); }
table.timeline td.commit { background: var(--c-commit); }
table.timeline td.squash { background: var(--c-squash); }
table.timeline td.stall { background: var(--c-stall); font-style: italic; }

table.timeline tr.squashed td.inst {
    text-decoration: line-through;
    color: var(--faint);
}

table.timeline tr.mispredicted td.inst {
    color: var(--warn);
}

/* Janela de simulação ------------------------------------------------------------------------------------- */

.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    background: color-mix(in srgb, var(--bg) 40%, rgba(10, 14, 22, 0.55));
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.modal.visible {
    pointer-events: auto;
    opacity: 1;
}

.modal .dialog {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-width: 96vw;
    max-height: 94vh;
    overflow: auto;
    padding: 18px 22px;
}

.modal .dialog.wide {
    width: 1200px;
}

.modal .dialog h1 {
    margin: 0 0 14px;
    font-size: 1.3rem;
    font-weight: 600;
}

.modal .close {
    position: absolute;
    top: 14px;
    right: 14px;
}

.editor-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
}

.editor-code {
    flex: 1 1 420px;
    min-width: 0;
}

.editor-config {
    flex: 1 1 480px;
    min-width: 0;
    font-size: 0.85rem;
}

.field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 5px 0;
}

.field select,
.field input[type='number'],
table.groups input,
table.exercise input {
    font: inherit;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 3px 5px;
}

.field input[type='number'] {
    width: 76px;
}

.field.check {
    justify-content: flex-start;
}

.editor-code > .field {
    justify-content: flex-start;
    margin-bottom: 8px;
}

.editor-code > .field select {
    flex: 1;
}

.code-box {
    display: flex;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    height: 54vh;
    min-height: 260px;
    overflow: hidden;
}

#novo-gutter {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 8px;
    min-width: 34px;
    font-family: var(--mono);
    font-size: 14px;
    line-height: 20px;
    text-align: right;
    color: var(--faint);
    background: var(--panel-2);
    border-right: 1px solid var(--line);
    overflow: hidden;
    user-select: none;
}

#novo-gutter .err {
    color: #fff;
    background: var(--warn);
    border-radius: 3px;
    padding: 0 3px;
}

.code-area {
    position: relative;
    flex: 1;
    overflow: hidden;
}

.code-area pre,
.code-area textarea {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 0;
    font-family: var(--mono);
    font-size: 14px;
    line-height: 20px;
    white-space: pre;
    tab-size: 4;
}

.code-area pre {
    overflow: hidden;
    color: var(--ink);
    pointer-events: none;
}

.code-area textarea {
    color: transparent;
    background: transparent;
    caret-color: var(--ink);
    outline: none;
    resize: none;
    overflow: auto;
}

.code-area textarea::selection {
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    color: transparent;
}

.hl-com { color: var(--faint); font-style: italic; }
.hl-op { color: var(--accent); font-weight: 600; }
.hl-reg { color: #8a4bc2; }
.hl-num { color: #b4532a; }
.hl-label { color: #a8650a; font-weight: 600; }
.hl-dir { color: #1d7fa6; font-weight: 600; }
.hl-str { color: var(--ok); }
.hl-bad { color: var(--warn); text-decoration: underline wavy var(--warn); }
.hl-err { background: color-mix(in srgb, var(--warn) 14%, transparent); text-decoration: underline wavy var(--warn); }

[data-theme='dark'] .hl-reg { color: #dcb6ff; }
[data-theme='dark'] .hl-num { color: #ffb68a; }
[data-theme='dark'] .hl-label { color: #ffd479; }
[data-theme='dark'] .hl-dir { color: #8fdcff; }

ul.errors {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    max-height: 120px;
    overflow: auto;
    color: var(--warn);
    font-size: 0.85rem;
}

ul.errors li {
    padding: 2px 0;
    cursor: pointer;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    margin: 0 0 12px;
    padding: 6px 14px 10px;
}

legend {
    font-weight: 600;
    padding: 0 4px;
}

table.groups {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 6px;
}

table.groups th {
    font-weight: 500;
    color: var(--muted);
    text-align: left;
    font-size: 0.9em;
}

table.groups td {
    padding: 4px 4px 4px 0;
    vertical-align: top;
    border-top: 1px solid var(--line);
}

table.groups input[type='number'] {
    width: 48px;
}

table.groups td.classes label,
table.groups td.units label {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    margin-right: 8px;
    white-space: nowrap;
}

.latencies {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    column-gap: 18px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

/* Exercício e comparação ---------------------------------------------------------------------------------- */

#sheet {
    position: absolute;
    inset: 0;
    overflow: auto;
    z-index: 16;
    background: var(--bg);
}

.sheet-inner {
    padding: 14px 24px 48px;
    font-size: 0.9rem;
}

.sheet-inner h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 4px 0 8px;
}

.sheet-inner > p {
    max-width: 80ch;
    color: var(--muted);
}

.sheet-inner .panel {
    margin-bottom: 14px;
}

.ex-grid,
.compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 14px;
}

pre.code {
    font-family: var(--mono);
    font-size: 0.9em;
    margin: 0;
    max-height: 320px;
    overflow: auto;
}

ul.summary {
    margin: 0;
    padding-left: 18px;
}

ul.summary li {
    margin: 2px 0;
}

table.exercise input {
    width: 64px;
    text-align: center;
}

table.exercise input.right {
    background: var(--ok-soft);
    border-color: var(--ok);
}

table.exercise input.wrong {
    background: var(--bad-soft);
    border-color: var(--warn);
}

table.exercise input.revealed {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.ex-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 12px;
}

.ex-actions .btn:not(.primary) {
    border-color: var(--line);
}

.score {
    font-weight: 600;
    color: var(--accent);
    margin-left: 6px;
}

p.big {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent);
}

.compare-timeline {
    overflow: auto;
    max-height: 460px;
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
}

/* Pipeline ------------------------------------------------------------------------------------------------ */

.pipe-wrap {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.pipe-head {
    display: flex;
    gap: 14px;
    align-items: baseline;
}

.pipe-head .sub {
    color: var(--muted);
}

.pcbox {
    font-family: var(--mono);
    font-weight: 600;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2px 10px;
}

.pcbox.focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 2px var(--focus);
}

.pipe-row {
    display: flex;
    align-items: stretch;
}

.panel.stage {
    width: 190px;
    min-height: 170px;
}

.panel.stage.busy {
    background: color-mix(in srgb, var(--tag) 9%, var(--panel));
    border-color: color-mix(in srgb, var(--tag) 55%, var(--line));
}

.panel.stage h3 {
    font-size: 1.1rem;
}

.latch {
    width: 24px;
    margin: 0 4px;
    background: repeating-linear-gradient(0deg, var(--line), var(--line) 5px, var(--panel-2) 5px, var(--panel-2) 10px);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.latch span {
    writing-mode: vertical-rl;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.pinst {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 3px 6px;
    margin-bottom: 6px;
}

.pinst.stalled {
    outline: 2px dashed var(--warn);
}

.kv {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.9em;
    color: var(--muted);
}

.kv b {
    font-family: var(--mono);
    font-weight: 500;
    color: var(--ink);
}

p.bubble {
    color: var(--faint);
    font-style: italic;
    text-align: center;
    margin-top: 40px;
}

.pipe-units {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.pipe-units .panel {
    min-width: 320px;
}

ul.fwd {
    margin: 0;
    padding-left: 18px;
    font-family: var(--mono);
}

.pipe-bottom,
.single-wrap {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.single-side {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Monociclo ----------------------------------------------------------------------------------------------- */

svg.datapath .w {
    fill: none;
    stroke: var(--wire);
    stroke-width: 2;
}

svg.datapath .w.on {
    stroke: var(--accent);
    stroke-width: 3;
}

svg.datapath .hd {
    fill: var(--wire);
    stroke: none;
}

svg.datapath .hd.on {
    fill: var(--accent);
}

svg.datapath .blk {
    fill: var(--panel);
    stroke: var(--line-strong);
    stroke-width: 2;
}

svg.datapath .blk.on {
    fill: var(--accent-soft);
    stroke: var(--accent);
}

svg.datapath .blk.focus {
    stroke: var(--focus);
    stroke-width: 4;
}

svg.datapath .bl {
    font-family: var(--sans);
    font-size: 14px;
    fill: var(--ink);
}

svg.datapath .bm {
    font-family: var(--sans);
    font-size: 11px;
    fill: var(--muted);
}

svg.datapath .val {
    font-family: var(--mono);
    font-size: 12.5px;
    font-weight: 600;
    fill: var(--warn);
    paint-order: stroke;
    stroke: var(--panel);
    stroke-width: 4px;
}

td.on {
    color: var(--accent);
    font-weight: 600;
}

@media (max-width: 760px) {
    #header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .brand {
        border-right: 0;
    }

    .brand-name {
        display: none;
    }

    .code-box {
        height: 40vh;
    }

    #control {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

/* Hierarquia de memória ----------------------------------------------------------------------------------- */

.panel.hierarchy {
    min-width: 280px;
}

.panel.hierarchy .level {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 6px 8px;
    margin-top: 8px;
}

.panel.hierarchy .level.hit {
    border-color: var(--ok);
    background: color-mix(in srgb, var(--ok) 7%, var(--panel));
}

.panel.hierarchy .level.miss {
    border-color: var(--warn);
    background: color-mix(in srgb, var(--warn) 6%, var(--panel));
}

.level-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.level-head .sub {
    color: var(--muted);
    font-size: 0.85em;
    flex: 1;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0 7px;
    border-radius: 8px;
}

.badge.hit {
    background: var(--ok-soft);
    color: var(--ok);
}

.badge.miss {
    background: var(--bad-soft);
    color: var(--warn);
}

/* Memória virtual */

.vm-split {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 4px 0;
    font-family: var(--mono, monospace);
    font-size: 0.85em;
}

.vm-f {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 2px 6px;
}

.vm-f.vpn {
    background: var(--accent-soft);
}

.vm-f b {
    margin-left: 2px;
}

.panel.hierarchy table.vm-walk {
    margin-top: 6px;
}

.panel.hierarchy td.cur,
.panel.hierarchy tr.cur td {
    background: var(--accent-soft);
    font-weight: 600;
}

table.levels input[type='number'] {
    width: 70px;
}

.panel table.perf {
    width: 100%;
}

.panel table.perf th,
.panel table.perf td {
    white-space: normal;
}

.panel table.perf tr.total th,
.panel table.perf tr.total td {
    border-top: 1px solid var(--line-strong);
}

.panel table.perf td.num {
    white-space: nowrap;
}

/* Figuras geradas em SVG (pipeline e Tomasulo) ------------------------------------------------------------ */

.panel.fig-panel {
    overflow-x: auto;
}

svg.fig {
    display: block;
    font-family: var(--sans);
    font-size: 12px;
}

svg.fig text {
    fill: var(--ink);
}

svg.fig text.small { font-size: 11.5px; }
svg.fig text.tiny { font-size: 10px; }
svg.fig text.mono { font-family: var(--mono); font-size: 11px; }
svg.fig text.mono.tiny { font-size: 10px; }
svg.fig text.strong { font-weight: 600; }
svg.fig text.italic { font-style: italic; }
svg.fig text.center { text-anchor: middle; }
svg.fig text.end { text-anchor: end; }
svg.fig text.dim { fill: var(--faint); }
svg.fig text.warn { fill: var(--warn); font-weight: 600; }
svg.fig text.val { fill: var(--warn); font-weight: 600; }

svg.fig rect,
svg.fig path.mux {
    fill: var(--panel);
    stroke: var(--line-strong);
    stroke-width: 1.5;
}

svg.fig .blk {
    fill: var(--panel);
    stroke: var(--line-strong);
    stroke-width: 1.5;
}

svg.fig .blk.on,
svg.fig path.mux.on {
    fill: var(--accent-soft);
    stroke: var(--accent);
}

svg.fig rect.latch {
    fill: color-mix(in srgb, var(--accent) 12%, var(--panel));
    stroke: var(--accent);
}

svg.fig rect.inst.empty {
    fill: var(--panel);
    stroke: var(--line);
    stroke-dasharray: 3 3;
}

svg.fig rect.inst.focus,
svg.fig rect.unit.focus,
svg.fig g.focus > rect.blk {
    stroke: var(--focus);
    stroke-width: 3;
}

svg.fig rect.unit {
    fill: color-mix(in srgb, var(--bg) 60%, var(--panel));
    stroke: var(--line-strong);
}

svg.fig rect.unit.on {
    fill: var(--focus-soft);
    stroke: var(--focus);
}

svg.fig rect.unit.off {
    stroke-dasharray: 3 3;
}

svg.fig .wire {
    fill: none;
    stroke: var(--wire);
    stroke-width: 1.8;
}

svg.fig .wire.on {
    stroke: var(--accent);
    stroke-width: 2.6;
}

svg.fig .wire.ctl {
    stroke-dasharray: 5 3;
    stroke-width: 1.4;
}

svg.fig .wire.ctl.on {
    stroke: var(--focus);
    stroke-width: 2;
}

svg.fig .wire.fwd.on {
    stroke: var(--ok);
}

svg.fig .head {
    fill: var(--wire);
    stroke: none;
}

svg.fig .head.on {
    fill: var(--accent);
}

svg.fig .head.ctl.on {
    fill: var(--focus);
}

svg.fig .head.fwd.on {
    fill: var(--ok);
}

svg.fig .dot {
    fill: var(--wire);
    stroke: none;
}

svg.fig .dot.on {
    fill: var(--accent);
}

svg.fig rect.tblbox {
    fill: var(--panel);
    stroke: var(--line-strong);
}

svg.fig rect.tblbox.focus {
    stroke: var(--focus);
    stroke-width: 3;
}

svg.fig rect.rowbg {
    stroke: none;
}

svg.fig rect.rowbg.focus {
    fill: var(--focus-soft);
    stroke: var(--focus);
    stroke-width: 1.5;
}

svg.fig line.sep {
    stroke: var(--line);
    stroke-width: 1;
}

svg.fig rect.tag {
    stroke-width: 1.2;
}

svg.fig text.imm {
    font-style: italic;
}

svg.fig path.fu {
    fill: color-mix(in srgb, var(--bg) 60%, var(--panel));
    stroke: var(--line-strong);
    stroke-width: 1.5;
}

svg.fig path.fu.on {
    fill: var(--accent-soft);
    stroke: var(--accent);
}

svg.fig rect.membox {
    fill: var(--c-mem);
    stroke: var(--line-strong);
}

svg.fig rect.membox.on {
    stroke: var(--accent);
    stroke-width: 2;
}

svg.fig rect.membox.focus {
    stroke: var(--focus);
    stroke-width: 3;
}

svg.fig .wire.bus {
    stroke-width: 4;
}

svg.fig .wire.cdb.on {
    stroke: var(--ok);
}

svg.fig .head.cdb.on {
    fill: var(--ok);
}

svg.fig g.focus > .wire.bus {
    stroke: var(--focus);
}
