/* LGP-30 IDE shell — shared by the editor and debugger pages. Reuses
 * site.css's color/font tokens (--bg, --bg-alt, --fg, --fg-dim, --accent,
 * --accent-dim, --border, --mono); no historically-styled chrome here on
 * purpose, this is deliberately a generic-IDE look, see STYLING.md's
 * Emulator UI principle. */

.ide-shell {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ide-toolbar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    padding: 0.6rem 0.8rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
}

.ide-toolbar button,
.ide-toolbar select {
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    color: var(--fg);
    font-family: var(--sans);
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
}

.ide-toolbar button:disabled {
    opacity: 0.5;
    cursor: default;
}

.ide-toolbar button:hover:not(:disabled),
.ide-toolbar select:hover {
    border-color: var(--fg);
}

.ide-status {
    color: var(--fg-dim);
    margin-left: auto;
    display: flex;
    gap: 1.25rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.ide-status strong {
    color: var(--fg);
    font-weight: normal;
}

/* Resizable pane region */

.ide-panes {
    display: flex;
    flex-direction: row;
    height: 560px;
    border: 1px solid var(--border);
}

.ide-panes[data-direction="column"] {
    flex-direction: column;
    height: auto;
}

.ide-pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
}

.ide-pane-header {
    flex: 0 0 auto;
    padding: 0.4rem 0.6rem;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    color: var(--fg-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ide-pane-header button {
    background: none;
    border: none;
    color: var(--fg-dim);
    font-family: var(--mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
}

.ide-pane-header button:hover {
    color: var(--accent);
}

.ide-pane-body {
    flex: 1 1 auto;
    overflow: auto;
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.ide-splitter {
    flex: 0 0 6px;
    background: var(--border);
    cursor: col-resize;
    touch-action: none;
}

.ide-splitter--column {
    cursor: row-resize;
}

.ide-splitter:hover,
.ide-splitter:active {
    background: var(--accent-dim);
}

/* Listing pane */

.ide-listing-line {
    display: flex;
    gap: 0.5rem;
    white-space: pre;
    cursor: pointer;
    padding: 0 0.2rem;
}

.ide-listing-line:hover {
    background: rgba(184, 135, 63, 0.08);
}

.ide-listing-gutter {
    width: 1.4em;
    flex-shrink: 0;
    text-align: center;
    user-select: none;
    color: var(--accent);
}

.ide-listing-line.is-pc {
    background: rgba(184, 135, 63, 0.2);
}

.ide-listing-line.is-breakpoint .ide-listing-gutter {
    color: #e05a5a;
}

/* Registers pane */

.ide-register-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.2rem 0;
    border-bottom: 1px dashed var(--border);
}

.ide-register-row:last-child {
    border-bottom: none;
}

.ide-register-row .ide-reg-label {
    color: var(--fg-dim);
}

.ide-register-row .ide-reg-value {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Drum tape — a re-rendered window centered on the current sector, not a
 * real scroll list (see debugger.js's renderDrumTape). */

.ide-drum-row {
    display: flex;
    gap: 0.6rem;
    white-space: pre;
    padding: 0.05rem 0.2rem;
    font-variant-numeric: tabular-nums;
}

.ide-drum-row.is-current {
    background: rgba(184, 135, 63, 0.25);
}

/* Sectors the drum turned past during the last step (rotational latency). */
.ide-drum-row.is-swept {
    background: rgba(127, 176, 214, 0.1);
}

.ide-drum-marker {
    width: 1em;
    flex-shrink: 0;
    color: var(--accent);
}

.ide-drum-sector {
    width: 2em;
    flex-shrink: 0;
    color: var(--fg-dim);
}

.ide-drum-addr {
    width: 4.5em;
    flex-shrink: 0;
    color: var(--accent);
}

.ide-drum-value {
    color: var(--fg);
}

/* Memory pane — flat hex grid, all 4096 words, built once and updated in
 * place (see debugger.js's buildMemoryGrid/renderMemoryGrid). */

.ide-memory-row {
    display: flex;
    gap: 0.5rem;
    white-space: pre;
    padding: 0.05rem 0.5rem;
    font-variant-numeric: tabular-nums;
}

.ide-memory-row:hover {
    background: rgba(184, 135, 63, 0.06);
}

.ide-memory-addr {
    width: 3.2em;
    flex-shrink: 0;
    color: var(--accent);
}

.ide-memory-cell {
    width: 5.4em;
    flex-shrink: 0;
    color: var(--fg-dim);
}

.ide-memory-cell.is-sector {
    color: var(--fg);
    background: rgba(184, 135, 63, 0.1);
}

.ide-memory-cell.is-current {
    color: var(--fg);
    background: rgba(184, 135, 63, 0.3);
}

/* Last step's accesses — outlined rather than filled so they stay legible
 * on top of the sector stripe when they coincide with it. */
.ide-memory-cell.is-fetch,
.ide-drum-row.is-fetch .ide-drum-value {
    color: var(--fg);
    outline: 1px solid #7fb0d6;
    outline-offset: -1px;
}

.ide-memory-cell.is-read,
.ide-drum-row.is-read .ide-drum-value {
    color: var(--fg);
    outline: 1px solid #8cc084;
    outline-offset: -1px;
}

.ide-memory-cell.is-write,
.ide-drum-row.is-write .ide-drum-value {
    color: var(--fg);
    outline: 1px solid #e0883a;
    outline-offset: -1px;
}

.ide-memory-legend {
    display: flex;
    gap: 0.4rem;
    font-size: 0.65rem;
    text-transform: none;
}

.ide-memory-legend .ide-memory-cell {
    width: auto;
    padding: 0 0.3rem;
}

/* On/off switch (the Flexowriter's Manual and 6-bit Input): a sliding knob in a
 * track, so it reads as a control rather than a label. Selector is
 * specific enough to beat .ide-pane-header button's plain-text style. */
.ide-pane-header button.ide-toggle {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.15rem 0.5rem 0.15rem 0.25rem;
    border: 1px solid var(--accent-dim);
    border-radius: 999px;
    color: var(--fg);
}

.ide-pane-header button.ide-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ide-toggle-track {
    position: relative;
    width: 1.9rem;
    height: 0.95rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--fg-dim);
    transition: background 0.15s;
}

.ide-toggle-knob {
    position: absolute;
    top: 1px;
    left: 1px;
    width: calc(0.95rem - 4px);
    height: calc(0.95rem - 4px);
    border-radius: 50%;
    background: var(--fg-dim);
    transition: left 0.15s, background 0.15s;
}

.ide-toggle[aria-pressed="true"] .ide-toggle-track {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.ide-toggle[aria-pressed="true"] .ide-toggle-knob {
    left: calc(1.9rem - 0.95rem + 1px);
    background: var(--accent);
}

/* Flexowriter (public/js/ide/flexowriter-pane.js): a full-width band
 * between the debugger's two pane rows, collapsible to its header. Paper
 * and tape invert to dark ink on light stock, like .lesson-paper in
 * site.css — physical things, not UI. */

.ide-panes[data-pane-region="debugger"] {
    height: 900px;
}

.ide-panes[data-pane-region="debugger"].has-flexo-open {
    height: 1190px;
}

.ide-flexo {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    --paper: #ece2cd;
    --ink: #2c2015;
    --ink-red: #a8321e;
    --tape: #d9c9a0;
}

.ide-flexo-header {
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    border-top: 1px solid var(--border);
}

.ide-pane-header button.ide-flexo-title {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--fg);
    padding: 0;
}

.ide-flexo-chevron::before {
    content: '▾';
    display: inline-block;
    transition: transform 0.15s;
}

.ide-flexo.is-collapsed .ide-flexo-chevron::before {
    transform: rotate(-90deg);
}

.ide-flexo-status {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.75rem;
    margin-right: auto;
}

.ide-flexo-status.is-waiting {
    color: var(--accent);
    animation: ide-flexo-pulse 1.2s ease-in-out infinite;
}

@keyframes ide-flexo-pulse {
    50% { opacity: 0.45; }
}

.ide-flexo-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.ide-flexo.is-collapsed .ide-flexo-body {
    display: none;
}

.ide-flexo-body {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 36rem) minmax(0, 1fr);
    gap: 1rem;
    height: 280px;
    padding: 0.7rem;
    border: 1px solid transparent;
    cursor: text;
}

.ide-flexo-body.is-typing {
    border-color: var(--accent-dim);
}

.ide-flexo-paper {
    overflow: auto;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre;
    padding: 0.6rem 0.9rem;
}

.ide-flexo-paper .is-red {
    color: var(--ink-red);
}

.ide-flexo-carriage {
    border-bottom: 2px solid var(--accent);
}

.ide-flexo-body.is-typing .ide-flexo-carriage {
    animation: ide-flexo-pulse 1s steps(2) infinite;
}

/* The keyboard: a real input (so phones raise a keyboard), kept out of
 * sight. Clicking the band focuses it. */
.ide-flexo-keys {
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.ide-flexo-side {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-width: 0;
    font-size: 0.8rem;
}

.ide-flexo-tape {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 7px;
    overflow: hidden;
    padding: 0.35rem 0.5rem 0.2rem;
    background: var(--tape);
    color: var(--ink);
}

/* Channel numbers down the left edge, in the manual's order. */
.ide-flexo-tape-key,
.ide-flexo-tape-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 0.8rem;
}

.ide-flexo-tape-key {
    margin-right: 0.3rem;
    padding-right: 0.4rem;
    border-right: 1px dashed rgba(0, 0, 0, 0.2);
}

.ide-flexo-tape-key span {
    height: 8px;
    font-family: var(--mono);
    font-size: 0.55rem;
    line-height: 8px;
    color: #7a6a4a;
}

.ide-flexo-tape-key .ide-flexo-feed-key {
    height: 4px;
    line-height: 4px;
    margin: 1px 0;
}

.ide-flexo-tape-empty {
    color: #7a6a4a;
    align-self: center;
    margin: 0 auto;
}

.ide-flexo-tape-col.is-read {
    opacity: 0.3;
}

.ide-flexo-hole,
.ide-flexo-feed {
    border-radius: 50%;
}

.ide-flexo-hole {
    width: 8px;
    height: 8px;
}

.ide-flexo-hole.is-punched {
    background: var(--bg);
}

.ide-flexo-feed {
    width: 4px;
    height: 4px;
    margin: 1px 0;
    background: var(--bg);
}

.ide-flexo-tape-label {
    font-family: var(--mono);
    font-size: 0.7rem;
    line-height: 1.2;
}

/* The reader head: everything left of it has been read. */
.ide-flexo-reader {
    flex: 0 0 2px;
    align-self: stretch;
    background: var(--accent);
    margin: -0.35rem 0 -0.2rem;
}

.ide-flexo-tape-actions {
    display: flex;
    gap: 0.5rem;
}

.ide-flexo-tape-actions button {
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    color: var(--fg);
    font-family: var(--sans);
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    cursor: pointer;
}

.ide-flexo-tape-actions button:hover {
    border-color: var(--fg);
}

.ide-flexo-readout {
    color: var(--fg);
}

.ide-flexo-acc {
    font-family: var(--mono);
    color: var(--fg-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ide-flexo-acc .is-new {
    color: var(--accent);
    font-weight: bold;
}

.ide-flexo-acc-label {
    font-family: var(--sans);
}

.ide-flexo-acc-word {
    color: var(--fg);
}

.ide-flexo-hint {
    margin-top: auto;
    color: var(--fg-dim);
}

.ide-flexo-hint.is-flash {
    color: var(--accent);
}

@media (max-width: 900px) {
    .ide-flexo-body {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
    }

    .ide-flexo-paper {
        height: 9rem;
    }
}

/* Editor page */

.ide-editor-body {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ide-file-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ide-file-list li {
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.ide-file-list li.is-active {
    background: var(--bg-alt);
    color: var(--accent);
}

.ide-editor-host {
    flex: 1 1 auto;
    overflow: hidden;
    min-height: 0;
}

.ide-editor-host .cm-editor {
    height: 100%;
    font-family: var(--mono);
    font-size: 0.9rem;
}

.ide-editor-host .cm-scroller {
    overflow: auto;
}

/* Quick-help panel — a toggleable overlay-ish panel, not a modal (keeps
 * DOM simple; it just replaces the toolbar row below it). */

.ide-help-panel {
    display: none;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
}

.ide-help-panel.is-open {
    display: block;
}

.ide-help-panel h3 {
    color: var(--accent);
    margin-top: 0;
}

.ide-help-panel h4 {
    color: var(--fg-dim);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    margin-bottom: 0.4rem;
}

table.ide-opcode-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 1.5rem;
}

table.ide-opcode-table th,
table.ide-opcode-table td {
    text-align: left;
    padding: 0.3rem 0.6rem 0.3rem 0;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.ide-opcode-table th {
    color: var(--fg-dim);
    font-weight: normal;
    text-transform: uppercase;
    font-size: 0.7rem;
}

table.ide-opcode-table td:first-child {
    color: var(--accent);
    font-weight: bold;
}

.ide-help-links {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.ide-assemble-error {
    color: #e0883a;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    white-space: pre-wrap;
}

@media (max-width: 900px) {
    .ide-panes {
        flex-direction: column !important;
        height: auto !important;
    }

    .ide-splitter {
        display: none;
    }
}

/* Program storage (editor) */

.ide-save-status[data-state="saving"] {
    color: var(--fg-dim);
}

.ide-save-status[data-state="error"] {
    color: #e0883a;
}

/* Tips pane (editor + debugger) — a muted paper panel against the dark
 * chrome: pale brown body, darker bar for the "Tips" header. */
.ide-tips {
    background: #d8cbad;
    color: #33281b;
    border: 1px solid #8a7350;
    font-size: 0.85rem;
}

.ide-tips summary {
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    background: #b9a47c;
    color: #2a2015;
    font-weight: bold;
    letter-spacing: 0.04em;
    user-select: none;
}

.ide-tips[open] summary {
    border-bottom: 1px solid #8a7350;
}

.ide-tips-body {
    padding: 0.5rem 0.8rem;
}

.ide-tips-body p {
    margin: 0 0 0.5rem;
}

.ide-tips-body p:last-child {
    margin-bottom: 0;
}

.ide-tips a {
    color: #6b3f0c;
}

.ide-tips code {
    color: inherit;
    background: rgba(43, 36, 27, 0.08);
    padding: 0 0.2em;
}

/* Editor: guests' "saved in this browser only" note. */
.ide-browser-storage-note {
    font-size: 0.85rem;
    margin: 0;
    padding: 0.5rem 0.8rem;
    color: var(--fg-dim);
    border: 1px solid var(--border);
}

.ide-storage-notice {
    font-size: 0.85rem;
    margin: 0;
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--accent);
    background: var(--accent-dim);
}

.ide-storage-notice[data-kind="error"] {
    border-color: #e0883a;
}

.ide-file-list li.ide-file-group {
    cursor: default;
    color: var(--fg-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--bg-alt);
}

.ide-drum-caption {
    color: var(--fg-dim);
    font-size: 0.75rem;
    padding: 0 0.2rem 0.3rem;
    white-space: nowrap;
}

.ide-program-name {
    display: inline-block;
    max-width: 18em;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

.ide-memory-follow {
    background: none;
    border: none;
    color: var(--fg-dim);
    font: inherit;
    font-size: 0.65rem;
    text-transform: none;
    cursor: pointer;
    padding: 0;
    margin-right: auto;
    margin-left: 0.8rem;
}

.ide-memory-follow.is-paused {
    color: var(--accent);
}

/* Code and machine data stay monospace now that the body font is sans:
 * listing, register values, drum tape, memory grid and I/O output. */
[data-pane-id="listing"] .ide-pane-body,
[data-pane-id="registers"] .ide-pane-body,
[data-pane-id="drum"] .ide-pane-body,
[data-pane-id="memory"] .ide-pane-body,
.ide-flexo-paper {
    font-family: var(--mono);
}
