/* ==========================================================================
   KS2-KS3 ICT & Computing Curriculum Experience Stylesheet
   Design Language: Premium Dark-Mode & HSL Tailored Neon Accents
   ========================================================================== */

/* Main Widget Container */
.aiad-ict-curriculum-widget {
    background: #0f172a; /* Sleek dark slate blue */
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 2.25rem;
    color: #e2e8f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    max-width: 1100px;
    margin: 2rem auto;
    position: relative;
    overflow: hidden;
}

/* Background glowing accents */
.aiad-ict-curriculum-widget::before {
    content: "";
    position: absolute;
    top: -150px;
    right: -150px;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
    pointer-events: none;
}

/* Header & Tabs */
.ict-widget__header {
    margin-bottom: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 1.5rem;
}

.ict-widget__badge {
    display: inline-block;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    margin-bottom: 0.75rem;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

/* Intro sits outside the widget, on the page background, so it inherits the
 * page text colour rather than the widget's light-on-dark palette. */
.aiad-ict-curriculum-intro {
    font-size: 1.05rem;
    line-height: 1.6;
    margin: 0 0 1.5rem 0;
    max-width: 800px;
}

.ict-widget__lead {
    color: #94a3b8;
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0 0 1.5rem 0;
    max-width: 800px;
}

/* Tab bar container */
.ict-widget__tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.5rem;
}

.ict-widget__tab-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 0.85rem 1.25rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    color: #94a3b8;
}

.ict-widget__tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
    color: #cbd5e1;
}

.ict-widget__tab-btn.is-active {
    background: rgba(99, 102, 241, 0.08);
    border-color: #6366f1;
    color: #ffffff;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15), inset 0 0 8px rgba(99, 102, 241, 0.05);
}

.tab-label-main {
    display: block;
    font-weight: 700;
    font-size: 1rem;
}

.tab-label-sub {
    display: block;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.15rem;
}

