/* Document Rendering Styles - Shared across all viewers */

/* ========================================
   Dark Theme (default)
   ======================================== */
.theme-dark,
.parser-output {
    --shadow-color: rgba(0, 0, 0, 0.2);
    --fill-color-1: rgba(255, 255, 255, 0.1);
    --fill-color-2: rgba(255, 255, 255, 0.05);
    --border-radius: 8px;
    --text-color-1: rgba(255, 255, 255, 0.9);
    --text-color-2: rgba(255, 255, 255, 0.5);
    --highlighted-block-fill-color: rgba(160, 218, 0, 0.1);
    --proposition-color: rgb(212, 184, 0);
    --définition-color: #ff9b88;

    color: var(--text-color-1);
}

/* Dark theme block styling */
.theme-dark .block,
.parser-output .block {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.2), 0 0 32px inset rgba(255, 255, 255, 0.05), 0 0 3px inset rgba(255, 255, 255, 0.1);
    color: white;
}

/* Search results: background on wrapper, block inherits */
.rendered-block-content.theme-dark {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.2), 0 0 32px inset rgba(255, 255, 255, 0.05), 0 0 3px inset rgba(255, 255, 255, 0.1);
}

.rendered-block-content.theme-dark .block {
    background: transparent;
    border: none;
    box-shadow: none;
    color: white;
}

/* Dark theme section/text blocks - no styling */
.theme-dark .block.section,
.theme-dark .block.sous-section,
.theme-dark .block.sous-sous-section,
.theme-dark .texte.block,
.parser-output .block.section,
.parser-output .block.sous-section,
.parser-output .block.sous-sous-section,
.parser-output .texte.block,
.rendered-block-content.theme-dark .block.section,
.rendered-block-content.theme-dark .block.sous-section,
.rendered-block-content.theme-dark .block.sous-sous-section,
.rendered-block-content.theme-dark .texte.block {
    background: none;
    border: none;
    box-shadow: none;
    color: white;
}

/* Dark theme theorem blocks - yellow tint */
.theme-dark .block.theoreme,
.theme-dark .block.theoremes,
.theme-dark .block.théorème,
.theme-dark .block.théorèmes,
.parser-output .block.theoreme,
.parser-output .block.theoremes,
.parser-output .block.théorème,
.parser-output .block.théorèmes {
    background: rgba(212, 184, 0, 0.1);
}

/* Search results theorem - yellow tint over dark base */
.rendered-block-content.theme-dark .block.theoreme,
.rendered-block-content.theme-dark .block.theoremes,
.rendered-block-content.theme-dark .block.théorème,
.rendered-block-content.theme-dark .block.théorèmes {
    background: rgba(212, 184, 0, 0.15);
}

/* Dark theme fold buttons - same style as blocks */
.theme-dark .fold-button,
.parser-output .fold-button {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.2), 0 0 32px inset rgba(255, 255, 255, 0.05), 0 0 3px inset rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    transform: translateY(0);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}

.theme-dark .fold-button:hover,
.parser-output .fold-button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

/* Half-pressed state when fold is open */
.theme-dark .fold-button.active,
.parser-output .fold-button.active {
    transform: translateY(2px);
    box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.2), 0 0 32px inset rgba(255, 255, 255, 0.05), 0 0 3px inset rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.08);
}

/* Fully pressed on click */
.theme-dark .fold-button:active,
.parser-output .fold-button:active {
    transform: translateY(4px);
    box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.2), 0 0 32px inset rgba(255, 255, 255, 0.05), 0 0 3px inset rgba(255, 255, 255, 0.1);
}

