/*
 * Turbo8bit - Commodore 64 Learning Website
 *
 * Colour system. The page is built around the emulated screen, in three
 * layers:
 *
 * --c64-*   The VIC-II's sixteen colours, the same values as PALETTE in
 *           js/emulator/vic-ii.js, so a colour on the page and on the
 *           emulated screen are the same colour. For anything that stands
 *           for the machine: the header and footer frame, swatches,
 *           selected-state fills.
 * --ui-*    Surfaces, lines and text for everything else. They take the C64
 *           blue's hue at low chroma and stay darker than the emulated
 *           screen, so the screen is always the brightest, most saturated
 *           thing on the page. Pure greys look dirty next to it.
 * --tint-*  Palette hues lifted so they pass WCAG AA as text on the --ui
 *           surfaces; most palette entries are too dark to read there
 *           (light blue on a panel is 3.2:1).
 *
 * Roles: yellow is the current or focused thing, light blue a selected
 * option, green runs, red stops or resets, cyan labels and links.
 */

:root {
    /* VIC-II palette (VICE "pepto-pal"); keep in step with vic-ii.js */
    --c64-black: #000000;
    --c64-white: #FFFFFF;
    --c64-red: #68372B;
    --c64-cyan: #70A4B2;
    --c64-purple: #6F3D86;
    --c64-green: #588D43;
    --c64-blue: #352879;
    --c64-yellow: #B8C76F;
    --c64-orange: #6F4F25;
    --c64-brown: #433900;
    --c64-light-red: #9A6759;
    --c64-dark-grey: #444444;
    --c64-grey: #6C6C6C;
    --c64-light-green: #9AD284;
    --c64-light-blue: #6C5EB5;
    --c64-light-grey: #959595;

    /* The header and footer frame the page the way the C64's border frames
       its screen. tools/gen_favicons.py puts the logo on the same blue. */
    --brand-bg: var(--c64-blue);
    --brand-edge: var(--c64-light-blue);
    --brand-text: var(--c64-white);
    --brand-text-muted: #CFCDEE;

    /* Surfaces, darkest first */
    --ui-sunken: #0A0918;   /* editors, logs, scopes */
    --ui-page: #121126;
    --ui-panel: #1B1931;
    --ui-raised: #252440;   /* buttons, inputs, table headers */
    --ui-hover: #302E50;

    --ui-line-soft: #303049;
    --ui-line: #444367;
    --ui-line-strong: #5F5D8C;

    /* Text, strongest first. Faint is for hints, placeholders and off
       states; it is the quietest that still reads at 4.5:1 on --ui-raised. */
    --ui-text: #E7E7F0;
    --ui-text-muted: #C2C2D2;
    --ui-text-dim: #9C9CB2;
    --ui-text-faint: #8C8DA4;

    --tint-light-blue: #B1A9F3;
    --tint-cyan: #89CADB;
    --tint-yellow: #CBDB82;
    --tint-green: #A3DE8C;
    --tint-red: #E7917A;
    --tint-orange: #E6B374;
    --tint-purple: #CA97E3;

    /* Dark grounds for the run, step and stop buttons */
    --go-bg: #1F3515;
    --step-bg: #2E3410;
    --stop-bg: #492015;

    /* One scheme for the editor and the quick-start listings, so code in
       the guides looks like the code it is copied into */
    --syntax-keyword: var(--tint-purple);
    --syntax-string: var(--tint-yellow);
    --syntax-number: var(--tint-light-blue);
    --syntax-variable: var(--tint-cyan);
    --syntax-function: var(--tint-green);
    --syntax-line-number: var(--tint-orange);
    --syntax-comment: var(--ui-text-dim);
    --syntax-error: var(--tint-red);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    background-color: var(--ui-page);
    color: var(--ui-text);
    min-height: 100vh;
    font-size: 1rem;
    line-height: 1.6;
}

/* Header */
.site-header {    
    background-color: var(--brand-bg);
    border-bottom: 4px solid var(--brand-edge);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    padding: 0rem 2rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Site brand (logo + wordmark) */
.site-brand {
    display: flex;
    align-items: center;
    gap: 18px;
    height: 100px;
    padding: 4px 8px;
    text-decoration: none;
    user-select: none;
}

.site-brand-logo {
    height: 100%;
    width: auto;
    display: block;
}

.site-brand-text {
    font-family: 'Michroma', sans-serif;
    font-size: 1.375rem;
    color: var(--brand-text);
    letter-spacing: 1px;
    line-height: 1;
}

.site-brand:hover .site-brand-text {
    color: var(--tint-yellow);
}

.main-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: auto;
}

.main-nav a {
    color: var(--brand-text-muted);
    font-size: 1.1rem;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.main-nav a:hover {
    color: var(--brand-text);
    border-color: var(--tint-light-blue);
}

/* Current page indicator */
.main-nav a.active {
    color: var(--tint-yellow);
    border-color: var(--tint-yellow);
}

/* User Authentication */
.user-auth {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-auth .user-name {
    color: var(--brand-text);
    font-size: 0.75rem;
}

.user-auth .auth-btn {
    background: var(--c64-light-blue);
    color: var(--c64-white);
    border: none;
    padding: 0.25rem 0.75rem;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.user-auth .auth-btn:hover {
    background: var(--tint-yellow);
    color: var(--c64-blue);
}

/* Footer: the C64's own READY screen, light blue on blue */
.site-footer {
    background-color: var(--brand-bg);
    border-top: 4px solid var(--brand-edge);
    padding: 2rem 2rem 1.5rem;
    text-align: center;
}

.site-footer .ready-prompt {
    color: var(--tint-light-blue);
    font-size: 1rem;
    margin-bottom: 1rem;
}

.site-footer .footer-text {
    color: var(--brand-text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.site-footer .footer-tagline {
    color: var(--tint-light-blue);
    font-size: 0.8125rem;
}

/* Main Content */
.main-content {
    min-height: calc(100vh - 200px);
}

/* Read by screen readers and search engines but not drawn: each page's h1 (base.html),
   since every page opens straight into its tool. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Responsive header/footer */
@media (max-width: 768px) {
    .site-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .main-nav a {
        padding: 0.4rem 0.6rem;
        font-size: 0.875rem;
    }
    
    .site-footer {
        padding: 1rem;
        font-size: 0.8125rem;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--ui-sunken);
}

::-webkit-scrollbar-thumb {
    background: var(--ui-line-strong);
    border: 2px solid var(--ui-sunken);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--c64-light-blue);
}

/* ======================================
   UNIFIED TWO-PANEL LAYOUT SYSTEM
   
   Design Philosophy:
   All screens follow a consistent two-panel layout:
   - Main workspace: Two equal 50% panels side-by-side
   - Full available vertical height
   - Information section below (multi-column for wide screens)
   - Responsive: stacks vertically on narrow screens
   ====================================== */

/* Main workspace container - fills available height */
.workspace {
    display: flex;
    gap: 20px;
    padding: 20px;
    min-height: calc(100vh - 140px);  /* Account for header + footer */
    box-sizing: border-box;
}

/* Left panel - 50% width */
.workspace-primary {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

/* Right panel - 50% width */
.workspace-secondary {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

/* Panel inner content wrapper */
.panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    padding: 15px;
    overflow: hidden;
}

/* Panel header with title and controls */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.panel-header h2 {
    color: var(--tint-cyan);
    font-size: 1rem;
    margin: 0;
}

/* Panel body - fills remaining space */
.panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Information section below workspace - multi-column layout */
.info-section-below {
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px 20px;
}

.info-section-below h2 {
    color: var(--tint-light-blue);
    font-size: 1.5rem;
    margin-bottom: 20px;
    text-align: center;
}

.info-section-below > p {
    color: var(--ui-text-muted);
    text-align: center;
    max-width: 800px;
    margin: 0 auto 25px;
    line-height: 1.6;
}

/* Multi-column content within info section */
.info-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

.info-column {
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    border-radius: 8px;
    padding: 20px;
}

.info-column h3 {
    color: var(--tint-yellow);
    font-size: 1.1rem;
    margin-bottom: 15px;
}

.info-column p {
    color: var(--ui-text-muted);
    line-height: 1.6;
    margin-bottom: 10px;
}

.info-column ul {
    margin: 10px 0 10px 20px;
    color: var(--ui-text-muted);
}

.info-column li {
    margin-bottom: 8px;
}

.info-column code {
    background: var(--ui-raised);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--tint-cyan);
    font-size: 0.9em;
}

/* Responsive: Stack panels vertically on narrow screens */
@media (max-width: 1024px) {
    .workspace {
        flex-direction: column;
        min-height: auto;
        padding: 15px;
    }
    
    .workspace-primary,
    .workspace-secondary {
        flex: none;
        width: 100%;
        min-height: 400px;
    }
    
    .info-columns {
        grid-template-columns: 1fr;
    }
}

/* ======================================
   C64 EMULATOR PAGE
   ====================================== */

.c64-page {
    display: flex;
    gap: 20px;
    padding: 20px 30px 20px 20px;
    min-height: calc(100vh - 100px);
    box-sizing: border-box;
}

/* Emulator column - left side (50%) */
.c64-emulator-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.c64-emulator-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* The frame is what goes full screen; the stage is the 4:3 picture that the
   canvas, the inspector's cell marker and the CRT overlay all share. */
.screen-frame {
    width: 725px;
    max-width: 100%;
}

.screen-stage {
    position: relative;
    width: 100%;
    /* 272px of VIC output at 2x, widened to the original CRT's 4:3 ratio */
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

#screen {
    display: block;
    background: var(--c64-blue);
    border-radius: 10px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    width: 100%;
    height: 100%;
    transition: box-shadow 0.2s, filter 0.3s;
}

#screen.drag-over {
    box-shadow: 0 0 30px color-mix(in srgb, var(--tint-cyan) 80%, transparent), 0 0 10px color-mix(in srgb, var(--tint-cyan) 50%, transparent) inset;
}

.screen-frame:fullscreen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--c64-black);
}

.screen-frame:fullscreen .screen-stage {
    width: min(100vw, 133.33vh);
    box-shadow: none;
}

.screen-frame:fullscreen #screen,
.screen-frame:fullscreen .screen-stage {
    border-radius: 0;
}

/* An old TV: a darkened gap under every raster line, a vignette and a
   little bloom. The gradient repeats once per C64 line at any display size. */
.screen-frame.crt .screen-stage::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.5) 100%),
        linear-gradient(to bottom, transparent 55%, rgba(0, 0, 0, 0.28) 55%);
    background-size: 100% 100%, 100% calc(100% / 272);
}

