/*
 * Coding Ireland proprietary interactive activity
 * Copyright (c) 2017-2026 Coding Ireland. All rights reserved.
 * Ref: CI-see-storyteller
 *
 * Budget: the player is exactly the height of its frame and never scrolls the
 * page. A 620px explore frame, a 600px display frame (fixed, see storyteller.js
 * applyConfig), the Activity Bank's whole window, or a 1920 x 1080 board in
 * fullscreen. The stage takes whatever the header, controls and credit leave,
 * and the part's words are sized by storyteller.js to the largest type that
 * fits it: about 22px in a lesson frame, about 34px on a full board.
 * Palette + [hidden] fix: ../shared/css/see-activity.css
 */

.st-activity {
    --st-ui: clamp(15px, 0.55vw + 10px, 21px);    /* buttons, labels, the credit */
    --st-gap: clamp(8px, 0.75vw, 16px);
    --st-radius: 14px;
    --st-paper: #fffdf8;
    --st-ink: #2a1f14;          /* 15:1 on the paper */
    --st-mark: #ffe08a;         /* the sentence being read */
    --st-mark-edge: #e3b341;
    --st-shade: #f3e9dc;
}

html { height: 100%; }

body.st-activity {
    margin: 0;
    min-height: 0;
    overflow: hidden;
}

/* --------------------------------------------------------------- the frame */

body.st-activity .st-container {
    box-sizing: border-box;
    height: 100vh;
    min-height: 520px;
    margin: 0;
    padding: var(--st-gap);
    display: flex;
    flex-direction: column;
    gap: var(--st-gap);
    background: var(--maths-bg);
    border-radius: 12px;
}

/* A display-mode lesson frame is sized from this height, never the other way. */
body.st-activity.st-fixed .st-container { height: 600px; min-height: 0; }

html:fullscreen body.st-activity .st-container {
    height: 100vh;
    min-height: 0;
    border-radius: 0;
}

/* A window shorter than the player can still be scrolled to its foot. */
@media (max-height: 519px) {
    body.st-activity { overflow: auto; }
}

/* -------------------------------------------------------------- the header
 * The shared display-mode rule hides the header, but the teacher needs Start
 * again and Fullscreen at the board, so it stays as a slim row (as map-explorer's
 * does). The story's title sits in it, which also stops display-resize.js adding
 * a second caption with the same words. */
body.st-activity .activity-header {
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    margin: 0;
    padding: .3em .55em .3em .9em;
    gap: .6em;
    font-size: var(--st-ui);
}

body.display-mode.st-activity .activity-header { display: flex; }

body.st-activity .st-heading {
    flex: 1 1 auto;
    min-width: 0;
    align-items: baseline;
    gap: .1em .8em;
}

.st-title {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    font-size: 1.2em;
    font-weight: 800;
    line-height: 1.2;
    color: var(--see-ink);
}

body.st-activity .activity-instructions {
    flex: 1 1 12em;
    min-width: 0;
    font-size: .88em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

body.st-activity .controls-container { flex: 0 0 auto; width: auto; }
body.st-activity .btn-group-activity { flex-wrap: nowrap; width: auto; }

body.st-activity .activity-header .btn-control {
    font-size: .82em;
    min-height: max(40px, 2.3em);
    padding: .25em .85em;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- the stage */

.st-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 44fr) minmax(0, 56fr);
    gap: var(--st-gap);
}

