/* CSS Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables */
:root {
    --color-header-bg: #1a1a2e;
    --color-header-text: #eaeaea;
    --color-body-bg: #f5f5f0;
    --color-text: #2c2c2c;
    --color-accent: #c9a227;
    --color-tab-active: #f5f5f0;
    --color-tab-inactive: #3a3a4e;
    --color-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --color-panel-bg: #4a4a4a;
}

/* Body */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-body-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* Header */
header {
    background: var(--color-header-bg);
    color: var(--color-header-text);
    padding: 2rem 1rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    letter-spacing: 0.3em;
    font-weight: 300;
}

header p {
    margin-top: 0.5rem;
    font-size: 1.1rem;
    opacity: 0.85;
}

/* Tab Bar */
.tab-bar {
    display: flex;
    background: #2a2a3e;
}

.tab-bar button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: var(--color-tab-inactive);
    color: #ccc;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.tab-bar button.active {
    background: var(--color-tab-active);
    color: var(--color-text);
    font-weight: bold;
}

.tab-bar button:hover:not(.active) {
    background: #4a4a5e;
}

/* Tab Panels */
.tab-panel {
    display: none;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.tab-panel.active {
    display: block;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    color: #666;
    font-size: 0.85rem;
}

/* Monospace areas */
code, pre, .mono {
    font-family: var(--color-mono);
}

/* Home Tab */
.hero {
    text-align: center;
    padding: 2rem 0 1.5rem;
}

.hero-title {
    font-size: 3rem;
    letter-spacing: 0.4em;
    font-weight: 200;
    color: var(--color-header-bg);
}

.hero-subtitle {
    font-size: 1.2rem;
    color: #555;
    margin-top: 0.5rem;
}

.home-intro {
    max-width: 700px;
    margin: 0 auto 2rem;
}

.home-intro p {
    margin-bottom: 1rem;
}

.home-origin {
    display: grid;
    grid-template-columns: minmax(220px, 320px) 1fr;
    gap: 1.5rem;
    align-items: center;
    margin-bottom: 2rem;
}

.home-origin-photo {
    margin: 0;
    text-align: center;
}

.home-origin-photo img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
}

