:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #d97706;
    --green: #4ade80;
    --red: #f87171;
    --orange: #fb923c;
    --font-mono: "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
}
body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Top bar ──────────────────────────────────────────────────────── */

.top-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent);
    white-space: nowrap;
}

.logo { height: 28px; width: auto; }

.game-nav {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.game-nav button {
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
}

.game-nav button small { opacity: 0.5; font-size: 0.6rem; }
.game-nav button:hover { border-color: var(--accent); color: var(--text); }
.game-nav button.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* Bottom status bar — IDE-style thin strip for compile meta, status,
   memory. Keeps the top-bar uncrowded (game nav already wraps) and
   gives long status text room to breathe with ellipsis truncation. */
.status-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.45rem 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.75rem;
    color: var(--muted);
    font-family: var(--font-mono);
    min-height: 2rem;
    flex-shrink: 0;
}
.status-bar .status-spacer { flex: 1; }
.status-bar [data-status] {
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.isolation-note {
    padding: 0.45rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(217, 119, 6, 0.12);
    color: var(--muted);
    font-size: 0.75rem;
}

.isolation-note code {
    background: rgba(15, 23, 42, 0.8);
    color: var(--text);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

[data-tone="success"] { color: var(--green); }
[data-tone="error"] { color: var(--red); }
[data-tone="info"] { color: var(--accent); }
[data-tone="warn"] { color: #fbbf24; }

/* ── Workspace (editor + output) ──────────────────────────────────── */

.workspace {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ── Editor pane ──────────────────────────────────────────────────── */

.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-width: 300px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.editor-toolbar button,
.editor-toolbar select {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
}

.editor-toolbar button:hover,
.editor-toolbar select:hover { border-color: var(--accent); }

[data-compile-run] {
    background: var(--accent) !important;
    color: var(--bg) !important;
    border-color: var(--accent) !important;
    font-weight: 600;
}

.btn-stop {
    color: var(--red) !important;
    border-color: rgba(248, 113, 113, 0.45) !important;
    font-weight: 600;
}
.btn-stop:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.1) !important;
    border-color: var(--red) !important;
}

/* Tool-specific accent borders — invite clicks without shouting.
   Each command's color matches its role: Audit = verification green,
   Why = justification purple, Context = navigation teal. */
.btn-audit {
    color: var(--green) !important;
    border-color: rgba(74, 222, 128, 0.45) !important;
    font-weight: 600;
}
.btn-audit:hover {
    background: rgba(74, 222, 128, 0.1) !important;
    border-color: var(--green) !important;
}
/* Hostile re-run as a verify-section header action — sits beside
   the regular ↻ re-run, distinct red accent so the user sees this
   is the harder/adversarial path. Hidden when the section has no
   verify blocks. */
.rerun-btn.audit-action-hostile {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.45);
    border-style: dashed;
}
.rerun-btn.audit-action-hostile:hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: #f87171;
}

/* Hostile-mode panel cosmetics. Subtle red tint so the user sees
   that the report on screen is the adversarial-world reading,
   distinguishing it visually from a regular declared audit. */
.audit-panel.hostile-mode {
    border-left: 3px solid rgba(248, 113, 113, 0.5);
    padding-left: 0.75rem;
    background: linear-gradient(
        to right,
        rgba(248, 113, 113, 0.04),
        transparent 30%
    );
}
.audit-panel.hostile-mode .audit-header-row .title {
    color: #f87171;
}

/* Easter egg — narrative one-liner that drops in when the hostile
   audit lands. Reads like a stage direction: "world has been
   substituted." Same red accent as the panel; dashed-bar prefix so
   it stands apart from real diagnostics. */