/* Comparing the retelling with the words as written: half and half. */
.st-stage.is-original { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.st-stage.is-single { grid-template-columns: minmax(0, 1fr); }

/* In a frame, nothing shows until the lesson's config (or the sample) arrives. */
body.st-waiting .activity-header,
body.st-waiting .st-stage,
body.st-waiting .st-controls,
body.st-waiting .st-credit { visibility: hidden; }

/* The picture, or the calm placeholder. Never a broken-image icon. */
.st-figure {
    position: relative;
    margin: 0;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border-radius: var(--st-radius);
    background: var(--st-shade);
    border: 1px solid var(--maths-border);
}

.st-picture-wrap { position: absolute; inset: 0; }

.st-picture {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
}

.st-picture img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.st-picture:focus-visible { outline: 4px solid var(--maths-focus-ring); outline-offset: -4px; }

.st-zoom-hint {
    position: absolute;
    right: .55em;
    bottom: .55em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.2em;
    height: 2.2em;
    border-radius: 50%;
    background: rgba(42, 31, 20, .7);
    color: #fff;
    font-size: var(--st-ui);
    pointer-events: none;
}

.st-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 45%, rgba(255, 255, 255, .7), rgba(255, 255, 255, 0) 62%),
        linear-gradient(160deg, #f6eee2, #ecdfcd);
    color: var(--see-bright);
}

.st-placeholder i { font-size: clamp(44px, 7vw, 130px); opacity: .5; }

/* -------------------------------------------------- the words as written */

.st-original {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: .4em;
    padding: .7em .9em .6em;
    background: #fbf6ec;
    font-size: var(--st-ui);
}

.st-original-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .3em .6em;
}

.st-original-label {
    margin: 0;
    font-weight: 800;
    font-size: .9em;
    color: var(--see-accent);
}

.st-mini {
    display: inline-flex;
    align-items: center;
    gap: .4em;
    min-height: 40px;
    padding: .2em .8em;
    border: 2px solid var(--maths-border);
    border-radius: 999px;
    background: #fff;
    color: var(--see-ink);
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: .8em;
    cursor: pointer;
}

.st-mini:hover { background: var(--see-subtle); border-color: var(--see-bright); }
.st-mini:focus-visible { outline: 3px solid var(--maths-focus-ring); outline-offset: 2px; }

.st-original-box {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    padding: 0 4px;          /* room for the lit sentence's edge */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Quotation style: a serif, the marks, a rule down the side. It must look like
 * somebody else's words, not ours. */
.st-original-text {
    margin: auto 0;
    padding: 0 0 0 .8em;
    border-left: 4px solid var(--see-bright);
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    line-height: 1.5;
    color: var(--st-ink);
    quotes: '\201C' '\201D';
}

.st-original-text p { margin: 0 0 .5em; }
.st-original-text p:last-child { margin-bottom: 0; }
.st-original-text p:first-child::before { content: open-quote; }
.st-original-text p:last-child::after { content: close-quote; }

.st-original-by {
    margin: 0;
    font-size: .82em;
    font-weight: 700;
    color: var(--maths-ink-muted);
}

/* ------------------------------------------------------------- the words */

.st-words {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: .65em 1em .6em;
    background: var(--st-paper);
    border: 1px solid var(--maths-border);
    border-radius: var(--st-radius);
    font-size: var(--st-ui);
}

.st-words-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .1em .7em;
    margin-bottom: .35em;
}

.st-count {
    font-weight: 800;
    font-size: .82em;
    letter-spacing: .02em;
    color: var(--see-accent);
}

.st-part-title {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    font-size: 1.15em;
    font-weight: 800;
    line-height: 1.25;
    color: var(--see-ink);
}

/* A short part sits in the middle of the panel with its title just above it; a
 * long one fills it from the top (auto margins collapse when the words overflow,
 * so nothing is ever cut off). */
.st-text-box {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    padding: 0 4px;          /* room for the lit sentence's edge */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.st-text-inner { margin: auto 0; }

.st-text {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    line-height: 1.55;
    color: var(--st-ink);
    overflow-wrap: break-word;
}

.st-text p { margin: 0 0 .55em; }
.st-text p:last-child { margin-bottom: 0; }

/* A sentence: tap to hear it from here; lit while the voice reads it. */
.st-s {
    padding: 0 .1em;
    margin: 0 -.1em;
    border-radius: .22em;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    cursor: pointer;
    transition: background-color .2s ease, box-shadow .2s ease;
}

.st-s:hover { background: rgba(201, 154, 95, .16); }

.st-s.is-reading,
.st-s.is-reading:hover {
    background: var(--st-mark);
    box-shadow: 0 .09em 0 var(--st-mark-edge);
}

body.st-novoice .st-s { cursor: text; }
body.st-novoice .st-s:hover { background: none; }

.st-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .45em;
    padding-top: .5em;
}

