/* Core Squiffy Runtime Styles. See https://squiffystory.com/styling/ for how to customise these. */

/* Colours. Each has a light and a dark value, and light-dark() picks one from the page's
   color-scheme. This file doesn't set color-scheme itself, so a story embedded in a page stays
   light unless the page opts in to dark mode. The exported story's page (squiffy.page.css) sets
   "color-scheme: light dark", so it follows the reader's system setting. */
:root
{
    --squiffy-text: light-dark(#1f2328, #e4e4e7);
    --squiffy-background: light-dark(#ffffff, #18181b);
    /* Secondary text: the header buttons, and links waiting for valid input */
    --squiffy-muted: light-dark(#6b6f76, #9a9ca3);
    /* The lines between sections */
    --squiffy-border: light-dark(#e2e2e6, #34343a);
    --squiffy-link: light-dark(#1d5fd6, #7aa7ff);
    --squiffy-link-hover: light-dark(#0f3f99, #b0cbff);
    --squiffy-error: light-dark(#c62828, #ff7b72);
    --squiffy-success: light-dark(#2e7d32, #6cc070);
}

/* Link styles */
a.squiffy-link
{
    color: var(--squiffy-link);
    text-decoration: underline;
    text-decoration-color: currentColor;
    text-decoration-thickness: from-font;
    text-underline-offset: 0.15em;
    cursor: pointer;
    transition: color 0.4s ease-in-out, text-decoration-color 0.4s ease-in-out;
}

a.squiffy-link:hover
{
    color: var(--squiffy-link-hover);
}

a.squiffy-link:focus-visible,
button.squiffy-header-button:focus-visible,
.squiffy-continue:focus-visible
{
    outline: 2px solid var(--squiffy-link);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Rotate/sequence links - visually distinct as they update in-place rather than advancing the story */
a.squiffy-link[data-handler="rotate"],
a.squiffy-link[data-handler="sequence"] {
    text-decoration-style: dotted;
}

/* Disabled link states */
a.squiffy-link.disabled,
div.squiffy-output-section:not(:last-child) a.squiffy-link,
div.squiffy-output-section.links-disabled a.squiffy-link
{
    text-decoration: inherit;
    text-decoration-color: transparent;
    color: inherit !important;
    cursor: inherit;
    pointer-events: none;
}

/* Links disabled due to input validation */
a.squiffy-link.validation-disabled
{
    text-decoration: inherit;
    text-decoration-color: transparent;
    color: var(--squiffy-muted) !important;
    cursor: not-allowed;
    pointer-events: none;
}

/* Invalid input field states */
input.squiffy-invalid,
textarea.squiffy-invalid,
select.squiffy-invalid
{
    border-color: var(--squiffy-error) !important;
    box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--squiffy-error) 25%, transparent);
}

/* Valid input field states (optional, provides positive feedback) */
input:not([disabled]):valid,
textarea:not([disabled]):valid,
select:not([disabled]):valid
{
    border-color: var(--squiffy-success);
}

/* Focus state for invalid inputs */
input.squiffy-invalid:focus,
textarea.squiffy-invalid:focus,
select.squiffy-invalid:focus
{
    outline: none;
    border-color: var(--squiffy-error) !important;
    box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--squiffy-error) 50%, transparent);
}

/* Header button styles: the Back, Restart and light/dark buttons, which are icons */
button.squiffy-header-button
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--squiffy-muted);
    cursor: pointer;
    background: none;
    border: none;
    border-radius: 0.375em;
    padding: 0.375em;
    font: inherit;
    vertical-align: middle;
    transition: color 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

button.squiffy-header-button:hover:not(:disabled)
{
    color: var(--squiffy-text);
    background-color: color-mix(in srgb, currentColor 10%, transparent);
}

button.squiffy-header-button svg
{
    width: 1.25em;
    height: 1.25em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* The light/dark button, when the story's CSS fixes the theme */
button.squiffy-header-button[hidden]
{
    display: none;
}

/* The Back button, when there's nothing to go back to */
button.squiffy-header-button:disabled
{
    cursor: default;
    opacity: 0.5;
}

/* Output block spacing */
div.squiffy-output-block:not(:last-child),
div.squiffy-output-passage:not(:last-child),
div.squiffy-output-section:not(:last-child)
{
    margin-bottom: 1em;
    border-bottom: 1px solid var(--squiffy-border);
}

/* ...but a block, passage or section that output no text (such as a passage that only does
   {{replace}}) gets no line, and nor does one followed only by those, so they don't add extra lines */
div.squiffy-output-block:not(:has(> div:not(:empty))),
div.squiffy-output-block:not(:has(~ div.squiffy-output-block > div:not(:empty), ~ div.squiffy-output-passage > div.squiffy-output-block > div:not(:empty))),
div.squiffy-output-passage:not(:has(> div.squiffy-output-block > div:not(:empty))),
div.squiffy-output-passage:not(:has(~ div.squiffy-output-block > div:not(:empty), ~ div.squiffy-output-passage > div.squiffy-output-block > div:not(:empty))),
div.squiffy-output-section:not(:has(div.squiffy-output-block > div:not(:empty))),
div.squiffy-output-section:not(:has(~ div.squiffy-output-section div.squiffy-output-block > div:not(:empty)))
{
    margin-bottom: 0;
    border-bottom: none;
}

/* Fade animations */
.fade-out {
    opacity: 0;
    transition: opacity 200ms;
}

.fade-in {
    opacity: 1;
    transition: opacity 200ms;
}

/* Continue animation - click to proceed */
.squiffy-continue {
    color: var(--squiffy-link);
    text-decoration: underline;
    text-decoration-color: currentColor;
    text-decoration-thickness: from-font;
    text-underline-offset: 0.15em;
    cursor: pointer;
}

/* Style: pulse - fades in and out */
.squiffy-continue-pulse {
    animation: squiffy-pulse 1.5s ease-in-out infinite;
}

@keyframes squiffy-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Style: glow - pulsing glow effect */
.squiffy-continue-glow {
    animation: squiffy-glow 1.5s ease-in-out infinite;
}

@keyframes squiffy-glow {
    0%, 100% { text-shadow: 0 0 4px color-mix(in srgb, currentColor 50%, transparent); }
    50% { text-shadow: 0 0 12px color-mix(in srgb, currentColor 80%, transparent), 0 0 20px color-mix(in srgb, currentColor 40%, transparent); }
}

/* Style: bounce - subtle vertical bounce */
.squiffy-continue-bounce {
    display: inline-block;
    animation: squiffy-bounce 0.6s ease-in-out infinite;
}

@keyframes squiffy-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Style: wave - character spans need special handling for underline */
.squiffy-continue-wave {
    text-decoration: none;
    border-bottom: 1px solid currentColor;
}

/* Text effects for {{#style}} (#453), e.g. {{#style "shudder"}}...{{/style}} */
span.squiffy-style:is(.shake, .shudder, .rumble, .sway, .buoy, .mirror, .upside-down, .tall, .flat) {
    /* Transforms don't apply to inline elements */
    display: inline-block;
}

.squiffy-style.shake {
    animation: squiffy-shake 0.4s ease-in-out infinite;
}

@keyframes squiffy-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.squiffy-style.shudder {
    animation: squiffy-shudder 0.1s linear infinite alternate;
}

@keyframes squiffy-shudder {
    from { transform: translateX(-1px); }
    to { transform: translateX(1px); }
}

.squiffy-style.rumble {
    animation: squiffy-rumble 0.1s linear infinite alternate;
}

@keyframes squiffy-rumble {
    from { transform: translateY(-1px); }
    to { transform: translateY(1px); }
}

.squiffy-style.sway {
    animation: squiffy-sway 2.5s ease-in-out infinite;
}

@keyframes squiffy-sway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

.squiffy-style.buoy {
    animation: squiffy-buoy 2.5s ease-in-out infinite;
}

@keyframes squiffy-buoy {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-0.25em); }
}

.squiffy-style.pulse {
    animation: squiffy-pulse 1.5s ease-in-out infinite;
}

.squiffy-style.fade-in-out {
    animation: squiffy-fade-in-out 3s ease-in-out infinite;
}

@keyframes squiffy-fade-in-out {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.squiffy-style.blink {
    animation: squiffy-blink 1s step-end infinite;
}

@keyframes squiffy-blink {
    50% { opacity: 0; }
}

.squiffy-style.flicker {
    animation: squiffy-flicker 3s linear infinite;
}

@keyframes squiffy-flicker {
    0%, 19%, 21%, 23%, 54%, 56%, 100% { opacity: 1; }
    20%, 22%, 55% { opacity: 0.2; }
}

.squiffy-style.blur {
    filter: blur(1px);
}

.squiffy-style.blurrier {
    filter: blur(3px);
}

.squiffy-style.smear {
    text-shadow: 0.15em 0 0.1em color-mix(in srgb, currentColor 50%, transparent), 0.3em 0 0.15em color-mix(in srgb, currentColor 25%, transparent);
}

.squiffy-style.mirror {
    transform: scaleX(-1);
}

.squiffy-style.upside-down {
    transform: scaleY(-1);
}

/* The typographic effects, which don't move (#541) */
.squiffy-style.shadow {
    text-shadow: 0.08em 0.08em 0.08em color-mix(in srgb, currentColor 50%, transparent);
}

/* A dimmed face, lit from the top left and shadowed at the bottom right */
.squiffy-style.emboss {
    color: color-mix(in srgb, currentColor 35%, var(--squiffy-background));
    text-shadow: -1px -1px 0 color-mix(in srgb, var(--squiffy-text) 80%, white),
        1px 1px 0 color-mix(in srgb, var(--squiffy-background) 40%, black);
}

.squiffy-style.outline {
    color: var(--squiffy-background);
    text-shadow: -1px -1px 0 var(--squiffy-text), 1px -1px 0 var(--squiffy-text),
        -1px 1px 0 var(--squiffy-text), 1px 1px 0 var(--squiffy-text);
}

.squiffy-style.condense {
    letter-spacing: -0.08em;
}

.squiffy-style.expand {
    letter-spacing: 0.1em;
}

.squiffy-style.tall {
    transform: scaleY(1.5);
}

.squiffy-style.flat {
    transform: scaleY(0.5);
}

.squiffy-style.double-underline {
    text-decoration: underline double;
}

.squiffy-style.wavy-underline {
    text-decoration: underline wavy;
}

.squiffy-style.double-strike {
    text-decoration: line-through double;
}

.squiffy-style.wavy-strike {
    text-decoration: line-through wavy;
}

/* Transitions for how a section or passage appears (#489), from @transition. The element has
   squiffy-transition and the transition's name as classes while it plays, and @transition's
   time in --squiffy-transition-time. @leave plays them backwards, with squiffy-leave too, except
   the slides, which leave the way they're named. A story's stylesheet can add its own, e.g.
   .squiffy-transition.swirl { animation-name: swirl; } */
.squiffy-transition {
    animation-duration: var(--squiffy-transition-time, 0.5s);
    animation-timing-function: ease-out;
    animation-fill-mode: both;
}

.squiffy-transition:is(.fade, .dissolve) {
    animation-name: squiffy-transition-fade;
}

@keyframes squiffy-transition-fade {
    from { opacity: 0; }
}

/* The slides move by --squiffy-slide-distance, e.g. 100% to slide all the way off and on */
@keyframes squiffy-transition-from-below {
    from { opacity: 0; transform: translateY(var(--squiffy-slide-distance, 2em)); }
}

@keyframes squiffy-transition-from-above {
    from { opacity: 0; transform: translateY(calc(-1 * var(--squiffy-slide-distance, 2em))); }
}

@keyframes squiffy-transition-from-right {
    from { opacity: 0; transform: translateX(var(--squiffy-slide-distance, 3em)); }
}

@keyframes squiffy-transition-from-left {
    from { opacity: 0; transform: translateX(calc(-1 * var(--squiffy-slide-distance, 3em))); }
}

/* A slide moves the way it's named: slide-left comes in from the right, and leaves to the left */
.squiffy-transition.slide-up {
    animation-name: squiffy-transition-from-below;
}

.squiffy-transition.slide-down {
    animation-name: squiffy-transition-from-above;
}

.squiffy-transition.slide-left {
    animation-name: squiffy-transition-from-right;
}

.squiffy-transition.slide-right {
    animation-name: squiffy-transition-from-left;
}

/* @leave plays the animations backwards, as the old text goes before the screen is cleared. So
   that a slide leaves the way it's named, it plays the opposite slide backwards. */
.squiffy-transition.squiffy-leave {
    animation-direction: reverse;
}

.squiffy-transition.squiffy-leave.slide-up {
    animation-name: squiffy-transition-from-above;
}

.squiffy-transition.squiffy-leave.slide-down {
    animation-name: squiffy-transition-from-below;
}

.squiffy-transition.squiffy-leave.slide-left {
    animation-name: squiffy-transition-from-left;
}

.squiffy-transition.squiffy-leave.slide-right {
    animation-name: squiffy-transition-from-right;
}

/* So a transition, a story's own too, doesn't make the page scroll sideways, or a slide make it
   longer */
:has(> .squiffy-transition) {
    overflow-x: clip;
}

:has(> .squiffy-transition:is(.slide-up, .slide-down)) {
    overflow-y: clip;
}

.squiffy-transition.zoom {
    animation-name: squiffy-transition-zoom;
}

@keyframes squiffy-transition-zoom {
    from { opacity: 0; transform: scale(0.9); }
}

.squiffy-transition.blur {
    animation-name: squiffy-transition-blur;
}

@keyframes squiffy-transition-blur {
    from { opacity: 0; filter: blur(8px); }
}

.squiffy-transition.pulse {
    animation-name: squiffy-transition-pulse;
}

@keyframes squiffy-transition-pulse {
    from { opacity: 0; transform: scale(0.95); }
    60% { opacity: 1; transform: scale(1.02); }
}

.squiffy-transition.rumble {
    animation-name: squiffy-transition-rumble;
}

@keyframes squiffy-transition-rumble {
    from { opacity: 0; }
    10%, 30%, 50%, 70% { transform: translateY(-2px); }
    20%, 40%, 60%, 80% { transform: translateY(2px); }
    50% { opacity: 1; }
}

.squiffy-transition.shudder {
    animation-name: squiffy-transition-shudder;
}

@keyframes squiffy-transition-shudder {
    from { opacity: 0; }
    10%, 30%, 50%, 70% { transform: translateX(-2px); }
    20%, 40%, 60%, 80% { transform: translateX(2px); }
    50% { opacity: 1; }
}

.squiffy-transition.flicker {
    animation-name: squiffy-transition-flicker;
}

@keyframes squiffy-transition-flicker {
    from, 15%, 35%, 55% { opacity: 0; }
    10%, 25%, 45% { opacity: 0.6; }
}

/* Respect the reader's reduced-motion setting */
@media (prefers-reduced-motion: reduce)
{
    /* Every transition, a story's own too, is a plain fade */
    .squiffy-transition {
        animation-name: squiffy-transition-fade !important;
    }

    .squiffy-continue-pulse,
    .squiffy-continue-glow,
    .squiffy-continue-bounce,
    .squiffy-style:is(.shake, .shudder, .rumble, .sway, .buoy, .pulse, .fade-in-out, .blink, .flicker)
    {
        animation: none;
    }
}

/* The Saved games dialog, opened by the page's Save button */
dialog.squiffy-saves
{
    width: min(28rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    box-sizing: border-box;
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.75rem;
    background-color: var(--squiffy-background);
    color: var(--squiffy-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.4;
    box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
}

dialog.squiffy-saves::backdrop
{
    background-color: rgb(0 0 0 / 0.4);
}

dialog.squiffy-saves svg
{
    width: 1.25em;
    height: 1.25em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.squiffy-saves-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.squiffy-saves-header h2
{
    margin: 0;
    font-size: 1.125rem;
}

.squiffy-saves button
{
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.squiffy-saves button:focus-visible,
.squiffy-saves input:focus-visible
{
    outline: 2px solid var(--squiffy-link);
    outline-offset: 2px;
}

.squiffy-saves-button
{
    flex: none;
    padding: 0.3em 0.8em;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.375em;
    background: none;
}

.squiffy-saves-button:hover
{
    background-color: color-mix(in srgb, currentColor 8%, transparent);
}

.squiffy-saves .squiffy-saves-primary
{
    border-color: var(--squiffy-link);
    background-color: var(--squiffy-link);
    color: var(--squiffy-background);
}

.squiffy-saves .squiffy-saves-danger-button
{
    border-color: var(--squiffy-error);
    background-color: var(--squiffy-error);
    color: var(--squiffy-background);
}

.squiffy-saves-icon-button
{
    display: inline-flex;
    padding: 0.3em;
    border: none;
    border-radius: 0.375em;
    background: none;
    color: var(--squiffy-muted) !important;
}

.squiffy-saves-icon-button:hover,
.squiffy-saves-icon-button[aria-expanded="true"]
{
    color: var(--squiffy-text) !important;
    background-color: color-mix(in srgb, currentColor 10%, transparent);
}

.squiffy-saves-error
{
    margin: 0 0 0.75rem;
    color: var(--squiffy-error);
}

.squiffy-saves-new
{
    display: flex;
    gap: 0.5rem;
}

.squiffy-saves input[type="text"]
{
    flex: 1;
    min-width: 0;
    padding: 0.3em 0.6em;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.375em;
    background-color: var(--squiffy-background);
    color: inherit;
    font: inherit;
}

.squiffy-saves-list
{
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
    max-height: 50vh;
    overflow-y: auto;
}

.squiffy-saves-empty
{
    padding: 0.75rem 0;
    color: var(--squiffy-muted);
}

.squiffy-saves-row
{
    padding: 0.5rem 0;
    border-top: 1px solid var(--squiffy-border);
}

.squiffy-saves-line
{
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.squiffy-saves-info
{
    flex: 1;
    min-width: 0;
}

.squiffy-saves-title
{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.squiffy-saves-meta
{
    color: var(--squiffy-muted);
    font-size: 0.8125rem;
}

.squiffy-saves-options
{
    position: relative;
}

.squiffy-saves-menu
{
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-width: 10rem;
    margin-top: 0.25rem;
    padding: 0.25rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.5rem;
    background-color: var(--squiffy-background);
    box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);
}

.squiffy-saves-menu[hidden]
{
    display: none;
}

/* In the top layer, placed by the script */
.squiffy-saves-menu:popover-open
{
    position: fixed;
    right: auto;
    bottom: auto;
    margin: 0;
    color: inherit;
}

.squiffy-saves-menu button
{
    padding: 0.4em 0.75em;
    border: none;
    border-radius: 0.25em;
    background: none;
    text-align: left;
}

.squiffy-saves-menu button:hover,
.squiffy-saves-menu button:focus-visible
{
    background-color: color-mix(in srgb, currentColor 10%, transparent);
}

.squiffy-saves .squiffy-saves-danger
{
    color: var(--squiffy-error);
}

.squiffy-saves-confirm
{
    margin-top: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.5rem;
    background-color: color-mix(in srgb, var(--squiffy-text) 5%, transparent);
}

.squiffy-saves-confirm p
{
    margin: 0 0 0.5rem;
}

.squiffy-saves-confirm-buttons
{
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.squiffy-saves-footer
{
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--squiffy-border);
}

.squiffy-saves-link
{
    display: inline-flex;
    align-items: center;
    gap: 0.375em;
    padding: 0;
    border: none;
    background: none;
    color: var(--squiffy-link) !important;
}

.squiffy-saves-link:hover
{
    text-decoration: underline;
}

/* A question for the player, such as whether to restart, in place of the browser's confirm() */
dialog.squiffy-confirm
{
    width: min(24rem, calc(100vw - 2rem));
    box-sizing: border-box;
    padding: 1.25rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.75rem;
    background-color: var(--squiffy-background);
    color: var(--squiffy-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.4;
    box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
}

dialog.squiffy-confirm::backdrop
{
    background-color: rgb(0 0 0 / 0.4);
}

.squiffy-confirm p
{
    margin: 0 0 1rem;
}

.squiffy-confirm-buttons
{
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.squiffy-confirm-button
{
    padding: 0.3em 0.8em;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.375em;
    background: none;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.squiffy-confirm-button:hover
{
    background-color: color-mix(in srgb, currentColor 8%, transparent);
}

.squiffy-confirm-button:focus-visible
{
    outline: 2px solid var(--squiffy-link);
    outline-offset: 2px;
}

.squiffy-confirm .squiffy-confirm-primary
{
    border-color: var(--squiffy-link);
    background-color: var(--squiffy-link);
    color: var(--squiffy-background);
}

.squiffy-confirm .squiffy-confirm-danger
{
    border-color: var(--squiffy-error);
    background-color: var(--squiffy-error);
    color: var(--squiffy-background);
}

.squiffy-confirm .squiffy-confirm-primary:hover,
.squiffy-confirm .squiffy-confirm-danger:hover
{
    filter: brightness(1.1);
}

/* The Settings dialog (#452), for a story with "settings" in its squiffy.json */
dialog.squiffy-settings
{
    width: min(28rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    box-sizing: border-box;
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.75rem;
    background-color: var(--squiffy-background);
    color: var(--squiffy-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.4;
    box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
}

dialog.squiffy-settings::backdrop
{
    background-color: rgb(0 0 0 / 0.4);
}

.squiffy-settings-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.squiffy-settings-header h2
{
    margin: 0;
    font-size: 1.125rem;
}

.squiffy-settings button,
.squiffy-settings select
{
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.squiffy-settings button:focus-visible,
.squiffy-settings input:focus-visible,
.squiffy-settings select:focus-visible
{
    outline: 2px solid var(--squiffy-link);
    outline-offset: 2px;
}

button.squiffy-settings-close
{
    display: inline-flex;
    padding: 0.25em;
    border: none;
    border-radius: 0.375em;
    background: none;
    color: var(--squiffy-muted);
}

button.squiffy-settings-close:hover
{
    color: var(--squiffy-text);
    background-color: color-mix(in srgb, currentColor 10%, transparent);
}

button.squiffy-settings-close svg
{
    width: 1.25em;
    height: 1.25em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.squiffy-setting
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--squiffy-border);
}

.squiffy-setting-text
{
    min-width: 0;
}

.squiffy-setting-text label
{
    display: block;
}

.squiffy-setting-text p
{
    margin: 0.125rem 0 0;
    color: var(--squiffy-muted);
    font-size: 0.875em;
}

.squiffy-setting select
{
    flex: none;
    max-width: 50%;
    padding: 0.25em 0.5em;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.375em;
    background-color: var(--squiffy-background);
}

/* A toggle is a switch */
.squiffy-setting input[type=checkbox]
{
    appearance: none;
    flex: none;
    position: relative;
    width: 2.5em;
    height: 1.5em;
    margin: 0;
    border-radius: 0.75em;
    background-color: color-mix(in srgb, var(--squiffy-text) 25%, transparent);
    cursor: pointer;
    transition: background-color 0.15s;
}

.squiffy-setting input[type=checkbox]::before
{
    content: "";
    position: absolute;
    top: 0.1875em;
    left: 0.1875em;
    width: 1.125em;
    height: 1.125em;
    border-radius: 50%;
    background-color: var(--squiffy-background);
    transition: transform 0.15s;
}

.squiffy-setting input[type=checkbox]:checked
{
    background-color: var(--squiffy-link);
}

.squiffy-setting input[type=checkbox]:checked::before
{
    transform: translateX(1em);
}

.squiffy-setting-slider
{
    display: flex;
    flex: none;
    align-items: center;
    gap: 0.5rem;
    width: 45%;
}

.squiffy-setting-slider input
{
    flex: 1;
    min-width: 0;
    accent-color: var(--squiffy-link);
}

.squiffy-setting-slider output
{
    min-width: 2ch;
    text-align: end;
    font-variant-numeric: tabular-nums;
}

.squiffy-settings-footer
{
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

button.squiffy-settings-reset
{
    padding: 0.3em 0.8em;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.375em;
    background: none;
}

button.squiffy-settings-reset:hover
{
    background-color: color-mix(in srgb, currentColor 8%, transparent);
}

@media (prefers-reduced-motion: reduce)
{
    .squiffy-setting input[type=checkbox],
    .squiffy-setting input[type=checkbox]::before
    {
        transition: none;
    }
}

/* Panels (squiffy.json's "panels"): passages always to hand, beside the story or in a dialog */
:root
{
    /* The width of a side panel */
    --squiffy-side-width: 16rem;
}

/* A panel's button in the header, when it has a label rather than an icon */
button.squiffy-panel-text-button
{
    padding: 0.375em 0.625em;
    line-height: 1.25;
}

/* Space between the panels' buttons and the page's own */
button.squiffy-panel-button:not(:has(+ button.squiffy-panel-button))
{
    margin-right: 0.5em;
}

/* The side panels. Like the header, they're smaller than the story text. */
aside.squiffy-panels-side
{
    font-size: 0.9375rem;
    line-height: 1.5;
}

aside.squiffy-panels-side[hidden],
aside.squiffy-panels-side > section.squiffy-panel[hidden]
{
    display: none;
}

aside.squiffy-panels-side > section.squiffy-panel + section.squiffy-panel
{
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--squiffy-border);
}

.squiffy-panel > :first-child
{
    margin-top: 0;
}

.squiffy-panel > :last-child
{
    margin-bottom: 0;
}

.squiffy-panel img
{
    max-width: 100%;
    height: auto;
}

/* On a screen too narrow for the story and a side panel, the panel is a button in the header,
   which shows it in a dialog */
@media (min-width: 64rem)
{
    button.squiffy-panel-side-button
    {
        display: none;
    }
}

@media (max-width: 63.99rem)
{
    aside.squiffy-panels-side
    {
        display: none;
    }
}

/* The dialog a panel's button opens */
dialog.squiffy-panel-dialog
{
    width: min(28rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    box-sizing: border-box;
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--squiffy-border);
    border-radius: 0.75rem;
    background-color: var(--squiffy-background);
    color: var(--squiffy-text);
    font-family: var(--squiffy-font-family, inherit);
    font-size: var(--squiffy-font-size, 1rem);
    line-height: var(--squiffy-line-height, 1.5);
    box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
}

dialog.squiffy-panel-dialog::backdrop
{
    background-color: rgb(0 0 0 / 0.4);
}

.squiffy-panel-dialog-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.squiffy-panel-dialog-header h2
{
    margin: 0;
    font-size: 1.125rem;
}

button.squiffy-panel-dialog-close
{
    display: inline-flex;
    padding: 0.25em;
    border: none;
    border-radius: 0.375em;
    background: none;
    color: var(--squiffy-muted);
    cursor: pointer;
}

button.squiffy-panel-dialog-close:hover
{
    color: var(--squiffy-text);
    background-color: color-mix(in srgb, currentColor 10%, transparent);
}

button.squiffy-panel-dialog-close:focus-visible
{
    outline: 2px solid var(--squiffy-link);
    outline-offset: 2px;
}

button.squiffy-panel-dialog-close svg
{
    width: 1.25em;
    height: 1.25em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}


/* Page layout styles for an exported story. See https://squiffystory.com/styling/ for how to customise these. */

:root
{
    /* The width of the story text */
    --squiffy-max-width: 42rem;
    /* The story's font. Charter, or Georgia if the reader doesn't have it */
    --squiffy-font-family: Charter, "Bitstream Charter", Georgia, serif;
    /* The size of the story text. The header's buttons are smaller, and don't change with it */
    --squiffy-font-size: 1.125rem;
    /* The space between lines of text */
    --squiffy-line-height: 1.6;
}

/* Follow the reader's light or dark system setting, or what they chose with the theme button.
   To keep a story light (or dark) whatever the setting, set ":root { color-scheme: light; }"
   (or dark). These rules use :where() so that a :root rule like that overrides them, and the
   theme button is hidden. */
:where(:root)
{
    color-scheme: light dark;
}

:where(:root[data-squiffy-theme="light"])
{
    color-scheme: light;
}

:where(:root[data-squiffy-theme="dark"])
{
    color-scheme: dark;
}

body
{
    margin: 0;
    background-color: var(--squiffy-background);
    color: var(--squiffy-text);
}

/* Wraps the header and the story: sets the page width and font */
div#squiffy-container
{
    max-width: var(--squiffy-max-width);
    margin-left: auto;
    margin-right: auto;
    padding: 0 1.25rem 3rem;
    font-family: var(--squiffy-font-family);
    line-height: var(--squiffy-line-height);
}

/* The bar above the story containing the Back, Restart and light/dark buttons. It stays at the
   top of the window as the story scrolls under it. */
div#squiffy-header
{
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0.5rem 0;
    background-color: var(--squiffy-background);
    font-size: 0.875rem;
    text-align: right;
    white-space: nowrap;
}

/* A short fade under the header, so the story scrolls under it rather than being cut off */
div#squiffy-header::after
{
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 0.75rem;
    background: linear-gradient(var(--squiffy-background), transparent);
    pointer-events: none;
}

/* Space between the Back, Restart and light/dark buttons */
button.squiffy-header-button + button.squiffy-header-button
{
    margin-left: 0.25em;
}

/* The button that switches between light and dark mode. It shows a moon in light mode and a sun
   in dark mode. */
button#squiffy-theme:not([data-next="light"]) .squiffy-icon-light,
button#squiffy-theme[data-next="light"] .squiffy-icon-dark
{
    display: none;
}

/* The mute button (#444), for a story with music or sounds. It shows a speaker, crossed out
   when the story is muted. */
button#squiffy-mute.squiffy-muted .squiffy-icon-sound,
button#squiffy-mute:not(.squiffy-muted) .squiffy-icon-muted
{
    display: none;
}

/* With a side panel (squiffy.json's "panels"), the page is wider, with the panel to the right of
   the story. It stays in view as the story scrolls, under the header. On a narrower screen, it's a
   button in the header instead. */
@media (min-width: 64rem)
{
    div#squiffy-container.squiffy-has-side
    {
        display: grid;
        grid-template-columns: minmax(0, 1fr) var(--squiffy-side-width);
        column-gap: 2.5rem;
        align-items: start;
        max-width: calc(var(--squiffy-max-width) + var(--squiffy-side-width) + 2.5rem);
    }

    div#squiffy-container.squiffy-has-side > div#squiffy-header
    {
        grid-column: 1 / -1;
    }

    /* :where() takes the container's id out of the selector's specificity, so a story's own
       aside.squiffy-panels-side { ... } rule, which comes after this, changes the border and the
       padding too */
    :where(div#squiffy-container.squiffy-has-side) > aside.squiffy-panels-side
    {
        position: sticky;
        top: 3.5rem;
        padding-left: 1.25rem;
        border-left: 1px solid var(--squiffy-border);
        max-height: calc(100vh - 4.5rem);
        overflow-y: auto;
    }
}

/* The story text */
div#squiffy
{
    font-size: var(--squiffy-font-size);
}

div#squiffy :is(h1, h2, h3, h4, h5, h6)
{
    line-height: 1.25;
}

div#squiffy p
{
    text-wrap: pretty;
}

/* Stop images overflowing the page */
div#squiffy img
{
    max-width: 100%;
    height: auto;
}