.hostile-easter-egg {
    margin: 0.6rem 0 0.9rem;
    padding: 0.5rem 0.75rem;
    border-left: 2px dashed #f87171;
    background: rgba(248, 113, 113, 0.06);
    color: rgba(248, 113, 113, 0.85);
    font-family: var(--font-mono, monospace);
    font-size: 0.78em;
    font-style: italic;
    letter-spacing: 0.01em;
    line-height: 1.5;
    animation: hostile-flicker 2.4s ease-out;
}
@keyframes hostile-flicker {
    0%   { opacity: 0; transform: translateX(-4px); }
    8%   { opacity: 0.95; }
    10%  { opacity: 0.4; }
    14%  { opacity: 0.95; }
    18%  { opacity: 0.5; }
    22%  { opacity: 0.95; transform: translateX(0); }
    100% { opacity: 1; }
}
.btn-why {
    color: #c084fc !important;
    border-color: rgba(192, 132, 252, 0.45) !important;
    font-weight: 600;
}
.btn-why:hover {
    background: rgba(192, 132, 252, 0.1) !important;
    border-color: #c084fc !important;
}
.btn-context {
    color: #38bdf8 !important;
    border-color: rgba(56, 189, 248, 0.45) !important;
    font-weight: 600;
}
.btn-context:hover {
    background: rgba(56, 189, 248, 0.1) !important;
    border-color: #38bdf8 !important;
}
/* Trace toolbar button — opens the Recording panel (which owns the
   record/replay/import/download flow). Amber so it's visually in the
   same family as effects-as-orange throughout the rest of the UI. */
.btn-trace {
    color: #fbbf24 !important;
    border-color: rgba(251, 191, 36, 0.45) !important;
    font-weight: 600;
}
.btn-trace:hover {
    background: rgba(251, 191, 36, 0.1) !important;
    border-color: #fbbf24 !important;
}
.btn-trace.has-recording {
    color: #fb923c !important;
    border-color: rgba(251, 146, 60, 0.55) !important;
}

