/* Figures (\includegraphics wrapped in \begin{figure}/\caption{}) --
   centered image with a caption underneath, matching the book's own
   \begin{center} convention around figures. */
.content figure {
    margin: 1.5em auto;
    text-align: center;
}

.content figure .checkbox-label {
    display: inline-block;
}

.content figcaption {
    margin-top: 0.5em;
    font-size: 0.9em;
    font-style: italic;
    opacity: 0.75;
}

/* \begin{wrapfigure} images (see tex2md.py's WRAPFIGURE_IMAGES) float
   beside body text -- without this, a heading landing while the float
   is still active would get squeezed down next to the image instead of
   spanning the full text width. */
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 {
    clear: both;
}

.content .wrapfigure-left {
    float: left;
    margin: 0 1em 0.5em 0;
}

.content .wrapfigure-right {
    float: right;
    margin: 0 0 0.5em 1em;
}

/* A fixed LaTeX width (e.g. Chapter 6's 5cm Cards.png) leaves too
   little room for the wrapped text beside it once the viewport itself
   is only a little wider than that -- drop the float below a phone-ish
   width and let the image sit full-width above its text like every
   other uncaptioned image instead. */
@media (max-width: 500px) {
    .content .wrapfigure-left,
    .content .wrapfigure-right {
        float: none;
        display: block;
        margin: 1em auto;
    }
}

/* \begin{webvideos}\webvideo{id}{title}...\end{webvideos} (see
   tex2md.py) -- a chapter's related videos from the YouTube lecture
   course, embedded as a responsive grid of players. The iframe has no
   width/height attributes (tex2md.py emits none), so its box comes
   entirely from this aspect-ratio rule -- that's what keeps each
   player a correct 16:9 rectangle at any grid width instead of the
   browser's unstyled default of 300x150. */
.content .webvideos {
    margin: 1.5em 0;
    padding: 1em;
    border-radius: 6px;
    background: var(--quote-bg);
}

.content .webvideo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25em;
}

.content .webvideo iframe {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: 4px;
}

.content .webvideo-caption {
    margin: 0.5em 0 0;
    font-size: 0.9em;
    text-align: center;
}

/* AI feedback widget on each numbered exercise (see tex2md.py's
   EXERCISEOPEN/EXERCISEMID/EXERCISECLOSE sentinel). The markup inside
   .exercise-feedback is built entirely by exercise-feedback.js; this
   only styles it. */
.content .exercise-feedback {
    margin-top: 0.75em;
}

.content .exercise-feedback-toggle {
    font-size: 0.85em;
    padding: 0.4em 0.9em;
    border: 1px solid var(--quote-border);
    border-radius: 4px;
    background: var(--quote-bg);
    color: var(--fg);
    cursor: pointer;
}

.content .exercise-feedback-toggle:hover {
    background: var(--theme-hover);
}

.content .exercise-feedback-panel {
    margin-top: 0.75em;
    padding: 1em;
    border-radius: 6px;
    background: var(--quote-bg);
}

.content .exercise-feedback-code {
    display: block;
    box-sizing: border-box;
    width: 100%;
    min-height: 8em;
    padding: 0.5em;
    font-family: var(--mono-font);
    font-size: var(--code-font-size);
    border: 1px solid var(--quote-border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--fg);
    resize: vertical;
}

.content .exercise-feedback-submit {
    margin-top: 0.6em;
    padding: 0.4em 1.1em;
    border: 1px solid var(--quote-border);
    border-radius: 4px;
    background: var(--links);
    color: var(--bg);
    cursor: pointer;
}

.content .exercise-feedback-submit:disabled {
    opacity: 0.6;
    cursor: default;
}

.content .exercise-feedback-result {
    margin-top: 0.75em;
    padding: 0.75em;
    border-radius: 4px;
    background: var(--bg);
}

.content .exercise-feedback-result.is-error {
    border: 1px solid var(--warning-border);
}

/* Rendered feedback markup (see exercise-feedback.js's renderFeedback) --
   the result div itself holds no whitespace-driven formatting, since its
   content is now real HTML, not preformatted text. */
.content .exercise-feedback-result > :first-child {
    margin-top: 0;
}

.content .exercise-feedback-result > :last-child {
    margin-bottom: 0;
}

.content .exercise-feedback-result p {
    margin: 0.6em 0;
}

.content .exercise-feedback-result ul {
    margin: 0.6em 0;
    padding-inline-start: 1.4em;
}

.content .exercise-feedback-result code {
    font-family: var(--mono-font);
    font-size: 0.9em;
    background: var(--quote-bg);
    border-radius: 3px;
    padding: 0.1em 0.3em;
}

.content .exercise-feedback-result pre {
    margin: 0.6em 0;
    padding: 0.6em;
    border-radius: 4px;
    background: var(--quote-bg);
    overflow-x: auto;
}

.content .exercise-feedback-result pre code {
    padding: 0;
    background: none;
}

.content .cf-turnstile {
    margin-top: 0.6em;
}