.screen-frame.crt #screen {
    filter: saturate(1.3) contrast(1.08) brightness(1.1) blur(0.4px);
}

.screen-frame.crt .screen-stage {
    box-shadow: 0 0 28px color-mix(in srgb, var(--c64-light-blue) 45%, transparent), 0 0 20px rgba(0,0,0,0.5);
}

/* Screen toolbar in the panel header */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.screen-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.screen-toolbar button {
    background: var(--ui-raised);
    color: var(--ui-text-muted);
    border: 1px solid var(--ui-line);
    border-radius: 4px;
    padding: 4px 10px;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.screen-toolbar button:hover {
    border-color: var(--c64-light-blue);
    color: var(--ui-text);
}

.screen-toolbar button[aria-pressed="true"] {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
}

.screen-toolbar button.active[data-screen-action="turbo"] {
    background: var(--c64-light-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
}

/* PAUSED / TURBO over the picture */
.screen-badge {
    position: absolute;
    top: 14px;
    right: 16px;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--tint-yellow);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    letter-spacing: 1px;
    pointer-events: none;
}

.screen-badge.turbo {
    color: var(--tint-green);
}

/* The character cell under the pointer */
.screen-cell-marker {
    position: absolute;
    outline: 2px solid var(--c64-yellow);
    outline-offset: 1px;
    box-shadow: 0 0 8px var(--c64-yellow);
    pointer-events: none;
}

/* Inspector readout under the screen */
.screen-inspector {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 725px;
    max-width: 100%;
    min-height: 66px;
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    border-radius: 6px;
}

.inspector-glyph {
    flex: none;
    width: 44px;
    height: 44px;
    image-rendering: pixelated;
    border: 1px solid var(--ui-line);
}

.inspector-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.inspector-title {
    color: var(--ui-text);
    font-size: 0.85rem;
}

.inspector-poke {
    color: var(--tint-yellow);
    font-size: 0.8rem;
}

.inspector-poke:empty {
    display: none;
}

.inspector-detail {
    color: var(--ui-text-dim);
    font-size: 0.75rem;
}

kbd {
    display: inline-block;
    padding: 0 5px;
    border: 1px solid var(--ui-line-strong);
    border-bottom-width: 2px;
    border-radius: 3px;
    background: var(--ui-raised);
    color: var(--ui-text);
    font-family: inherit;
    font-size: 0.85em;
    line-height: 1.4;
}

.c64-controls {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.c64-controls button {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 3px;
    font-size: 0.875rem;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.c64-controls button:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.c64-controls button.reset-btn {
    background: var(--stop-bg);
    border-color: var(--tint-red);
    color: var(--tint-red);
}

.c64-controls button.reset-btn:hover {
    background: var(--tint-red);
    color: var(--c64-black);
}

/* Green while the sound is on */
.c64-controls button.mute-btn {
    background: var(--go-bg);
    border-color: var(--c64-green);
    color: var(--tint-green);
}

.c64-controls button.mute-btn:hover {
    border-color: var(--tint-green);
}

.c64-controls button.mute-btn.muted {
    background: var(--ui-raised);
    border-color: var(--ui-line);
    color: var(--ui-text);
}

.c64-controls button.mute-btn.muted:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.c64-joystick-controls {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.c64-joystick-controls .joystick-label {
    color: var(--ui-text-dim);
    font-size: 0.8rem;
    margin-right: 4px;
}

.c64-joystick-controls .joystick-hint {
    color: var(--ui-text-dim);
    font-size: 0.7rem;
    margin-left: 4px;
}

.c64-joystick-controls button {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    padding: 6px 16px;
    cursor: pointer;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: bold;
    transition: background 0.2s, border-color 0.2s;
}

.c64-joystick-controls button:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.c64-joystick-controls button.active {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
}

.c64-info {
    margin-top: 15px;
    color: var(--ui-text-muted);
    font-size: 0.9375rem;
    text-align: center;
    max-width: 640px;
    line-height: 1.5;
}

.c64-info code {
    background: var(--ui-raised);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--tint-cyan);
}

.c64-status {
    margin-top: 10px;
    color: var(--tint-yellow);
    text-align: center;
}

.c64-status:empty {
    display: none;
}

/* Editor panel on right side (50%) */
.c64-editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    align-self: stretch;
    overflow: hidden;
    min-width: 0;
    /* The workspace, not the line-number stack, determines editor height. */
    contain: size;
}

.c64-editor-panel h2 {
    color: var(--tint-cyan);
    font-size: 1.2rem;
    margin: 0 0 0.75rem 0;
}

.c64-editor-panel .panel-header {
    flex-wrap: wrap;
}

/* Sample selector dropdown */
.sample-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    min-width: 0;
    max-width: 100%;
}

/* Panel headers already provide the spacing */
.panel-header .sample-selector {
    margin-bottom: 0;
}

/* Line the emulator's panel header up with the screen below it */
.c64-emulator-panel .panel-header {
    width: 725px;
    max-width: 100%;
}

.sample-selector .sample-label {
    color: var(--ui-text-dim);
    font-size: 0.875rem;
}

.sample-selector select {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 0.875rem;
    cursor: pointer;
    width: 200px;
    min-width: 0;
    max-width: 100%;
}

.sample-selector select:hover {
    border-color: var(--c64-light-blue);
}

.sample-selector select:focus {
    outline: none;
    border-color: var(--tint-yellow);
}

.sample-selector select optgroup {
    background: var(--ui-panel);
    color: var(--ui-text-dim);
    font-style: normal;
}

.sample-selector select option {
    background: var(--ui-raised);
    color: var(--ui-text);
    padding: 4px;
}

.c64-editor-panel #basic-editor,
.c64-editor-panel #asm-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.c64-editor-panel .basic-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.c64-editor-panel .editor-container {
    flex: 1;
    min-height: 300px;
    max-height: none;
}

/* Live program view under the BASIC editor */
.program-view {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 320px;
    overflow: auto;
    margin-top: 12px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 6px;
    color: var(--ui-text-muted);
    font-size: 0.85rem;
}

.program-view summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    position: sticky;
    top: 0;
    background: var(--ui-panel);
    z-index: 1;
}

.program-view-title {
    color: var(--tint-cyan);
    font-weight: bold;
    letter-spacing: 0.04em;
}

.program-view-state {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--ui-raised);
    color: var(--tint-light-blue);
    white-space: nowrap;
}

.program-view-state[data-state="running"] {
    background: color-mix(in srgb, var(--c64-green) 20%, transparent);
    color: var(--tint-green);
}

.program-view-state[data-state="input"] {
    background: color-mix(in srgb, var(--tint-yellow) 20%, transparent);
    color: var(--tint-yellow);
}

.program-view-state[data-state="paused"],
.program-view-state[data-state="nobasic"] {
    background: color-mix(in srgb, var(--tint-orange) 25%, transparent);
    color: var(--tint-orange);
}

.program-view-body {
    padding: 0 12px 12px;
}