/* Dark theme tables */
.theme-dark th,
.parser-output th {
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.theme-dark td:not(:last-child),
.theme-dark th:not(:last-child),
.parser-output td:not(:last-child),
.parser-output th:not(:last-child) {
    border-right-color: rgba(255, 255, 255, 0.2);
}

.theme-dark tr.single-line,
.parser-output tr.single-line {
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.theme-dark tr.double-line,
.parser-output tr.double-line {
    border-bottom-color: rgba(255, 255, 255, 0.2);
    border-top-color: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Light Theme
   ======================================== */
.theme-light {
    --shadow-color: rgba(0, 0, 0, 0.04);
    --fill-color-1: rgb(235, 235, 235);
    --fill-color-2: #ffffff;
    --border-radius: 8px;
    --text-color-1: rgba(0, 0, 0, 0.85);
    --text-color-2: rgba(0, 0, 0, 0.5);
    --highlighted-block-fill-color: rgba(255, 229, 92, 0.17);
    --proposition-color: rgb(191, 150, 0);
    --définition-color: #ea7a64;

    /* Code syntax highlighting (light theme) */
    --code-default-color: #59554E;
    --code-blue: #00AFDC;
    --code-string-yellow: #D2B700;
    --code-comment-grey: #737373;
    --code-number-orange: #9B57D3;
    --code-operator-orange: #D6006A;
    --code-punctuation-blue: #333333;
    --code-border-color: #CACACA;
    --code-function-color: #2FB000;

    color: var(--text-color-1);
}

/* Light theme block styling */
.theme-light .block {
    background: #eeeeee;
    border: none;
    border-top: 1px solid white;
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.1), 0 0 32px inset rgba(255, 255, 255, 0.9), 0 0 3px inset rgba(255, 255, 255, 0.9);
    color: rgba(0, 0, 0, 0.85);
}

/* Search results: background on wrapper, block inherits */
.rendered-block-content.theme-light {
    background: #eeeeee;
    border-radius: 15px;
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.1), 0 0 32px inset rgba(255, 255, 255, 0.9), 0 0 3px inset rgba(255, 255, 255, 0.9);
}

.rendered-block-content.theme-light .block {
    background: transparent;
    border: none;
    box-shadow: none;
    color: rgba(0, 0, 0, 0.85);
}

/* Light theme section/text blocks - no styling */
.theme-light .block.section,
.theme-light .block.sous-section,
.theme-light .block.sous-sous-section,
.theme-light .texte.block,
.rendered-block-content.theme-light .block.section,
.rendered-block-content.theme-light .block.sous-section,
.rendered-block-content.theme-light .block.sous-sous-section,
.rendered-block-content.theme-light .texte.block {
    background: none;
    border: none;
    box-shadow: none;
    color: rgba(0, 0, 0, 0.85);
}

/* Light theme theorem blocks - yellow tint */
.theme-light .block.theoreme,
.theme-light .block.theoremes,
.theme-light .block.théorème,
.theme-light .block.théorèmes {
    background: rgba(255, 220, 0, 0.15);
}

/* Search results theorem - yellow tint over grey base */
.rendered-block-content.theme-light .block.theoreme,
.rendered-block-content.theme-light .block.theoremes,
.rendered-block-content.theme-light .block.théorème,
.rendered-block-content.theme-light .block.théorèmes {
    background: #f5edd5;
}

/* Light theme fold buttons - same style as blocks */
.theme-light .fold-button {
    background: #eeeeee;
    border: none;
    border-top: 1px solid white;
    box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.1), 0 0 32px inset rgba(255, 255, 255, 0.9), 0 0 3px inset rgba(255, 255, 255, 0.9);
    color: rgba(0, 0, 0, 0.6);
    transform: translateY(0);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}

.theme-light .fold-button:hover {
    background: #e8e8e8;
    color: rgba(0, 0, 0, 0.8);
}

/* Half-pressed state when fold is open */
.theme-light .fold-button.active {
    transform: translateY(2px);
    box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.1), 0 0 32px inset rgba(255, 255, 255, 0.9), 0 0 3px inset rgba(255, 255, 255, 0.9);
    background: #e8e8e8;
}

/* Fully pressed on click */
.theme-light .fold-button:active {
    transform: translateY(4px);
    box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.1), 0 0 32px inset rgba(255, 255, 255, 0.9), 0 0 3px inset rgba(255, 255, 255, 0.9);
}

/* Light theme tables */
.theme-light th {
    border-bottom-color: rgba(0, 0, 0, 0.15);
}

.theme-light td:not(:last-child),
.theme-light th:not(:last-child) {
    border-right-color: rgba(0, 0, 0, 0.1);
}

.theme-light tr.single-line {
    border-bottom-color: rgba(0, 0, 0, 0.15);
}

.theme-light tr.double-line {
    border-bottom-color: rgba(0, 0, 0, 0.15);
    border-top-color: rgba(0, 0, 0, 0.15);
}

/* Light theme code blocks */
.theme-light code {
    background: #f8f8f8;
    border-top-color: #e0e0e0;
    box-shadow: 0 0 4px inset rgba(0, 0, 0, 0.05), 0 0 56px inset rgba(0, 0, 0, 0.02);
}

.theme-light pre {
    background: transparent;
}

/* ========================================
   Base Structural Styles (theme-agnostic)
   ======================================== */

/* Block base styles */
.block {
    position: relative;
    box-sizing: border-box;
    background-color: var(--fill-color-2);
    padding: 18px 20px;
    margin-top: 15px;
    margin-bottom: 15px;
    border-top: 1px solid var(--fill-color-1);
    border-radius: 15px;
    box-shadow: 0px 4px 0px var(--shadow-color);
    font-size: 16px;
    text-align: left;
}