.st-chip {
    display: inline-flex;
    align-items: center;
    gap: .45em;
    min-height: max(40px, 2.2em);
    padding: .2em .9em;
    border: 2px solid var(--see-bright);
    border-radius: 999px;
    background: var(--see-subtle);
    color: var(--see-ink);
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: .88em;
    cursor: pointer;
}

.st-chip:hover { background: #f3e4cf; }
.st-chip.is-on { background: var(--see-accent); border-color: var(--see-accent); color: #fff; }
.st-chip:focus-visible { outline: 3px solid var(--maths-focus-ring); outline-offset: 2px; }

/* ---------------------------------------------------------- talk about it */

.st-ask {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--st-gap);
    background: rgba(253, 250, 246, .84);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.st-ask-card {
    box-sizing: border-box;
    width: min(100%, 64em);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: .6em;
    padding: .9em 1.3em 1em;
    background: #fff;
    border: 3px solid var(--see-bright);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(74, 49, 23, .18);
    font-size: var(--st-ui);
}

.st-ask-label {
    margin: 0;
    display: flex;
    align-items: center;
    gap: .45em;
    font-weight: 800;
    font-size: 1.05em;
    color: var(--see-accent);
}

.st-ask-box { flex: 0 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 0 4px; }

.st-ask-q {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    line-height: 1.4;           /* above Nunito's 1.36em glyph box, so it measures true */
    color: var(--st-ink);
}

.st-ask-q p { margin: 0 0 .3em; }
.st-ask-q p:last-child { margin-bottom: 0; }

.st-ask-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .6em;
}

/* -------------------------------------------------------------- the end */

.st-end,
.st-empty {
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .45em;
    padding: 1em;
    text-align: center;
    background: var(--st-paper);
    border: 1px solid var(--maths-border);
    border-radius: var(--st-radius);
    font-size: var(--st-ui);
}

.st-end p { margin: 0; }

.st-end-story { font-weight: 800; font-size: 1.15em; color: var(--see-accent); }

.st-end-title {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(40px, 4.6vw, 96px);
    line-height: 1.1;
    color: var(--see-ink);
}

.st-end-credit { max-width: 44em; font-weight: 700; font-size: 1.05em; color: var(--st-ink); }
.st-end-source { max-width: 52em; font-size: .85em; color: var(--maths-ink-muted); }
.st-end .st-btn { margin-top: .5em; }

.st-empty { color: var(--maths-ink-muted); font-weight: 700; }
.st-empty i { font-size: 2.4em; opacity: .5; }

/* ---------------------------------------------------------- the controls */

.st-controls {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .45em .8em;
    font-size: var(--st-ui);
}

.st-voice, .st-nav, .st-dots {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .4em;
}

/* The numbers stay on one row with their arrows: when the controls do not fit,
 * the whole group moves to a second row rather than breaking apart. */
.st-nav { margin-left: auto; flex-wrap: nowrap; }
.st-dots { gap: .3em; flex-wrap: nowrap; }

.st-dot-gap {
    min-width: 1.1em;
    text-align: center;
    font-weight: 800;
    color: var(--maths-ink-muted);
}

.st-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45em;
    min-height: max(44px, 2.5em);
    padding: .25em .95em;
    border: 2px solid var(--maths-border);
    border-radius: 999px;
    background: #fff;
    color: var(--see-ink);
    font-family: 'Nunito', sans-serif;
    font-size: 1em;
    font-weight: 800;
    line-height: 1.1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}

.st-btn:hover { background: var(--see-subtle); border-color: var(--see-bright); }
.st-btn:active { transform: translateY(1px); }
.st-btn:focus-visible { outline: 3px solid var(--maths-focus-ring); outline-offset: 2px; }