/* Panels */
.ict-widget__panel {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.ict-widget__panel.is-active {
    display: block;
}

.ict-widget__panel-intro {
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid #6366f1;
    border-radius: 0 8px 8px 0;
    padding: 1rem 1.25rem;
    margin-bottom: 2rem;
}

.ict-widget__panel-intro h3 {
    margin: 0 0 0.4rem 0;
    font-size: 1.15rem;
    color: #f1f5f9;
}

.ict-widget__panel-intro p {
    margin: 0;
    font-size: 0.9rem;
    color: #94a3b8;
    line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Key Stage 2: Scratch Block Editor & Stage Layout
   -------------------------------------------------------------------------- */
.playground-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 850px) {
    .playground-layout {
        grid-template-columns: 1fr;
    }
}

/* Visual Scratch Editor */
.scratch-editor {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.editor-header {
    background: #0f172a;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.dot-btn {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    display: inline-block;
}

.dot-btn.red { background: #ef4444; }
.dot-btn.yellow { background: #f59e0b; }
.dot-btn.green { background: #10b981; }

.editor-title {
    margin-left: auto;
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.scratch-blocks-list {
    padding: 1.5rem;
    background: #111827; /* Dark playground feel */
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex-grow: 1;
}

/* Scratch Block Types */
.scratch-block {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    padding: 0.55rem 0.85rem;
    border-radius: 4px 12px 12px 4px;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    width: fit-content;
}

.scratch-block--event {
    background: #e2a900; /* Scratch Gold */
    border-left: 4px solid #b58700;
    border-radius: 12px 12px 4px 4px; /* Hat block */
}

.scratch-block--motion {
    background: #4c97ff; /* Scratch Blue */
    border-left: 4px solid #206ecf;
}

.scratch-block--control {
    background: #ffab19; /* Scratch Orange */
    border-left: 4px solid #cf8700;
}

.scratch-block--pen {
    background: #0fbd8c; /* Scratch Pen Green */
    border-left: 4px solid #0b8e69;
}

/* Nested blocks shape representing visual control loops */
.block-has-children {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.45rem 0.45rem 0.45rem 0.45rem;
    border-radius: 4px 12px 12px 4px;
    width: auto;
    align-self: stretch;
}

.block-top-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0.4rem;
}

.block-nested-contents {
    margin: 0.4rem 0 0.4rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    border-left: 4px solid rgba(255, 255, 255, 0.28);
    padding-left: 0.75rem;
    align-self: stretch;
}

.block-bottom-row {
    height: 6px;
    align-self: stretch;
}

/* Custom inputs inside blocks */
.scratch-select {
    background: #ffffff;
    color: #111827;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.1rem 0.35rem;
    cursor: pointer;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.scratch-select:focus {
    outline: 2px solid #ffffff;
}

.block-input-value {
    background: #ffffff;
    color: #111827;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-weight: 700;
}

/* Editor actions */
.editor-actions {
    background: #0f172a;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    gap: 0.75rem;
}

.playground-btn {
    border: none;
    border-radius: 8px;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.playground-btn--run {
    background: #10b981;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.playground-btn--run:hover {
    background: #059669;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.playground-btn--run:active {
    transform: translateY(0);
}

.playground-btn--reset {
    background: #334155;
    color: #cbd5e1;
}

.playground-btn--reset:hover {
    background: #475569;
    color: #ffffff;
}

.btn-icon {
    font-size: 0.75rem;
    margin-right: 2px;
}

/* Grid Simulator Preview */
.grid-simulator {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.simulator-header {
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.6rem 1rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 600;
}

.grid-canvas-wrap {
    background: #090d16;
    height: 320px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Subtle grid graph lines */
.grid-lines-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: 40px 40px;
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
}

.grid-sprite {
    position: absolute;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.85rem;
    z-index: 10;
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: center center;
}

.grid-gem {
    position: absolute;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 9;
    animation: gemFloat 1.8s ease-in-out infinite;
}

@keyframes gemFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-6px) scale(1.1); filter: drop-shadow(0 0 10px rgba(0, 245, 255, 0.4)); }
}

.grid-svg-trace {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8;
}

.simulator-instruction {
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.85rem 1rem;
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
}

.instruction-icon {
    font-size: 1.15rem;
    margin-top: -0.1rem;
}

.simulator-instruction p {
    margin: 0;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.4;
}

/* --------------------------------------------------------------------------
   Key Stage 3: Binary decoder & Python mockup terminal
   -------------------------------------------------------------------------- */
.ks3-playground {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

/* Part A: Binary lock register block */
.binary-lock-section {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 1.25rem;
}

.binary-lock__header {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.lock-icon {
    font-size: 1.75rem;
}

.binary-lock__header h4 {
    margin: 0 0 0.2rem 0;
    color: #f1f5f9;
    font-size: 1rem;
}

.binary-lock__header p {
    margin: 0;
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.45;
}

.binary-register {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.bit-card {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.bit-value-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
}

.bit-toggle-btn {
    background: #0f172a;
    border: 2px solid #334155;
    border-radius: 8px;
    font-size: 1.5rem;
    font-family: monospace;
    font-weight: 700;
    color: #64748b;
    width: 60px;
    height: 60px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}

.bit-toggle-btn:hover {
    border-color: #475569;
    color: #94a3b8;
}

/* Active glowing state when bit is 1 */
.bit-toggle-btn.is-active {
    border-color: #6366f1;
    color: #6366f1;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.3), inset 0 0 8px rgba(99, 102, 241, 0.2);
    background: rgba(99, 102, 241, 0.05);
}

.bit-status-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: #475569;
}

.bit-card:has(.bit-toggle-btn.is-active) .bit-status-label {
    color: #6366f1;
}

.binary-display-bar {
    background: #0f172a;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.bar-formula {
    font-family: monospace;
    font-size: 0.85rem;
    color: #475569;
}

.formula-term.is-highlighted {
    color: #6366f1;
    font-weight: 700;
}

.bar-total {
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 600;
}

.total-number {
    font-size: 1.1rem;
    font-weight: 800;
    color: #ffffff;
    font-family: monospace;
    background: #1e293b;
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
}

.binary-feedback {
    margin-top: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    animation: fadeIn 0.3s ease-out;
}

.binary-feedback.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #34d399;
}

/* Part B: Python terminal simulator (Locked State) */
.python-section {
    position: relative;
    transition: all 0.4s ease;
}

.python-section.is-locked {
    filter: blur(1px);
    opacity: 0.4;
    pointer-events: none;
}

.python-lock-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    border-radius: 12px;
}

.overlay-lock-icon {
    font-size: 2.25rem;
}

.python-lock-overlay p {
    font-size: 0.95rem;
    font-weight: 700;
    color: #cbd5e1;
    margin: 0;
}

.python-terminal-wrap {
    background: #111827; /* Dark black terminal IDE color */
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    margin-bottom: 1.5rem;
}

.terminal-header {
    background: #0f172a;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.terminal-dots {
    display: flex;
    gap: 5px;
}

.t-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.t-dot.red { background: #ef4444; }
.t-dot.yellow { background: #f59e0b; }
.t-dot.green { background: #10b981; }

.terminal-title {
    margin-left: auto;
    font-size: 0.7rem;
    color: #64748b;
    font-family: monospace;
}

.terminal-editor {
    padding: 1.25rem;
    max-height: 260px;
    overflow-y: auto;
    overflow-x: auto; /* long code lines scroll inside the terminal instead of leaking */
}

.python-code-pre {
    margin: 0;
    font-family: "Fira Code", "Courier New", Courier, monospace;
    font-size: 0.85rem;
    line-height: 1.55;
    background: transparent;
    padding: 0;
}

.py-line {
    display: block;
    padding-left: 0.5rem;
    border-left: 3px solid transparent;
}

/* Syntax highlighting */
.py-comment { color: #64748b; font-style: italic; }
.py-keyword { color: #f43f5e; font-weight: 700; }
.py-var { color: #f8fafc; }
.py-val { color: #38bdf8; }

/* Traced highlight line during terminal simulation */
.py-line.is-traced {
    background: rgba(99, 102, 241, 0.15);
    border-left-color: #6366f1;
}

.terminal-output-bar {
    background: #090d16;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-family: monospace;
    font-size: 0.85rem;
    color: #10b981; /* Emerald green output */
    display: flex;
    gap: 0.5rem;
}

.terminal-output-bar.is-error {
    color: #ef4444;
}

.output-text {
    word-break: break-all;
}

/* Blinking terminal cursor */
.blink-cursor::after {
    content: "▋";
    margin-left: 3px;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Multiple choice options */
.python-question-panel {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 1.25rem;
}

.question-title {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
    color: #cbd5e1;
    line-height: 1.4;
}

.python-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

@media (max-width: 500px) {
    .python-options {
        grid-template-columns: repeat(2, 1fr);
    }
}

.python-opt-btn {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 0.65rem;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: monospace;
    color: #e2e8f0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.python-opt-btn:hover {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.15);
}

.python-opt-btn.is-active {
    background: #6366f1;
    border-color: #6366f1;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.python-opt-btn.is-correct {
    background: #10b981;
    border-color: #10b981;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.python-opt-btn.is-wrong {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

/* --------------------------------------------------------------------------
   Educational Feedback Card
   -------------------------------------------------------------------------- */
.ict-feedback-card {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(15px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.feedback-status {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 1.25rem;
}

.status-icon {
    font-size: 2rem;
}

.feedback-status h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1.05rem;
}

.feedback-status p {
    margin: 0;
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.4;
}

.feedback-status.success h4 { color: #34d399; }
.feedback-status.error h4 { color: #f87171; }

.feedback-curriculum-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.feedback-tab-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-tab-btn:hover {
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.03);
}

.feedback-tab-btn.is-active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.feedback-tab-content {
    font-size: 0.85rem;
    line-height: 1.55;
    color: #cbd5e1;
    animation: fadeIn 0.3s ease-out;
}

.feedback-tab-content p {
    margin: 0 0 0.75rem 0;
}

.feedback-tab-content p:last-child {
    margin: 0;
}

.feedback-tab-content blockquote {
    margin: 1rem 0 0 0;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.05);
    border-left: 3px solid #6366f1;
    border-radius: 0 6px 6px 0;
    font-size: 0.8rem;
    color: #94a3b8;
}

.feedback-tab-content blockquote strong {
    display: block;
    color: #6366f1;
    margin-bottom: 0.2rem;
}

/* Footer Credit */
.ict-widget__credit {
    font-size: 0.75rem;
    color: #475569;
    text-align: center;
    margin: 2rem 0 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1rem;
}

.ict-widget__credit a {
    color: #64748b;
    text-decoration: none;
    font-weight: 600;
}

.ict-widget__credit a:hover {
    color: #cbd5e1;
}

/* --------------------------------------------------------------------------
   Key Stage 4: Count-controlled loops (iteration)
   -------------------------------------------------------------------------- */
.ks4-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 720px) {
    .ks4-layout {
        grid-template-columns: 1fr;
    }
}

.ks4-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: -0.5rem;
}

.playground-btn--run:disabled {
    background: #1e293b;
    color: #475569;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Loop body highlight (shares the KS3 terminal trace look) */
.ks4-line {
    display: block;
    padding-left: 0.5rem;
    border-left: 3px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.ks4-line.is-traced {
    background: rgba(99, 102, 241, 0.15);
    border-left-color: #6366f1;
}

/* Trace table card */
.ks4-trace-card {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.ks4-trace-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
}

.ks4-trace-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #cbd5e1;
    letter-spacing: 0.02em;
}

.ks4-total-chip {
    font-family: "Fira Code", "Courier New", Courier, monospace;
    font-size: 0.8rem;
    color: #94a3b8;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
}

.ks4-total-chip strong {
    color: #a5b4fc;
    margin-left: 0.25rem;
}

.ks4-trace-table {
    width: 100%;
    border-collapse: collapse;
    font-family: "Fira Code", "Courier New", Courier, monospace;
    font-size: 0.85rem;
}

.ks4-trace-table th {
    text-align: left;
    color: #64748b;
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ks4-trace-table td {
    color: #e2e8f0;
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.ks4-trace-row {
    animation: slideUp 0.3s ease-out;
}

.ks4-cell-total {
    color: #34d399;
    font-weight: 700;
}

.ks4-trace-hint {
    margin: 0.85rem 0 0 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #64748b;
}

.ks4-question {
    margin-top: 1.5rem;
}

/* --------------------------------------------------------------------------
   Key Stage 5: Recursion & the call stack
   -------------------------------------------------------------------------- */
.ks5-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 720px) {
    .ks5-layout {
        grid-template-columns: 1fr;
    }
}

.ks5-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: -0.5rem;
}

.ks5-line {
    display: block;
    padding-left: 0.5rem;
    border-left: 3px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.ks5-line.is-traced {
    background: rgba(99, 102, 241, 0.15);
    border-left-color: #6366f1;
}

/* Call stack card */
.ks5-stack-card {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.ks5-stack-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
}

.ks5-stack-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #cbd5e1;
    letter-spacing: 0.02em;
}

.ks5-phase-chip {
    font-family: "Fira Code", "Courier New", Courier, monospace;
    font-size: 0.72rem;
    color: #a5b4fc;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
}

.ks5-stack-frames {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 120px;
    justify-content: flex-end;
}

.ks5-stack-empty {
    font-size: 0.78rem;
    line-height: 1.45;
    color: #64748b;
}

.ks5-frame {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-family: "Fira Code", "Courier New", Courier, monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 3px solid #475569;
    border-radius: 8px;
    padding: 0.55rem 0.8rem;
    animation: slideUp 0.25s ease-out;
}

.ks5-frame.is-top {
    border-left-color: #6366f1;
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25);
}

.ks5-frame.is-base {
    border-left-color: #f59e0b;
}

.ks5-frame.is-returning {
    border-left-color: #10b981;
    color: #34d399;
}

.ks5-frame-name {
    font-weight: 700;
}

.ks5-frame-return {
    font-size: 0.78rem;
    color: #34d399;
    font-weight: 700;
}

.ks5-frame-tag {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fbbf24;
    background: rgba(245, 158, 11, 0.12);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
}

.ks5-stack-hint {
    margin: 0.85rem 0 0 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #64748b;
}

.ks5-question {
    margin-top: 1.5rem;
}

/* Common Utilities */
.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --------------------------------------------------------------------------
   Mobile overflow hardening
   -------------------------------------------------------------------------- */
/* Grid/flex children must be allowed to shrink below their content width,
   otherwise wide code terminals force the whole layout to overflow. */
.ks4-code-col,
.ks4-trace-col,
.ks5-code-col,
.ks5-stack-col,
.scratch-editor,
.grid-simulator {
    min-width: 0;
}

/* Trace table and stack frames should never push the layout wider. */
.ks4-trace-table,
.ks5-stack-frames {
    max-width: 100%;
}

@media (max-width: 600px) {
    .aiad-ict-curriculum-widget {
        padding: 1.25rem;
        border-radius: 12px;
    }

    /* Stack the key-stage tabs in a single column on narrow screens. */
    .ict-widget__tabs {
        grid-template-columns: 1fr;
    }

    /* Shrink the 4-bit binary register so all four bits fit on one row. */
    .binary-register {
        gap: 0.5rem;
    }

    .bit-card {
        padding: 0.5rem 0.25rem;
    }

    .bit-toggle-btn {
        width: 100%;
        max-width: 56px;
        height: 48px;
        font-size: 1.2rem;
    }

    .bit-value-label {
        font-size: 0.6rem;
        text-align: center;
    }

    /* Slightly smaller code so more of each line is visible before scrolling. */
    .python-code-pre {
        font-size: 0.8rem;
    }

    /* Binary place-value formula can wrap rather than overflow. */
    .bar-formula {
        flex-wrap: wrap;
    }
}