/* Block star button styles are now in page.css as part of unified toolbar */

/* Section headers */
.block.section,
.block.sous-section,
.block.sous-sous-section {
    display: block;
    font-weight: bold;
    border: none;
    box-shadow: none;
    background: none;
    padding: 0;
}

.block.section {
    font-size: 1.8em;
    counter-reset: subsection;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.block.sous-section {
    font-size: 1.5em;
    counter-reset: subsubsection;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.block.sous-sous-section {
    font-size: 1.3em;
    margin-top: 1.3rem;
    margin-bottom: 1rem;
}

.block.section:before {
    content: counter(section) "\0000a0\0000a0";
    counter-increment: section;
}

.block.sous-section:before {
    content: counter(section) "." counter(subsection) "\0000a0\0000a0";
    counter-increment: subsection;
}

.block.sous-sous-section:before {
    content: counter(section) "." counter(subsection) "." counter(subsubsection) "\0000a0\0000a0";
    counter-increment: subsubsection;
}

/* Non-numbered sections (Section* syntax) */
.block.section.no-number:before,
.block.sous-section.no-number:before,
.block.sous-sous-section.no-number:before {
    content: none;
    counter-increment: none;
}

/* Text blocks */
.texte.block {
    background: none;
    border: none;
    box-shadow: none;
    margin-top: 10px;
    margin-bottom: 10px;
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
    padding-right: 0;
}

:not(.texte.block, .section.block, .sous-section.block, .sous-sous-section) + .texte.block {
    margin-top: 30px;
}

.texte.block + :not(.texte.block, .section.block, .sous-section.block, .sous-sous-section) {
    margin-top: 30px; 
}

/* Block type headers */
h5 {
    margin: 0 0 0.1em 0;
    font-size: 14px;
    font-variant: small-caps;
    text-align: left;
    letter-spacing: 0.05em;
}

h6 {
    margin-top: 0;
    margin-bottom: 6px;
    font-size: 17px;
    line-height: 1.2em;
    text-align: left;
}

/* Block type colors */
.definition h5,
.definitions h5,
.définition h5,
.définitions h5,
.exemple h5,
.exemples h5 {
    color: var(--définition-color);
}

.proposition h5,
.propositions h5,
.theoreme h5,
.theoremes h5,
.théorème h5,
.théorèmes h5,
.propriete h5,
.proprietes h5,
.propriété h5,
.propriétés h5,
.lemme h5,
.lemmes h5,
.corollaire h5,
.corollaires h5 {
    color: var(--proposition-color);
}

/* Highlighted blocks */
.highlight {
    background-color: var(--highlighted-block-fill-color);
}

/* Paragraphs */
p {
    margin: 0.5em 0;
}

p:empty {
    display: none;
}

/* Lists */
ol {
    margin-left: 0;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    padding-left: 2em;
}

ol > li {
    margin: 8px 0;
}

ol.arabic-centered {
    counter-reset: list;
    padding-left: 3em;
}

ol.arabic-centered > li {
    list-style: none;
    position: relative;
    text-align: left;
    margin: 8px 0;
}

ol.arabic-centered > li:before {
    counter-increment: list;
    content: "(" counter(list, decimal) ")";
    position: absolute;
    right: calc(100% + 12px);
    top: 0;
}

ol.lower-roman-centered {
    counter-reset: list;
    padding-left: 3em;
}

ol.lower-roman-centered > li {
    list-style: none;
    position: relative;
    text-align: left;
    margin: 8px 0;
}

ol.lower-roman-centered > li:before {
    counter-increment: list;
    content: "(" counter(list, lower-roman) ")";
    position: absolute;
    right: calc(100% + 12px);
    top: 0;
}

ul.asterisk {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    padding-left: 2em;
}

ul.asterisk > li {
    list-style: none;
    position: relative;
    text-align: left;
    margin: 8px 0;
}

ul.asterisk > li:before {
    content: "*";
    position: absolute;
    right: calc(100% + 12px);
    top: 0;
}

ul.dash {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    padding-left: 2em;
}

ul.dash > li {
    list-style: none;
    position: relative;
    text-align: left;
    margin: 8px 0;
}

ul.dash > li:before {
    content: "\2014";
    position: absolute;
    right: calc(100% + 12px);
    top: 0;
}

/* Tables */
.table-group {
    margin: 1.5em 0;
    display: flex;
    justify-content: space-evenly;
    align-items: flex-end;
    flex-wrap: wrap;
}

.table-container {
    display: inline-block;
    margin: 1em;
    overflow-x: auto;
    text-align: center;
}

table {
    border-collapse: collapse;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.4;
}

td, th {
    padding: 0.6em 1em;
    text-align: center;
}

th {
    border-bottom: 1px solid var(--text-color-2);
    font-weight: normal;
}

td:not(:last-child), th:not(:last-child) {
    border-right: 1px solid var(--text-color-2);
}

td.empty-cell:empty {
    width: 3px;
    padding: 0;
}

tr.single-line {
    border-bottom: 1px solid var(--text-color-2);
}

tr.single-line td {
    padding: 0;
    height: 0;
}

tr.double-line {
    border-bottom: 1px solid var(--text-color-2);
    border-top: 1px solid var(--text-color-2);
}

tr.double-line td {
    padding: 0;
    height: 3px;
}

.table-name {
    margin-top: 1em;
    text-align: center;
    counter-increment: table;
}

.table-name::before {
    content: "Tableau " counter(table) " \2014 ";
    font-variant: small-caps;
}

/* Strong / emphasis */
strong {
    font-weight: bold;
}

em {
    font-style: italic;
}

/* KaTeX */
.katex {
    font: normal 1em KaTeX_Main, Times New Roman, serif !important;
}

.katex-display {
    margin: 1rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.katex-display > .katex {
    padding: 3px 0;
}

/* Fold/accordion */
.fold {
    margin-top: 0.75rem;
}

.fold-button {
    background: var(--fill-color-1);
    border: 1px solid var(--fill-color-1);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: CMSerif, 'Times New Roman', serif;
    margin-right: 0.5rem;
}

.fold-button:hover {
    opacity: 0.8;
}

.fold-accordion {
    display: none;
    overflow: hidden;
}

.fold-accordion.active {
    display: block;
    margin-top: 1rem;
    margin-left: 0.5rem;
    padding-left: 1rem;
    border-left: 2px solid var(--fill-color-1);
    animation: foldOpen 0.2s ease-out;
}

@keyframes foldOpen {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cqfd {
    float: right;
    font-size: 1.2rem;
}

/* Sketch placeholders */
.sketch-placeholder {
    position: relative;
    width: 100%;
    min-height: 50px;
    background: transparent;
    border-radius: var(--border-radius);
    margin: 1em 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sketch-placeholder canvas {
    display: block;
}

.sketch-loading {
    color: var(--text-color-2);
    font-style: italic;
}

/* Sketch fullscreen button */
.sketch-fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(128, 128, 128, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.sketch-placeholder:hover .sketch-fullscreen-btn {
    opacity: 0.7;
}

.sketch-fullscreen-btn:hover {
    opacity: 1 !important;
    background: rgba(128, 128, 128, 0.3);
}

.sketch-fullscreen-btn svg {
    width: 16px;
    height: 16px;
}

.sketch-fullscreen-btn svg path {
    fill: rgba(255, 255, 255, 0.7);
}

/* Light mode override */
.theme-light .sketch-fullscreen-btn svg path {
    fill: rgba(0, 0, 0, 0.6);
}

/* Sketch fullscreen overlay */
.sketch-fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--fill-color-2, #000);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sketch-fullscreen-container {
    position: relative;
    width: 90vw;
    height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sketch-fullscreen-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.sketch-fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sketch-fullscreen-close svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Light theme fullscreen overlay */
.sketch-fullscreen-overlay.theme-light {
    background: #f5f5f5;
}

.theme-light .sketch-fullscreen-close,
.sketch-fullscreen-overlay.theme-light .sketch-fullscreen-close {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
}

.theme-light .sketch-fullscreen-close:hover,
.sketch-fullscreen-overlay.theme-light .sketch-fullscreen-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

.theme-light .sketch-fullscreen-close svg,
.sketch-fullscreen-overlay.theme-light .sketch-fullscreen-close svg {
    fill: #333;
}

/* ========================================
   Locked Document Placeholder
   ======================================== */
.locked-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px;
    text-align: center;
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--border-radius, 8px);
    border: 2px dashed rgba(0, 0, 0, 0.15);
}

.locked-placeholder p {
    margin: 0;
    color: var(--text-color-2);
    font-size: 1.1em;
}

.locked-placeholder::before {
    content: '🔒';
    font-size: 2.5em;
    margin-bottom: 16px;
    opacity: 0.6;
}

/* Dark theme locked placeholder */
.theme-dark .locked-placeholder,
.parser-output .locked-placeholder {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Light theme locked placeholder */
.theme-light .locked-placeholder {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}
