:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.05);
  }
  
  * { box-sizing: border-box; margin: 0; padding: 0; }
  
  html, body {
    height: 100%;
  }
  
  body {
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  
  a { color: var(--primary); text-decoration: none; }
  a:hover { text-decoration: underline; }
  
  /* =========================================================
     Layout base
     ========================================================= */
  .page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  
  .topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .topbar-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  .topbar .brand {
    font-weight: 700;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .topbar .brand-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--primary);
  }
  .topbar .progress-info {
    font-size: 13px;
    color: var(--text-muted);
  }
  
  .main {
    flex: 1;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 60px;
  }
  
  @media (max-width: 640px) {
    .main { padding: 16px 12px 40px; }
  }
  
  /* =========================================================
     Barra de progreso
     ========================================================= */
  .progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
  }
  .progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    width: 0%;
    transition: width .4s ease;
  }
  
  /* =========================================================
     Cards
     ========================================================= */
  .card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 28px;
    border: 1px solid var(--border);
  }
  @media (max-width: 640px) {
    .card { padding: 20px; }
  }
  
  .card + .card { margin-top: 20px; }
  
  .card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
  }
  .card h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.01em;
  }
  .card .subtitle {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 20px;
  }
  
  /* =========================================================
     Hero (bienvenida)
     ========================================================= */
  .hero {
    text-align: center;
    padding: 40px 20px;
  }
  .hero .icon-hero {
    font-size: 48px;
    margin-bottom: 16px;
    line-height: 1;
  }
  .hero h1 {
    font-size: 28px;
    margin-bottom: 12px;
    letter-spacing: -0.02em;
  }
  .hero p {
    color: var(--text-muted);
    font-size: 16px;
    max-width: 480px;
    margin: 0 auto 24px;
  }
  
  /* Pasos visuales de bienvenida */
  .steps-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 24px 0;
  }
  .steps-preview .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
  }
  .steps-preview .arrow {
    color: var(--text-muted);
    font-size: 14px;
  }
  
  /* =========================================================
     Formularios
     ========================================================= */
  .field {
    margin-bottom: 18px;
  }
  .field label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
  }
  .field label .req {
    color: var(--danger);
    margin-left: 2px;
  }
  .field input,
  .field select,
  .field textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
  }
  .field input:focus,
  .field select:focus,
  .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
  }
  .field textarea { resize: vertical; min-height: 100px; }
  .field .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
  }
  .field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  @media (max-width: 540px) {
    .field-row { grid-template-columns: 1fr; }
  }
  
  /* Checkbox grande */
  .field-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    background: #f8fafc;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color .15s;
  }
  .field-check:hover { border-color: var(--border); }
  .field-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    flex-shrink: 0;
    margin-top: 1px;
    cursor: pointer;
  }
  .field-check label {
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    margin: 0;
    font-weight: 400;
  }
  
  /* =========================================================
     Botones
     ========================================================= */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
  }
  .btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
  .btn:disabled { opacity: .5; cursor: not-allowed; }
  .btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
  .btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
  .btn-primary:disabled { background: var(--primary); opacity: .6; }
  .btn-block { width: 100%; }
  .btn-lg { padding: 15px 28px; font-size: 16px; }
  
  /* =========================================================
     Alertas
     ========================================================= */
  .alert {
    padding: 14px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }
  .alert-error { background: var(--danger-light); color: #991b1b; }
  .alert-info { background: var(--primary-light); color: #1e40af; }
  .alert-success { background: var(--success-light); color: #166534; }
  .alert-warn { background: #fef3c7; color: #92400e; }
  
  /* =========================================================
     Video
     ========================================================= */
  .video-card {
    background: #0f172a;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 16/9;
    position: relative;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
  }
  .video-card iframe,
  .video-card video {
    width: 100%;
    height: 100%;
    display: block;
    border: 0;
    background: #000;
  }
  
  .video-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0,0,0,.7);
    color: #fff;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .video-badge .dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 1.5s infinite;
  }
  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
  }
  
  .video-progress {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
  }
  .video-progress .labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
  }
  .video-progress .bar {
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
  }
  .video-progress .bar .fill {
    height: 100%;
    background: var(--success);
    width: 0%;
    transition: width .3s;
    border-radius: 999px;
  }
  
  /* =========================================================
     Examen
     ========================================================= */
  .question-block {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
  }
  .question-block:last-child { border-bottom: none; }
  
  .q-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }
  .q-num {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    padding: 3px 9px;
    border-radius: 999px;
    flex-shrink: 0;
    margin-top: 1px;
  }
  .q-text {
    font-size: 16px;
    font-weight: 500;
    line-height: 1.5;
  }
  .q-required {
    color: var(--danger);
    margin-left: 4px;
    font-weight: 700;
  }
  
  .q-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    padding-left: 4px;
  }
  
  .option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all .15s;
    background: #fff;
  }
  .option:hover {
    border-color: var(--primary);
    background: #f8fafc;
  }
  .option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
  }
  .option input[type="radio"],
  .option input[type="checkbox"] {
    accent-color: var(--primary);
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .option .text {
    flex: 1;
    font-size: 15px;
    color: var(--text);
  }
  
  .option-tf {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 4px;
  }
  @media (max-width: 480px) {
    .option-tf { grid-template-columns: 1fr; }
  }
  .option-tf .option {
    justify-content: center;
    text-align: center;
  }
  
  /* =========================================================
     Resultado final
     ========================================================= */
  .result-hero {
    text-align: center;
    padding: 20px 0;
  }
  .result-score {
    font-size: 72px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.04em;
    margin: 16px 0 8px;
  }
  .result-score.pass { color: var(--success); }
  .result-score.fail { color: var(--danger); }
  .result-label {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 24px;
  }
  .result-status {
    display: inline-block;
    padding: 8px 20px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
  }
  .result-status.pass { background: var(--success-light); color: #166534; }
  .result-status.fail { background: var(--danger-light); color: #991b1b; }
  
  .result-breakdown {
    margin-top: 32px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
  }
  .result-breakdown h3 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-bottom: 14px;
  }
  .result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 15px;
  }
  .result-row:last-child { border-bottom: none; }
  .result-row .label { color: var(--text); }
  .result-row .score {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
  }
  .result-row .score.pass { color: var(--success); }
  .result-row .score.fail { color: var(--danger); }
  
  /* =========================================================
     Loader
     ========================================================= */
  .loader-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
    color: var(--text-muted);
  }
  .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  
  /* =========================================================
     Toast
     ========================================================= */
  #toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
    max-width: 90vw;
  }
  .toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    background: #1e293b;
    color: #fff;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: toastIn .2s ease-out;
    text-align: center;
  }
  .toast-error { background: var(--danger); }
  .toast-success { background: var(--success); }
  @keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  
  /* =========================================================
     Utilidades
     ========================================================= */
  .hidden { display: none !important; }
  .text-center { text-align: center; }
  .mt-8 { margin-top: 8px; }
  .mt-16 { margin-top: 16px; }
  .mt-24 { margin-top: 24px; }
  .mb-8 { margin-bottom: 8px; }
  .mb-16 { margin-bottom: 16px; }
  .muted { color: var(--text-muted); }
  .small { font-size: 13px; }