/*
 * Simulador de Multiprocessamento 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 ----------------------------------------------------------------------------------------------- */

#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;
}


/* Ajuda */

#readme {
    display: none;
    position: fixed;
    inset: 0;
    overflow: auto;
    z-index: 40;
    background: var(--bg);
    scroll-behavior: smooth;
}

#readme.overlay {
    display: block;
}


.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;
}


.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;
    }
}


/* Editor de código */


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

.code-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;
}

.code-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;
}

/* Simulador de multiprocessamento ------------------------------------------------------------------------ */

:root,
[data-theme='light'] {
    --snp: #d9730d; --data: #23865b; --M: #d1495b; --O: #d9792b; --E: #9a5bc4; --S: #2f9e6e; --I: #b9c3d3; --hl: #fff4d4;
}

[data-theme='dark'] {
    --snp: #f2a04a; --data: #4cc58f; --I: #56627a; --hl: #3a3320;
}

#header .tools { margin-left: auto; }
main { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; padding: 16px; }
main section, main > div > section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
main h2 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
main label { display: block; font-size: 13px; margin: 6px 0; color: var(--muted); }
main select, main input { font: inherit; font-size: 0.85rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px 6px; }
.btn.outline { border-color: var(--line); }
.ctl .icon-btn { border-color: var(--line); }
.tabs { display: flex; margin: 8px 0; }
.tabs .btn { flex: 1; justify-content: center; border-color: var(--line); border-radius: 0; }
.tabs .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.tabs .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.tabs .btn.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.code-box { margin-top: 2px; }

table { border-collapse:collapse; font-size:13px; width:100%; } th, td { border-bottom:1px solid var(--line); padding:4px 6px; text-align:center; }
th { color:var(--muted); font-weight:600; } td.mono { font-family:'IBM Plex Mono',monospace; }
.st { display:inline-block; min-width:22px; padding:1px 5px; border-radius:4px; font-weight:700; color:#fff; }
.st.I { background:var(--I); color:var(--ink); } .st.S { background:var(--S); } .st.E { background:var(--E); } .st.M { background:var(--M); } .st.O { background:var(--O); }
td.chg { background:var(--hl); outline:2px solid var(--focus); outline-offset:-2px; }
#steps tr[data-i] { cursor:pointer; } #steps tr.cur td { background:color-mix(in srgb,var(--accent) 14%,var(--panel)); }
.note { color:var(--muted); font-size:13px; }  .row { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:16px; } @media (max-width:1000px){ main,.grid2{grid-template-columns:1fr;} }
.figs { display:flex; flex-wrap:wrap; gap:16px; align-items:flex-start; margin-top:10px; } .figs > div { max-width:100%; overflow-x:auto; }

/* Figuras em SVG */
.fig-svg text { font-family:'IBM Plex Sans',system-ui,sans-serif; font-size:12px; fill:var(--ink); }
.fig-svg .title { font-size:13px; font-weight:600; } .fig-svg .small { font-size:11px; } .fig-svg .mono { font-family:'IBM Plex Mono',monospace; }
.fig-svg .muted { fill:var(--muted); } .fig-svg .bold { font-weight:700; } .fig-svg .warn { fill:var(--M); font-weight:600; } .fig-svg .snptxt { fill:var(--snp); font-weight:600; }
.fig-svg .blk { fill:var(--panel); stroke:var(--ink); stroke-width:1.2; } .fig-svg .blk.act { stroke:var(--accent); stroke-width:2.4; }
.fig-svg .blk.inv { stroke:var(--M); stroke-width:1.8; stroke-dasharray:5 3; }
.fig-svg .rowhl { fill:color-mix(in srgb,var(--focus) 24%,var(--panel)); }
.fig-svg .chip.stM { fill:var(--M); } .fig-svg .chip.stO { fill:var(--O); } .fig-svg .chip.stE { fill:var(--E); } .fig-svg .chip.stS { fill:var(--S); } .fig-svg .chip.stI { fill:var(--I); }
.fig-svg .chipt { font-size:10px; font-weight:700; fill:#fff; } .fig-svg .chipt.tI { fill:var(--ink); }
.fig-svg .wire { fill:none; stroke:var(--muted); stroke-width:1.3; } .fig-svg .head { fill:var(--muted); }
.fig-svg .wire.on { stroke:var(--accent); stroke-width:2.4; } .fig-svg .head.on { fill:var(--accent); }
.fig-svg .wire.snp { stroke:var(--snp); stroke-width:2.4; } .fig-svg .head.snp { fill:var(--snp); }
.fig-svg .wire.data { stroke:var(--data); stroke-width:2.4; } .fig-svg .head.data { fill:var(--data); }
.fig-svg .wire.wb { stroke:var(--M); stroke-width:2.4; } .fig-svg .head.wb { fill:var(--M); }
.fig-svg .bus { stroke:var(--ink); stroke-width:3; } .fig-svg .bus.on { stroke:var(--accent); } .fig-svg .bus.data { stroke:var(--data); }
.fig-svg .dot { fill:var(--ink); }
.fig-svg .lblbg { fill:var(--panel); } .fig-svg .lbl { font-size:11px; } .fig-svg .lbl.on { fill:var(--accent); font-weight:700; }
.fig-svg .lbl.snp { fill:var(--snp); font-weight:700; } .fig-svg .who { font-size:10px; font-weight:700; fill:var(--ink); }
.fig-svg .edge { fill:none; stroke:var(--muted); stroke-width:1.4; } .fig-svg .edge.snoop { stroke-dasharray:6 4; }
.fig-svg .edge.on { stroke:var(--accent); stroke-width:3; } .fig-svg .edge.snp { stroke:var(--snp); stroke-width:3; }
.fig-svg .head.snoop { fill:var(--muted); } .fig-svg .head.snoop.snp { fill:var(--snp); }
.fig-svg .state { stroke:var(--ink); stroke-width:1.5; } .fig-svg .state.cur { stroke:var(--accent); stroke-width:4; }
.fig-svg .state.stM { fill:color-mix(in srgb,var(--M) 28%,var(--panel)); } .fig-svg .state.stO { fill:color-mix(in srgb,var(--O) 28%,var(--panel)); }
.fig-svg .state.stE { fill:color-mix(in srgb,var(--E) 28%,var(--panel)); } .fig-svg .state.stS { fill:color-mix(in srgb,var(--S) 28%,var(--panel)); }
.fig-svg .state.stI { fill:color-mix(in srgb,var(--I) 35%,var(--panel)); }
.fig-svg .stname { font-size:20px; font-weight:700; } .fig-svg .leg { font-size:11px; fill:var(--muted); }

