/* Custom tooltip styling */
[title] {
    position: relative;
    cursor: help;
}

[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #3a3a5c;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 18px;
    line-height: 1.4;
    white-space: nowrap;
    z-index: 2000;
    pointer-events: none;
    font-weight: 400;
}

/* Top-level tabs (below header) */
.top-tabs {
    display: flex;
    gap: 2px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.top-tab {
    background: transparent;
    color: var(--dim);
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 22px;
    font-family: var(--mono);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    text-transform: lowercase;
    letter-spacing: 0.5px;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.top-tab:hover {
    color: var(--text);
}

.top-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--dim);
    font-size: 13px;
    font-weight: 700;
    cursor: help;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    vertical-align: middle;
}

.tab-help:hover {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.top-tab.active .tab-help {
    border-color: var(--accent);
    color: var(--accent);
}

.top-tab.active .tab-help:hover {
    background: var(--accent);
    color: var(--bg);
}

/* Debugger layout */
.debugger {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Simplified REPL (forth-in-forth tab): output panel takes full width. */
.repl-simple .output-panel.repl-output-panel {
    flex: 1;
    border-right: none;
}

.switch.switch-disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.switch.switch-disabled:hover {
    transform: none;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.toolbar button {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 14px;
    font-family: var(--mono);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
}

.toolbar button:hover {
    background: var(--border);
}

.toolbar button.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.toolbar select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 18px;
}

.toolbar .tier-desc {
    font-size: 18px;
    color: var(--dim);
    margin-left: 4px;
}

.demo-select {
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 18px;
    cursor: pointer;
}

.upload-btn {
    background: var(--surface) !important;
    color: var(--green) !important;
    border: 1px solid var(--green) !important;
    border-radius: 4px;
    padding: 6px 10px !important;
    font-family: var(--mono);
    font-size: 15px !important;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.upload-btn:hover {
    background: var(--green) !important;
    color: var(--bg) !important;
}

.about-btn {
    background: var(--surface) !important;
    color: var(--accent) !important;
    border: 1px solid var(--accent) !important;
    border-radius: 4px;
    padding: 6px 10px !important;
    font-family: var(--mono);
    font-size: 15px !important;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.about-btn:hover {
    background: var(--accent) !important;
    color: var(--bg) !important;
}

/* Memory map */
.memory-map {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.memory-map-label {
    font-size: 18px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* Main panels */
.panels {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Output / terminal panel (60%) */
.output-panel {
    flex: 60;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    border-right: 1px solid var(--border);
    position: relative;
}

.output-panel .output {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
    font-size: 18px;
    line-height: 1.5;
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-all;
}

/* Forth panel (25%) */
.forth-panel {
    flex: 25;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-right: 1px solid var(--border);
}

/* COR24 panel (15%) */
.cor24-panel {
    flex: 15;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
}

.panel-section h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Register display */
.registers {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 12px;
    font-size: 18px;
}

.registers .reg-name {
    color: var(--dim);
}

.registers .reg-value {
    color: var(--text);
    text-align: right;
}

.registers .reg-value.changed {
    color: var(--yellow);
}

/* Stack display */
.stack-display {
    font-size: 18px;
}

.stack-display .stack-empty {
    color: var(--dim);
    font-style: italic;
}

.stack-display .stack-entry {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.stack-display .stack-index {
    color: var(--dim);
    min-width: 28px;
    text-align: right;
}

.stack-display .stack-value {
    color: var(--text);
}

.stack-display .stack-tos {
    color: var(--accent);
    font-size: 18px;
}

/* Caller chain */
.caller-chain {
    font-size: 18px;
}

.caller-entry {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.caller-depth {
    color: var(--dim);
    min-width: 16px;
}

.caller-name {
    color: var(--accent);
    flex: 1;
}

.caller-addr {
    color: var(--dim);
    font-size: 18px;
}

/* Status bar */
.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 20px;
    font-size: 18px;
    color: var(--dim);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.status-bar .status-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-bar .status-label {
    color: var(--dim);
}

.status-bar .status-value {
    color: var(--text);
}

/* Floating hardware panel (top-right of output) */
.hw-float {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    background: rgba(17, 17, 34, 0.85);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hw-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hw-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--dim);
    min-width: 26px;
}

.led {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    transition: all 0.15s;
}

.led-off {
    background: #222;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.led-on {
    background: radial-gradient(circle at 30% 30%, #ff5555, #ff0000, #cc0000);
    box-shadow: 0 0 14px #ff0000, 0 0 28px rgba(255,0,0,0.3);
}

.switch {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.switch-off {
    background: linear-gradient(to bottom, #444, #222);
    border: 1px solid #555;
}

.switch-on {
    background: linear-gradient(to bottom, #00d9ff, #0099cc);
    border: 1px solid #00d9ff;
    box-shadow: 0 0 10px rgba(0, 217, 255, 0.4);
}

.switch:hover {
    transform: scale(1.1);
}

.switch:active {
    transform: scale(0.95);
}

.hw-sep {
    border-top: 1px solid var(--border);
    margin: 2px 0;
}

.hw-stats {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 10px;
    font-size: 18px;
}

.hw-stat-label {
    color: var(--dim);
}

.hw-stat-value {
    color: var(--text);
    font-family: var(--mono);
}

/* Input bar */
.input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-bar .prompt {
    color: var(--accent);
    font-size: 18px;
    font-weight: 700;
}

.input-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 18px;
    outline: none;
}

.input-bar.input-busy .prompt {
    color: var(--dim);
    animation: spin 1s linear infinite;
}

.input-bar.input-busy input::placeholder {
    color: var(--dim);
}

.input-bar.input-ready .prompt {
    color: #4ec94e;
}

@keyframes spin {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Memory region bar */
.region-bar {
    display: flex;
    height: 18px;
    border-radius: 3px;
    overflow: hidden;
    font-size: 18px;
    flex: 1;
}

.region-bar .region {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    font-weight: 700;
    min-width: 2px;
    transition: width 0.3s;
}

.region-bar .region-kernel { background: #585b70; }
.region-bar .region-dict { background: var(--accent); }
.region-bar .region-free { background: #2a2a44; }
.region-bar .region-rstack { background: var(--orange); }
.region-bar .region-dstack { background: var(--green); }

/* Disassembly view */
.disasm-view {
    font-size: 18px;
    line-height: 1.6;
}

.disasm-label {
    color: var(--accent);
    font-size: 18px;
    font-weight: 700;
    padding: 2px 4px 0;
    opacity: 0.8;
}

.disasm-line {
    display: flex;
    gap: 6px;
    padding: 1px 4px;
    border-radius: 2px;
    cursor: pointer;
    user-select: none;
}

.disasm-line:hover {
    background: rgba(255, 255, 255, 0.06);
}

.disasm-line.disasm-current {
    background: rgba(102, 204, 255, 0.15);
    color: var(--accent);
}

.disasm-line.disasm-breakpoint .disasm-bp-gutter {
    color: var(--red);
}

.disasm-bp-gutter {
    width: 12px;
    flex-shrink: 0;
    text-align: center;
    color: transparent;
    font-size: 18px;
    line-height: 1.6;
}

.disasm-line:hover .disasm-bp-gutter {
    color: var(--dim);
}

.disasm-line.disasm-breakpoint .disasm-bp-gutter {
    color: var(--red);
}

.disasm-addr {
    color: var(--dim);
    flex-shrink: 0;
}

.disasm-current .disasm-addr {
    color: var(--accent);
}

.disasm-instr {
    color: var(--text);
    white-space: pre;
}

.disasm-current .disasm-instr {
    color: var(--accent);
    font-weight: 700;
}

/* Disabled button styling */
.toolbar button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Bottom tab panel */
.bottom-tabs {
    padding: 0;
}

.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    background: transparent;
    color: var(--dim);
    border: none;
    padding: 8px 16px;
    font-family: var(--mono);
    font-size: 18px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Dictionary panel */
.dict-panel {
    padding: 8px;
}

.dict-list {
    max-height: 200px;
    overflow-y: auto;
}

.dict-entry {
    display: flex;
    gap: 8px;
    padding: 3px 4px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
}

.dict-entry:hover {
    background: rgba(255, 255, 255, 0.06);
}

.dict-entry.dict-selected {
    background: rgba(102, 204, 255, 0.15);
}

.dict-addr {
    color: var(--dim);
    font-size: 18px;
    flex-shrink: 0;
}

.dict-name {
    color: var(--text);
    flex: 1;
}

.dict-kind {
    font-size: 18px;
    padding: 0 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

.dict-primitive .dict-kind {
    color: var(--green);
}

.dict-colon .dict-kind {
    color: var(--accent);
}

.dict-thread .dict-kind {
    color: var(--orange);
}

/* Word inspector */
.word-inspector {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.word-inspector h4 {
    font-size: 18px;
    color: var(--accent);
    margin-bottom: 6px;
    font-weight: 700;
}

.word-thread, .prim-disasm {
    font-size: 18px;
}

.thread-entry {
    display: flex;
    gap: 8px;
    padding: 2px 4px;
}

.thread-addr {
    color: var(--dim);
    flex-shrink: 0;
}

.thread-name {
    color: var(--text);
}

.word-inspector-empty {
    padding: 12px 8px;
    color: var(--dim);
    font-size: 18px;
    font-style: italic;
}

/* Compile log */
.compile-log {
    padding: 8px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 18px;
}

.log-line {
    display: flex;
    gap: 8px;
    padding: 2px 4px;
    line-height: 1.5;
}

.log-line.log-label-line {
    margin-top: 4px;
}

.log-addr {
    color: var(--dim);
    flex-shrink: 0;
    min-width: 48px;
}

.log-bytes {
    color: var(--yellow);
    flex-shrink: 0;
    min-width: 110px;
    font-size: 18px;
}

.log-source {
    color: var(--text);
    white-space: pre;
    overflow: hidden;
    text-overflow: ellipsis;
}

.log-label-line .log-source {
    color: var(--accent);
}

/* About dialog */
.about-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.about-dialog {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: min(720px, 92vw);
    max-height: 85vh;
    color: var(--text);
    font-family: var(--mono);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.about-content {
    padding: 30px 40px;
    overflow-y: auto;
}

.about-close {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 1;
    margin: 0;
    padding: 2px 10px 4px;
    background: transparent;
    color: var(--dim);
    border: none;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.about-close:hover {
    color: var(--text);
    background: var(--border);
}

.about-dialog h2 {
    color: var(--accent);
    margin: 0 0 10px 0;
    font-size: 24px;
}

.about-dialog h3 {
    color: var(--text);
    margin: 15px 0 8px 0;
    font-size: 18px;
}

.about-dialog p {
    color: var(--dim);
    font-size: 18px;
    margin: 8px 0;
    line-height: 1.5;
}

.about-dialog pre {
    background: var(--bg);
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1.6;
    color: var(--green);
    overflow-x: auto;
}

.about-hint {
    font-size: 13px !important;
}

.about-dialog button {
    margin-top: 15px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    padding: 8px 24px;
    font-family: var(--mono);
    font-size: 18px;
    cursor: pointer;
}

/* Toolbar "Help" button — orange-accented sibling of .about-btn. Lives
 * in each tab's toolbar next to About, well clear of the GitHub corner. */
.help-btn {
    background: var(--surface) !important;
    color: var(--orange) !important;
    border: 1px solid var(--orange) !important;
    border-radius: 4px;
    padding: 6px 10px !important;
    font-family: var(--mono);
    font-size: 15px !important;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.help-btn:hover {
    background: var(--orange) !important;
    color: var(--bg) !important;
}

/* Global Help dialog — reuses .about-overlay for the backdrop. */
.help-dialog {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: min(960px, 94vw);
    max-height: 88vh;
    color: var(--text);
    font-family: var(--mono);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.help-tabs {
    display: flex;
    gap: 2px;
    padding: 10px 14px 0 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.help-tab {
    background: transparent;
    color: var(--dim);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 6px 16px;
    font-family: var(--mono);
    font-size: 14px;
    cursor: pointer;
    margin-bottom: -1px;
}

.help-tab:hover {
    color: var(--text);
    background: var(--bg);
}

.help-tab.active {
    color: var(--accent);
    background: var(--surface);
    border-color: var(--border);
    border-bottom-color: var(--surface);
}

/* Rendered markdown content from docs/*.md (pulldown-cmark → HTML).
 * Scoped styles so doc output doesn't affect the rest of the app. */
.help-md {
    padding: 18px 28px 24px 28px;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--surface);
}

.help-md h1,
.help-md h2,
.help-md h3,
.help-md h4 {
    color: var(--accent);
    margin: 18px 0 10px 0;
    line-height: 1.2;
}

.help-md h1 { font-size: 22px; margin-top: 6px; }
.help-md h2 { font-size: 18px; }
.help-md h3 { font-size: 15px; color: var(--text); }
.help-md h4 { font-size: 14px; color: var(--dim); }

.help-md p {
    margin: 8px 0;
}

.help-md a {
    color: var(--accent);
    text-decoration: underline;
}

.help-md a:hover {
    color: var(--orange);
}

.help-md ul,
.help-md ol {
    margin: 8px 0 10px 0;
    padding-left: 24px;
}

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

.help-md code {
    background: var(--bg);
    color: var(--green);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 13px;
}

.help-md pre {
    background: var(--bg);
    padding: 10px 14px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 10px 0;
}

.help-md pre code {
    background: transparent;
    padding: 0;
    color: var(--green);
}

.help-md table {
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
    width: auto;
    max-width: 100%;
}

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

.help-md th {
    background: var(--bg);
    color: var(--accent);
    font-weight: 700;
}

.help-md td code {
    white-space: nowrap;
}

.help-md strong {
    color: var(--text);
    font-weight: 700;
}

.help-md em {
    color: var(--dim);
    font-style: italic;
}

.help-md hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

.word-inspector-dialog {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.file-preview-dialog {
    max-width: 650px;
    max-height: 80vh;
    overflow-y: auto;
}

.file-preview {
    background: var(--bg);
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1.6;
    color: var(--green);
    overflow-x: auto;
    max-height: 50vh;
    overflow-y: auto;
}

.dialog-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.dialog-buttons .run-btn {
    background: var(--green);
    color: var(--bg);
}

.dialog-buttons button {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    padding: 8px 24px;
    font-family: var(--mono);
    font-size: 18px;
    cursor: pointer;
}