.program-view h4 {
    margin: 0 0 6px;
    color: var(--ui-text-dim);
    font-size: 0.75rem;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.program-view-now {
    margin: 0 0 10px;
    display: flex;
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}

.program-view-label {
    color: var(--ui-text-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.program-view-now code {
    color: var(--ui-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.program-view-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.program-view-columns section {
    min-width: 0;
    max-height: 132px;
    overflow: auto;
}

.program-view-empty {
    margin: 0;
    color: var(--ui-text-faint);
    font-style: italic;
}

.program-view-hot {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Each line's bar is its share of the time since RUN. */
.program-view-hot li {
    display: flex;
    gap: 8px;
    padding: 2px 6px;
    margin-bottom: 2px;
    border-radius: 3px;
    background: linear-gradient(to right,
        color-mix(in srgb, var(--tint-red) 35%, transparent) calc(var(--share) * 100%), transparent 0);
    white-space: nowrap;
    overflow: hidden;
}

.program-view-hot .hot-percent {
    flex: none;
    width: 3.2em;
    text-align: right;
    color: var(--tint-orange);
    font-family: 'Courier New', monospace;
}

.program-view-hot code {
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ui-text);
}

.program-view-vars {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Courier New', monospace;
}

.program-view-vars th,
.program-view-vars td {
    padding: 1px 6px;
    text-align: left;
    vertical-align: top;
}

.program-view-vars th {
    width: 1%;
    color: var(--tint-light-blue);
    font-weight: bold;
    white-space: nowrap;
    cursor: help;
}

.program-view-vars td {
    color: var(--ui-text);
    word-break: break-all;
}

.program-view-vars .program-view-more {
    color: var(--ui-text-dim);
    font-style: italic;
}

.program-view-memory {
    margin-top: 12px;
}

.basic-memory-bar {
    display: flex;
    height: 14px;
    border-radius: 3px;
    overflow: hidden;
    background: var(--ui-raised);
}

/* Small areas stay visible next to tens of kilobytes of free memory. */
.basic-memory-bar span {
    min-width: 3px;
}

.basic-memory-program { background: var(--c64-light-blue); }
.basic-memory-variables { background: var(--c64-yellow); }
.basic-memory-arrays { background: var(--tint-orange); }
.basic-memory-free { background: var(--ui-raised); }
.basic-memory-strings { background: var(--c64-light-green); }

.basic-memory-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    font-size: 0.78rem;
    color: var(--ui-text-dim);
}

.basic-memory-legend li {
    display: flex;
    align-items: center;
    gap: 5px;
}

.basic-memory-legend b {
    color: var(--ui-text);
    font-family: 'Courier New', monospace;
    font-weight: normal;
}

.basic-memory-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid var(--ui-line);
}

@media (max-width: 600px) {
    .program-view-columns {
        grid-template-columns: 1fr;
    }
}

/* ======================================
   SAMPLE GALLERY AND DEMO REEL (BASIC page)
   ====================================== */

.sample-gallery {
    max-width: 1400px;
    margin: 40px auto 0;
    padding: 0 30px;
    box-sizing: border-box;
}

.gallery-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin-bottom: 14px;
}

.gallery-header h2 {
    color: var(--tint-light-blue);
    font-size: 1.5rem;
    margin: 0 0 4px;
}

.gallery-header p {
    margin: 0;
    color: var(--ui-text-muted);
    max-width: 60ch;
    line-height: 1.5;
}

.demo-reel-btn {
    background: var(--ui-raised);
    color: var(--tint-cyan);
    border: 1px solid var(--tint-cyan);
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.demo-reel-btn:hover {
    background: var(--ui-hover);
}

.demo-reel-btn[aria-pressed="true"] {
    background: var(--c64-cyan);
    color: var(--c64-black);
}

.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.gallery-filters button {
    background: transparent;
    color: var(--ui-text-muted);
    border: 1px solid var(--ui-line);
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 0.85rem;
    cursor: pointer;
}

.gallery-filters button:hover {
    border-color: var(--c64-light-blue);
}

.gallery-filters button[aria-pressed="true"] {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
}

.gallery-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.gallery-card {
    display: flex;
    flex-direction: column;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.gallery-card[hidden] {
    display: none;
}

.gallery-card:hover,
.gallery-card:focus-within {
    border-color: var(--c64-light-blue);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* The sample in the editor */
.gallery-card.active {
    border-color: var(--tint-yellow);
}

.gallery-run {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.gallery-run:focus-visible {
    outline: 2px solid var(--tint-yellow);
    outline-offset: -2px;
}

.gallery-preview {
    position: relative;
    display: block;
    aspect-ratio: 384 / 272;
    background: var(--c64-black);
}

.gallery-preview img {
    display: block;
    width: 100%;
    height: 100%;
}

/* A hint of CRT scanlines over the recording */
.gallery-preview::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px);
    pointer-events: none;
}

.gallery-play,
.gallery-loaded {
    position: absolute;
    bottom: 8px;
    padding: 2px 8px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.8);
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 1;
}

.gallery-play {
    right: 8px;
    color: var(--tint-green);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.gallery-loaded {
    left: 8px;
    color: var(--tint-yellow);
    display: none;
}

.gallery-card:hover .gallery-play,
.gallery-run:focus-visible .gallery-play {
    opacity: 1;
}

.gallery-card.active .gallery-loaded {
    display: block;
}

.gallery-title {
    display: block;
    padding: 10px 12px 0;
    color: var(--ui-text);
    font-weight: bold;
}

.gallery-sound {
    font-size: 0.85em;
}

.gallery-description {
    flex: 1;
    margin: 4px 12px 8px;
    color: var(--ui-text-dim);
    font-size: 0.85rem;
    line-height: 1.45;
}

.gallery-tags {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0 12px 12px;
    padding: 0;
}

.gallery-tags li {
    padding: 1px 6px;
    border: 1px solid color-mix(in srgb, var(--tint-cyan) 40%, transparent);
    border-radius: 3px;
    color: var(--tint-cyan);
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
}

.demo-reel-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    width: 725px;
    max-width: 100%;
    margin-top: 10px;
    padding: 6px 10px;
    box-sizing: border-box;
    background: var(--ui-panel);
    border: 1px solid var(--tint-cyan);
    border-radius: 6px;
}

.demo-reel-bar[hidden] {
    display: none;
}

.demo-reel-label {
    color: var(--tint-cyan);
    font-size: 0.75rem;
    font-weight: bold;
    letter-spacing: 0.08em;
}

.demo-reel-title {
    flex: 1;
    min-width: 0;
    color: var(--ui-text);
}

.demo-reel-progress {
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: var(--ui-raised);
    overflow: hidden;
}

.demo-reel-progress span {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--c64-cyan);
    transform: scaleX(0);
    transform-origin: left;
}

.demo-reel-progress span.running {
    animation: demo-reel-progress var(--demo-seconds, 12s) linear forwards;
}

@keyframes demo-reel-progress {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

.demo-reel-bar button {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 0.8rem;
    cursor: pointer;
}

.demo-reel-bar button:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

@media (max-width: 520px) {
    .sample-gallery {
        padding: 0 15px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .gallery-description {
        font-size: 0.78rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-card,
    .gallery-play {
        transition: none;
    }

    .gallery-card:hover,
    .gallery-card:focus-within {
        transform: none;
    }

    .demo-reel-progress {
        display: none;
    }
}

/* BASIC Quick Start Guide */
.basic-quickstart,
.asm-quickstart {
    max-width: 1400px;
    margin: 40px auto;
    padding: 30px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    border-radius: 10px;
    color: var(--ui-text-muted);
    line-height: 1.6;
}

.basic-quickstart h2,
.asm-quickstart h2 {
    color: var(--tint-light-blue);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.basic-quickstart h3,
.asm-quickstart h3 {
    color: var(--tint-yellow);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.basic-quickstart h3:first-child,
.asm-quickstart h3:first-child {
    margin-top: 0;
}

.basic-quickstart p,
.asm-quickstart p {
    margin-bottom: 10px;
}

.basic-quickstart .intro-list,
.asm-quickstart .intro-list {
    margin: 10px 0 20px 20px;
}

.basic-quickstart ul,
.asm-quickstart ul {
    margin: 10px 0 10px 20px;
}

.basic-quickstart li,
.asm-quickstart li {
    margin-bottom: 8px;
}

/* Two-column layout */
.quickstart-columns {
    display: flex;
    gap: 40px;
    margin-top: 20px;
}

.quickstart-col {
    flex: 1;
    min-width: 0;
}

@media (max-width: 900px) {
    .quickstart-columns {
        flex-direction: column;
        gap: 20px;
    }
}

/* Syntax highlighted code */
.basic-quickstart code.basic-code,
.basic-quickstart pre.basic-code,
.asm-quickstart code.asm-code,
.asm-quickstart pre.asm-code {
    background: var(--ui-raised);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'C64 Pro Mono', monospace;
    font-size: 0.9em;
    color: var(--ui-text-muted);
}

.basic-quickstart pre.basic-code,
.asm-quickstart pre.asm-code {
    padding: 12px 16px;
    margin: 10px 0;
    overflow-x: auto;
    display: block;
}

/* BASIC syntax colors */
.basic-code .keyword { color: var(--syntax-keyword); font-weight: bold; }
.basic-code .string { color: var(--syntax-string); }
.basic-code .number { color: var(--syntax-number); }
.basic-code .variable { color: var(--syntax-variable); }
.basic-code .line-num { color: var(--syntax-line-number); }

/* ASM syntax colors */
.asm-code .mnemonic { color: var(--syntax-keyword); font-weight: bold; }
.asm-code .register { color: var(--syntax-variable); }
.asm-code .number { color: var(--syntax-number); }
.asm-code .label { color: var(--syntax-variable); }
.asm-code .directive { color: var(--syntax-function); }
.asm-code .comment { color: var(--syntax-comment); font-style: italic; }

.basic-quickstart code,
.asm-quickstart code {
    background: var(--ui-raised);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--tint-cyan);
    font-family: 'C64 Pro Mono', monospace;
    font-size: 0.9em;
}

.basic-quickstart pre,
.asm-quickstart pre {
    background: var(--ui-raised);
    padding: 12px 16px;
    border-radius: 5px;
    color: var(--tint-cyan);
    font-family: 'C64 Pro Mono', monospace;
    font-size: 0.9em;
    overflow-x: auto;
    margin: 10px 0;
}

.basic-quickstart table.basic-commands {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.basic-quickstart table.basic-commands th,
.basic-quickstart table.basic-commands td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--ui-line-soft);
}

.basic-quickstart table.basic-commands th {
    background: var(--ui-raised);
    color: var(--tint-cyan);
}

.basic-quickstart table.basic-commands td:first-child {
    width: 140px;
}

.basic-quickstart em,
.asm-quickstart em {
    color: var(--ui-text-dim);
}

/* Games page: below the lab, one card per game and tips for changing them */
.games-guide {
    max-width: 1400px;
    margin: 40px auto;
    padding: 30px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    border-radius: 10px;
    color: var(--ui-text-muted);
    line-height: 1.6;
}

.games-guide h2 {
    color: var(--tint-light-blue);
    margin-bottom: 12px;
    font-size: 1.5rem;
}

.games-guide code {
    background: var(--ui-raised);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--tint-cyan);
    font-family: 'C64 Pro Mono', monospace;
    font-size: 0.9em;
}

.games-intro {
    max-width: 80ch;
    margin-bottom: 24px;
}

/* Three to a row on a desktop, with a short last row centred */
.game-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
}

.game-card {
    flex: 0 1 380px;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: var(--ui-raised);
    border: 2px solid var(--ui-line-soft);
    border-radius: 8px;
}

/* The game in the editor */
.game-card.current {
    border-color: var(--tint-yellow);
    box-shadow: 0 0 12px color-mix(in srgb, var(--tint-yellow) 25%, transparent);
}

.game-card h3 {
    color: var(--tint-yellow);
    font-size: 1.2rem;
}

.game-card h4 {
    color: var(--tint-cyan);
    font-size: 0.95rem;
    margin: 12px 0 4px;
}

.game-card p {
    margin-bottom: 8px;
}

.game-card .game-style {
    color: var(--ui-text-dim);
    font-style: italic;
}

.game-card ul {
    margin: 0 0 16px 20px;
}

.game-card li {
    margin-bottom: 4px;
}

/* Pushed to the bottom, so the buttons line up across a row of cards */
.game-card .game-play {
    margin-top: auto;
    align-self: flex-start;
    padding: 8px 18px;
    background: var(--go-bg);
    color: var(--tint-green);
    border: 1px solid var(--c64-green);
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.game-card .game-play:hover {
    background: var(--c64-light-green);
    color: var(--c64-black);
}

.games-tips {
    margin-top: 28px;
}

.games-tips h3 {
    color: var(--tint-yellow);
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.games-tips ul {
    margin-left: 20px;
}

.games-tips li {
    margin-bottom: 8px;
}

.games-joystick-note {
    margin-top: 10px;
    color: var(--ui-text-dim);
    font-size: 0.85rem;
    text-align: center;
}

@media (max-width: 1024px) {
    .c64-page {
        flex-direction: column;
        height: auto;
    }
    
    .c64-emulator-column {
        flex: none;
        width: 100%;
    }
    
    .c64-emulator-panel {
        position: relative;
        top: 0;
    }
    
    #screen {
        width: 100%;
        max-width: 100%;
        height: auto;
        aspect-ratio: 4 / 3;
    }
    
    .c64-editor-panel {
        contain: none;
        max-width: 100%;
    }

    /* Bound the code area without clipping wrapped controls or error feedback. */
    .c64-editor-panel .editor-container {
        flex: 0 0 300px;
    }
}

/* ======================================
   ASSEMBLY LAB STYLES
   ====================================== */

/* Register display */
.register-display {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 15px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 6px;
    padding: 12px 16px;
    font-family: 'Courier New', monospace;
    max-width: 640px;
}

.register-row {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.reg-label {
    color: var(--ui-text-dim);
    font-size: 0.8125rem;
}

.reg-value {
    color: var(--tint-cyan);
    font-size: 0.9375rem;
    font-weight: 600;
    min-width: 50px;
}

.flags-row {
    border-top: 1px solid var(--ui-line-soft);
    padding-top: 8px;
    margin-top: 4px;
}

.flag-bit {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    background: var(--ui-raised);
    color: var(--ui-text-faint);
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.15s;
}

.flag-bit.set {
    background: var(--tint-cyan);
    color: var(--ui-sunken);
}

.flag-bit.dim {
    opacity: 0.3;
}

.status-text {
    margin-left: auto;
    color: var(--ui-text-dim);
    font-size: 0.8125rem;
}

/* Source line row in register display */
.source-row {
    border-top: 1px solid var(--ui-line-soft);
    padding-top: 8px;
    margin-top: 4px;
}

.source-line {
    color: var(--tint-yellow);
    font-size: 0.8125rem;
    font-family: 'Courier New', monospace;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Registers in hex, decimal and binary (asm.html) */
.register-display {
    width: 725px;
    max-width: 100%;
}

.cpu-registers {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 18px;
}

.cpu-reg {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.cpu-reg .reg-label {
    min-width: 22px;
}

.cpu-reg .reg-value {
    min-width: 0;
}

.reg-alt {
    color: var(--ui-text-dim);
    font-size: 0.75rem;
}

.reg-bits {
    color: var(--ui-text-dim);
    font-size: 0.75rem;
    letter-spacing: 1px;
}

.cycles-row {
    border-top: 1px solid var(--ui-line-soft);
    padding-top: 8px;
    margin-top: 4px;
}

.cycle-count {
    color: var(--tint-green);
    font-weight: 600;
}

/* Live memory viewer (lab/memory-viewer.js) */
.memory-viewer {
    width: 725px;
    max-width: 100%;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 6px;
    font-family: 'Courier New', monospace;
}

.memory-viewer-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.memory-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ui-text-dim);
    font-size: 0.8rem;
}

.memory-address {
    width: 8ch;
    padding: 2px 6px;
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line);
    border-radius: 3px;
    color: var(--tint-cyan);
    font: inherit;
}

.memory-address[aria-invalid="true"] {
    border-color: var(--tint-red);
}

.memory-viewer-bar button {
    background: var(--ui-raised);
    border: 1px solid var(--ui-line);
    border-radius: 3px;
    color: var(--ui-text-muted);
    padding: 2px 8px;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

.memory-viewer-bar button:hover {
    border-color: var(--c64-light-blue);
    color: var(--ui-text);
}

.memory-dump {
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
}

.memory-row {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.memory-row-address {
    margin-right: 6px;
    color: var(--ui-text-dim);
}

.memory-byte {
    padding: 0 2px;
    border-radius: 2px;
    color: var(--ui-text-muted);
    transition: background 0.3s;
}

.memory-byte.stack {
    color: var(--tint-green);
}

.memory-byte.changed {
    background: color-mix(in srgb, var(--tint-yellow) 35%, transparent);
    color: var(--ui-text);
}

.memory-byte.pc {
    outline: 1px solid var(--tint-yellow);
    color: var(--tint-yellow);
}

.memory-text {
    margin-left: 10px;
    color: var(--tint-green);
    letter-spacing: 1px;
}

.memory-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--ui-text-dim);
    font-size: 0.7rem;
}

.memory-legend .memory-byte {
    margin-left: 8px;
}

.asm-code .string {
    color: var(--tint-yellow);
}

/* Assembly controls */
.asm-controls {
    gap: 6px !important;
}

.asm-controls button {
    font-size: 0.8125rem !important;
    padding: 6px 12px !important;
}

/* ======================================
   HARDWARE SIMULATOR PAGE
   ====================================== */

/* Hardware page uses workspace layout */
.hardware-info {
    background: var(--ui-panel);
    border: 1px solid var(--ui-line-soft);
    padding: 30px;
    border-radius: 8px;
}

.hardware-info .chip-section-title {
    color: var(--tint-yellow);
    font-size: 1.3rem;
    text-align: center;
    margin: 30px 0 20px;
    /* Centred, so the left rule of a plain section title would float alone */
    border-left: none;
    padding-left: 0;
}

/* Canvas fills panel body */
.workspace #simCanvas {
    background-color: var(--c64-blue);
    border: 4px solid var(--c64-light-blue);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    border-radius: 8px;
    width: 100%;
    height: auto;
    flex: 1;
    min-height: 400px;
}

.bus-legend {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 15px;
    padding: 10px;
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--ui-text-muted);
}

.bus-legend .dot {
    width: 12px;
    height: 12px;
    display: inline-block;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* The packet colours drawn on the canvas: COLORS in js/hardware.js */
.bus-legend .address-dot {
    background: #ff5555;
    box-shadow: 0 0 8px #ff5555;
}

.bus-legend .data-dot {
    background: #ffff55;
    box-shadow: 0 0 8px #ffff55;
}

/* Log Panel in workspace */
.workspace .log-panel {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    flex: 1;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
    padding: 12px;
    font-size: 0.875rem;
    color: var(--tint-green);
    font-family: 'VT323', 'Courier New', monospace;
    margin-bottom: 15px;
}

.log-entry {
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Bus trace lines: the instruction, then each access it made */
.log-entry.log-title {
    color: var(--tint-yellow);
    font-weight: bold;
}

.log-entry.log-instruction {
    margin-top: 6px;
    color: var(--tint-cyan);
}

.log-entry.log-read {
    padding-left: 1.5em;
    color: var(--tint-yellow);
}

.log-entry.log-write {
    padding-left: 1.5em;
    color: var(--tint-red);
}

.log-entry.log-note {
    margin: 4px 0 6px 1.5em;
    padding: 4px 8px;
    border-left: 3px solid var(--c64-light-green);
    color: var(--tint-green);
}

.log-entry.log-end {
    margin-top: 8px;
    color: var(--ui-text-dim);
}

.trace-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    color: var(--ui-text-dim);
    font-size: 0.8rem;
}

.trace-controls button,
.trace-controls select {
    background: var(--ui-raised);
    border: 1px solid var(--ui-line);
    border-radius: 4px;
    color: var(--ui-text-muted);
    padding: 4px 10px;
    font: inherit;
    cursor: pointer;
}

.trace-controls button:disabled {
    opacity: 0.4;
    cursor: default;
}

.trace-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.scenario-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.scenario-btn {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    padding: 12px 15px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 1rem;
    cursor: pointer;
    text-align: left;
    border-radius: 4px;
    transition: all 0.2s;
}

.scenario-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
    transform: translateX(3px);
}

.scenario-btn:active {
    transform: translateY(1px);
}

/* Info Section within workspace panel */
.workspace .info-section {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    padding: 15px;
    margin-top: auto;
}

.workspace .info-section h2 {
    color: var(--tint-cyan);
    font-size: 0.875rem;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--ui-line);
    padding-bottom: 8px;
}

.default-info {
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    line-height: 1.6;
}

.default-info p {
    margin-bottom: 10px;
}

.default-info strong {
    color: var(--tint-yellow);
}

/* Motherboard Section */
.motherboard-section {
    margin-bottom: 3rem;
}

.motherboard-section h2 {
    color: var(--tint-yellow);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--ui-line-soft);
    padding-bottom: 0.5rem;
}