.home-origin-photo figcaption {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

.home-origin-text p:first-child {
    font-size: 1.08rem;
    color: var(--color-header-bg);
}

.home-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.home-gallery figure {
    text-align: center;
}

.home-gallery img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.home-gallery figcaption {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

.home-credits {
    border-top: 1px solid #ddd;
    padding-top: 1.5rem;
    margin-bottom: 2rem;
}

.home-credits h3 {
    margin-bottom: 0.75rem;
}

.home-credits ul {
    list-style: none;
    padding: 0;
}

.home-credits li {
    margin-bottom: 0.5rem;
}

.home-credits a {
    color: #1a5276;
    text-decoration: underline;
}

.attribution {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.75rem;
}

.home-nav-hints {
    margin-top: 2rem;
}

.home-nav-hints h3 {
    margin-bottom: 1rem;
}

.nav-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.nav-card {
    display: block;
    padding: 1.25rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-decoration: none;
    color: var(--color-text);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.nav-card:hover {
    border-color: var(--color-accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.nav-card strong {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
}

.nav-card span {
    font-size: 0.9rem;
    color: #666;
}

/* ISA Tab */
.isa-wrapper {
    max-width: 1100px;
    margin: 0 auto;
}

.isa-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.28);
    padding-bottom: 1.5rem;
}

.isa-kicker {
    color: #fff;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    margin-bottom: 0.25rem;
}

.isa-header h2 {
    font-size: 2.2rem;
    color: #fff;
    margin-bottom: 0.5rem;
}

.isa-section p {
    color: #444;
}

.isa-header p {
    color: #fff;
}

.isa-section {
    margin-bottom: 2rem;
}

.isa-section h3 {
    color: var(--color-header-bg);
    margin-bottom: 0.75rem;
    font-size: 1.45rem;
}

.isa-section h4 {
    margin: 1.5rem 0 0.75rem;
    color: var(--color-header-bg);
    font-size: 1.08rem;
}

.isa-format {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid #d8d8d8;
    border-radius: 6px;
    overflow: hidden;
    margin: 1rem 0;
    background: #fff;
}

.isa-format-half {
    padding: 1rem;
    display: grid;
    gap: 0.35rem;
    border-right: 1px solid #d8d8d8;
}

.isa-format-half:last-child {
    border-right: none;
}

.isa-format-half strong {
    color: var(--color-header-bg);
}

.isa-format-half span {
    font-family: var(--color-mono);
    font-size: 0.9rem;
    color: #555;
}

.isa-facts,
.isa-note-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
}

.isa-facts div,
.isa-note-grid article {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
}

.isa-facts strong,
.isa-note-grid h4 {
    display: block;
    margin: 0 0 0.35rem;
    color: var(--color-header-bg);
}

.isa-facts span,
.isa-note-grid p {
    color: #555;
    font-size: 0.92rem;
}

.isa-table {
    min-width: 900px;
}

.isa-table td:first-child {
    font-family: var(--color-mono);
    font-weight: 700;
    color: var(--color-header-bg);
}

.isa-table code,
.isa-code code {
    font-family: var(--color-mono);
}

.isa-steps,
.isa-notes {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem 1rem 1rem 2rem;
}

.isa-steps li,
.isa-notes li {
    margin-bottom: 0.5rem;
}

.isa-code {
    background: #1f2430;
    color: #f2f2f2;
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    margin-top: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
    .tab-bar {
        flex-direction: column;
    }

    .tab-bar button {
        padding: 10px 16px;
    }

    .tab-panel {
        padding: 1rem;
    }

    .home-origin {
        grid-template-columns: 1fr;
    }

    .isa-format {
        grid-template-columns: 1fr;
    }

    .isa-format-half {
        border-right: none;
        border-bottom: 1px solid #d8d8d8;
    }

    .isa-format-half:last-child {
        border-bottom: none;
    }

    header h1 {
        font-size: 1.8rem;
        letter-spacing: 0.15em;
    }
}

/* ===========================
   History Tab
   =========================== */

/* Language Toggle */
.lang-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.lang-btn {
    padding: 0.5rem 1.5rem;
    border: 2px solid var(--color-accent);
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.95rem;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
}

.lang-btn.active {
    background: var(--color-accent);
    color: #fff;
}

.lang-btn:hover:not(.active) {
    background: rgba(201, 162, 39, 0.15);
}

/* Language content visibility */
.history-content {
    display: none;
}

.history-content.active {
    display: block;
}

/* History Title & Lead */
.history-title {
    font-size: 2.4rem;
    font-weight: 300;
    color: var(--color-header-bg);
    text-align: center;
    margin-bottom: 0.25rem;
}

.history-lead {
    text-align: center;
    font-size: 1.15rem;
    color: #666;
    font-style: italic;
    margin-bottom: 2.5rem;
}

.history-photo-credit {
    text-align: center;
    font-size: 0.9rem;
    color: #777;
    margin-top: -1.5rem;
    margin-bottom: 2rem;
}

/* Chapters */
.history-chapter {
    max-width: 780px;
    margin: 0 auto 2.5rem;
}

.history-chapter h3 {
    font-size: 1.5rem;
    color: var(--color-header-bg);
    margin-bottom: 0.75rem;
    border-bottom: 2px solid var(--color-accent);
    padding-bottom: 0.4rem;
}

.history-chapter p {
    margin-bottom: 1rem;
    line-height: 1.8;
}

.history-chapter a {
    color: #1a5276;
    text-decoration: underline;
    text-decoration-color: rgba(26, 82, 118, 0.3);
    transition: text-decoration-color 0.2s;
}

.history-chapter a:hover {
    text-decoration-color: #1a5276;
}

/* Figures */
.history-figure {
    margin: 1.5rem 0;
}

.history-figure img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    border: 1px solid #ddd;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.history-figure figcaption {
    text-align: center;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
    margin-top: 0.5rem;
}

.history-figure--wide {
    max-width: 100%;
}

.history-figure--right {
    float: right;
    width: 45%;
    margin: 0 0 1rem 1.5rem;
}

/* Blockquotes */
.history-quote {
    border-left: 4px solid var(--color-accent);
    padding: 1rem 1.5rem;
    margin: 1.5rem 0;
    background: rgba(201, 162, 39, 0.06);
    font-style: italic;
    font-size: 1.05rem;
    line-height: 1.7;
    border-radius: 0 6px 6px 0;
}

.history-quote cite {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    font-style: normal;
    color: #888;
}

/* History List */
.history-list {
    list-style: none;
    padding: 0;
}

.history-list li {
    padding: 0.5rem 0 0.5rem 1.5rem;
    position: relative;
    line-height: 1.7;
}

.history-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--color-accent);
    font-size: 1.1rem;
}

/* Specs Table */
.specs-table-wrap {
    overflow-x: auto;
    margin: 1rem 0;
}

.specs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.specs-table th {
    background: var(--color-header-bg);
    color: #fff;
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
}

.specs-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.specs-table tr:nth-child(even) {
    background: rgba(0,0,0,0.02);
}

.specs-table tr:hover {
    background: rgba(201, 162, 39, 0.08);
}

.specs-highlight td {
    background: rgba(201, 162, 39, 0.1);
    font-weight: 600;
}

/* ===== TIMELINE ===== */
.timeline {
    position: relative;
    padding: 1rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 60px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to bottom, var(--color-accent), var(--color-header-bg));
    border-radius: 2px;
}

.timeline-item {
    position: relative;
    padding-left: 100px;
    margin-bottom: 2rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 52px;
    top: 4px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: var(--color-body-bg);
    border: 3px solid var(--color-accent);
    z-index: 1;
}

