/* === REAGLE'S CSS CUSTOM PROPERTIES === */
/* Design tokens for consistent theming across components.
   Uses color-mix() for transparency to maintain design flexibility. */
:root {
    --border-color: #666;
    --callout-bg: white;
    /* Cream background at 80% opacity for readable overlays */
    --frame-bg: color-mix(in srgb, #fcfaeb 80%, transparent);
    --highlight-bg: #d3d8f7;
    --img-spacing: 25px;
    --img-floating-padding: 10px;
    --indent-spacing: 20px;
    --list-margin: 50px;
    /* Semi-transparent shadows for depth without overwhelming visuals */
    --shadow-dark: color-mix(in srgb, black 60%, transparent);
    --shadow-gray: gray;
}

/* === BASE === */
/* Inherit background color from parent to avoid white flashes during transitions.
   Addresses reveal.js issue #668 where slides briefly show default background. */
html { background-color: inherit; }

/* === BASE TYPOGRAPHY AND SIZING === */
/* Base font size for all slide content. Reveal.js scales from this value. */
.reveal { font-size: 36px; }

/* Title slides (level1 sections) use larger text for emphasis */
section.level1 { font-size: 125%; }

/* Highlight class adds background color to draw attention to key content */
section.highlight h2,
span.highlight { background-color: var(--highlight-bg); }

/* Reset fit-text sections to default styles.
   Reveal.js's r-fit-text can interfere with custom styling,
   so we revert all properties to their initial values. */
section.r-fit-text { all: revert; }

/* Use lowercase letters (a, b, c) instead of uppercase for alphabetic lists */
ol[type="a"] { list-style-type: lower-alpha; }

/* === BLOCK QUOTES === */
/* Simple border styling for quotes with subtle background tint */
:root {
    --quote-border-color: #2a76dd;
    --quote-bg: color-mix(in srgb, var(--quote-border-color) 5%, transparent);
}

.reveal blockquote {
  position: relative;
  font-style: normal; /* Override reveal.js italic default */
  font-size: 95%;
  background: var(--quote-bg);
  padding: 0.2em 0.6em;
  border-left: 4px solid var(--quote-border-color); /* Default: left border */
  padding-left: 1em;
}

/* === CODE === */
/* Subtle green-tinted background distinguishes inline code from body text */
:root {
  --code-bg: color-mix(in srgb, hsl(120, 72%, 52%) 5%, transparent);
}

code {
  font-family: monospace;
  font-size: 95%;
  background: var(--code-bg);
  padding: 0.1em 0.1em;
}

/* === TABLES === */
/* Center tables horizontally and add border for visual separation */
.reveal table {
    margin-left: auto;
    margin-right: auto;
    border: 1px solid var(--border-color);
}

/* Cell borders and padding create clear grid structure.
   Top alignment prevents content from jumping when cells have different heights. */
.reveal table td,
.reveal table th {
    border: 1px solid var(--border-color);
    padding: 0px 4px 0px 16px;
    vertical-align: top;
}

/* === FRAGMENT ANIMATIONS === */
/* Custom fragment behavior without reveal.js's default transform scaling.
   Addresses issue #2126 where transforms cause layout shifts.
   We control size changes purely through font-size for smoother inline growth. */

/* Grow fragments: emphasize with bold and size increase */
.reveal .slides section span.fragment.grow.visible {
    font-weight: bold;
    font-size: 130%;
    transform: none; /* Disable reveal.js transform to prevent layout jumps */
}

/* Shrink fragments: de-emphasize with lighter weight and smaller size */
.reveal .slides section span.fragment.shrink.visible {
    font-weight: lighter;
    font-size: 70%;
    transform: none; /* Disable reveal.js transform to prevent layout jumps */
}

/* === DEFINITION LISTS === */
/* Left-align definition lists for better readability of term-definition pairs */
.reveal dl { text-align: left; }
.reveal dd { margin-left: 2em; }

/* === LIST FORMATTING === */
/* Pandoc generates <p> tags inside <li> elements for "loose" lists.
   We display them inline to create visually "tight" lists without extra spacing. */
.reveal ul li p,
.reveal ol li p {
    margin: 0;
    display: inline;
}

/* Blockquotes within lists are indented for visual hierarchy.
   Box-sizing prevents padding from expanding beyond the calculated width. */
.reveal ul li blockquote,
.reveal ol li blockquote {
    margin: 0.5em 0 0 1.5em;
    padding: 0 1em 0 0;
    width: calc(100% - 1.5em);
    box-sizing: border-box;
}

.reveal ul li blockquote p {
    margin: 0;
    display: inline;
}

/* Fix for reveal.js issue #2892: column layout breaks list rendering.
   Force "display: block" to restore proper list column distribution. */
div[style*="column-count"] ul,
div[style*="column-count"] ol {
    display: block;
}

/* Line blocks (poetry/verse formatted with pandoc) should be left-aligned,
   not center-aligned like normal slide content. */
div.line-block { text-align: left; }

/* === HEADINGS === */
/* Remove text shadow from main headings for cleaner appearance.
   Line-height of 1 prevents extra spacing above/below. */
.reveal h1 {
    text-shadow: none;
    line-height: 1;
}

/* Add consistent spacing around h3 subheadings */
.reveal h3 {
    margin: 35px 0 10px 0;
}

/* === IMAGES === */
/* Responsive image sizing with reveal.js default styling removed.
   Addresses Stack Overflow #23082660 for cleaner image presentation. */
.reveal section img {
    max-height: calc(480px + 1vh);
    width: auto;
    background: none;
    border: none;
    box-shadow: none;
}

/* Images with captions need reduced height to accommodate caption below */
.reveal section figure img {
    max-height: calc(420px + 1vh);
}

/* === BACKGROUNDS === */
/* ISSUE: Text legibility on busy backgrounds remains an unsolved problem.
   blur_on_bg makes text too dark/fuzzy; frame_on_bg can be ugly with dense text.
   No single CSS solution handles all cases (gradients, solid colors, varied brightness,
   text overlays, busy images). May require light/dark background variations.
   Last reviewed: 2025-04-02 */

/* Text shadow provides contrast against busy backgrounds.
   Double shadow (light + dark) works across more background types. */
.reveal .blur_on_bg {
    text-shadow: 2px 1px 6px silver,
                 2px 1px 8px black;
}

/* Special formatting for lists on framed backgrounds.
   Inside positioning with manual indentation keeps bullets within frame. */
.reveal section.frame_on_bg :is(ul, ol) > li {
    list-style-position: inside;
    margin-left: 70px;
    text-indent: -50px; /* Outdent bullets/numbers from text */
}

/* Display inline prevents heading/paragraph backgrounds from spanning full width.
   Without this, the cream background would extend edge-to-edge. */
.reveal section.frame_on_bg > :is(h2, p) {
    display: inline;
}

/* Apply semi-transparent cream background to all direct children.
   Creates readable "frame" over busy background images. */
.reveal section.frame_on_bg > * {
    background: var(--frame-bg);
}

/* Global slide background dimming when HTML element has dim_background class.
   !important overrides reveal.js inline styles. */
html.dim_background .slide-background {
    opacity: 0.7 !important;
}

/* === LEFT- AND RIGHT-FLOATED IMAGE LAYOUT SECTIONS === */
/* Shared styles for img_left and img_right sections.
   These sections float images and flow text around them. */

/* z-index: -1 pushes blockquotes behind floated images to prevent overlap issues.
   Negative z-index is safe here because content remains interactive. */
section:is(.img_left, .img_right) blockquote {
    z-index: -1;
}

/* Left-floated images: override to use right border (away from image) */
section.img_left blockquote {
    border-left: none;
    border-right: 4px solid var(--quote-border-color);
    padding-left: 0.6em; /* Reset to base padding */
    padding-right: 1em;
}

/* Right-floated images: keep left border (away from image) */
section.img_right blockquote {
    /* Inherits left border from base blockquote style */
}

section:is(.img_left, .img_right) blockquote p {
    display: inline !important;
}

/* Remove default list markers and position them manually with ::before pseudo-elements.
   Default markers don't participate in box model, so we use precise control 
   over bullet/number placement alongside floated images because */
section:is(.img_left, .img_right) ul,
section:is(.img_left, .img_right) ol {
    display: inline !important;
    list-style-position: inside;
    list-style: none; /* Disable default markers; we create custom ones below */
}

/* Negative text-indent + margin creates hanging indent for list items.
   This keeps markers aligned while allowing text to wrap properly. */
section:is(.img_left, .img_right) ul li,
section:is(.img_left, .img_right) ol li {
    text-indent: calc(var(--indent-spacing) * -1);
    margin-left: var(--list-margin);
}

/* Figures containing both image and caption, constrained to 50% width
   to leave room for surrounding text. */
section:is(.img_left, .img_right) figure {
    width: fit-content;
    max-width: 50%;
}

section:is(.img_left, .img_right) figure img {
    display: block;
    width: 100%;
    height: auto; /* Maintain aspect ratio */
}

/* Caption appears below image, centered, with small top margin */
section:is(.img_left, .img_right) figure figcaption {
    display: block;
    width: 100%;
    clear: both; /* Ensure caption doesn't flow beside image */
    text-align: center;
    margin-top: 0.5em;
}

/* === LEFT-FLOATED IMAGE SECTIONS === */
/* Float images left with right margin to create space for text flow.
   The margin calculation adds a 20px buffer to the standard --img-spacing
   specifically to prevent list counters (like "1.") from crowding the image edge. */
section.img_left :is(img, figure, a:has(img)) {
    float: left;
    margin-right: calc(var(--img-spacing) + 20px);
    position: relative;
    z-index: 1;
}

/* Reset float/margin on nested images to prevent doubling */
section.img_left :is(a, figure) img {
    float: none;
    margin-right: 0;
}

/* Shadow on left side suggests depth and visual weight */
section.img_left img {
    box-shadow: -5px 5px 10px 2px var(--shadow-gray);
}

/* Right-align blockquote text for visual balance with left-floated image */
section.img_left blockquote p {
    text-align: right;
}

/* Custom list markers using CSS counters and ::before pseudo-elements.
   Counter reset initializes counter for this section. */
section.img_left ul,
section.img_left ol {
    counter-reset: imgleft;
}

/* Bullet marker with precise spacing */
section.img_left ul li::before {
    content: "•";
    padding-right: 7px;
    margin-left: -5px; /* Fine-tune alignment */
}

/* Numbered list increments counter and displays number */
section.img_left ol li {
    counter-increment: imgleft;
}

section.img_left ol li::before {
    content: counter(imgleft, decimal) ". ";
    /* Make the marker a rigid box so it doesn't shrink/grow */
    display: inline-block; 
    /* The width must exactly fill the negative indent gap.
       (Indent Spacing 20px - Padding 5px = 15px Width) */
    width: calc(var(--indent-spacing) - 5px);
    /* Right-align pushes the number toward the text and AWAY from the image */
    text-align: right; 
    /* Keeps breathing room between number and text */
    padding-right: 5px; 
    /* Reset manual tweaks so the math works */
    margin-left: 0px; 
}

/* === RIGHT-FLOATED IMAGE SECTIONS === */
/* Float images right with left margin to create space for text flow */
section.img_right :is(img, figure, a:has(img)) {
    float: right;
    margin-left: var(--img-spacing);
    position: relative;
    z-index: 1;
}

/* Reset float/margin on nested images to prevent doubling */
section.img_right :is(a, figure) img {
    float: none;
    margin-left: 0;
}

/* Shadow on right side suggests depth and visual weight */
section.img_right img {
    box-shadow: 5px 5px 10px 2px var(--shadow-gray);
}

/* Custom list markers for right-floated sections.
   Separate counter from img_left to prevent conflicts. */
section.img_right ul,
section.img_right ol {
    counter-reset: imgright;
}

section.img_right ul li::before {
    content: "•";
    padding-right: 10px;
    margin-left: -5px; /* Fine-tune alignment */
}

section.img_right ol li {
    counter-increment: imgright;
}

section.img_right ol li::before {
    content: counter(imgright, decimal) ". ";
    padding-right: 5px;
    margin-left: -11px; /* Fine-tune alignment */
}

/* === FIGURE CAPTIONS === */
.reveal figure {
    margin-bottom: 0.1em;
}

/* Captions are smaller than body text for visual hierarchy */
.reveal figcaption {
    font-size: 75%;
}

/* Pandoc doesn't wrap images in <figure> elements; it uses <a title="caption">.
   Emulate figure/figcaption behavior by displaying the title attribute as caption.
   Uses ::after pseudo-element to display caption without modifying markup. */
a[title]:has(img)::after {
    content: attr(title);
    display: block;
    text-align: center;
    font-size: 75%;
}

/* === TOOLTIP HOVER === */
/* Spans with title attributes are styled as interactive help text.
   Dotted underline indicates hoverability; cursor changes to help icon. */
span[title] {
  border-bottom: 1px dotted #666;
  cursor: help;
  position: relative; /* Positions tooltip pseudo-elements */
  background-color: color-mix(in srgb, yellow 20%, transparent);
  padding: 0.1em 0.2em;
  border-radius: 3px;
}

/* Nested tooltips compound background colors to indicate depth.
   Each level becomes progressively darker to show hierarchy. */
span[title] span[title] {
  background-color: color-mix(in srgb, orange 25%, transparent);
}

span[title] span[title] span[title] {
  background-color: color-mix(in srgb, darkorange 30%, transparent);
}

/* Custom tooltip appears above element on hover.
   Uses pseudo-elements to avoid JavaScript and maintain accessibility. */
span[title]:hover::after {
  content: attr(title); /* Display title attribute content */
  position: absolute;
  bottom: 100%; /* Position above element */
  left: 50%;
  transform: translateX(-50%); /* Center horizontally */
  padding: 0.5em 0.75em;
  background: #333;
  color: white;
  font-size: 0.7em;
  white-space: nowrap; /* Prevent line breaks in tooltip */
  border-radius: 4px;
  margin-bottom: 0.5em; /* Space between element and tooltip */
  z-index: 1000; /* Appear above other content */
  box-shadow: 0 2px 8px color-mix(in srgb, black 30%, transparent);
}

/* Downward-pointing triangle arrow connects tooltip to element.
   Creates visual relationship between tooltip and trigger. */
span[title]:hover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #333; /* Only top border visible, forming triangle */
  z-index: 1000;
}