.motherboard-section .section-intro {
    color: var(--ui-text-muted);
    margin-bottom: 1.5rem;
}

.motherboard-image-container {
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--ui-line-soft);
    border-radius: 8px;
    padding: 1rem;
}

.motherboard-image {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Chip Reference */
.chip-section-title {
    color: var(--tint-cyan);
    font-size: 1.1rem;
    margin: 2rem 0 1rem 0;
    padding-left: 0.5rem;
    border-left: 4px solid var(--c64-light-blue);
}

.chip-section-title:first-of-type {
    margin-top: 0;
}

.chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 20px;
}

.chip-card {
    min-width: 0;
    background: var(--ui-raised);
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    padding: 20px;
    transition: all 0.2s;
}

.chip-card:hover {
    border-color: var(--c64-light-blue);
    transform: translateY(-2px);
}

.chip-card h3 {
    color: var(--tint-yellow);
    font-size: 1rem;
    margin-bottom: 10px;
}

.chip-card p {
    color: var(--ui-text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 12px;
}

.chip-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chip-card li {
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    padding: 4px 0;
    border-bottom: 1px solid var(--ui-line-soft);
}

.chip-card li:last-child {
    border-bottom: none;
}

.chip-card .label {
    color: var(--tint-cyan);
}

/* 3D Chip Container */
.chip-3d-container {
    width: 100%;
    height: 150px;
    margin-bottom: 15px;
    border-radius: 6px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    cursor: grab;
}

/* Dual Chip Container (for 2 RAM chips side by side) */
.chip-3d-dual-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.chip-3d-dual-container .chip-3d-small {
    flex: 1;
    min-width: 0;
    height: 120px;
    margin-bottom: 0;
}

.chip-3d-container:active {
    cursor: grabbing;
}

.chip-3d-container canvas {
    display: block;
    max-width: 100%;
    border-radius: 6px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    #simCanvas {
        max-width: 100%;
    }
}