.st-btn:disabled,
.st-btn:disabled:hover {
    opacity: .45;
    cursor: default;
    transform: none;
    background: #fff;
    border-color: var(--maths-border);
}

.st-btn-primary { background: var(--see-accent); border-color: var(--see-accent); color: #fff; }
.st-btn-primary:hover { background: var(--see-ink); border-color: var(--see-ink); color: #fff; }

.st-btn.is-on { background: var(--see-ink); border-color: var(--see-ink); color: #fff; }

.st-dot { min-width: max(44px, 2.5em); padding: .25em .5em; }
.st-dot.is-current { background: var(--see-accent); border-color: var(--see-accent); color: #fff; }

/* A part read with nothing to ask: a nudge on Next, and nothing moves by itself. */
.st-next.is-ready {
    border-color: var(--see-accent);
    box-shadow: 0 0 0 4px rgba(201, 154, 95, .45);
    animation: st-nudge 1.4s ease-in-out 2;
}

@keyframes st-nudge {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(4px); }
}

.st-voice-note {
    margin: 0;
    display: flex;
    align-items: center;
    gap: .5em;
    max-width: 34em;
    padding: .45em .8em;
    border: 1px dashed var(--see-bright);
    border-radius: 10px;
    background: var(--see-subtle);
    color: var(--see-ink);
    font-weight: 700;
    font-size: .9em;
    line-height: 1.3;
}

/* ------------------------------------------------------------- the credit */

.st-credit {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: .7em;
    padding: .35em .8em;
    border: 1px solid var(--see-bright);
    border-radius: 12px;
    background: var(--see-subtle);
    font-size: var(--st-ui);
}

.st-credit-kind {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: .35em;
    padding: .2em .7em;
    border-radius: 999px;
    background: var(--see-accent);
    color: #fff;
    font-weight: 800;
    font-size: .78em;
    white-space: nowrap;
}

.st-credit-words { min-width: 0; }

.st-credit-line {
    margin: 0;
    font-weight: 700;
    font-size: .9em;
    line-height: 1.3;
    color: var(--see-ink);
}

.st-credit-source {
    margin: .1em 0 0;
    font-size: .74em;
    line-height: 1.3;
    color: var(--maths-ink-muted);
}

.st-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ----------------------------------------------------------- the lightbox */

.st-lightbox {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background: rgba(24, 17, 10, .9);
    font-size: var(--st-ui);
}

.st-lightbox-stage { flex: 1 1 auto; min-height: 0; }

.st-lightbox .sv-host { box-sizing: border-box; height: 100%; padding: 0; background: transparent; }
.st-lightbox .sv-viewport { min-height: 0; background: transparent; border: 0; }

.st-lightbox-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
}

.st-lightbox-cap { margin: 0; color: #fff; font-weight: 700; }

/* ------------------------------------------------------- narrow and tall
 * A lesson column on a 1024px screen is about 640px wide, still landscape: keep
 * the picture beside the words (a stacked picture would eat the words' height)
 * and give the words more of the width. Stack only when the frame is narrow or
 * taller than it is wide. */

@media (max-width: 900px) {
    .st-stage { grid-template-columns: minmax(0, 38fr) minmax(0, 62fr); }
}

/* A lesson frame: Back and Next become arrows beside the numbers. */
@media (max-width: 900px) {
    .st-nav .st-btn:not(.st-dot) span { display: none; }
    .st-dot { min-width: 42px; }
}

@media (max-width: 760px) {
    body.st-activity .activity-instructions { display: none; }
    .st-btn { padding: .25em .7em; gap: .35em; }
    .st-controls { gap: .4em; }
    .st-voice, .st-nav { gap: .3em; }
}

@media (max-width: 480px) {
    .st-nav, .st-dots { flex-wrap: wrap; }
}

@media (max-width: 560px), (max-aspect-ratio: 5/6) {
    .st-stage,
    .st-stage.is-original { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 38fr) minmax(0, 62fr); }
    .st-stage.is-single { grid-template-rows: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .st-s, .st-btn { transition: none; }
    .st-next.is-ready { animation: none; }
}