/* === CALLOUT/TOOLTIP BOXES === */
/* Expandable "thinking" callout in top-right corner.
   Collapsed state shows only emoji; expands on hover to reveal full content. */
div.call {
    position: absolute;
    z-index: 2; /* Above most content but below modals */
    top: 50px;
    right: 10px;
    height: 1.5em;
    width: 4em;
    overflow: hidden; /* Clips content in collapsed state */
    transition: transform 1.2s; /* Smooth expansion animation */
}

/* Thinking emoji (🤔) indicates expandable content.
   Grayscale reduces visual prominence until hover. */
div.call::before {
    content: "🤔";
    opacity: 1.0;
    filter: grayscale(80%);
}

/* Compact text formatting for callout content */
div.call p,
div.call ul {
    list-style: inside;
    font-size: 90%;
}

/* Expanded state on hover: reveals full content with scroll if needed.
   Transform scale creates subtle zoom effect for attention. */
div.call:hover {
    overflow: auto; /* Enable scrolling for long content */
    transform: scale(1.1);
    width: auto;
    height: auto;
    max-width: 600px;
    max-height: 300px;
    background-color: var(--callout-bg);
    padding: 10px;
    padding-right: 25px; /* Extra padding for scrollbar */
    border: solid 1px #555;
    box-shadow: 10px 10px 5px var(--shadow-dark);
    border-radius: 25px;
}