/* ======================================
   MEMORY MAP PAGE
   ====================================== */

/* Memmap workspace adjustments: 25% / 50% / 25% (flex ratios share gap correctly) */
.memmap-workspace .workspace-primary {
    flex: 1 1 0;
    min-width: 0;
}

.memmap-workspace .workspace-secondary {
    flex: 2 1 0;
    min-width: 0;
}

.memmap-workspace .workspace-tertiary {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.region-details-body {
    overflow-y: auto;
}

/* Stack title and subtitle vertically in the region details header */
.memmap-workspace .workspace-tertiary .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

@media (max-width: 1024px) {
    .memmap-workspace {
        flex-wrap: wrap;
    }
    .memmap-workspace .workspace-primary,
    .memmap-workspace .workspace-secondary,
    .memmap-workspace .workspace-tertiary {
        flex: 1 1 100%;
    }
}

.banking-controls-body {
    overflow-y: auto;
}

.memmap-table-panel {
    overflow: hidden;
}

.memmap-table-body {
    overflow: auto;
}

/* Region details panel */
.region-details-panel h3 {
    color: var(--tint-cyan);
    font-size: 0.875rem;
    margin-bottom: 10px;
}

.region-details-panel .region-info h4 {
    color: var(--tint-yellow);
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.region-details-panel .region-info .range {
    color: var(--tint-green);
    font-size: 0.75rem;
    margin-bottom: 8px;
}

.region-details-panel .region-info p {
    color: var(--ui-text-muted);
    font-size: 0.75rem;
    line-height: 1.5;
    margin-bottom: 8px;
}

.region-details-panel .current-config h4 {
    color: var(--tint-cyan);
    font-size: 0.75rem;
    margin-top: 10px;
}

.region-details-panel .config-value {
    background: var(--ui-sunken);
    padding: 8px;
    border-radius: 4px;
    color: var(--tint-green);
    font-size: 0.75rem;
}

/* Control group styles */
.control-group {
    margin-bottom: 20px;
}

.control-group h3 {
    color: var(--tint-yellow);
    font-size: 0.8125rem;
    margin-bottom: 10px;
}

.bit-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.bit-btn {
    width: 40px;
    height: 40px;
    background: var(--ui-raised);
    border: 2px solid var(--ui-line);
    color: var(--ui-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.bit-btn:hover {
    border-color: var(--c64-light-blue);
}

.bit-btn.active {
    background: var(--c64-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
}

.bit-btn .bit-name {
    font-size: 0.625rem;
    margin-top: 2px;
}

.port-value {
    background: var(--c64-blue);
    padding: 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--tint-light-blue);
    margin-top: 10px;
}

.port-value code {
    color: var(--tint-yellow);
}

/* Quick presets */
.presets {
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
}

.preset-btn {
    background: var(--ui-raised);
    border: 2px solid var(--ui-line);
    color: var(--ui-text-muted);
    padding: 10px;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    text-align: left;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
    color: var(--ui-text);
}

.preset-btn.active {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
}

/* External signals */
.signal-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.signal-btn {
    flex: 1;
    min-width: 80px;
    padding: 10px;
    background: var(--ui-raised);
    border: 2px solid var(--ui-line);
    color: var(--ui-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.signal-btn:hover {
    border-color: var(--c64-light-blue);
}

.signal-btn.active {
    background: var(--c64-red);
    border-color: var(--c64-light-red);
    color: var(--ui-text);
}

/* VIC Bank Controls */
.vic-bank-controls {
    display: flex;
    gap: 5px;
}

.vic-bank-btn {
    flex: 1;
    padding: 8px 6px;
    background: var(--ui-raised);
    border: 2px solid var(--ui-line);
    color: var(--ui-text-muted);
    font-size: 0.6875rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.vic-bank-btn:hover {
    border-color: var(--c64-light-blue);
}

.vic-bank-btn.active {
    background: var(--c64-purple);
    border-color: var(--tint-purple);
    color: var(--ui-text);
}

.vic-bank-btn .bank-num {
    font-size: 0.75rem;
}

.vic-bank-btn .bank-range {
    font-size: 0.5625rem;
    opacity: 0.7;
    margin-top: 2px;
}

/* Memory Map Display - 4KB Grid Table Layout */
.memory-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    table-layout: fixed;
}

.memory-table thead th {
    background: var(--ui-raised);
    color: var(--tint-cyan);
    font-size: 0.8125rem;
    padding: 10px 6px;
    text-align: center;
    border-bottom: 2px solid var(--ui-line-strong);
    font-weight: bold;
    letter-spacing: 1px;
}

.memory-table thead th.addr-header {
    width: 70px;
    border-right: 1px solid var(--ui-line-strong);
}

.memory-table thead th.cpu-header {
    width: auto;
    border-right: 1px solid var(--ui-line-strong);
}

.memory-table thead th.vic-header {
    width: 80px;
    background: #4a2d5a;
    border-right: 1px solid var(--ui-line-strong);
}

.memory-table thead th.details-header {
    width: 180px;
    background: var(--ui-raised);
}

.memory-table tbody tr {
    border-bottom: 1px solid var(--ui-line-soft);
    height: 1px;
    min-height: 60px;
}

.memory-table tbody tr:last-child {
    border-bottom: none;
}

.memory-table td {
    padding: 0;
    vertical-align: middle;
    height: 100%;
    position: relative;
}

.memory-table td.addr-cell {
    background: var(--ui-sunken);
    text-align: center;
    font-size: 0.875rem;
    color: var(--ui-text-muted);
    border-right: 1px solid var(--ui-line-strong);
    padding: 6px;
    vertical-align: middle;
}

.memory-table td.addr-cell .addr-start {
    display: block;
    color: var(--tint-cyan);
    font-size: 0.875rem;
    font-weight: bold;
}

.memory-table td.cpu-cell {
    border-right: 1px solid var(--ui-line-strong);
    border-bottom: 1px solid var(--ui-line);
    padding: 0;
    position: relative;
}

.memory-table td.vic-cell {
    border-right: 1px solid var(--ui-line-strong);
    padding: 0;
    position: relative;
}

.memory-table td.details-cell {
    vertical-align: top;
    padding: 0;
    position: relative;
}

/* Details cells inherit region colors from CPU view */
.memory-table td.details-cell.region-ram { background: #2d5a27; }
.memory-table td.details-cell.region-basic { background: #5a2d5a; }
.memory-table td.details-cell.region-kernal { background: #5a5a2d; }
.memory-table td.details-cell.region-io { background: #5a2d2d; }
.memory-table td.details-cell.region-charrom { background: #2d5a5a; }
.memory-table td.details-cell.region-cart-lo { background: #5a4a2d; }
.memory-table td.details-cell.region-cart-hi { background: #4a5a2d; }

/* CPU cells inherit region colors */
.memory-table td.cpu-cell.region-ram { background: #2d5a27; }
.memory-table td.cpu-cell.region-basic { background: #5a2d5a; }
.memory-table td.cpu-cell.region-kernal { background: #5a5a2d; }
.memory-table td.cpu-cell.region-io { background: #5a2d2d; }
.memory-table td.cpu-cell.region-charrom { background: #2d5a5a; }
.memory-table td.cpu-cell.region-cart-lo { background: #5a4a2d; }
.memory-table td.cpu-cell.region-cart-hi { background: #4a5a2d; }

/* Memory region cells that fill table cells */
.memory-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 60px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #2d5a27;
    text-align: center;
    padding: 8px;
    box-sizing: border-box;
    appearance: none;
    border: 0;
    font-family: inherit;
    color: inherit;
}

.memory-table td > .memory-cell {
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* CPU cells should not be absolute - let content determine row height */
.memory-table td.cpu-cell > .memory-cell {
    position: relative;
    min-height: 60px;
    height: auto;
}

.memory-cell:hover {
    filter: brightness(1.2);
}

.memory-cell .region-name {
    display: block;
    font-size: 0.875rem;
    font-weight: bold;
    line-height: 1.3;
    letter-spacing: 0.5px;
}

.memory-cell .region-size {
    display: block;
    font-size: 0.875rem;
    opacity: 0.8;
    letter-spacing: 0.3px;
}

/* CPU cells: horizontal text layout */
.memory-table td.cpu-cell .memory-cell > span {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.memory-table td.cpu-cell .memory-cell .region-size {
    margin-top: 0;
}

/* VIC empty regions */
.region-vic-empty {
    background: var(--ui-sunken);
}

.region-vic-empty:hover {
    filter: none;
    cursor: default;
}

.vic-inactive {
    color: var(--ui-text-faint);
    font-size: 0.875rem;
    font-style: normal;
}

/* VIC visible regions */
.vic-visible {
    border-left: 3px solid var(--tint-cyan);
}

/* Details column cells grid */
.details-cells {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
    align-items: flex-start;
    align-content: flex-start;
    min-height: 100%;
}

.mem-cell {
    min-width: 6px;
    min-height: 6px;
    width: 6px;
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 1px;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    appearance: none;
    border: 0;
    padding: 0;
    font-family: inherit;
}

.memory-cell:focus-visible {
    outline-offset: -3px;
}

.mem-cell:focus-visible {
    position: relative;
    z-index: 2;
}

.mem-cell:hover {
    background: var(--c64-yellow);
    transform: scale(1.5);
    z-index: 10;
    position: relative;
}

.mem-cell.active {
    background: var(--c64-cyan);
}

/* Region colors */
.region-ram { background: #2d5a27; color: #9ae29b; }
.region-basic { background: #5a2d5a; color: #d4a5d4; }
.region-kernal { background: #5a5a2d; color: #d4d4a5; }
.region-io { background: #5a2d2d; color: #d4a5a5; }
.region-charrom { background: #2d5a5a; color: #a5d4d4; }
.region-cart-lo { background: #5a4a2d; color: #d4c4a5; }
.region-cart-hi { background: #4a5a2d; color: #c4d4a5; }
.region-unmapped { background: var(--ui-raised); color: var(--ui-text-muted); }

/* VIC-specific region colors */
.region-vic-screen { background: #4a2d5a; color: #c4a5d4; }
.region-vic-chars { background: #2d4a5a; color: #a5c4d4; }
.region-vic-bitmap { background: #5a3d2d; color: #d4b4a5; }

/* Stack direction arrow */
.stack-arrow {
    display: block;
    font-size: 0.625rem;
    color: var(--tint-yellow);
    font-weight: normal;
    white-space: nowrap;
}

.stack-arrow::before {
    content: '↓';
    margin-right: 4px;
    font-size: 1.4rem;
    font-weight: bold;
}

/* Region details panel contents */
.region-info {
    display: none;
}

.region-info.active {
    display: block;
}

.region-info h3 {
    color: var(--tint-yellow);
    font-size: 0.875rem;
    margin-bottom: 10px;
}

.region-info .range {
    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    margin-bottom: 15px;
}

.region-info p {
    color: var(--tint-light-blue);
    font-size: 0.8125rem;
    line-height: 1.6;
    margin-bottom: 15px;
}

.region-info .details {
    background: var(--c64-blue);
    padding: 10px;
    border-radius: 4px;
}

.region-info .details h4 {
    color: var(--tint-cyan);
    font-size: 0.8125rem;
    margin-bottom: 8px;
}

.region-info .details ul {
    list-style: none;
    padding: 0;
}

.region-info .details li {
    color: var(--ui-text-muted);
    font-size: 0.75rem;
    padding: 4px 0;
    border-bottom: 1px solid var(--ui-line-soft);
}

.region-info .details li:last-child {
    border-bottom: none;
}

.region-info .details .label {
    color: var(--tint-yellow);
}

/* Current config display */
.current-config {
    background: var(--c64-blue);
    padding: 10px;
    border-radius: 4px;
    margin-top: 15px;
}

.current-config h4 {
    color: var(--tint-cyan);
    font-size: 0.8125rem;
    margin-bottom: 8px;
}

.config-value {
    color: var(--tint-yellow);
    font-size: 0.75rem;
}

/* Memory Map Legend */
.memory-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    padding: 10px;
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
}

.memory-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.6875rem;
    color: var(--ui-text-muted);
}

.memory-legend .legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* ==========================================
   SID PAGE STYLES
   ========================================== */

/* SID workspace adjustments */
.sid-workspace .workspace-primary,
.sid-workspace .workspace-secondary {
    flex: 1;
}

.sid-workspace .panel-header {
    flex-wrap: wrap;
}

.sid-workspace .panel-header h2 {
    margin: 0;
}

/* SID intro row with text and 3D chip */
.sid-intro-row {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 2rem;
    margin: 0 auto 1.5rem;
    max-width: 50%;
    /* min-width beats max-width, so the row goes full width once 50% would be
       too narrow for the text and the chip side by side. */
    min-width: min(100%, 480px);
}

.sid-intro-text {
    flex: 1;
}

.sid-intro-text h2 {
    margin-top: 0;
}

#sid-3d-container-mini {
    width: 150px;
    height: 130px;
    flex-shrink: 0;
}

.sid-monitor-body {
    gap: 10px;
}

.sid-player-body {
    gap: 12px;
}

.section-intro {
    color: var(--ui-text-muted);
    margin-bottom: 1.5rem;
}

/* ==========================================
   ABOUT PAGE STYLES
   ========================================== */

.about-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.about-content {
    padding: 2rem;
}

.about-section {
    margin-bottom: 2.5rem;
}

.about-section:last-child {
    margin-bottom: 0;
}

.about-section h2 {
    color: var(--tint-light-blue);
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--ui-line);
    padding-bottom: 0.5rem;
}

.about-section p {
    color: var(--ui-text);
    line-height: 1.8;
    margin-bottom: 1rem;
}

.about-section p:last-child {
    margin-bottom: 0;
}

.about-section a,
.gallery-header a {
    color: var(--tint-cyan);
    text-decoration: underline;
}

.about-section a:hover,
.gallery-header a:hover {
    color: var(--tint-green);
}

.story-intro {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.story-intro .story-text {
    flex: 1;
    min-width: 0;
}

/* The logo is transparent, so it stands on the page without a frame */
.about-logo {
    flex: 0 0 auto;
    width: auto;
    height: 256px;
}

@media (max-width: 700px) {
    .story-intro {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .about-logo {
        height: 192px;
    }
}

.author-section .author-card {
    padding: 1.5rem;
    border-radius: 4px;
}

.author-info p {
    margin-bottom: 1rem;
}

.author-info strong {
    color: var(--tint-cyan);
}

.author-info blockquote {
    border-left: 3px solid var(--c64-light-green);
    padding-left: 1.5rem;
    margin: 1.5rem 0 0;
    font-style: italic;
}

.author-info blockquote p {
    color: var(--tint-light-blue);
    margin-bottom: 0.5rem;
}

.author-info blockquote cite {
    color: var(--tint-green);
    font-style: normal;
}

/* ==========================================
   SID Player Styles
   ========================================== */

.song-title {
    color: var(--tint-green);
    font-size: 1.25rem;
    font-weight: bold;
}

.song-author {
    color: var(--tint-cyan);
    font-size: 0.9rem;
}

.song-released {
    color: var(--ui-text-muted);
    font-size: 0.8rem;
}

.player-btn {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 2px solid var(--ui-line);
    padding: 0.5rem 1rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.player-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.player-btn:disabled,
.sid-btn:disabled,
.track-btn:disabled,
.mute-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.player-btn.play-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1.25rem;
}

.player-btn.playing {
    background: var(--c64-light-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
}

.frame-counter {
    color: var(--tint-cyan);
    font-size: 0.85rem;
    margin-left: 1rem;
    padding: 0.25rem 0.5rem;
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Voice Visualizer */
.voice-visualizer {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.voice-panel {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    padding: 1rem;
    border-radius: 4px;
    position: relative;
}

.voice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--ui-line-soft);
}

.voice-label {
    color: var(--tint-light-blue);
    font-weight: bold;
}

.voice-waveform {
    background: var(--c64-purple);
    color: var(--ui-text);
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 2px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.voice-meters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.meter-row {
    display: grid;
    grid-template-columns: 40px 1fr 50px;
    align-items: center;
    gap: 0.5rem;
}

.meter-label {
    color: var(--ui-text-muted);
    font-size: 0.75rem;
}

.meter-bar {
    height: 12px;
    background: var(--ui-raised);
    border-radius: 2px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0%;
    transition: width 0.05s ease-out;
    border-radius: 2px;
}

.freq-fill {
    background: linear-gradient(90deg, var(--c64-cyan), var(--c64-light-blue));
}

.env-fill {
    background: linear-gradient(90deg, var(--c64-green), var(--c64-light-green));
}

.meter-value {
    color: var(--tint-yellow);
    font-size: 0.7rem;
    text-align: right;
    font-family: monospace;
}

.adsr-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.adsr-label {
    color: var(--ui-text-muted);
    font-size: 0.7rem;
}

.adsr-label span {
    color: var(--tint-cyan);
}

.gate-indicator {
    display: inline-block;
    margin-top: 0.5rem;
    background: var(--ui-raised);
    color: var(--ui-text-faint);
    padding: 0.15rem 0.35rem;
    font-size: 0.6rem;
    border-radius: 2px;
    transition: all 0.1s ease;
}

.gate-indicator.active {
    background: var(--c64-light-green);
    color: var(--c64-black);
    box-shadow: 0 0 8px var(--c64-light-green);
}

/* Waveform sketch, note name and mixer buttons (sid.html) */
.voice-shape {
    display: block;
    width: 100%;
    height: 36px;
    margin-bottom: 0.5rem;
    background: var(--ui-sunken);
    border-radius: 2px;
}

.voice-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.voice-footer .gate-indicator {
    margin-top: 0;
}

.voice-note {
    min-width: 2.5em;
    color: var(--tint-yellow);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
}

.voice-mix {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.voice-mix button {
    background: var(--ui-raised);
    border: 1px solid var(--ui-line);
    border-radius: 2px;
    color: var(--ui-text-muted);
    padding: 1px 6px;
    font: inherit;
    font-size: 0.6rem;
    cursor: pointer;
}

.voice-mix .voice-mute[aria-pressed="true"] {
    background: var(--c64-red);
    border-color: var(--c64-light-red);
    color: var(--ui-text);
}

.voice-mix .voice-solo[aria-pressed="true"] {
    background: var(--c64-yellow);
    border-color: var(--c64-yellow);
    color: var(--c64-black);
}

.voice-panel.silenced {
    opacity: 0.45;
}

/* Output oscilloscope */
.sid-scope {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    border-radius: 4px;
    padding: 0.75rem 1rem 1rem;
}

.sid-scope .filter-header {
    margin-bottom: 0.5rem;
}

#sid-scope {
    display: block;
    width: 100%;
    height: 90px;
    border-radius: 2px;
}

/* Play your own .sid */
.sid-upload {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.75rem;
    border: 1px dashed var(--ui-line);
    border-radius: 6px;
    color: var(--ui-text-dim);
    font-size: 0.8rem;
    transition: border-color 0.2s, background 0.2s;
}

.sid-upload.drag-over {
    border-color: var(--c64-light-green);
    background: color-mix(in srgb, var(--c64-light-green) 8%, transparent);
}

.sid-upload-btn {
    background: var(--ui-raised);
    border: 1px solid var(--c64-light-blue);
    border-radius: 4px;
    color: var(--tint-light-blue);
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
    font: inherit;
}

.sid-upload-btn:hover,
.sid-upload-btn:focus-visible {
    background: var(--c64-light-blue);
    color: var(--c64-white);
}

.sid-upload a {
    color: var(--tint-cyan);
}

/* Filter Display */
.filter-display {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    padding: 1rem;
    border-radius: 4px;
}

.filter-header {
    color: var(--tint-yellow);
    font-weight: bold;
    margin-bottom: 0.75rem;
    text-align: center;
}

.filter-info {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 1.5rem;
    align-items: center;
}

.filter-param {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-param .param-label {
    color: var(--ui-text-muted);
    font-size: 0.75rem;
}

.filter-bar {
    height: 10px;
}

.cutoff-fill {
    background: linear-gradient(90deg, var(--c64-orange), var(--c64-yellow));
}

.res-fill {
    background: linear-gradient(90deg, var(--c64-purple), var(--c64-light-red));
}

.param-value {
    color: var(--tint-yellow);
    font-size: 0.7rem;
    font-family: monospace;
}

.filter-modes, .filter-voices {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-mode, .filter-voice {
    background: var(--ui-raised);
    color: var(--ui-text-faint);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 2px;
    transition: all 0.1s ease;
}

.filter-mode.active, .filter-voice.active {
    background: var(--c64-cyan);
    color: var(--c64-black);
}

.volume-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--ui-line-soft);
}

.volume-meter {
    display: flex;
    gap: 3px;
    flex: 1;
}

.volume-bar {
    flex: 1;
    height: 20px;
    background: var(--ui-raised);
    border-radius: 2px;
    transition: background 0.1s ease;
}

.volume-bar.active:nth-child(-n+5) {
    background: var(--c64-green);
}

.volume-bar.active:nth-child(n+6):nth-child(-n+10) {
    background: var(--c64-yellow);
}

.volume-bar.active:nth-child(n+11) {
    background: var(--c64-light-red);
}

/* Register Activity */
.register-activity {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    padding: 0.75rem;
    border-radius: 4px;
}

.register-header {
    color: var(--tint-yellow);
    font-weight: bold;
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 0.85rem;
}

.register-grid {
    display: grid;
    /* minmax(0, ...) lets the cells shrink below the width of their labels;
       a bare 1fr floors at min-content and overflows on narrow screens. */
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.3rem;
}

.register-cell {
    background: var(--ui-raised);
    padding: 0.25rem;
    border-radius: 2px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    transition: background 0.1s ease;
}

.register-cell.updated {
    background: var(--c64-light-blue);
}

.register-cell .reg-value {
    min-width: 0;
}

.reg-name {
    color: var(--ui-text-muted);
    font-size: 0.6rem;
}

.reg-value {
    color: var(--tint-green);
    font-family: monospace;
    font-size: 0.8rem;
}

/* SID page on narrow screens */
@media (max-width: 768px) {
    .voice-visualizer {
        grid-template-columns: 1fr;
    }
    
    .filter-info {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    
    .register-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* SID Song Selector - Horizontal Grid */
.sid-selector-horizontal {
    margin-bottom: 1rem;
}

.sid-btn-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
}

/* Caption above the song and track pickers */
.selector-label {
    color: var(--ui-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}

/* Song Info - Vertical */
.song-info-vertical {
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line);
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
}

.song-info-vertical .song-title {
    color: var(--tint-green);
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.song-info-vertical .song-author {
    color: var(--tint-cyan);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.song-info-vertical .song-released {
    color: var(--ui-text-muted);
    font-size: 0.8rem;
}

/* Track Section */
.track-section {
    margin-bottom: 1rem;
}

/* Player Controls - Horizontal */
.player-controls-horizontal {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.player-controls-horizontal .player-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    text-align: center;
}

.player-controls-horizontal .play-btn {
    background: var(--c64-light-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
    font-weight: bold;
}

.player-controls-horizontal .play-btn:hover {
    background: var(--tint-green);
    border-color: var(--tint-green);
}

/* Playing: the button now stops the tune */
.player-controls-horizontal .play-btn.playing {
    background: var(--tint-orange);
    border-color: var(--tint-orange);
}

.sid-player-body > .frame-counter {
    color: var(--tint-cyan);
    font-size: 0.85rem;
    text-align: center;
    padding: 0.5rem;
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    border-radius: 4px;
}

.sid-btn {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 2px solid var(--ui-line);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.sid-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.sid-btn.active {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
    font-weight: bold;
}

/* Track Selector */
.track-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0.75rem 0;
    padding: 0.5rem;
    background: var(--ui-sunken);
    border: 1px solid var(--ui-line-soft);
    border-radius: 4px;
}

.track-btn {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    min-width: 2rem;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.track-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.track-btn.active {
    background: var(--c64-light-blue);
    border-color: var(--c64-light-blue);
    color: var(--c64-white);
    font-weight: bold;
}

/* ============================================================================
   BASIC EDITOR STYLES
   ============================================================================ */

.basic-editor {
    display: flex;
    flex-direction: column;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    overflow: hidden;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(180deg, var(--ui-raised), var(--ui-panel));
    border-bottom: 1px solid var(--ui-line);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.editor-btn {
    background: var(--ui-raised);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    border-radius: 4px;
    padding: 0.35rem 0.75rem;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.editor-btn:hover {
    background: var(--ui-hover);
    border-color: var(--c64-light-blue);
}

.editor-btn.load-btn {
    background: var(--go-bg);
    border-color: var(--c64-green);
    color: var(--tint-green);
}

.editor-btn.load-btn:hover {
    background: var(--c64-light-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
}

.btn-icon {
    font-size: 0.9rem;
}

/* Search Container */
.search-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.search-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ui-line);
    border-radius: 3px;
    color: var(--ui-text-muted);
    padding: 0.25rem 0.5rem;
    font-family: inherit;
    font-size: 0.8rem;
    width: 120px;
    transition: border-color 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--c64-light-blue);
}

.search-input::placeholder {
    color: var(--ui-text-faint);
}

.search-btn {
    background: transparent;
    border: 1px solid var(--ui-line);
    border-radius: 3px;
    color: var(--ui-text-dim);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.search-btn:hover {
    border-color: var(--c64-light-blue);
    color: var(--tint-light-blue);
}

/* Run/Step/Stop buttons for ASM mode */
.editor-btn.run-btn {
    background: var(--go-bg);
    border-color: var(--c64-green);
    color: var(--tint-green);
}

.editor-btn.run-btn:hover {
    background: var(--c64-light-green);
    border-color: var(--c64-light-green);
    color: var(--c64-black);
}

.editor-btn.step-btn {
    background: var(--step-bg);
    border-color: var(--c64-yellow);
    color: var(--tint-yellow);
}

.editor-btn.step-btn:hover {
    background: var(--tint-yellow);
    border-color: var(--tint-yellow);
    color: var(--c64-black);
}

.editor-btn.stop-btn {
    background: var(--stop-bg);
    border-color: var(--tint-red);
    color: var(--tint-red);
}

.editor-btn.stop-btn:hover {
    background: var(--tint-red);
    color: var(--c64-black);
}

/* Active state for Run/Step buttons */
.editor-btn.run-btn.active {
    background: var(--c64-light-green);
    color: var(--c64-black);
    box-shadow: 0 0 10px var(--c64-light-green);
}

.editor-btn.step-btn.active {
    background: var(--tint-yellow);
    color: var(--c64-black);
    box-shadow: 0 0 10px var(--tint-yellow);
}

/* Editor Container */
.editor-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 200px;
    max-height: 400px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
}

/* Focus state - highlighted border when editor has focus */
.editor-container.focused {
    border-color: var(--c64-light-blue);
    box-shadow: 0 0 8px color-mix(in srgb, var(--c64-light-blue) 40%, transparent);
}

/* Line Numbers. The editor sets the width; containment keeps the browser
   from measuring every row whenever the rest of the editor changes. */
.line-numbers {
    flex: none;
    contain: strict;
    background: var(--ui-sunken);
    color: var(--ui-text-faint);
    padding: 0.5rem 0;
    text-align: right;
    user-select: none;
    overflow: hidden;
    min-width: 40px;
    border-right: 1px solid var(--ui-line-soft);
}

.line-number {
    padding: 0 0.5rem;
    height: 1.4em;
    line-height: 1.4em;
}

.line-number.error {
    background: color-mix(in srgb, var(--tint-red) 20%, transparent);
    color: var(--tint-red);
}

.line-number.warning {
    background: color-mix(in srgb, var(--tint-orange) 15%, transparent);
    color: var(--tint-orange);
}

/* Debug highlight - current line being executed */
.line-number.debug-highlight {
    background: color-mix(in srgb, var(--tint-yellow) 30%, transparent);
    color: var(--tint-yellow);
    font-weight: bold;
}

/* A running BASIC program: hotter lines take more of the time. */
.line-number.hot {
    background: color-mix(in srgb, var(--tint-red) calc(var(--heat) * 45%), transparent);
    color: var(--ui-text);
}

.line-number.running {
    box-shadow: inset 3px 0 0 var(--c64-light-green);
    color: var(--tint-green);
    font-weight: bold;
}

/* Editor Wrapper (contains both textarea and highlight overlay) */
.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Textarea (actual editable element) */
.editor-textarea {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0.5rem;
    margin: 0;
    border: none;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: var(--tint-light-blue);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    white-space: pre;
    overflow: auto;
    z-index: 2;
    tab-size: 2;
    -moz-tab-size: 2;
}

.editor-textarea::selection {
    background: color-mix(in srgb, var(--c64-light-blue) 40%, transparent);
}

/* Syntax Highlight Overlay */
.editor-highlight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0.5rem;
    margin: 0;
    background: var(--ui-sunken);
    color: var(--ui-text-muted);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre;
    overflow: auto;
    pointer-events: none;
    z-index: 1;
    tab-size: 2;
    -moz-tab-size: 2;
}

/* Syntax Highlighting Token Colors */
.token-keyword {
    color: var(--syntax-keyword);
    font-weight: bold;
}

.token-string {
    color: var(--syntax-string);
}

.token-number {
    color: var(--syntax-number);
}

.token-operator {
    color: var(--syntax-keyword);
}

.token-comment {
    color: var(--syntax-comment);
    font-style: italic;
}

.token-variable {
    color: var(--syntax-variable);
}

.token-function {
    color: var(--syntax-function);
}

.token-linenumber {
    color: var(--syntax-line-number);
}

.token-punctuation {
    color: var(--ui-text-muted);
}

.token-error {
    color: var(--syntax-error);
    text-decoration: wavy underline;
    text-decoration-color: var(--syntax-error);
}

/* {CLR}-style control codes inside strings, shown as the C64's reversed
   quote-mode characters would stand out. Colour only: the overlay must keep
   every character exactly as wide as in the textarea underneath. */
.token-control,
.basic-code .control {
    color: var(--ui-sunken);
    background: var(--tint-cyan);
    border-radius: 2px;
}

/* File menu in the editor toolbar */
.editor-menu {
    position: relative;
}

.editor-menu > summary {
    list-style: none;
    cursor: pointer;
    border: 1px solid var(--ui-line);
    border-radius: 3px;
    color: var(--ui-text-muted);
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
    user-select: none;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.editor-menu > summary::-webkit-details-marker {
    display: none;
}

.editor-menu > summary::after {
    content: ' ▾';
}

.editor-menu > summary:hover,
.editor-menu[open] > summary {
    border-color: var(--c64-light-blue);
    color: var(--ui-text);
}

.editor-menu > summary:focus-visible {
    outline: 2px solid var(--tint-yellow);
    outline-offset: 2px;
}

/* The File button follows the search box, so there is always room to its
   left; opening rightwards would be clipped by the editor on a phone. */
.editor-menu-items {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    min-width: 230px;
    padding: 4px;
    background: var(--ui-panel);
    border: 1px solid var(--c64-light-blue);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.editor-menu-items button {
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--ui-text-muted);
    padding: 6px 10px;
    font: inherit;
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}

.editor-menu-items button:hover,
.editor-menu-items button:focus-visible {
    background: var(--c64-light-blue);
    color: var(--c64-white);
}

/* Editor Status Bar */
.editor-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.75rem;
    background: var(--ui-sunken);
    border-top: 1px solid var(--ui-line-soft);
    font-size: 0.8rem;
    color: var(--ui-text-dim);
}

.status-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.error-count {
    margin-left: 1rem;
}

.error-count.has-errors {
    color: var(--tint-red);
}

.error-count.has-warnings {
    color: var(--tint-orange);
}

/* Responsive adjustments for editor */
@media (max-width: 1200px) {
    .editor-container {
        min-height: 180px;
        max-height: 350px;
    }
}

@media (max-width: 900px) {
    .editor-container {
        min-height: 150px;
        max-height: 300px;
    }
    
    .editor-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .toolbar-left, .toolbar-right {
        width: 100%;
        justify-content: center;
    }
}

/* ======================================
   ACCESSIBILITY
   ====================================== */

/* Site-wide keyboard focus ring. :focus-visible keeps it off mouse clicks.
   Scoped to canvas rather than [tabindex] because index/asm put tabindex on
   <body>, which would otherwise draw an outline around the whole page. */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
canvas[tabindex]:focus-visible {
    outline: 2px solid var(--tint-yellow);
    outline-offset: 2px;
}

/* The C64 screen is the keyboard target on / and /asm, so make it obvious
   when keystrokes are going to the emulated machine. */
#screen:focus-visible {
    outline: 2px solid var(--tint-yellow);
    outline-offset: 4px;
    box-shadow: 0 0 20px color-mix(in srgb, var(--tint-yellow) 30%, transparent);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
