/* ==========================================================================
   Eduplayify Shared Lesson Content Styles (.lesson-rich-content)
   Used by lessons/show and the lesson editor live preview.
   Logical CSS properties only for full RTL / LTR support.
   ========================================================================== */

.lesson-rich-content {
    --lc-body-color: var(--text-main, #1e293b);
    --lc-h2-color: var(--primary, #4f46e5);
    --lc-h2-border: #c7d2fe;
    --lc-h3-color: #0369a1;
    --lc-h4-color: var(--dark, #0f172a);

    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1.9;
    color: var(--lc-body-color);
    text-align: start;
    margin-bottom: 2.5rem;
    overflow-wrap: break-word;
}

.lesson-rich-content p,
.lesson-rich-content h1,
.lesson-rich-content h2,
.lesson-rich-content h3,
.lesson-rich-content h4,
.lesson-rich-content li,
.lesson-rich-content blockquote,
.lesson-rich-content td,
.lesson-rich-content th {
    text-align: start;
}

.lesson-rich-content h1,
.lesson-rich-content h2,
.lesson-rich-content h3,
.lesson-rich-content h4 {
    line-height: 1.5;
    margin: 1.5rem 0 0.75rem;
}

.lesson-rich-content h1 {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--lc-h4-color);
}

.lesson-rich-content h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--lc-h2-color);
    border-bottom: 2px solid var(--lc-h2-border);
    padding-bottom: 0.35rem;
    margin-top: 1.6em;
}

.lesson-rich-content h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--lc-h3-color);
    border-inline-start: 4px solid var(--lc-h3-color);
    padding-inline-start: 10px;
}

.lesson-rich-content h4 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--lc-h4-color);
}