/* === Photo Album === */

/* 1. The Container */
.photo-album {
  display: grid;
  /* Auto-fill tiles: roughly 150px wide, fitting as many as possible */
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  align-items: end; /* Aligns images to the bottom if aspect ratios differ */
}

/* Handle if Markdown parser wraps the HTML in a <p> tag inside the div */
.photo-album p {
  display: contents; /* Removes the <p> from the layout calculation */
}

/* 2. The Items (The Links) */
.photo-album a {
  display: flex;
  flex-direction: column; /* Stack image on top, text on bottom */
  align-items: center;
  text-decoration: none;
  border: none !important; /* Remove reveal.js link borders */
}

.photo-album img {
  margin: 0 !important;
  max-width: 100%;
  max-height: 120px; /* Keep images from getting too tall */
  object-fit: contain;
}

/* 3. The Caption Extraction */
.photo-album a::after {
  content: attr(title); /* <--- The magic part */
  display: block;
  font-size: 0.4em;
  line-height: 1.2;
  margin-top: 5px;
  text-align: center;
  color: #666; /* Muted color for credits */
  
  /* Truncate long credits (like the CC BY-SA one) */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* === ACCESSIBILITY === */
/* Respect user preference for reduced motion.
   Disables animations for users with vestibular disorders or motion sensitivity. */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important; /* Near-instant */
        animation-iteration-count: 1 !important; /* Single iteration only */
        transition-duration: 0.01ms !important; /* Near-instant */
    }
}