.timeline-item--highlight::before {
    background: var(--color-accent);
    box-shadow: 0 0 0 4px rgba(201, 162, 39, 0.25);
}

.timeline-date {
    position: absolute;
    left: 0;
    top: 0;
    width: 45px;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--color-header-bg);
}

.timeline-content {
    background: #fff;
    padding: 1rem 1.25rem;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.timeline-content strong {
    display: block;
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
    color: var(--color-header-bg);
}

.timeline-content p {
    font-size: 0.9rem;
    margin: 0;
    color: #555;
}

/* ===== PEOPLE GRID ===== */
.people-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-top: 1rem;
}

.person-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.person-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.person-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-header-bg);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    margin: 0 auto 0.75rem;
    letter-spacing: 0.05em;
}

.person-card h4 {
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
    color: var(--color-header-bg);
}

.person-role {
    font-size: 0.8rem;
    color: var(--color-accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.person-card p:last-child {
    font-size: 0.85rem;
    color: #555;
    line-height: 1.5;
    text-align: left;
}

/* ===== REFERENCES ===== */
.references-list {
    padding-left: 1.5rem;
}

.references-list li {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #555;
}

.references-list a {
    color: #1a5276;
}

/* ===== RTL SUPPORT ===== */
.lang-he .history-chapter {
    direction: rtl;
    text-align: right;
}

.lang-he .history-quote {
    border-left: none;
    border-right: 4px solid var(--color-accent);
    border-radius: 6px 0 0 6px;
}

.lang-he .history-list li {
    padding: 0.5rem 1.5rem 0.5rem 0;
}

.lang-he .history-list li::before {
    left: auto;
    right: 0;
    content: '◂';
}

.lang-he .specs-table th {
    text-align: right;
}

.lang-he .history-figure--right {
    float: left;
    margin: 0 1.5rem 1rem 0;
}

.lang-he .timeline::before {
    left: auto;
    right: 60px;
}

.lang-he .timeline-item {
    padding-left: 0;
    padding-right: 100px;
}

.lang-he .timeline-item::before {
    left: auto;
    right: 52px;
}

.lang-he .timeline-date {
    left: auto;
    right: 0;
}

.lang-he .timeline-content {
    text-align: right;
}

.lang-he .person-card p:last-child {
    text-align: right;
}

/* ===== HISTORY RESPONSIVE ===== */
@media (max-width: 768px) {
    .history-title {
        font-size: 1.8rem;
    }

    .history-chapter h3 {
        font-size: 1.25rem;
    }

    .history-figure--right {
        float: none;
        width: 100%;
        margin: 1rem 0;
    }

    .timeline::before {
        left: 20px;
    }

    .timeline-item {
        padding-left: 55px;
    }

    .timeline-item::before {
        left: 12px;
        width: 17px;
        height: 17px;
    }

    .timeline-date {
        width: auto;
        font-size: 0.85rem;
    }

    .lang-he .timeline::before {
        left: auto;
        right: 20px;
    }

    .lang-he .timeline-item {
        padding-left: 0;
        padding-right: 55px;
    }

    .lang-he .timeline-item::before {
        left: auto;
        right: 12px;
    }

    .people-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== TRAINING TAB ===== */
.training-wrapper {
    max-width: 1080px;
    margin: 0 auto;
    padding: 1rem;
}

.training-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.training-main {
    min-width: 0;
}

.lesson-tracker {
    position: sticky;
    top: 1rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 0.9rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.lesson-tracker h3 {
    margin-bottom: 0.65rem;
    font-size: 1rem;
    color: var(--color-header-bg);
}

.lesson-tracker-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.lesson-tracker-item {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 0.6rem;
    align-items: center;
    border: 1px solid #ddd;
    background: #fafafa;
    color: #333;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    text-align: left;
}

.lesson-tracker-item:hover {
    background: #f0f0f0;
}

.lesson-tracker-item.active {
    border-color: var(--color-accent);
    background: #fff9e7;
}

.lesson-tracker-item.completed {
    border-color: #4caf50;
}

.lesson-tracker-index {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ececec;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.lesson-tracker-item.active .lesson-tracker-index {
    background: var(--color-accent);
    color: #fff;
}

.lesson-tracker-item.completed .lesson-tracker-index {
    background: #4caf50;
    color: #fff;
}

.lesson-tracker-title {
    font-size: 0.9rem;
    line-height: 1.2;
}

.lesson-nav-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #ddd;
}

.lesson-progress {
    font-size: 0.9rem;
    color: #666;
}

.lesson-progress-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.lesson-nav-top-buttons {
    display: flex;
    gap: 0.5rem;
}

.progress-dots {
    display: flex;
    gap: 0.5rem;
}

.progress-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ddd;
    border: 2px solid #999;
}

.progress-dots .dot.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.progress-dots .dot.completed {
    background: #4caf50;
    border-color: #388e3c;
}

.lesson-title {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    color: var(--color-header-bg);
}

.lesson-section {
    margin-bottom: 2rem;
}

.lesson-section h3 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    color: #333;
}

.section-text {
    line-height: 1.7;
}

.section-text ul, .section-text ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.section-text li {
    margin-bottom: 0.4rem;
}

.section-text code {
    background: #e8e8e8;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-family: var(--color-mono);
    font-size: 0.9em;
}

.section-text pre {
    background: #1a1a2e;
    color: #eaeaea;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.4;
    margin: 1rem 0;
}

.register-table, .opcode-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.register-table th, .opcode-table th {
    background: var(--color-header-bg);
    color: var(--color-header-text);
    padding: 0.6rem 0.8rem;
    text-align: left;
}

.register-table td, .opcode-table td {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid #ddd;
}

.register-table code, .opcode-table code {
    background: #e8e8e8;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    font-family: var(--color-mono);
}

.word-diagram, .instr-diagram {
    display: flex;
    margin: 1rem 0;
    border: 2px solid #333;
    border-radius: 4px;
    overflow: hidden;
}

.word-diagram span, .instr-diagram span {
    flex: 1;
    padding: 0.8rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: bold;
}

.left-instr, .opcode-field {
    background: #e3f2fd;
    border-right: 2px solid #333;
}

.right-instr, .addr-field {
    background: #e8f5e9;
}

.bit-layout {
    font-size: 0.7rem !important;
}

/* Exercises */
.exercises {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--color-accent);
}

.exercises h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--color-header-bg);
}