/* ── Recording panel ─────────────────────────────────────────────── */
.recording-panel {
    background: var(--surface);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 6px;
    margin: 0.75rem;
    overflow: hidden;
}
.recording-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    background: rgba(251, 191, 36, 0.08);
    border-bottom: 1px solid var(--border);
}
.recording-header .title {
    font-weight: 600;
    color: #fbbf24;
    font-size: 0.85rem;
}
.recording-header .rec-btn,
.recording-event .rec-btn {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 3px;
    cursor: pointer;
    font-family: inherit;
}
.recording-header .rec-btn:hover,
.recording-event .rec-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}
.recording-header .rec-btn.rec-primary {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.45);
}
.recording-header .rec-btn.rec-primary:hover {
    background: rgba(251, 191, 36, 0.1);
}
.recording-header .rec-btn.rec-close {
    color: var(--muted);
    padding: 0.15rem 0.4rem;
    font-size: 0.85rem;
}
.recording-replay-banner {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.recording-replay-banner .icon { font-weight: 700; font-size: 0.85rem; }
.recording-replay-banner.match {
    background: rgba(74, 222, 128, 0.1);
    color: #4ade80;
}
.recording-replay-banner.prefix {
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8;
}
.recording-replay-banner.diverge {
    background: rgba(248, 113, 113, 0.12);
    color: #f87171;
}

.recording-outcome {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    color: var(--muted);
    font-family: var(--font-mono);
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}
.recording-outcome.capped {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
}
.recording-outcome.capped .label { color: #fbbf24; font-weight: 600; }
.recording-outcome.capped code { color: #fde68a; }
.recording-outcome .label { margin-right: 0.4rem; color: var(--muted); }
.recording-outcome .label.err { color: var(--red, #f87171); }
.recording-outcome code { color: var(--text); }
.recording-empty {
    padding: 0.75rem;
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
    text-align: center;
}
/* Independent-product grouping — effects inside a `?!` / `!` boxed
   so the trace panel visually reflects Aver's core concurrency
   semantics. Left border in accent colour, branches stacked with
   small labels so the reader sees which branch produced what. */
.recording-group {
    border-left: 3px solid rgba(56, 189, 248, 0.55);
    border-radius: 4px;
    background: rgba(56, 189, 248, 0.05);
    margin: 0.35rem 0.5rem 0.35rem 0.25rem;
}
.recording-group-header {
    padding: 0.35rem 0.6rem;
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    color: #38bdf8;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    border-bottom: 1px dashed rgba(56, 189, 248, 0.2);
    background: rgba(56, 189, 248, 0.05);
}
.recording-group-label {
    font-weight: 600;
    text-transform: uppercase;
}
.recording-group-hint {
    color: var(--muted);
    font-style: italic;
    font-size: 0.7rem;
    cursor: help;
}
.recording-group-branches { display: flex; flex-direction: column; }
.recording-branch {
    border-top: 1px dashed rgba(56, 189, 248, 0.15);
    padding-left: 0.4rem;
}
.recording-branch:first-child { border-top: none; }
.recording-branch-label {
    padding: 0.2rem 0.5rem;
    color: #38bdf8;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.7;
}
.recording-group-header .rec-btn {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
}
.recording-branch-add {
    padding: 0.25rem 0.75rem 0.4rem;
    display: flex;
    justify-content: flex-start;
}
.recording-branch-add .rec-btn {
    font-size: 0.68rem;
    padding: 0.2rem 0.55rem;
    background: transparent;
    border: 1px dashed rgba(56, 189, 248, 0.35);
    color: #38bdf8;
}
.recording-branch-add .rec-btn:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: #38bdf8;
}

.recording-events {
    /* No own scroll — the enclosing .console-surface scrolls the
       whole Trace panel, so short traces use minimal height and
       long ones expand to fill the available pane. */
}
.recording-event {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}
.recording-event:last-child { border-bottom: none; }
.recording-event .ev-head {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.recording-event .ev-head .ev-spacer { flex: 1; }
.recording-event .ev-seq {
    color: var(--muted);
    font-size: 0.7rem;
}
.recording-event .ev-type {
    color: #f97316;
    font-weight: 600;
}
.recording-event .ev-type-edit {
    background: transparent;
    border: 1px dashed transparent;
    color: #f97316;
    font-weight: 600;
    font-family: inherit;
    font-size: inherit;
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    /* Auto-sizing via the `size` attribute (set from JS); CSS just
       sets a sensible floor so an empty input still reads as a field. */
    min-width: 6rem;
    width: auto;
    box-sizing: content-box;
}
.recording-event .ev-type-edit:hover { border-color: var(--border); }
.recording-event .ev-type-edit:focus {
    border-color: var(--accent);
    background: var(--bg);
    outline: none;
}
.recording-event .ev-args-row {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    color: var(--muted);
}
.recording-event .ev-side-label { color: var(--muted); }
.recording-event .ev-args-edit {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}
.recording-event .ev-args-edit:focus {
    border-color: var(--accent);
    outline: none;
}
.recording-event .ev-args-edit.invalid { border-color: var(--red, #f87171); }
.recording-event .ev-caller {
    color: var(--muted);
    font-size: 0.68rem;
    font-style: italic;
}
.recording-event .ev-args {
    color: var(--muted);
    word-break: break-all;
}
.recording-event .ev-outcome {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.recording-event .ev-arrow {
    color: var(--accent);
    font-weight: 600;
}
.recording-event .ev-arrow.err { color: var(--red, #f87171); }
.recording-event .ev-outcome-edit {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
    border-radius: 3px;
}
.recording-event .ev-outcome-edit:focus {
    border-color: var(--accent);
    outline: none;
}
.recording-event .ev-outcome-edit.invalid {
    border-color: var(--red, #f87171);
}
.recording-event .ev-outcome-edit.err {
    color: #fca5a5;
}
.recording-event .ev-actions {
    display: flex;
    gap: 0.2rem;
}
.recording-intro {
    padding: 0.9rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
}
.recording-intro p { margin-bottom: 0.6rem; line-height: 1.5; }
.recording-intro .rec-btn.rec-primary { font-size: 0.78rem; padding: 0.35rem 0.8rem; }

.recording-append {
    padding: 0.6rem 0.75rem;
    display: flex;
    justify-content: center;
    background: rgba(251, 191, 36, 0.04);
}
.recording-append .rec-btn {
    font-size: 0.75rem;
    padding: 0.35rem 1rem;
    background: transparent;
    border: 1px dashed rgba(251, 191, 36, 0.45);
    color: #fbbf24;
    letter-spacing: 0.02em;
    font-weight: 600;
    transition: background 0.12s, border-color 0.12s;
}
.recording-append .rec-btn:hover {
    background: rgba(251, 191, 36, 0.1);
    border-color: #fbbf24;
    border-style: solid;
    color: #fde68a;
}
.rec-btn[disabled] {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-download {
    color: var(--muted) !important;
    border-color: var(--border) !important;
}
.btn-download:hover {
    color: var(--text) !important;
    border-color: var(--accent) !important;
}

/* Download dropdown — small caret button glued to the main download
 * button, plus a popup list below with the four export formats. */
.download-group {
    position: relative;
    display: inline-flex;
}
.download-group .btn-download {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    margin-right: 0;
}
.btn-download-toggle {
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    padding: 0.32rem 0.5rem;
    font-size: 0.78rem;
    cursor: pointer;
    line-height: 1;
}
.btn-download-toggle:hover {
    color: var(--text);
    border-color: var(--accent);
}
.download-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
    background: var(--surface, #1e293b);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    min-width: 180px;
}
.download-menu li { margin: 0; }
.download-menu button {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    font: inherit;
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
}
.download-menu button:hover {
    background: rgba(148, 163, 184, 0.08);
    color: var(--accent);
}
.download-menu .dl-ext {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--muted);
}
.download-menu button:hover .dl-ext { color: var(--accent); }
.btn-subtle { opacity: 0.6; }
.btn-subtle:hover { opacity: 1; }
.toolbar-spacer { flex: 1; }

.compile-meta {
    font-size: 0.75rem;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.3rem;
    font-family: var(--font-mono);
    white-space: nowrap;
}
.compile-meta:empty { display: none; }
.compile-meta .size-label { color: var(--muted); }
.compile-meta .size-main { color: var(--text); }
.compile-meta .compile-footnote {
    color: var(--accent);
    cursor: help;
    font-weight: 600;
    margin-left: -0.15rem;
}

/* Drop target moved to the editor area itself. When something is
   being dragged over the wrap, dim-tint and outline so the user
   knows the drop will land. JS toggles `data-drag="true"` on the
   wrap node. */
.editor-wrap[data-drag="true"] {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    background: rgba(74, 222, 128, 0.04);
}

/* "+ N more failures" button at the end of a capped issue list.
   Subtle muted look — it's an info / continuation cue, not a
   primary action. */
.diag-expand-more {
    display: block;
    margin: 0.6rem 0 0.3rem;
    padding: 0.35rem 0.6rem;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 3px;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.8em;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color 80ms ease, border-color 80ms ease;
}
.diag-expand-more:hover {
    color: var(--text);
    border-color: var(--accent);
}

.editor-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0.2rem 0.3rem 0;
    background: rgba(15, 23, 42, 0.6);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    min-height: 1.9rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}
.editor-tabs:empty { display: none; }
.editor-tabs .tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.45rem 0.25rem 0.55rem;
    border: 1px solid transparent;
    border-bottom: none;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.1s, background 0.1s, border-color 0.1s;
}
.editor-tabs .tab:hover { color: var(--text); background: rgba(148, 163, 184, 0.08); }
.editor-tabs .tab.active {
    color: var(--text);
    background: var(--bg);
    border-color: var(--border);
}
.editor-tabs .tab .tab-close {
    color: var(--muted);
    padding: 0 0.2rem;
    line-height: 1;
    border-radius: 2px;
    font-size: 0.85em;
    cursor: pointer;
}
.editor-tabs .tab .tab-close:hover { color: var(--red); background: rgba(248, 113, 113, 0.1); }
.editor-tabs .tab-dirty::after {
    content: "●";
    color: var(--accent);
    font-size: 0.7em;
    margin-left: 0.15rem;
}
.editor-tabs .tab-new {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--muted);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    margin-left: 0.3rem;
}
.editor-tabs .tab-new:hover { color: var(--accent); border-color: var(--accent); }

.editor-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}
.editor-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 2rem;
    background: rgba(15, 23, 42, 0.92);
    color: var(--text);
    text-align: center;
    font-family: system-ui, -apple-system, sans-serif;
}
.editor-overlay strong {
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
}
.editor-overlay p {
    max-width: 32rem;
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0;
}

.editor-highlight, [data-code-editor] {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: auto;
    border: none;
}

.editor-highlight {
    color: var(--text);
    background: var(--bg);
    pointer-events: none;
    z-index: 0;
}

[data-code-editor] {
    background: transparent;
    color: transparent;
    caret-color: var(--text);
    resize: none;
    outline: none;
    z-index: 1;
}

/* Syntax colors */
.hl-keyword { color: #c084fc; }
.hl-fn { color: #67e8f9; }
.hl-type { color: #fde68a; }
.hl-builtin { color: #fde68a; }
.hl-string { color: #86efac; }
.hl-desc { color: #86efac; font-style: italic; }
.hl-number { color: #fda4af; }
.hl-constant { color: #fda4af; }
.hl-comment { color: #64748b; font-style: italic; }
.hl-effect { color: #f97316; font-weight: 600; }
.hl-operator { color: #94a3b8; }

/* ── Output pane ──────────────────────────────────────────────────── */

.output-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    min-height: 0;
    background: #111827;
}

/* Terminal */
.terminal-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #111827;
}

.terminal-surface {
    flex: 1;
    padding: 0.5rem 0.75rem 0 1rem;
    outline: none;
    overflow: hidden;
    box-sizing: border-box;
}

.terminal-canvas {
    image-rendering: pixelated;
}

.terminal-empty {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.terminal-hint {
    padding: 0.3rem 0.75rem;
    font-size: 0.7rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

/* Console */
.console-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.console-surface {
    flex: 1;
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.console-surface .stdout { color: var(--text); }
.console-surface .stderr { color: var(--red); }
.console-surface .warning { color: var(--orange); }
.console-surface .success { color: var(--green); }
.console-surface .section-title {
    color: var(--muted);
    font-weight: 600;
    margin-top: 0.5rem;
    padding-top: 0.3rem;
    border-top: 1px solid var(--border);
}
.console-surface .section-hint {
    color: var(--muted);
    font-style: italic;
    opacity: 0.75;
}

/* ── Audit sections (collapsible) ─────────────────────────────── */
.audit-panel {
    padding: 0.5rem 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text);
    overflow-y: auto;
    height: 100%;
    /* Override parent `.console-surface` word-break: break-all so
       words don't split mid-token in the structured panel. */
    word-break: normal;
    overflow-wrap: break-word;
    white-space: normal;
}
.audit-panel .diag-line {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
}
.audit-section {
    margin-bottom: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.03);
}
.audit-section > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.55rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    border-radius: 6px;
    user-select: none;
}
.audit-section > summary::-webkit-details-marker { display: none; }
.audit-section > summary::before {
    content: "▸";
    display: inline-block;
    transition: transform 0.15s;
    color: var(--muted);
    width: 0.8rem;
    font-size: 0.7em;
}
.audit-section[open] > summary::before { transform: rotate(90deg); }
.audit-section .section-label { flex: 1; }
.audit-section .status-pass { color: var(--green); margin-right: 0.3rem; }
.audit-section .status-fail { color: var(--red); margin-right: 0.3rem; }
.audit-section .status-warn { color: var(--orange); margin-right: 0.3rem; }
.audit-section .status-count { color: var(--muted); font-weight: 400; font-size: 0.88em; }
.audit-section .rerun-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.78rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.audit-section .rerun-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.audit-section .section-body {
    padding: 0.4rem 0.9rem 0.7rem 1.9rem;
    border-top: 1px solid var(--border);
}
.audit-section .teach {
    color: var(--muted);
    font-style: italic;
    font-size: 0.8rem;
    margin-bottom: 0.6rem;
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.45;
}
.audit-section .diag-line {
    padding: 0.1rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.audit-section .diag-err { color: var(--red); }
.audit-section .diag-warn { color: var(--orange); }
.audit-section .diag-ok { color: var(--green); }
.audit-section .diag-meta {
    color: var(--muted);
    padding-left: 1.2rem;
    font-size: 0.85em;
}
.audit-section .diag-repair {
    color: var(--accent);
    padding-left: 1.2rem;
    font-size: 0.85em;
}
.audit-section .diag-snippet-line {
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--muted);
    white-space: pre;
    padding: 0;
    line-height: 1.35;
}
.audit-section .diag-snippet-caret {
    font-weight: 700;
}
.audit-section .diag-snippet-caret.diag-err { color: var(--red); }
.audit-section .diag-snippet-caret.diag-warn { color: var(--orange); }
/* Invisible copy of the source so the highlighted range above sits
   at the exact same column widths regardless of glyph — plain
   " ".repeat(col-1) drifts on em-dash / CJK / emoji. */
.audit-section .diag-snippet-ghost { color: transparent; }

/* ── Shared download button for panels ────────────────────────── */
.ctx-header-row, .audit-header-row, .why-header-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}
.ctx-header-row { flex: 1; }
.audit-header-row, .why-header-row {
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.6rem;
}
.audit-header-row .title, .why-header-row .title {
    flex: 1;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    font-family: system-ui, -apple-system, sans-serif;
}
.ctx-header-row h2 { flex: 1; }
.ctx-download-btn, .download-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: system-ui, -apple-system, sans-serif;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.ctx-download-btn:hover, .download-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(217, 119, 6, 0.08);
}

/* ── Context panel (markdown-style rendered) ──────────────────── */
.context-panel {
    padding: 0.9rem 1.1rem;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 0.88rem;
    color: var(--text);
    overflow-y: auto;
    height: 100%;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.5;
}
.context-panel h2 {
    font-size: 1.05rem;
    margin: 0 0 0.4rem 0;
    color: #38bdf8;
}
.context-panel h3 {
    font-size: 0.95rem;
    margin: 1rem 0 0.4rem 0;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.context-panel blockquote {
    margin: 0.3rem 0 0.8rem 0;
    padding-left: 0.8rem;
    border-left: 3px solid rgba(56, 189, 248, 0.4);
    color: var(--text);
    font-style: italic;
}
.context-panel .ctx-meta { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.3rem; }
.context-panel .ctx-meta code {
    color: var(--text);
    background: rgba(148, 163, 184, 0.1);
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}
.context-panel .ctx-fn {
    margin: 0.8rem 0;
    padding: 0.5rem 0.7rem;
    background: rgba(148, 163, 184, 0.04);
    border-left: 3px solid var(--border);
    border-radius: 3px;
}
.context-panel .ctx-fn.exposed { border-left-color: var(--green); }
.context-panel .ctx-fn-sig { font-family: var(--font-mono); font-size: 0.88rem; color: var(--text); }
.context-panel .ctx-fn-desc { color: var(--muted); font-style: italic; margin-top: 0.2rem; font-size: 0.82rem; }
.context-panel .ctx-tags { margin-top: 0.25rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.context-panel .ctx-tag {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: rgba(148, 163, 184, 0.15);
    color: var(--muted);
    font-family: var(--font-mono);
}
.context-panel .ctx-tag.effect { color: #fb923c; background: rgba(251, 146, 60, 0.12); }
.context-panel .ctx-tag.pure { color: var(--green); background: rgba(74, 222, 128, 0.12); }
.context-panel .ctx-verify { margin-top: 0.35rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.context-panel .ctx-verify-sample { padding-left: 1rem; color: var(--text); opacity: 0.85; }
.context-panel .ctx-type { margin: 0.4rem 0; font-family: var(--font-mono); font-size: 0.85rem; }
.context-panel .ctx-type-kind { color: #c084fc; font-weight: 600; margin-right: 0.3rem; }
.context-panel .ctx-decision {
    margin: 0.6rem 0;
    padding: 0.5rem 0.7rem;
    background: rgba(217, 119, 6, 0.06);
    border-left: 3px solid var(--accent);
    border-radius: 3px;
}
.context-panel .ctx-decision-name { font-weight: 600; color: var(--accent); }
.context-panel .ctx-decision-date { color: var(--muted); font-size: 0.8rem; }
.context-panel .ctx-decision-reason { color: var(--text); font-style: italic; margin-top: 0.25rem; font-size: 0.85rem; }
.context-panel .ctx-empty { color: var(--muted); font-style: italic; font-size: 0.82rem; }

.readline-bar {
    display: flex;
    gap: 0.3rem;
    padding: 0.4rem 0.6rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.readline-bar input {
    flex: 1;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    outline: none;
}

.readline-bar input:focus { border-color: var(--accent); }

.readline-bar button {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
}

/* ── Header links ────────────────────────────────────────────────── */

.intro-link {
    font-size: 0.75rem;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
}
.intro-link:hover { color: var(--accent); }

/* ── About overlay ───────────────────────────────────────────────── */

.about-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.about-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    position: relative;
}

.about-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}
.about-close:hover { color: var(--text); }

.about-card h2 {
    font-size: 1.5rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.about-tagline {
    color: var(--muted);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.about-features {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.about-feature strong {
    color: var(--text);
    display: block;
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}

.about-feature span {
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

.about-feature code {
    background: var(--bg);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

.about-example {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.about-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.about-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
}
.about-links a:hover { text-decoration: underline; }

/* ── Layout modes ─────────────────────────────────────────────────── */

/* When terminal is visible, console hides */
.output-pane[data-mode="terminal"] .console-wrap { display: none; }
.output-pane[data-mode="terminal"] .terminal-wrap { display: flex !important; flex: 1; }

/* When console is active, terminal hides */
.output-pane[data-mode="console"] .terminal-wrap { display: none !important; }
.output-pane[data-mode="console"] .console-wrap { display: flex; flex: 1; }

/* Draggable divider between editor and output panes. Replaces the
   old in-game-layout divider; always present so the user can resize
   code vs console/terminal regardless of game/edit mode. */
.workspace-divider {
    width: 6px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.15s;
}
.workspace-divider:hover, .workspace-divider.dragging { background: var(--accent); }

/* ── Touch controls (mobile gamepad) ─────────────────────────────── */

.touch-controls {
    display: flex;
    gap: 0.9rem;
    padding: 0.75rem 0.85rem 0.8rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    justify-content: center;
    align-items: flex-start;
    flex-shrink: 0;
}


.touch-group { text-align: center; }

.touch-label {
    font-size: 0.62rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}

.touch-controls button {
    width: 38px;
    height: 38px;
    font-size: 0.8rem;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

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

/* Keyboard layout for WASD and arrows */
.touch-grid {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(2, 40px);
    gap: 5px;
}

/* QWE / ASD layout */
.wasd button:nth-child(1) { grid-column: 1; grid-row: 1; } /* Q */
.wasd button:nth-child(2) { grid-column: 2; grid-row: 1; } /* W */
.wasd button:nth-child(3) { grid-column: 3; grid-row: 1; } /* E */
.wasd button:nth-child(4) { grid-column: 1; grid-row: 2; } /* A */
.wasd button:nth-child(5) { grid-column: 2; grid-row: 2; } /* S */
.wasd button:nth-child(6) { grid-column: 3; grid-row: 2; } /* D */

/*   ↑  / ←↓→ layout */
.arrows button:nth-child(1) { grid-column: 2; grid-row: 1; } /* ↑ */
.arrows button:nth-child(2) { grid-column: 1; grid-row: 2; } /* ← */
.arrows button:nth-child(3) { grid-column: 2; grid-row: 2; } /* ↓ */
.arrows button:nth-child(4) { grid-column: 3; grid-row: 2; } /* → */

.touch-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 144px;
}


/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .top-bar {
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .intro-link { display: none; }
    .game-nav { order: 3; width: 100%; }

    .workspace {
        flex-direction: column;
    }
    .editor-pane {
        min-width: 0;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .output-pane {
        min-width: 0;
        min-height: 200px;
    }
    .workspace-divider {
        display: none;
    }
}
