.f8-practice, .lesson-runtime-note { margin: 1.5rem 0; padding: 1rem; border: 1px solid #69737d; border-radius: 8px; background: var(--bg-panel); overflow-wrap: anywhere; }
.f8-practice label { display: block; margin: .8rem 0; }
.f8-practice textarea, .f8-practice select { display: block; box-sizing: border-box; width: 100%; max-width: 100%; min-height: 44px; padding: .5rem; color: var(--text-title); background: var(--bg-dark); border: 1px solid #8795a2; border-radius: 4px; font: inherit; }
.f8-practice input[type="checkbox"] { margin-left: .7rem; width: 20px; height: 20px; vertical-align: middle; }
.f8-practice button { min-height: 44px; margin: .4rem .3rem .4rem 0; white-space: normal; }
.f8-practice :focus-visible { outline: 3px solid #70c7ff; outline-offset: 3px; }
:root {
    --bg-dark: #1e1e1e;
    --bg-panel: #252526;
    --text-main: #cccccc;
    --text-title: #ffffff;
    --accent: #007acc;
    --success: #4caf50;
    --error: #f44336;
    --warning: #ffcc00;
    --lesson-reading-width: 78ch;
    --lesson-code-bg: #101418;
    --lesson-border: #3b4148;
}

.curriculum-open-btn { display: flex; align-items: center; justify-content: center; gap: .55rem; width: 100%; min-height: 44px; margin: .75rem 0; padding: .6rem .8rem; border: 1px solid #6c7884; border-radius: 7px; color: var(--text-title); background: #30343a; font: 600 1rem/1.2 inherit; cursor: pointer; }
.curriculum-open-btn:hover { background: #3a4149; }

.curriculum-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: min(820px, calc(100dvh - 32px));
    padding: 0;
    border: 1px solid #59636d;
    border-radius: 12px;
    color: var(--text-main);
    background: var(--bg-panel);
    box-shadow: 0 20px 70px rgba(0, 0, 0, .65);
}
.curriculum-dialog::backdrop { background: rgba(0, 0, 0, .74); backdrop-filter: blur(3px); }
.curriculum-dialog-panel { display: grid; gap: 14px; padding: 20px; }
.curriculum-dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.curriculum-dialog-header h2 { margin: 0; color: var(--text-title); font-size: 1.5rem; }
.curriculum-dialog-header p { margin: 5px 0 0; color: #b9c0c7; }
.curriculum-close-btn { min-width: 44px; min-height: 44px; border: 1px solid #69737d; border-radius: 7px; color: var(--text-title); background: #30343a; font: 1.7rem/1 inherit; cursor: pointer; }
.curriculum-dialog label { font-weight: 700; color: var(--text-title); }
.curriculum-dialog select { width: 100%; min-height: 46px; padding: .55rem .7rem; border: 1px solid #78828c; border-radius: 7px; color: var(--text-title); background: #17191c; font: inherit; }
.curriculum-lesson-list { display: grid; gap: 8px; max-height: min(60dvh, 610px); margin: 0; padding: 2px; overflow-y: auto; list-style: none; }
.curriculum-lesson { display: grid; grid-template-columns: 2.25rem minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 10px; border: 1px solid #474e55; border-radius: 8px; color: var(--text-main); background: #202327; text-align: left; font: inherit; cursor: pointer; }
.curriculum-lesson:hover { border-color: #72b8e8; background: #282e34; }
.curriculum-lesson.is-current { border-color: #3fa7e8; background: #172b39; }
.curriculum-lesson-number { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: #343a40; font-weight: 700; }
.curriculum-lesson.is-completed .curriculum-lesson-number { color: #102414; background: #76cf87; }
.curriculum-lesson-title { min-width: 0; color: var(--text-title); font-weight: 600; }
.curriculum-lesson-state { color: #b8c0c8; font-size: .86rem; }
.curriculum-lesson.is-completed .curriculum-lesson-state { color: #9de2aa; }

@media (max-width: 600px) {
    .curriculum-dialog { width: 100vw; max-width: none; max-height: 88dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
    .curriculum-dialog-panel { padding: 16px 14px calc(16px + env(safe-area-inset-bottom, 0px)); }
    .curriculum-lesson-list { max-height: 58dvh; }
    .curriculum-lesson { grid-template-columns: 2.25rem minmax(0, 1fr); }
    .curriculum-lesson-state { grid-column: 2; }
}

/* ── REGLAS GLOBALES TOUCH-FIRST ────────────────────────────────────────── */
* {
    box-sizing: border-box;
    touch-action: manipulation; /* Elimina retraso de 300ms en toque */
    -webkit-tap-highlight-color: transparent; /* Elimina recuadro gris al tocar en iOS/Android */
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    flex-direction: column;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 2000;
    padding: 10px 14px;
    border-radius: 6px;
    background: #ffffff;
    color: #111111;
    transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

:focus-visible {
    outline: 3px solid #71c4ff;
    outline-offset: 3px;
}

/* Scrollbars táctiles fluidos */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

/* ── HEADER PRINCIPAL ─────────────────────────────────────────────────── */
#main-header {
    height: 54px;
    background-color: #252526;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    flex-shrink: 0;
    gap: 10px;
    z-index: 30;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.header-icon-btn {
    background: transparent;
    border: 1px solid #444;
    color: #ccc;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.header-icon-btn:hover, .header-icon-btn.active {
    background: #333;
    color: #fff;
    border-color: var(--accent);
}

.header-icon-btn:active {
    transform: scale(0.95);
    background: #444;
}

.header-file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #cccccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-file-info .file-icon {
    font-size: 18px;
    color: #3776ab;
}

.icon-svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.icon-python {
    color: #3776ab;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Pestañas para Móvil */
.mobile-view-tabs {
    display: none;
}

/* ── BOTONES GENERALES (OBJETIVOS TÁCTILES 44x44 MIN) ───────────────── */
.btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 10px 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    border-radius: 8px;
    transition: background-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
    user-select: none;
    min-height: 44px;
    min-width: 44px;
}

.btn:hover { background-color: #005999; }
.btn:active { transform: scale(0.96); opacity: 0.9; }
.btn:disabled { background-color: #555; color: #888; cursor: not-allowed; opacity: 0.7; transform: none; }

.btn-run {
    background-color: #2e7d32;
    color: white;
}

.btn-run:hover:not(:disabled) {
    background-color: #388e3c;
}

.btn-icon-only {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-icon-only .run-icon {
    margin-left: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.btn-secondary {
    background-color: #3a3d41;
    color: #e0e0e0;
    font-weight: normal;
}

.btn-secondary:hover { background-color: #4a4d51; }

.btn-sm {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 44px;
}

/* ── LAYOUT PRINCIPAL ─────────────────────────────────────────────────── */
#app-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

/* ── SIDEBAR (PANEL DE LECCIÓN) ────────────────────────────────────────── */
#sidebar {
    width: clamp(430px, 38vw, 620px);
    flex-shrink: 0;
    background-color: var(--bg-panel);
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s ease, width 0.25s ease;
    z-index: 15;
    -webkit-overflow-scrolling: touch;
}

#sidebar.collapsed {
    margin-left: clamp(-620px, -38vw, -430px);
}

.sidebar-header {
    margin-bottom: 15px;
}

.sidebar-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-title-row h2 { margin-bottom: 0; }

.reading-mode-btn {
    min-height: 44px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 11px;
    border: 1px solid #606872;
    border-radius: 8px;
    background: #30343a;
    color: #f0f3f6;
    font: inherit;
    font-size: 1rem;
    cursor: pointer;
}

.reading-mode-btn:hover,
.reading-mode-btn[aria-pressed="true"] {
    background: #114d73;
    border-color: #71c4ff;
}

h1, h2, h3 { color: var(--text-title); margin-top: 0; }
h1 { font-size: clamp(1.45rem, 2vw, 1.85rem); line-height: 1.2; margin-bottom: 10px; }
#lesson-title { overflow-wrap: anywhere; word-break: break-word; }
h2 { font-size: 18px; margin-bottom: 12px; }
h3 { font-size: 17px; margin-bottom: 8px; line-height: 1.35; }

/* Select táctil: font-size 16px previene auto-zoom molesto en iPhones */
.lesson-selector {
    background: #2d2d30;
    color: #fff;
    border: 1px solid #444;
    padding: 12px 14px;
    width: 100%;
    margin-bottom: 15px;
    border-radius: 8px;
    font-size: 16px;
    min-height: 48px;
    outline: none;
    cursor: pointer;
    touch-action: manipulation;
}

.progress-bar {
    font-size: 13px;
    color: #aaa;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.progress-bar .count {
    color: var(--success);
    font-weight: bold;
}

.lesson-meta {
    font-size: 1rem;
    color: #b9c0c8;
    margin: 0 0 22px;
    line-height: 1.6;
}

.explanation-box {
    font-size: 1rem;
    margin-bottom: 20px;
    line-height: 1.72;
    display: none;
    overflow-wrap: anywhere;
}

.lesson-inline-code {
    background: #121619;
    border: 1px solid #3c434a;
    padding: 0.12em 0.38em;
    border-radius: 4px;
    color: #e8edf2;
    font-size: 1em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    overflow-wrap: anywhere;
}

.lesson-section {
    min-width: 0;
    margin: 0 0 18px;
    padding: 18px;
    border: 1px solid #383d43;
    border-radius: 10px;
    background: #292c2f;
}

.lesson-section-intro:empty { display: none; }

.lesson-section > :last-child { margin-bottom: 0; }

.lesson-section-title {
    margin: 0 0 10px;
    color: #f4f7fa;
    font-size: 1.08rem;
    line-height: 1.35;
}

.lesson-section p { margin: 0 0 0.9em; }
.lesson-section ul,
.lesson-section ol { padding-left: 1.45rem; }
.lesson-section li + li { margin-top: 0.45rem; }

.lesson-code-block {
    min-width: 0;
    margin: 14px 0 18px;
    overflow: hidden;
    border: 1px solid #46505a;
    border-radius: 9px;
    background: var(--lesson-code-bg);
}

.lesson-code-toolbar {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 8px 5px 13px;
    border-bottom: 1px solid #343b42;
    background: #1b2025;
}

.lesson-code-language {
    color: #aeb8c2;
    font: 600 1rem/1 system-ui, sans-serif;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.lesson-copy-button {
    min-height: 44px;
    padding: 5px 9px;
    border: 1px solid #59636d;
    border-radius: 6px;
    background: #292f35;
    color: #e8edf2;
    font: 600 1rem/1 system-ui, sans-serif;
    cursor: pointer;
}

.lesson-copy-button:hover { background: #37414a; }

.lesson-pre {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 16px;
    color: #e6edf3;
    background: var(--lesson-code-bg);
    font: 1rem/1.62 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    tab-size: 4;
    overflow-x: visible;
}

.lesson-pre:focus-visible { outline-offset: -3px; }

.lesson-code-block-output { border-color: #356341; }
.lesson-code-block-output .lesson-code-toolbar { background: #17251b; }
.lesson-pre-output { color: #a7e3b1; background: #101b13; }
.lesson-code-block-diagram { border-color: #665d3d; }
.lesson-code-block-diagram .lesson-code-toolbar { background: #282417; }
.lesson-pre-diagram { color: #efe2ad; background: #18160f; }
.lesson-pre-diagram { white-space: pre; overflow-x: auto; overscroll-behavior-inline: contain; }
.lesson-code-block-reference { border-color: #495c70; }
.lesson-code-block-reference .lesson-code-toolbar { background: #18222c; }
.lesson-pre-reference { color: #d7e7f7; background: #111820; }
.lesson-code-block-template { border-color: #735c96; }
.lesson-code-block-template .lesson-code-toolbar { background: #251d31; }
.lesson-pre-template { background: #17121f; }

.syntax-comment { color: #8b949e; font-style: italic; }
.syntax-string { color: #a5d6ff; }
.syntax-number { color: #79c0ff; }
.syntax-keyword { color: #ff7b72; font-weight: 600; }
.syntax-builtin { color: #d2a8ff; }
.syntax-operator { color: #ffa657; }

.lesson-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    margin: 14px 0;
    border: 1px solid var(--lesson-border);
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}

.lesson-table-scroll table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
}

.lesson-table-scroll caption {
    padding: 10px 12px;
    color: #f0f3f6;
    background: #1b2025;
    font-weight: 700;
    text-align: left;
}

.lesson-table-scroll th,
.lesson-table-scroll td {
    padding: 9px 12px;
    border: 1px solid #3d444d;
    text-align: left;
}

.section-heading {
    margin: 28px 0 10px;
    color: #eee;
    font-size: 1.22rem;
}

.statement-box {
    line-height: 1.7;
    margin-bottom: 20px;
    font-size: 1rem;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#lesson-content {
    width: 100%;
    max-width: var(--lesson-reading-width);
    margin: 0 auto;
}

#lesson-title:focus {
    outline: 3px solid #71c4ff;
    outline-offset: 5px;
}

@media (min-width: 901px) {
    body.reading-mode #sidebar {
        width: 100%;
        border-right: 0;
        padding-inline: max(24px, calc((100vw - 1040px) / 2));
    }

    body.reading-mode #main-content { display: none; }
    body.reading-mode #lesson-content { max-width: 920px; }
    body.reading-mode .sidebar-header { max-width: 920px; width: 100%; margin-inline: auto; }
}

#hint-btn {
    width: 100%;
    margin-top: 10px;
    margin-bottom: 16px;
    justify-content: center;
    min-height: 48px;
    font-size: 1rem;
    border-radius: 8px;
}

.hint-box {
    background-color: #332b00;
    border-left: 4px solid var(--warning);
    padding: 14px;
    font-size: 1rem;
    margin-bottom: 20px;
    display: none;
    line-height: 1.65;
    overflow-wrap: anywhere;
    border-radius: 0 8px 8px 0;
}

#status-badge {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 24px;
    display: none;
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
}

/* ── NAVEGACIÓN INFERIOR DE LECCIÓN (ANTERIOR / SIGUIENTE) ─────────────── */
.lesson-navigation {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid #333333;
}

.lesson-step-indicator {
    font-size: 1rem;
    font-weight: 600;
    color: #aaaaaa;
    white-space: nowrap;
    text-align: center;
}

.btn-nav {
    min-height: 44px;
    min-width: 90px;
    padding: 8px 16px;
    font-size: 1rem;
}

/* ── WORKSPACE (MAIN CONTENT) ─────────────────────────────────────────── */
#main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-dark);
}

#editor-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.workspace-files {
    flex: 0 0 auto;
    min-width: 0;
    padding: 8px 10px;
    border-bottom: 1px solid #3b3b3d;
    background: #202022;
}

.workspace-files[hidden] { display: none !important; }

.workspace-files section,
.workspace-files [role="tablist"],
.workspace-file-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.workspace-files section { flex-wrap: wrap; }
.workspace-files [role="tablist"] { flex: 1 1 360px; flex-wrap: wrap; }

.workspace-files button {
    min-height: 40px;
    max-width: 100%;
    padding: 7px 11px;
    border: 1px solid #50545a;
    border-radius: 7px;
    background: #2c2f33;
    color: #e5e7eb;
    font: 600 0.86rem/1.2 system-ui, sans-serif;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.workspace-files [role="tab"][aria-selected="true"] {
    border-color: #58bfff;
    background: #12344a;
    color: #fff;
}

.workspace-files > section > button[aria-haspopup="dialog"] { display: none; }
.workspace-file-actions { margin-inline-start: auto; flex-wrap: wrap; }
.workspace-file-actions button { color: #cfeaff; }

.workspace-files [role="status"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.workspace-files dialog {
    width: min(32rem, calc(100vw - 24px));
    max-height: min(70vh, 34rem);
    padding: 16px;
    border: 1px solid #62666d;
    border-radius: 10px;
    background: #202124;
    color: #f2f2f2;
}

.workspace-files dialog::backdrop { background: rgba(0, 0, 0, 0.68); }
.workspace-files dialog h2 { margin: 0 0 12px; font-size: 1.15rem; }
.workspace-files [role="listbox"] { display: grid; gap: 7px; margin-bottom: 12px; }
.workspace-files [role="option"] { width: 100%; text-align: left; }
.workspace-files [role="option"][aria-selected="true"] { border-color: #58bfff; }

#editor-container {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
}

/* CodeMirror Optimizado para Pantalla Táctil: 16px previene auto-zoom en teléfonos */
.cm-editor {
    height: 100% !important;
    font-size: 16px !important;
}

.cm-content {
    padding: 12px 8px !important;
    line-height: 1.5 !important;
}

.cm-line {
    padding: 0 4px !important;
}

.cm-scroller {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x pan-y pinch-zoom !important;
}

/* ── BARRA TÁCTIL MÓVIL (QUICK TOOLBAR) ──────────────────────────────── */
#mobile-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #252526;
    border-bottom: 1px solid #333;
    overflow-x: auto;
    white-space: nowrap;
    flex-shrink: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
}

#mobile-toolbar::-webkit-scrollbar {
    display: none;
}

#mobile-toolbar button {
    background: #33373b;
    color: #4ec9b0;
    border: 1px solid #45494e;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
    touch-action: manipulation;
    transition: background-color 0.15s ease, transform 0.1s ease;
}

#mobile-toolbar button:active {
    background: var(--accent);
    color: #fff;
    transform: scale(0.94);
}

/* ── CONSOLA / TERMINAL ───────────────────────────────────────────────── */
#console-container {
    height: 240px;
    min-height: 140px;
    background-color: #0e0e0e;
    border-top: 1px solid #333;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.console-header {
    background-color: #1a1a1a;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #aaa;
    border-bottom: 1px solid #252525;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    min-height: 42px;
}

.console-action-btn {
    background: transparent;
    border: 1px solid #444;
    color: #ccc;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    gap: 6px;
    touch-action: manipulation;
}

.console-action-btn:hover {
    color: #fff;
    border-color: #666;
    background: #222;
}

.console-action-btn:active {
    transform: scale(0.95);
}

#terminal-output {
    padding: 16px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14.5px;
    overflow-y: auto;
    flex-grow: 1;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
    -webkit-overflow-scrolling: touch;
}

.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-muted { color: #888888; font-style: italic; }

.console-output-block {
    margin-bottom: 14px;
}

.console-label {
    font-size: 11.5px;
    font-weight: bold;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 6px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.console-output-text {
    margin: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    color: #e6e6e6;
    background: #181818;
    padding: 12px 14px;
    border-radius: 8px;
    border-left: 4px solid var(--accent);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Traceback de Python: borde y tinte rojo para distinguirlo del output normal */
.console-traceback {
    color: #ffb3b3;
    background: #1e1010;
    border-left: 4px solid var(--error);
}


.console-status-box {
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.55;
}

.console-status-box.success {
    background-color: rgba(76, 175, 80, 0.15);
    border: 1px solid var(--success);
    color: #81c784;
}

.console-status-box.error {
    background-color: rgba(244, 67, 54, 0.15);
    border: 1px solid var(--error);
    color: #e57373;
}

/* ── BARRA DE NAVEGACIÓN INFERIOR MÓVIL (BOTTOM NAV BAR) ───────────────── */
.mobile-nav-bar {
    display: none;
}

/* Tablets y Pantallas Medianas (<= 900px) */
@media (max-width: 900px) {
    #toggle-sidebar-btn {
        display: none;
    }

    .reading-mode-btn { display: none; }

    .mobile-nav-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(56px + env(safe-area-inset-bottom, 0px));
        background-color: #1a1a1b;
        border-top: 1px solid #333333;
        z-index: 50;
        justify-content: space-around;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.5);
    }

    .mobile-nav-bar .nav-tab {
        flex: 1;
        height: 100%;
        background: transparent;
        border: none;
        color: #888888;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 11px;
        font-weight: 600;
        cursor: pointer;
        transition: color 0.15s ease, background-color 0.15s ease;
        padding: 6px 0;
        touch-action: manipulation;
    }

    .mobile-nav-bar .nav-tab .nav-icon {
        font-size: 18px;
    }

    .mobile-nav-bar .nav-tab.active {
        color: #58bfff;
        background: rgba(0, 122, 204, 0.08);
    }

    .mobile-nav-bar .nav-tab:active {
        transform: scale(0.95);
    }

    #app-layout {
        height: calc(100vh - 54px - 56px - env(safe-area-inset-bottom, 0px));
        height: calc(100dvh - 54px - 56px - env(safe-area-inset-bottom, 0px));
    }

    /* Layout Móvil basado en data-view */
    body[data-view="lesson"] #sidebar {
        display: flex;
        width: 100%;
        height: 100%;
        border-right: none;
        padding: 18px 16px calc(80px + env(safe-area-inset-bottom, 0px));
        margin-left: 0 !important;
        transition: none;
    }
    body[data-view="lesson"] #main-content {
        display: none;
    }

    body[data-view="editor"] #sidebar {
        display: none;
    }
    body[data-view="editor"] #main-content {
        display: flex;
        width: 100%;
        height: 100%;
    }
    body[data-view="editor"] #editor-wrapper {
        display: flex;
        flex: 1;
    }
    body[data-view="editor"] #console-container {
        display: none;
    }

    .workspace-files { padding: 7px 9px; }
    .workspace-files [role="tablist"] { display: none; }
    .workspace-files > section > button[aria-haspopup="dialog"] {
        display: block;
        flex: 1 1 12rem;
        text-align: left;
    }
    .workspace-file-actions { flex: 1 1 100%; margin-inline-start: 0; }

    body[data-view="console"] #sidebar {
        display: none;
    }
    body[data-view="console"] #main-content {
        display: flex;
        width: 100%;
        height: 100%;
    }
    body[data-view="console"] #editor-wrapper {
        display: none;
    }
    body[data-view="console"] #console-container {
        display: flex;
        flex: 1;
        height: 100%;
        border-top: none;
    }

    #lesson-content { max-width: 46rem; }

    .lesson-section {
        padding: 16px;
        margin-bottom: 14px;
    }

    .explanation-box,
    .statement-box { font-size: 1rem; line-height: 1.72; }

    .lesson-pre { font-size: 1rem; padding: 14px; }
}

/* Teléfonos Pequeños (<= 500px) */
@media (max-width: 500px) {
    #main-header {
        padding: 0 10px;
    }

    .header-file-info {
        font-size: 13px;
    }

    .btn-sm .btn-text {
        display: none;
    }
    
    .btn-sm {
        padding: 8px 12px;
        min-width: 44px;
        min-height: 44px;
    }

    #sidebar {
        padding: 16px 12px calc(76px + env(safe-area-inset-bottom, 0px));
    }

    .statement-box {
        font-size: 1rem;
    }

    .lesson-section { padding: 14px; border-radius: 8px; }
    .lesson-code-block { margin-inline: -6px; }
    .lesson-pre { font-size: 1rem; }
    .lesson-navigation { gap: 6px; }
    .btn-nav { min-width: 72px; padding-inline: 10px; }
    .lesson-step-indicator { min-width: 0; white-space: normal; font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* Aviso PWA: el estado listo es temporal; errores y acciones permanecen visibles. */
.pwa-status {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 900;
    max-width: min(360px, calc(100vw - 24px));
    padding: 8px 12px;
    border: 1px solid #555;
    border-radius: 8px;
    background: #252526;
    color: #d4d4d4;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    font-size: 13px;
    line-height: 1.4;
}

.pwa-status[data-state="ready"] { border-color: #4b8f5a; color: #b9e7c1; }
.pwa-status[data-state="update"] { border-color: #d7a928; color: #ffe39a; }
.pwa-status[data-state="error"] { border-color: #d66565; color: #ffc0c0; }

@media (max-width: 900px) {
    .pwa-status {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}

/* ── MODAL DE CONFIGURACIÓN ────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.15s ease-out;
}

.modal-dialog {
    background-color: #252526;
    border: 1px solid #3c3c3c;
    border-radius: 12px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.15s ease-out;
}

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

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #333;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: #aaa;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.modal-close-btn:hover {
    background: #333;
    color: #fff;
}

.modal-body {
    padding: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-label {
    font-size: 14px;
    font-weight: 600;
    color: #ddd;
}

.lang-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.lang-option-btn {
    background-color: #1e1e1e;
    border: 2px solid #333;
    border-radius: 8px;
    color: #ccc;
    padding: 12px 14px;
    min-height: 48px;
    font-size: 15px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.lang-option-btn:hover {
    background-color: #2a2a2d;
    border-color: #555;
    color: #fff;
}

.lang-option-btn.active {
    background-color: rgba(0, 122, 204, 0.15);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.flag-icon {
    font-size: 20px;
}

.setting-group-data {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #333;
}

.data-status {
    min-height: 18px;
    font-size: 13px;
    color: #8fd48f;
}

.data-status-error {
    color: #ff8a80;
}

.modal-footer {
    padding: 14px 20px 20px 20px;
}
/* ══════════════════════════════════════════════════════════════════
   TUTORIAL DE PRIMER USO (Tour.js)
   Overlay spotlight: hueco sobre el elemento resaltado + tarjeta.
   ══════════════════════════════════════════════════════════════════ */

.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: transparent;
    /* Bloquea la interacción con la app mientras se explica;
       el oscurecido visual lo pinta el hueco (box-shadow gigante). */
    pointer-events: auto;
}

/* En gates el usuario debe pulsar el botón REAL: dejamos pasar los clics */
.tour-overlay.tour-click-through { pointer-events: none; }

.tour-hole {
    position: fixed;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(14, 14, 16, 0.62);
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    pointer-events: none;
    transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
}

/* En modo centrado (sin objetivo o gate idioma) no hay hueco */
.tour-overlay.tour-centered .tour-hole { display: none; }
.tour-overlay.tour-centered .tour-card {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
}

.tour-card {
    position: fixed;
    max-width: 380px;
    width: calc(100vw - 24px);
    background-color: var(--bg-panel);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 18px 20px 16px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    z-index: 10001;
    outline: none;
}

.tour-title {
    margin: 0 44px 10px 0;
    font-size: 17px;
    color: #e8e8e8;
}

.tour-body {
    font-size: 14px;
    line-height: 1.65;
    color: var(--fg, #d4d4d4);
}
.tour-body code {
    font-family: 'Courier New', Courier, monospace;
    background: rgba(0, 122, 204, 0.15);
    border: 1px solid rgba(0, 122, 204, 0.35);
    border-radius: 4px;
    padding: 1px 5px;
    color: #9cdcfe;
    font-size: 13px;
}
.tour-body ul { margin: 8px 0 8px 20px; }
.tour-comment {
    /* mismo color que los comentarios de CodeMirror (oneDark) */
    color: #7f8c98;
    font-style: italic;
    font-family: 'Courier New', Courier, monospace;
}

.tour-note {
    display: none;
    margin: 12px 0 0;
    padding: 10px 12px;
    border-left: 4px solid var(--accent);
    background: rgba(0, 122, 204, 0.12);
    border-radius: 4px;
    font-size: 13.5px;
    animation: tour-pulse 1.6s ease-in-out infinite;
}
@keyframes tour-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.tour-count {
    position: absolute;
    top: 14px;
    right: 46px;
    font-size: 12px;
    color: var(--fg-dim, #808080);
}

.tour-skip {
    position: absolute;
    top: 8px;
    right: 8px;
}

.tour-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.tour-btn {
    min-height: 44px;
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.tour-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.tour-btn-primary {
    background-color: var(--accent);
    color: #ffffff;
}
.tour-btn-primary:hover:not(:disabled) { filter: brightness(1.12); }

.tour-btn-secondary {
    background-color: transparent;
    color: var(--fg, #d4d4d4);
    border-color: var(--border, #3c3c3c);
}
.tour-btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: #ffffff; }

.tour-btn-ghost {
    background: transparent;
    border: none;
    color: var(--fg-dim, #808080);
    padding: 6px 10px;
    min-height: 36px;
}
.tour-btn-ghost:hover { color: #ffffff; }

/* Selector de idioma del primer paso */
.tour-lang {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}
.tour-lang-btn { flex: 1; }
/* Visible independently of terminal output and settings. */
#storage-warning:not([hidden]) {
  flex-shrink: 0;
  max-height: 25vh;
  overflow-y: auto;
  padding: 12px 20px;
  background: #492d00;
  color: #fff4dc;
  border-top: 2px solid #ffbf47;
  font: 14px/1.5 sans-serif;
}