.exercise {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.exercise-question {
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.exercise-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.exercise-options .option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.exercise-options .option:hover {
    background: #f0f0f0;
}

.exercise-options input[type="radio"] {
    accent-color: var(--color-accent);
}

.btn-check, .btn-run-sim {
    background: var(--color-accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-check:hover, .btn-run-sim:hover {
    background: #b8911f;
}

.exercise-feedback {
    margin-top: 0.75rem;
    min-height: 1.5em;
}

.feedback-correct {
    color: #2e7d32;
    font-weight: 600;
}

.feedback-wrong {
    color: #c62828;
    font-weight: 600;
}

.feedback-hint {
    color: #666;
    font-style: italic;
}

.sim-output {
    margin: 0.75rem 0;
    padding: 0.5rem;
    background: #1a1a2e;
    color: #4caf50;
    border-radius: 4px;
    font-family: var(--color-mono);
}

.sim-output:empty {
    display: none;
}

/* Lesson Navigation (bottom) */
.lesson-nav-bottom {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #ddd;
}

.btn-prev, .btn-next {
    background: var(--color-header-bg);
    color: var(--color-header-text);
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
}

.btn-prev:hover, .btn-next:hover {
    background: #2a2a4e;
}

.btn-prev:disabled, .btn-next:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.loading-msg {
    text-align: center;
    color: #666;
    padding: 3rem;
}

/* Training Responsive */
@media (max-width: 768px) {
    .training-wrapper {
        padding: 0.5rem;
    }

    .training-layout {
        grid-template-columns: 1fr;
    }

    .lesson-tracker {
        position: static;
    }

    .lesson-tracker-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .lesson-nav-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
    }

    .lesson-title {
        font-size: 1.4rem;
    }

    .word-diagram, .instr-diagram {
        flex-direction: column;
    }

    .left-instr, .opcode-field {
        border-right: none;
        border-bottom: 2px solid #333;
    }
}

/* ===== SIMULATOR TAB (SPRINT 7) ===== */
.simulator-shell {
    background: linear-gradient(145deg, #575757, #464646);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='1'%3E%3Crect width='200' height='1' fill='rgba(255,255,255,0.02)'/%3E%3C/svg%3E");
    background-size: 100% 2px;
    border: 2px solid #2c2c2c;
    border-radius: 14px;
    padding: 1rem;
    color: #f4f4f4;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    font-family: 'Century Gothic', 'Futura', -apple-system, sans-serif;
}

.sim-titlebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
}

.sim-titlebar h2 {
    margin: 0;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 600;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.08);
}

.sim-titlebar p {
    margin-top: 0.4rem;
    color: #d8d8d8;
}

.sim-audio-controls {
    margin-top: 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.sim-audio-controls label {
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #e8e8e8;
}

.sim-audio-controls input[type="range"] {
    width: 180px;
}

.sim-audio-controls button {
    border: 1px solid #8d8d8d;
    border-radius: 8px;
    background: linear-gradient(180deg, #f1f1f1, #c9c9c9);
    color: #1d1d1d;
    font-weight: 700;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
}

.sim-audio-controls button.muted {
    background: linear-gradient(180deg, #b95e5e, #8a3f3f);
    color: #fff;
}

#sim-btn-authentic.active {
    background: linear-gradient(180deg, #4f764f, #2e4f2e);
    color: #fff;
}

.sim-panel-grid {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 220px;
    gap: 0.8rem;
    align-items: start;
}

.sim-tools-overlay {
    margin-bottom: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    background: rgba(210, 222, 240, 0.12);
    backdrop-filter: blur(6px);
    padding: 0.55rem;
}

.sim-tools-overlay.collapsed .tools-panel {
    display: none;
}

.sim-tools-overlay.collapsed .tools-tab {
    display: none;
}

.tools-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

#tools-toggle {
    border: 2px solid #f0d97b;
    border-radius: 8px;
    background: linear-gradient(180deg, #3a3520, #1d1a0e);
    color: #f0d97b;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-right: 0.4rem;
}

#tools-toggle:hover {
    background: linear-gradient(180deg, #4a4520, #2d2a1e);
    box-shadow: 0 0 8px rgba(240, 217, 123, 0.4);
}

.sim-tools-overlay.collapsed #tools-toggle {
    background: linear-gradient(180deg, #1a2a1a, #0d1a0d);
    border-color: #4ade80;
    color: #4ade80;
}

.tools-toolbar button.tools-tab {
    border: 1px solid #9eb0c7;
    border-radius: 7px;
    background: linear-gradient(180deg, #ecf3fc, #c9d8ea);
    color: #18232e;
    font-size: 0.78rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
}

.tools-tab.active {
    background: linear-gradient(180deg, #83a6cd, #668cb8);
    color: #fff;
}

.tools-panel {
    display: none;
}

.tools-panel.active {
    display: block;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
}

.tools-target-grid {
    grid-template-columns: 1fr auto auto;
    align-items: end;
}

.tools-builder-desc {
    font-size: 0.72rem;
    color: #1a1a1a;
    line-height: 1.4;
    padding: 0.35rem 0.5rem;
    margin-top: 0.2rem;
    background: rgba(200, 215, 230, 0.25);
    border-left: 2px solid rgba(88, 166, 255, 0.4);
    border-radius: 3px;
    min-height: 1.4em;
}

.tools-target-grid button {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    background: #2a3a52;
    border: 1px solid #5a7a9a;
    color: #e6edf7;
    border-radius: 3px;
}

.tools-target-grid button:hover {
    background: #3a5070;
}

.tools-panel label {
    display: grid;
    gap: 0.18rem;
    font-size: 0.75rem;
    color: #e6edf7;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tools-panel input,
.tools-panel select,
.tools-panel textarea {
    border: 1px solid #7b8ea5;
    border-radius: 6px;
    background: #14181d;
    color: #d8f4d8;
    font-family: var(--color-mono);
    font-size: 0.78rem;
    padding: 0.35rem 0.45rem;
}

.tools-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.45rem;
}

.tools-actions button {
    border: 1px solid #8ea0b6;
    border-radius: 6px;
    background: linear-gradient(180deg, #f1f7ff, #cedaeb);
    color: #152331;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
}

.tools-readout {
    margin-top: 0.45rem;
    min-height: 2.1em;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    background: rgba(10, 16, 24, 0.5);
    color: #d9e8fb;
    font-family: var(--color-mono);
    font-size: 0.76rem;
    padding: 0.35rem 0.45rem;
}

/* Assembly Editor */
.asm-editor-wrap {
    display: flex;
    position: relative;
    border: 1px solid #5a6a80;
    border-radius: 6px;
    background: #0d1117;
    overflow: hidden;
    width: 100%;
    min-width: 0;
    max-height: 260px;
    overflow-y: auto;
}

.asm-line-numbers {
    width: 2.8rem;
    min-width: 2.8rem;
    padding: 0.45rem 0.3rem;
    background: #161b22;
    border-right: 1px solid #30363d;
    color: #6e7681;
    font-family: var(--color-mono);
    font-size: 0.74rem;
    line-height: 1.45;
    text-align: right;
    overflow: hidden;
    user-select: none;
}

.asm-line-numbers div {
    height: 1.45em;
    cursor: help;
}

.asm-line-numbers div[title]:hover {
    color: #58a6ff;
    background: rgba(56, 139, 253, 0.08);
}

.asm-line-numbers div.error {
    color: #f85149;
    font-weight: 700;
    background: rgba(248, 81, 73, 0.15);
    border-radius: 2px;
}

.asm-help-hint {
    font-size: 0.68rem;
    color: #6e7681;
    align-self: center;
    margin-left: 0.5rem;
}

.asm-examples-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
    flex-wrap: wrap;
}

.asm-examples-bar label {
    font-size: 0.75rem;
    color: #e6edf7;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.asm-examples-bar select {
    border: 1px solid #5a7a9a;
    border-radius: 5px;
    background: #1c2128;
    color: #c9d1d9;
    font-size: 0.78rem;
    padding: 0.25rem 0.4rem;
}

.asm-example-desc {
    font-size: 0.7rem;
    color: #8b949e;
    font-style: italic;
}

.asm-editor-area {
    flex: 1;
    min-width: 0;
    position: relative;
}

.asm-highlight {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 0.45rem 0.5rem;
    font-family: var(--color-mono);
    font-size: 0.8rem;
    line-height: 1.45;
    white-space: pre;
    overflow: hidden;
    pointer-events: none;
    color: transparent;
    border: none;
    tab-size: 4;
}

.asm-line-error {
    background: rgba(248, 81, 73, 0.15);
    border-bottom: 2px wavy #f85149;
    display: inline-block;
    width: 100%;
}

.asm-editor-area textarea {
    width: 100%;
    min-height: 320px;
    resize: vertical;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #c9d1d9;
    font-family: var(--color-mono);
    font-size: 0.8rem;
    line-height: 1.45;
    padding: 0.45rem 0.5rem;
    outline: none;
    white-space: pre;
    overflow-x: auto;
    tab-size: 4;
    position: relative;
    z-index: 1;
}

.asm-errors {
    padding: 0 0.5rem 0.3rem;
}

.asm-error-msg {
    color: #f85149;
    font-family: var(--color-mono);
    font-size: 0.7rem;
    padding: 0.1rem 0;
    border-left: 3px solid #f85149;
    padding-left: 0.4rem;
    margin-top: 0.2rem;
}

.asm-autocomplete {
    position: absolute;
    bottom: 100%;
    left: 3rem;
    background: #1c2128;
    border: 1px solid #444c56;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    max-height: 180px;
    overflow-y: auto;
    z-index: 100;
    min-width: 180px;
}

.asm-ac-item {
    padding: 0.3rem 0.6rem;
    font-family: var(--color-mono);
    font-size: 0.76rem;
    color: #c9d1d9;
    cursor: pointer;
}

.asm-ac-item.active,
.asm-ac-item:hover {
    background: #388bfd33;
    color: #58a6ff;
}

/* Make tools overlay full width when editor tab is active */
.sim-tools-overlay {
    max-width: 100%;
}

.sim-registers,
.sim-memory,
.sim-tape,
.sim-log {
    background: #2f2f2f;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 0.75rem;
}

.sim-registers h3,
.sim-memory h3,
.sim-tape h3,
.sim-log h3 {
    margin: 0 0 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.92rem;
    color: #f0d97b;
}
    .sim-memory-tools {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        margin-bottom: 0.45rem;
    }
    .sim-memory-tools label {
        font-size: 0.72rem;
        color: #d7d7d7;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }
    .sim-memory-tools input {
        width: 92px;
        padding: 0.18rem 0.35rem;
        border: 1px solid #767676;
        border-radius: 5px;
        background: #151515;
        color: #9eea9e;
        font-family: var(--color-mono);
        font-size: 0.78rem;
    }
    .sim-memory-tools button {
        border: 1px solid #9a9a9a;
        border-radius: 5px;
        background: linear-gradient(180deg, #f7f7f7, #cfcfcf);
        color: #111;
        font-weight: 700;
        padding: 0.15rem 0.5rem;
        cursor: pointer;
    }

.sim-register-row {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    align-items: center;
}

.sim-register-row code {
    background: #151515;
    border: 1px solid #666;
    color: #8de28d;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
}

.sim-memory-head,
.sim-memory-row {
    display: grid;
    grid-template-columns: 60px 160px minmax(180px, 1fr) minmax(180px, 1fr);
    gap: 0.4rem;
    align-items: center;
}

.sim-memory-head {
    color: #d3d3d3;
    font-size: 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 0.35rem;
}

.sim-memory-rows {
    margin-top: 0.45rem;
    max-height: 400px;
    overflow: auto;
    font-family: var(--color-mono);
    font-size: 0.76rem;
    position: relative;
}

.sim-memory-row {
    padding: 0.25rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.sim-memory-row.pc-left {
    background: rgba(255, 220, 96, 0.18);
}

.sim-memory-row.pc-right {
    background: rgba(98, 175, 255, 0.2);
}

.sim-memory-row.load-flash {
    background: rgba(120, 220, 120, 0.2);
    box-shadow: inset 0 0 0 1px rgba(150, 255, 150, 0.45);
}

.sim-memory-row.builder-target {
    background: rgba(100, 180, 255, 0.18);
    box-shadow: inset 0 0 0 1px rgba(100, 180, 255, 0.5);
    cursor: pointer;
}

.sim-memory-row {
    cursor: pointer;
}

.sim-memory-row code {
    color: #9eea9e;
}

.simulator-shell.authentic-mode .sim-memory-tools {
    display: none;
}

.simulator-shell.authentic-mode .sim-tools-overlay {
    display: none;
}

.simulator-shell.authentic-mode .sim-memory-head,
.simulator-shell.authentic-mode .sim-memory-rows,
.simulator-shell.authentic-mode .sim-log-rows {
    visibility: hidden;
    pointer-events: none;
}

.sim-instr-ref {
    text-decoration: underline dotted rgba(158, 234, 158, 0.5);
    text-underline-offset: 2px;
    cursor: help;
}

.sim-indicators {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.sim-light {
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    text-align: center;
    font-size: 0.72rem;
    padding: 0.2rem 0.35rem;
    background: #2a2a2a;
    color: #bbb;
}

.sim-light.on {
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 230, 120, 0.7);
    background: linear-gradient(180deg, #96864d, #786327);
}

.sim-controls {
    display: grid;
    grid-template-columns: auto repeat(6, minmax(0, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

.sim-controls button {
    border: 1px solid #8d8d8d;
    border-radius: 8px;
    background: linear-gradient(180deg, #f1f1f1, #c9c9c9);
    color: #1d1d1d;
    font-weight: 700;
    padding: 0.45rem 0.3rem;
    cursor: pointer;
}

/* Power button: larger, prominent, with call-to-action pulse on load */
.sim-controls button.power-cta {
    padding: 0.7rem 1.2rem;
    font-size: 1rem;
    border-radius: 10px;
    background: linear-gradient(180deg, #4ade80, #16a34a);
    color: #fff;
    border: 2px solid #15803d;
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.5);
    animation: power-pulse 1.8s ease-in-out infinite;
    position: relative;
}

.sim-controls button.power-cta::after {
    content: '▶ Press to start';
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    font-weight: 400;
    color: #4ade80;
    white-space: nowrap;
    letter-spacing: 0.04em;
    animation: power-pulse 1.8s ease-in-out infinite;
}

@keyframes power-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(74, 222, 128, 0.4); }
    50% { box-shadow: 0 0 20px rgba(74, 222, 128, 0.8), 0 0 40px rgba(74, 222, 128, 0.3); }
}

/* Once powered on, remove the CTA styling */
.sim-controls button.power-cta.powered {
    padding: 0.45rem 0.3rem;
    font-size: inherit;
    border-radius: 8px;
    background: linear-gradient(180deg, #f87171, #dc2626);
    color: #fff;
    border: 1px solid #991b1b;
    box-shadow: none;
    animation: none;
}

.sim-controls button.power-cta.powered::after {
    display: none;
}

.sim-controls button:hover {
    filter: brightness(1.05);
}

/* Speed dial */
.sim-speed-dial {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.7rem;
}
.sim-speed-dial label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #1d1d1d;
}
.sim-speed-dial input[type="range"] {
    width: 160px;
    accent-color: #c9a227;
}
.sim-speed-dial .speed-label {
    font-family: var(--color-mono);
    font-size: 0.72rem;
    color: #1d1d1d;
    min-width: 80px;
}

/* Light blink animations */
@keyframes light-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.sim-light.blink {
    animation: light-blink 0.4s ease-in-out infinite;
}
#light-power.on {
    background: linear-gradient(180deg, #4a9e4a, #2a6e2a);
    box-shadow: 0 0 12px rgba(80, 200, 80, 0.7);
}
#light-halt.on {
    background: linear-gradient(180deg, #c94040, #8a2020);
    box-shadow: 0 0 12px rgba(220, 80, 80, 0.7);
}
#light-error.on {
    background: linear-gradient(180deg, #c94040, #8a2020);
    box-shadow: 0 0 12px rgba(220, 80, 80, 0.7);
    animation: light-blink 0.2s ease-in-out infinite;
}
#light-left.on, #light-right.on {
    background: linear-gradient(180deg, #e8e8e8, #b8b8b8);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
    color: #222;
}

/* Register decimal display */
.sim-register-decimal {
    font-size: 0.68rem;
    color: #aadaaa;
    margin-top: 0.1rem;
    font-family: var(--color-mono);
}
.sim-register-row code[title] {
    cursor: help;
}

/* Breakpoint dot */
.sim-memory-row.breakpoint::before {
    content: '●';
    color: #e83030;
    position: absolute;
    left: -14px;
    font-size: 0.9rem;
}
.sim-memory-row {
    position: relative;
}

.sim-log {
    margin-top: 0.9rem;
}

.sim-log-rows {
    max-height: 180px;
    overflow: auto;
    background: #111;
    border: 1px solid #4f4f4f;
    border-radius: 8px;
    padding: 0.5rem;
    font-family: var(--color-mono);
    font-size: 0.72rem;
    color: #86df86;
    white-space: pre;
    tab-size: 22;
    -moz-tab-size: 22;
}

.sim-log-row {
    margin-bottom: 0.3rem;
    border-bottom: 1px dotted rgba(134, 223, 134, 0.2);
    padding-bottom: 0.25rem;
}

.sim-tape-strip {
    margin-top: 0.25rem;
    max-height: 260px;
    overflow: hidden;
    border: 1px solid #a09070;
    border-radius: 2px;
    /* Oiled paper: slightly translucent yellowish */
    background: #e8dbb4;
    background-image:
        /* Paper fiber texture */
        repeating-linear-gradient(0deg, rgba(180,160,120,0.04) 0px, transparent 1px, transparent 2px),
        repeating-linear-gradient(90deg, rgba(180,160,120,0.03) 0px, transparent 1px, transparent 3px),
        /* Oil-soaked translucency gradient */
        linear-gradient(180deg, #ece0c0, #e0d4a8, #e5d9b0);
    padding: 0.4rem 0.4rem 0.4rem 0.4rem;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.1);
}

.sim-tape-strip::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    /* Subtle worn edges */
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(100,80,50,0.08) 0px, transparent 3px),
        linear-gradient(270deg, rgba(100,80,50,0.08) 0px, transparent 3px);
    z-index: 1;
}

/* Reader slot visual — dark metal bar at top where tape feeds in */
.sim-tape-strip::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(180deg, #2a2520, #4a4035);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 2;
}

.sim-tape-strip.feeding {
    animation: tape-feed 0.6s linear infinite;
}

@keyframes tape-feed {
    from { background-position-y: 0; }
    to   { background-position-y: 14px; }
}

.sim-tape-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.3rem;
}

.sim-tape-header h3 {
    margin: 0;
}

.sim-tape-load-btn {
    border: 1px solid #8d8d8d;
    border-radius: 6px;
    background: linear-gradient(180deg, #f1f1f1, #c9c9c9);
    color: #1d1d1d;
    font-weight: 700;
    font-size: 0.72rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    letter-spacing: 0.03em;
}

.sim-tape-load-btn:hover {
    filter: brightness(1.05);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.sim-tape-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.4rem;
}

.sim-tape-run-btn {
    border: 1px solid #8d8d8d;
    border-radius: 6px;
    background: linear-gradient(180deg, #f1f1f1, #c9c9c9);
    color: #1d1d1d;
    font-weight: 700;
    font-size: 0.72rem;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    letter-spacing: 0.03em;
}

.sim-tape-run-btn:hover {
    filter: brightness(1.05);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.sim-tape-note {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #ccc;
}

.tape-word {
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px dashed rgba(160, 140, 100, 0.25);
    transition: opacity 0.5s ease-in, transform 0.5s ease-in, max-height 0.5s ease-in, margin 0.4s ease-in;
    transform-origin: top center;
    max-height: 70px;
    overflow: visible;
}

.tape-word.tape-consumed {
    opacity: 0;
    transform: translateY(-40px) scaleY(0.1) scaleX(0.85) perspective(300px) rotateX(75deg);
    max-height: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom-color: transparent;
    filter: blur(0.5px);
}

/* After full tape is read, the strip "swallows" the last bit */
.sim-tape-strip.tape-swallowed {
    max-height: 24px;
    transition: max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.sim-tape-strip.tape-swallowed::after {
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.tape-word.tape-entering {
    animation: tape-punch-in 0.35s ease-out;
}

@keyframes tape-punch-in {
    from { opacity: 0; transform: translateY(20px) scaleY(0.7); }
    to   { opacity: 1; transform: translateY(0) scaleY(1); }
}

.tape-row {
    display: grid;
    grid-template-columns: repeat(20, 1fr);
    gap: 1px;
    margin-bottom: 2px;
    justify-content: start;
}

.tape-bit {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: block;
    /* Unpunched: just a faint impression in the paper */
    border: 1px solid rgba(160, 140, 100, 0.3);
    background: rgba(220, 210, 180, 0.4);
}

.tape-bit.on {
    /* Pre-punch: position marked but not yet punched through */
    background: rgba(120, 100, 60, 0.15);
    border-color: rgba(140, 120, 80, 0.5);
}

.tape-bit.on.punched {
    /* Punched through: you see the dark reader backing through the hole */
    background: #1a1410;
    border-color: #302820;
    box-shadow: inset 0 0.5px 1px rgba(0,0,0,0.9), 0 0 0.5px rgba(0,0,0,0.3);
}

/* Sprocket feed holes — smaller, centered between data rows */
.tape-sprocket {
    display: flex;
    gap: 5px;
    justify-content: center;
    align-items: center;
    height: 6px;
    margin: 1px 0;
    padding: 0 2px;
}

.tape-sprocket-hole {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #1a1410;
    border: 0.5px solid #302820;
    box-shadow: inset 0 0.5px 0.5px rgba(0,0,0,0.8);
    flex-shrink: 0;
}



@media (max-width: 1100px) {
    .sim-panel-grid {
        grid-template-columns: 1fr;
    }

    .sim-memory-head,
    .sim-memory-row {
        grid-template-columns: 56px 140px minmax(140px, 1fr) minmax(140px, 1fr);
    }
}

@media (max-width: 760px) {
    .sim-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sim-indicators {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* Reduced motion: disable animations for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sim-tape-strip {
        animation: none !important;
    }

    .sim-indicator.on {
        transition: none !important;
    }

    .tape-bit.on.punched {
        transition: none !important;
    }

    .tape-word.tape-consumed {
        transition: none !important;
        transform: none !important;
        opacity: 0.15 !important;
    }

    .sim-controls button.power-cta {
        animation: none !important;
        box-shadow: 0 0 12px rgba(74, 222, 128, 0.6);
    }
    .sim-controls button.power-cta::after {
        animation: none !important;
    }
}