/* Optional preset heading colours (WCAG AA compliant on white) */
.lesson-rich-content .h-blue { color: #1d4ed8; }
.lesson-rich-content h2.h-blue { border-bottom-color: #bfdbfe; }
.lesson-rich-content h3.h-blue { border-inline-start-color: #1d4ed8; }

.lesson-rich-content .h-green { color: #047857; }
.lesson-rich-content h2.h-green { border-bottom-color: #a7f3d0; }
.lesson-rich-content h3.h-green { border-inline-start-color: #047857; }

.lesson-rich-content .h-orange { color: #c2410c; }
.lesson-rich-content h2.h-orange { border-bottom-color: #fed7aa; }
.lesson-rich-content h3.h-orange { border-inline-start-color: #c2410c; }

.lesson-rich-content .h-red { color: #b91c1c; }
.lesson-rich-content h2.h-red { border-bottom-color: #fecaca; }
.lesson-rich-content h3.h-red { border-inline-start-color: #b91c1c; }

.lesson-rich-content .h-purple { color: #6d28d9; }
.lesson-rich-content h2.h-purple { border-bottom-color: #ddd6fe; }
.lesson-rich-content h3.h-purple { border-inline-start-color: #6d28d9; }

.lesson-rich-content .h-dark { color: #0f172a; }
.lesson-rich-content h2.h-dark { border-bottom-color: #cbd5e1; }
.lesson-rich-content h3.h-dark { border-inline-start-color: #0f172a; }

.lesson-rich-content p {
    margin: 0 0 1rem;
}

.lesson-rich-content ul,
.lesson-rich-content ol {
    margin: 0 0 1rem;
    padding-inline: 1.5rem;
}

.lesson-rich-content li {
    margin-bottom: 0.35rem;
}

.lesson-rich-content blockquote {
    margin: 0 0 1rem;
    padding: 0.85rem 1.1rem;
    background: var(--bg-surface, #f1f5f9);
    border-inline-start: 4px solid var(--primary, #4f46e5);
    border-radius: var(--radius-sm, 8px);
    color: var(--dark, #0f172a);
}

.lesson-rich-content a {
    color: var(--primary, #4f46e5);
    font-weight: 600;
}

.lesson-rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md, 12px);
    margin: 0.5rem 0;
}

.lesson-rich-content .lesson-figure {
    margin: 1.25rem auto;
    max-width: 100%;
    display: block;
}

.lesson-rich-content .lesson-figure.size-small {
    width: 40%;
    max-width: 100%;
}

.lesson-rich-content .lesson-figure.size-medium {
    width: 70%;
    max-width: 100%;
}

.lesson-rich-content .lesson-figure.size-full {
    width: 100%;
    max-width: 100%;
}

.lesson-rich-content .lesson-figure.align-start {
    margin-inline-start: 0;
    margin-inline-end: auto;
}

.lesson-rich-content .lesson-figure.align-center {
    margin-inline-start: auto;
    margin-inline-end: auto;
}

.lesson-rich-content .lesson-figure.align-end {
    margin-inline-start: auto;
    margin-inline-end: 0;
}

.lesson-rich-content .lesson-figure img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0;
    border-radius: var(--radius-md, 12px);
}

.lesson-rich-content .lesson-figure figcaption {
    margin-top: 0.45rem;
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text-muted, #64748b);
    text-align: start;
}

.lesson-rich-content .lesson-img-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 88px;
    padding: 1rem;
    background: var(--bg-surface, #f1f5f9);
    border: 1px dashed var(--border-color, #cbd5e1);
    border-radius: var(--radius-md, 12px);
    color: var(--text-muted, #64748b);
    font-size: 0.9rem;
    text-align: center;
}

.lesson-rich-content .lesson-video {
    width: 100%;
    max-width: 800px;
    margin: 1.25rem auto;
}

.lesson-rich-content .lesson-video.size-full {
    max-width: 100%;
}

.lesson-rich-content .lesson-figure.lesson-video-figure {
    width: 100%;
    max-width: 800px;
    margin: 1.25rem auto;
}

.lesson-rich-content .lesson-figure.lesson-video-figure.size-full {
    max-width: 100%;
}

.lesson-rich-content .lesson-figure.lesson-video-figure .lesson-video {
    margin: 0;
    max-width: 100%;
}

.lesson-rich-content .lesson-video-box {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    overflow: hidden;
    border-radius: var(--radius-md, 12px);
    background: #0f172a;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
}

@supports (aspect-ratio: 16 / 9) {
    .lesson-rich-content .lesson-video-box {
        height: auto;
        padding-bottom: 0;
        aspect-ratio: 16 / 9;
    }
}

.lesson-rich-content .lesson-video-box iframe,
.lesson-rich-content .lesson-video-box video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    border-radius: var(--radius-md, 12px);
}

/* Inline Simulation & Game Embeds (Stage 5) */
.lesson-rich-content .lesson-embed {
    --le-height: 520px;
    width: 100%;
    max-width: 900px;
    margin: 1.25rem auto;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
    background: #fff;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
}

.lesson-rich-content .lesson-embed.is-tall {
    --le-height: 720px;
}

@media (max-width: 900px) {
    .lesson-rich-content .lesson-embed,
    .lesson-rich-content .lesson-embed.is-tall {
        --le-height: 420px;
    }
}

@media (max-width: 560px) {
    .lesson-rich-content .lesson-embed,
    .lesson-rich-content .lesson-embed.is-tall {
        --le-height: 360px;
    }
}

.lesson-rich-content .lesson-embed-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0.55rem 0.85rem;
    background: var(--bg-surface, #f1f5f9);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    text-align: start;
}

.lesson-rich-content .lesson-embed-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.lesson-rich-content .lesson-embed-title {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 700;
    font-size: 0.94rem;
    color: var(--dark, #0f172a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lesson-rich-content .lesson-embed-fs-btn,
.lesson-rich-content .lesson-embed-fs-exit,
.lesson-rich-content .lesson-embed-ext {
    padding: 3px 9px;
    font-size: 0.85rem;
    line-height: 1.2;
    flex-shrink: 0;
    text-decoration: none;
}

.lesson-rich-content .lesson-embed-fs-exit {
    display: none;
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.lesson-rich-content .lesson-embed.is-fullscreen .lesson-embed-fs-exit,
.lesson-rich-content .lesson-embed:fullscreen .lesson-embed-fs-exit {
    display: inline-flex;
}

.lesson-rich-content .lesson-embed.is-fullscreen .lesson-embed-fs-btn,
.lesson-rich-content .lesson-embed:fullscreen .lesson-embed-fs-btn {
    display: none;
}

.lesson-rich-content .lesson-embed:fullscreen {
    max-width: none;
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.lesson-rich-content .lesson-embed:fullscreen .lesson-embed-stage {
    flex: 1 1 auto;
    height: auto;
}

.lesson-rich-content .lesson-embed-stage {
    position: relative;
    width: 100%;
    height: var(--le-height);
    background: #fff;
    overflow: hidden;
}

.lesson-rich-content .lesson-embed-stage iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.lesson-rich-content .lesson-embed-ph {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 1rem;
    background: var(--bg-surface, #f1f5f9);
    text-align: center;
}

.lesson-rich-content .lesson-embed-ph-icon {
    font-size: 2rem;
    line-height: 1;
}

.lesson-rich-content .lesson-embed-ph-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--dark, #0f172a);
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-rich-content .lesson-embed-missing {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 900px;
    margin: 1rem auto;
    padding: 0.9rem 1.25rem;
    background: var(--bg-surface, #f1f5f9);
    border: 1px dashed var(--border-color, #cbd5e1);
    border-radius: var(--radius-md, 12px);
    color: var(--text-muted, #64748b);
    font-size: 0.92rem;
    text-align: center;
}

.lesson-rich-content .lesson-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.15rem 0;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 12px);
    background: #fff;
}

.lesson-rich-content table {
    width: 100%;
    min-width: 0;
    border-collapse: collapse;
    margin: 0 0 1rem;
    font-size: 0.95rem;
}

.lesson-rich-content .lesson-table-wrap > table {
    margin: 0;
}

.lesson-rich-content th,
.lesson-rich-content td {
    border: 1px solid var(--border-color, #e2e8f0);
    padding: 0.5rem 0.75rem;
    text-align: start;
    vertical-align: middle;
    overflow-wrap: break-word;
}

.lesson-rich-content th {
    background: var(--bg-surface, #f1f5f9);
    font-weight: 700;
}

.lesson-rich-content table.lesson-table {
    width: 100%;
    min-width: 0;
    border-collapse: collapse;
    font-size: 0.96rem;
    background: #fff;
}

.lesson-rich-content table.lesson-table th,
.lesson-rich-content table.lesson-table td {
    border: 1px solid var(--border-color, #e2e8f0);
    padding: 10px 12px;
    text-align: start;
    vertical-align: middle;
    line-height: 1.6;
    overflow-wrap: break-word;
}

.lesson-rich-content .lesson-table-wrap > table tr:first-child th,
.lesson-rich-content .lesson-table-wrap > table tr:first-child td {
    border-top: 0;
}

.lesson-rich-content .lesson-table-wrap > table tr:last-child th,
.lesson-rich-content .lesson-table-wrap > table tr:last-child td {
    border-bottom: 0;
}

.lesson-rich-content .lesson-table-wrap > table th:first-child,
.lesson-rich-content .lesson-table-wrap > table td:first-child {
    border-inline-start: 0;
}

.lesson-rich-content .lesson-table-wrap > table th:last-child,
.lesson-rich-content .lesson-table-wrap > table td:last-child {
    border-inline-end: 0;
}

.lesson-rich-content table.lesson-table thead th,
.lesson-rich-content table.lesson-table tbody th:first-child {
    background: var(--primary-light, #eef2ff);
    font-weight: 700;
    color: var(--lc-h3-color, #0369a1);
}

.lesson-rich-content table.lesson-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.lesson-rich-content table.lesson-table tbody tr:nth-child(even) th:first-child {
    background: var(--primary-light, #eef2ff);
}

.lesson-rich-content table.lesson-table th .katex-display,
.lesson-rich-content table.lesson-table td .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0.35em 0;
}

.lesson-rich-content table.lesson-table th .katex,
.lesson-rich-content table.lesson-table td .katex {
    max-width: 100%;
}

.lesson-rich-content code {
    background: var(--bg-surface, #f1f5f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 6px;
    padding: 0.1rem 0.4rem;
    font-size: 0.9em;
}

.lesson-rich-content pre {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: var(--radius-md, 12px);
    padding: 1rem;
    overflow-x: auto;
    direction: ltr;
    text-align: start;
}

.lesson-rich-content pre code {
    background: none;
    border: none;
    color: inherit;
    padding: 0;
}

.lesson-rich-content hr {
    border: none;
    border-top: 1px solid var(--border-color, #e2e8f0);
    margin: 1.5rem 0;
}

/* Visual WYSIWYG Lesson Editor (Stage 6) */
.le-editor-frame {
    border: 1px solid var(--border-color, #cbd5e1);
    border-radius: var(--radius-md, 12px);
    background: #fff;
    overflow: hidden;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.04));
}

.le-editor-frame:focus-within {
    border-color: var(--primary, #4f46e5);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.le-editor-bar-wrap {
    padding: 8px 10px;
    background: var(--bg-surface, #f8fafc);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.le-editor-bar-wrap .lesson-editor-toolbar {
    margin-top: 0 !important;
}

.lesson-editor-toolbar .btn.is-active {
    background: var(--primary-light, #eef2ff);
    border-color: var(--primary, #4f46e5);
    color: var(--primary, #4f46e5);
    font-weight: 800;
}

.le-table-bar {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #eef2ff;
    border-bottom: 1px solid #c7d2fe;
}

.le-table-bar .btn {
    background: #fff;
    font-size: 0.78rem;
    padding: 3px 8px;
}

.le-table-bar .btn.is-active {
    background: var(--primary, #4f46e5);
    border-color: var(--primary, #4f46e5);
    color: #fff;
}

.le-surface {
    background: #fff;
}

.le-surface .le-prosemirror {
    min-height: 290px;
    max-height: 68vh;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    margin-bottom: 0;
    outline: none;
    text-align: start;
}

.le-surface .le-prosemirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    pointer-events: none;
    float: inline-start;
    height: 0;
}

.le-surface .le-prosemirror .tableWrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.15rem 0;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-md, 12px);
    background: #fff;
}

.le-surface .le-prosemirror .tableWrapper > table.lesson-table {
    margin: 0;
}

.le-surface .le-prosemirror table.lesson-table tbody tr:first-child th,
.le-surface .le-prosemirror table.lesson-table tbody tr th:first-child {
    background: var(--primary-light, #eef2ff);
    font-weight: 700;
    color: var(--lc-h3-color, #0369a1);
}

.le-surface .le-prosemirror table.lesson-table .selectedCell {
    background: rgba(79, 70, 229, 0.12) !important;
}

.le-surface .le-eq-node {
    display: inline-block;
    vertical-align: middle;
    padding: 1px 5px;
    margin: 0 2px;
    border-radius: 6px;
    background: rgba(79, 70, 229, 0.06);
    border: 1px dashed rgba(79, 70, 229, 0.3);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.le-surface .le-eq-node.is-display {
    display: block;
    text-align: center;
    padding: 6px 10px;
    margin: 0.6rem 0;
}

.le-surface .le-eq-node:hover,
.le-surface .le-eq-node.ProseMirror-selectednode {
    background: rgba(79, 70, 229, 0.14);
    border-color: var(--primary, #4f46e5);
}

.le-surface .le-block-atom {
    position: relative;
}

.le-surface .le-block-atom.ProseMirror-selectednode {
    outline: 2px solid var(--primary, #4f46e5);
    outline-offset: 2px;
    border-radius: var(--radius-md, 12px);
}

.le-surface .le-block-tools {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    z-index: 8;
    display: flex;
    gap: 5px;
    opacity: 0.92;
    background: rgba(15, 23, 42, 0.78);
    padding: 4px 6px;
    border-radius: 8px;
}

.le-atom-btn {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.4;
}

.lesson-embed-bar .le-atom-btn {
    background: #fff;
    color: var(--dark, #0f172a);
    border-color: var(--border-color, #cbd5e1);
}

.lesson-embed-bar .le-atom-btn.is-del,
.lesson-embed-missing .le-atom-btn.is-del {
    color: #b91c1c;
    border-color: #fecaca;
    background: #fef2f2;
}

.le-atom-btn:hover {
    filter: brightness(0.95);
}

.le-video-preview-card {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
}

.le-video-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.65;
}

.le-video-overlay {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-align: center;
    padding: 1rem;
}

.le-video-play-badge {
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: rgba(79, 70, 229, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.le-video-meta {
    background: rgba(15, 23, 42, 0.78);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.le-embed-stage-preview {
    height: 220px !important;
}

.le-embed-preview-note {
    font-size: 0.84rem;
    color: var(--text-muted, #64748b);
}

.le-raw-source-box {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    direction: ltr !important;
    text-align: start !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
}
