/* Design tokens — Modern, bright, professional training-platform palette.
   Rich blue primary + amber accent on clean light/white surfaces. */
:root {
    --background: 210 40% 98%;
    --foreground: 222 47% 13%;

    --card: 0 0% 100%;
    --card-foreground: 222 47% 13%;

    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 13%;

    --primary: 211 79% 42%;
    --primary-foreground: 0 0% 100%;

    --secondary: 210 40% 94%;
    --secondary-foreground: 222 40% 22%;

    --muted: 210 40% 96%;
    --muted-foreground: 215 18% 42%;

    --accent: 38 92% 50%;
    --accent-foreground: 222 47% 13%;

    --destructive: 0 72% 51%;
    --destructive-foreground: 0 0% 100%;

    --border: 214 32% 88%;
    --input: 214 32% 86%;
    --ring: 211 79% 42%;

    --radius: 0.625rem;
    --radius-sm: calc(0.625rem - 4px);
    --radius-lg: calc(0.625rem + 4px);
    --radius-full: 9999px;

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;
    --spacing-3xl: 64px;

    --shadow-sm: 0 1px 2px 0 rgb(15 40 80 / 0.06), 0 1px 3px 0 rgb(15 40 80 / 0.08);
    --shadow-md: 0 4px 6px -1px rgb(15 40 80 / 0.08), 0 2px 4px -2px rgb(15 40 80 / 0.06);
    --shadow-lg: 0 12px 24px -6px rgb(15 40 80 / 0.12), 0 6px 10px -6px rgb(15 40 80 / 0.08);

    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 350ms;

    --chart-1: 173 58% 39%;
    --chart-2: 38 92% 50%;
    --chart-3: 262 83% 58%;
    --chart-4: 197 37% 54%;
    --chart-5: 12 76% 61%;

    --font-sans: 'DM Sans', system-ui, sans-serif;
    --font-display: 'Plus Jakarta Sans', var(--font-sans);
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* Kept in sync with :root so the app renders the same bright theme
   regardless of the `.dark` class. */
.dark {
    --background: 210 40% 98%;
    --foreground: 222 47% 13%;

    --card: 0 0% 100%;
    --card-foreground: 222 47% 13%;

    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 13%;

    --primary: 211 79% 42%;
    --primary-foreground: 0 0% 100%;

    --secondary: 210 40% 94%;
    --secondary-foreground: 222 40% 22%;

    --muted: 210 40% 96%;
    --muted-foreground: 215 18% 42%;

    --accent: 38 92% 50%;
    --accent-foreground: 222 47% 13%;

    --destructive: 0 72% 51%;
    --destructive-foreground: 0 0% 100%;

    --border: 214 32% 88%;
    --input: 214 32% 86%;
    --ring: 211 79% 42%;
}

/* NOTE: the global `border-color` default is applied through the Tailwind
   runtime config (borderColor.DEFAULT), mirroring `@apply border-border`. */

html,
body {
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: hsl(210 40% 94%);
}

::-webkit-scrollbar-thumb {
    background: hsl(214 20% 72%);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: hsl(214 20% 58%);
}

/* Rich Markdown slide content */
.slide-prose {
    color: hsl(var(--foreground));
    font-size: 0.95rem;
    line-height: 1.7;
}

.slide-prose > *:first-child {
    margin-top: 0;
}

.slide-prose > *:last-child {
    margin-bottom: 0;
}

.slide-prose p {
    margin: 0.75rem 0;
    color: hsl(var(--foreground) / 0.9);
}

.slide-prose strong {
    color: hsl(var(--foreground));
    font-weight: 700;
}

.slide-prose em {
    font-style: italic;
}

.slide-prose h1,
.slide-prose h2,
.slide-prose h3 {
    font-family: var(--font-display, inherit);
    font-weight: 700;
    line-height: 1.3;
    margin: 1.25rem 0 0.5rem;
    color: hsl(var(--foreground));
}

.slide-prose h1 {
    font-size: 1.5rem;
}

.slide-prose h2 {
    font-size: 1.25rem;
}

.slide-prose h3 {
    font-size: 1.1rem;
}

.slide-prose ul {
    list-style: none;
    margin: 0.75rem 0;
    padding-left: 0.25rem;
}

.slide-prose ul ul {
    margin: 0.35rem 0 0.35rem 0.5rem;
    padding-left: 1rem;
    border-left: 1px solid hsl(var(--border));
}

.slide-prose li {
    position: relative;
    padding-left: 1.4rem;
    margin: 0.4rem 0;
    color: hsl(var(--foreground) / 0.9);
}

.slide-prose li::before {
    content: "";
    position: absolute;
    left: 0.15rem;
    top: 0.6rem;
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
}

.slide-prose ul ul li::before {
    background: hsl(var(--primary) / 0.5);
    width: 0.3rem;
    height: 0.3rem;
    top: 0.65rem;
}

.slide-prose a {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}

.slide-prose code {
    background: hsl(var(--secondary));
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    font-size: 0.85em;
}

.slide-prose table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.slide-prose th,
.slide-prose td {
    border: 1px solid hsl(var(--border));
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.slide-prose thead th {
    background: hsl(var(--primary) / 0.12);
    font-weight: 700;
    color: hsl(var(--foreground));
}

.slide-prose tbody tr:nth-child(even) {
    background: hsl(var(--secondary) / 0.4);
}

/* Markdown tables are wrapped to match the react-markdown table renderer */
.slide-table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
}

/* Motion utilities replacing framer-motion entrance animations */
@keyframes ucsse-fade-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ucsse-slide-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes ucsse-pop-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes ucsse-collapse-in {
    from {
        opacity: 0;
        max-height: 0;
    }

    to {
        opacity: 1;
        max-height: 40rem;
    }
}

.motion-fade-up {
    animation: ucsse-fade-up 0.3s ease-out both;
}

.motion-slide-in {
    animation: ucsse-slide-in 0.2s ease-out both;
}

.motion-pop-in {
    animation: ucsse-pop-in 0.25s ease-out both;
}

.motion-collapse-in {
    animation: ucsse-collapse-in 0.25s ease-out both;
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .motion-fade-up,
    .motion-slide-in,
    .motion-pop-in,
    .motion-collapse-in {
        animation: none;
    }
}

/* Toaster (port of sonner) */
.ucsse-toaster {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.ucsse-toast {
    pointer-events: auto;
    min-width: 18rem;
    max-width: 22rem;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    background: hsl(var(--popover));
    color: hsl(var(--popover-foreground));
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    animation: ucsse-fade-up 0.2s ease-out both;
}

.ucsse-toast--success {
    border-color: hsl(var(--primary) / 0.4);
}

.ucsse-toast--error {
    border-color: hsl(var(--destructive) / 0.5);
}

.ucsse-toast--info {
    border-color: hsl(var(--accent) / 0.4);
}

.ucsse-toast__icon {
    flex-shrink: 0;
    margin-top: 0.0625rem;
}

.ucsse-toast--success .ucsse-toast__icon {
    color: hsl(var(--primary));
}

.ucsse-toast--error .ucsse-toast__icon {
    color: hsl(var(--destructive));
}

.ucsse-toast--info .ucsse-toast__icon {
    color: hsl(var(--accent));
}


/* ── Drag-and-drop sorting (content admin) ─────────────────────────────── */
.drag-handle {
    cursor: grab;
    color: var(--mud-palette-text-secondary);
}

.drag-over {
    border: 2px dashed var(--mud-palette-primary) !important;
    background: var(--mud-palette-primary-lighten) !important;
}

.dragging {
    opacity: 0.5;
}

/* ── Markdown image styles ──────────────────────────────────────────────
   Triggered by the MarkdownEditor "Add image" style dropdown, which emits
   images tagged with {style="Name"}. Markdig's generic-attributes
   extension turns that into an actual style attribute containing just the
   name (e.g. style="Background"). The name is not a valid CSS declaration
   so browsers ignore its inline effect, but we match on it via attribute
   selectors. Rules apply everywhere Markdown is rendered — the editor
   preview (.bme-preview / .markdown-body) and the slide renderer
   (.rendered-md / .slide-prose).

   NOTE: use exact-value selectors ([style="TopRight"]) so that "TopRight"
   does NOT also match "TopRightSmall". */

/* Common image reset for tagged markdown images */
.bme-preview img[style="Background"],
.bme-preview img[style="TopRight"],
.bme-preview img[style="TopRightSmall"],
.markdown-body img[style="Background"],
.markdown-body img[style="TopRight"],
.markdown-body img[style="TopRightSmall"],
.rendered-md img[style="Background"],
.rendered-md img[style="TopRight"],
.rendered-md img[style="TopRightSmall"],
.slide-prose img[style="Background"],
.slide-prose img[style="TopRight"],
.slide-prose img[style="TopRightSmall"] {
    display: block;
    border: 0;
}

/* Ensure the surrounding markdown container can host absolutely
   positioned children (Background) or a floated child (TopRight*). */
.bme-preview:has(img[style="Background"]),
.markdown-body:has(img[style="Background"]),
.rendered-md:has(img[style="Background"]),
.slide-prose:has(img[style="Background"]) {
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

/* Background — cover the whole markdown container behind the text. */
.bme-preview img[style="Background"],
.markdown-body img[style="Background"],
.rendered-md img[style="Background"],
.slide-prose img[style="Background"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.12;
    z-index: 0;
    pointer-events: none;
    user-select: none;
}

/* Keep text/content above the background image. */
.bme-preview:has(> img[style="Background"]) > :not(img[style="Background"]),
.markdown-body:has(> img[style="Background"]) > :not(img[style="Background"]),
.rendered-md:has(> img[style="Background"]) > :not(img[style="Background"]),
.slide-prose:has(> img[style="Background"]) > :not(img[style="Background"]) {
    position: relative;
    z-index: 1;
}

/* TopRight — floats a decorative image into the top-right corner. */
.bme-preview img[style="TopRight"],
.markdown-body img[style="TopRight"],
.rendered-md img[style="TopRight"],
.slide-prose img[style="TopRight"] {
    float: right;
    clear: right;
    width: 38%;
    max-width: 320px;
    height: auto;
    margin: 0 0 var(--spacing-md, 16px) var(--spacing-md, 16px);
    border-radius: var(--radius, 0.625rem);
    box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,0.08));
    shape-outside: margin-box;
}

/* TopRightSmall — same corner, roughly half the size. */
.bme-preview img[style="TopRightSmall"],
.markdown-body img[style="TopRightSmall"],
.rendered-md img[style="TopRightSmall"],
.slide-prose img[style="TopRightSmall"] {
    float: right;
    clear: right;
    width: 20%;
    max-width: 160px;
    height: auto;
    margin: 0 0 var(--spacing-sm, 8px) var(--spacing-sm, 8px);
    border-radius: var(--radius-sm, 0.375rem);
    box-shadow: var(--shadow-sm, 0 1px 2px 0 rgba(0,0,0,0.06));
    shape-outside: margin-box;
}

/* Narrow viewports: fall back to full-width blocks for the corner styles. */
@media (max-width: 640px) {
    .bme-preview img[style="TopRight"],
    .bme-preview img[style="TopRightSmall"],
    .markdown-body img[style="TopRight"],
    .markdown-body img[style="TopRightSmall"],
    .rendered-md img[style="TopRight"],
    .rendered-md img[style="TopRightSmall"],
    .slide-prose img[style="TopRight"],
    .slide-prose img[style="TopRightSmall"] {
        float: none;
        width: 100%;
        max-width: 100%;
        margin: var(--spacing-sm, 8px) 0;
    }
}
