:root {
    --book-text: #3b3a4a;
    --activity-surface: #fffdf8;
    --activity-green: #2d7256;
}

[hidden] { display: none !important; }
.book-reader :is(a, button, summary, label) { touch-action: manipulation; }

.book-reader {
    width: min(46rem, calc(100% - 2rem));
    margin-inline: auto;
    padding-block: 1.15rem 2.5rem;
}

.book-toolbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: .75rem 1rem;
    margin-block-end: .9rem;
}

.book-toolbar h1 {
    margin: 0;
    font: 400 clamp(1.55rem, 4.6vw, 2.3rem)/1.18 Georgia, serif;
}

.reader-control {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 2.75rem;
    padding: .35rem .75rem;
    border: 1px solid var(--rule);
    border-radius: .5rem;
    background: var(--activity-surface);
    color: var(--ink);
    font: 600 .875rem/1.3 "Segoe UI", sans-serif;
    text-decoration: none;
}

:is(button, summary).reader-control { cursor: pointer; }
.reader-control:is(a[href], button, summary):hover { background: #f1eadc; }
.reader-control[aria-disabled="true"] { color: #706b63; background: #eee9e0; }
.reader-contents summary { gap: .65rem; list-style: none; }
.reader-contents summary::-webkit-details-marker { display: none; }
.reader-contents summary::after {
    width: .38rem;
    height: .38rem;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    content: "";
    transform: translateY(-.12rem) rotate(45deg);
}

.reader-contents ol {
    position: absolute;
    z-index: 3;
    inset-block-start: 100%;
    inset-inline-end: 0;
    width: min(21rem, 100%);
    max-height: min(34rem, 64vh);
    overflow: auto;
    overscroll-behavior: contain;
    margin: .4rem 0 0;
    padding: .5rem .7rem .5rem 2.4rem;
    border: 1px solid var(--rule);
    border-radius: .6rem;
    background: var(--activity-surface);
    box-shadow: 0 .5rem 1.5rem #3a2a1c20;
}

.reader-contents li a {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding: .3rem .45rem;
    border-radius: .35rem;
    text-underline-offset: .2em;
}

.reader-contents a:is(:hover, [aria-current]) { background: #e9eff6; }

.reader-pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .4rem;
    margin-block-start: .9rem;
    font-size: .875rem;
    font-variant-numeric: tabular-nums;
}

.reader-pagination [data-previous] { justify-self: start; }
.reader-pagination [data-next] { justify-self: end; }

.reader-page {
    --page-inset: clamp(1rem, 4.5vw, 2.5rem);
    position: relative;
    min-width: 0;
    border: 1px solid var(--rule);
    border-radius: .6rem;
    background: var(--paper);
    color: var(--book-text);
    box-shadow: 0 4px 16px #5339180c;
    font: 650 clamp(1.075rem, 2.3vw, 1.25rem)/1.48 Nunito, "Segoe UI", sans-serif;
}

.reader-page:not([hidden]) + .reader-page:not([hidden]) { margin-block-start: .9rem; }
.reader-page:focus { outline: none; }
.reader-page img { display: block; max-width: 100%; }
.reader-page:not(.cover) h2 {
    margin: 0;
    color: var(--book-blue);
    font: 600 clamp(1.65rem, 5.1vw, 2.65rem)/1.12 Fredoka, "Segoe UI", sans-serif;
}

.reader-page p { margin-block: .5rem 0; }
.reader-page .pn {
    margin: 0;
    padding: 1.55rem var(--page-inset) 1rem;
    color: var(--muted);
    font: 500 .875rem/1 Fredoka, "Segoe UI", sans-serif;
    text-align: center;
}

.reader-page.cover { background: #fbf3e2; }
.reader-page.cover .cover-art { aspect-ratio: 1; height: auto; }
.reader-page :is(.sub, .s, .foot) { color: var(--muted); }

.reader-page :is(.spot, .txt), .reader-page.tp, .reader-page.back { text-align: center; }
.opening .spot {
    width: min(84%, 36rem);
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: clamp(.7rem, 2vw, 1.25rem);
    margin: var(--page-inset) auto 0;
}

.reader-page .txt { margin: 1.1rem var(--page-inset) 0; }
.reader-page.tp, .reader-page.back { padding: clamp(2rem, 8vw, 5rem) var(--page-inset); }
.tp .s { margin-block: .55rem 1.1rem; }
.tp .with { font: 500 1.15rem/1.3 Fredoka, "Segoe UI", sans-serif; }
.tp .foot { margin-block-start: clamp(1.75rem, 6.5vw, 4rem); font-size: .875rem; }
.facerow {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: .6rem;
    margin-block-start: 1.25rem;
}

.facerow img { width: clamp(2.05rem, 11vw, 4.05rem); aspect-ratio: 1; border-radius: 50%; }
.reader-page.back { background: var(--book-blue); color: white; }
.reader-page.back h2 { color: white; }
.back .ring {
    width: min(11rem, 56%);
    aspect-ratio: 1;
    border: .25rem solid white;
    border-radius: 50%;
    margin: 1.5rem auto 1.1rem;
}

.back .age { font: 500 .85rem/1.4 Fredoka, "Segoe UI", sans-serif; letter-spacing: .05em; }

.artwork {
    position: relative;
    aspect-ratio: 8.5 / 5.25;
    overflow: hidden;
    border-radius: .55rem .55rem 0 0;
}

.artwork .art { width: 100%; height: 100%; object-fit: cover; }
.artwork .wave {
    position: absolute;
    inset: auto 0 -1px;
    width: 100%;
    height: 8.6%;
    pointer-events: none;
}

.artwork .chip {
    position: absolute;
    inset-block-start: 8.6%;
    inset-inline-start: var(--page-inset);
    border-radius: 2rem;
    padding: .35rem .75rem;
    background: var(--badge);
    box-shadow: 0 2px 6px #31241333;
    color: white;
    font: 500 clamp(.875rem, 2.1vw, 1.05rem)/1.15 Fredoka, "Segoe UI", sans-serif;
}

.reader-page .panel { padding: .55rem var(--page-inset) 0; }
.reader-page:not(.cover) .panel h2 { color: var(--accent-ink); }
.reader-page .facts { padding-inline-start: 1.15em; margin: .55rem 0 0; }
.facts li { padding-inline-start: .15em; margin-block: .25em; }
.facts li::marker { color: var(--accent); }

.reader-page:is(.toc, .recap, .quiz, .breathe, .ans, .journal) {
    padding: var(--page-inset) var(--page-inset) 0;
}

.reader-page:is(.toc, .recap, .breathe, .ans, .journal) > :is(h2, .sub),
.qhead { text-align: center; }
.reader-page:not(.cover) .sub { margin-block: .55rem 1rem; }
.toc :is(.intro, .cols, .end) { margin-block: .4rem; }
.toc .end { border-block-start: 2px dotted var(--rule); padding-block-start: .4rem; }
.toc .trow {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-height: 2.75rem;
    padding: .25rem .2rem;
    border-radius: .35rem;
    font: 500 1rem/1.2 Fredoka, "Segoe UI", sans-serif;
    text-decoration: none;
}

.trow:hover { background: #f0e7d6; }
.toc .trow > :is(.ic, img) { width: 1.7rem; height: 1.7rem; flex: none; }
.trow .ic { display: grid; place-items: center; }
.trow img { border-radius: 50%; }
.trow .dots { flex: 1; border-block-end: 2px dotted var(--rule); }
.trow .n, .qnum {
    display: inline-grid;
    min-width: 1.8rem;
    padding: .2rem .4rem;
    place-items: center;
    border-radius: 1rem;
    background: var(--badge, var(--activity-green));
    color: white;
    font: 500 .9rem/1.2 Fredoka, "Segoe UI", sans-serif;
}

.rgrid, .jfaces .row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-items: center;
    gap: .85rem .35rem;
    margin-block: 1rem;
}

.rcell, .jf {
    display: grid;
    justify-items: center;
    gap: .3rem;
    min-width: 0;
    font: 500 clamp(.875rem, 2vw, 1.125rem)/1.2 Fredoka, "Segoe UI", sans-serif;
    text-align: center;
}

.rcell img, .jf img, .match-board img {
    aspect-ratio: 1;
    border-radius: 50%;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--rule);
}

.rcell img { width: clamp(3.1rem, 16vw, 7.5rem); }
.qhead { margin-block-end: 1.05rem; }
.qhead .ul { width: 7.5rem; height: .65rem; display: block; margin: .3rem auto 0; }
.qhead p, .activity-hint, .gj, .activity-footer { font-size: .95rem; color: var(--muted); }
.qstar { position: absolute; width: clamp(.78rem, 2.7vw, 1.4rem); pointer-events: none; }
.qstar:nth-child(1) { inset: .8rem auto auto 1rem; transform: rotate(-12deg); }
.qstar:nth-child(2) { inset: 1.8rem auto auto .55rem; width: .65rem; }
.qstar:nth-child(3) { inset: .8rem 1rem auto auto; transform: rotate(14deg); }
.qstar:nth-child(4) { inset: 1.8rem .55rem auto auto; width: .65rem; }
.qcards, .steps, .agrid, .jlines { display: grid; gap: .6rem; }

.qcard, .feelings-match, .cert, .step, .jbox {
    min-width: 0;
    border: 1px solid var(--rule);
    border-radius: .75rem;
    background: var(--activity-surface);
}

.qcard {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: start;
    gap: .5rem;
    padding: .75rem;
}

.qthumb { width: clamp(2.75rem, 8vw, 4rem); aspect-ratio: 1; border-radius: 50%; }
.qq { font: 600 clamp(1.05rem, 2.4vw, 1.22rem)/1.25 Fredoka, "Segoe UI", sans-serif; }
.opts { display: flex; flex-wrap: wrap; gap: .4rem; margin-block-start: .55rem; }
.reader-choice, .jf {
    min-height: 2.75rem;
    padding: .4rem .6rem;
    border: 1px solid var(--rule);
    border-radius: .5rem;
    background: var(--activity-surface);
    cursor: pointer;
}

.reader-choice {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .95rem;
    line-height: 1.25;
}

.reader-page input[type="radio"] { accent-color: var(--book-blue); margin: 0; }
:is(.reader-choice, .jf):has(input:checked) { border-color: var(--book-blue); background: #eaf0f9; }
.feelings-match { padding: .85rem; }
.feelings-match > :is(.qnum, .qq) { display: inline; }
.feelings-match > .qnum { display: inline-grid; margin-inline-end: .45rem; }

.match-board { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 17%; margin-block: .75rem; }
.match-board .mcol { display: grid; gap: .45rem; }
.match-board .mrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .28rem;
    min-height: clamp(3.5rem, 10vw, 4.5rem);
    padding: .3rem .45rem;
    border: 1px solid var(--rule);
    border-radius: .55rem;
    background: #fcf7ed;
    color: var(--book-text);
    font: 500 clamp(.875rem, 2vw, 1.15rem)/1.1 Fredoka, "Segoe UI", sans-serif;
    cursor: pointer;
}

.match-board img { width: clamp(2.15rem, 7vw, 3.25rem); }
.match-board .dot { width: .65rem; height: .65rem; flex: none; border: 1px solid #7da590; border-radius: 50%; }
.mrow:is([aria-pressed="true"], .paired) { background: #e8f0e6; border-color: var(--activity-green); }
.mrow:is([aria-pressed="true"], .paired) .dot { background: var(--activity-green); border-color: var(--activity-green); }
.match-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.match-lines path { fill: none; stroke: var(--activity-green); stroke-width: 2.25; stroke-linecap: round; }
.activity-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.activity-footer button { margin-inline-start: auto; }
.gj, .stars { display: flex; justify-content: center; align-items: center; gap: .35rem; margin-block: .75rem 0; }
:is(.gj, .stars) svg { width: 1rem; height: 1rem; flex: none; }

.breathing-pictures { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-block: 1rem; }
.bfig { text-align: center; }
.bimg img { width: min(100%, 12rem); margin-inline: auto; }
.bcap { color: var(--activity-green); font: 600 1.15rem/1.4 Fredoka, "Segoe UI", sans-serif; }
.step { display: flex; align-items: center; gap: .55rem; padding: .5rem .7rem; }
.step p { margin: 0; font-size: 1rem; }
.sn, .agrid b { color: var(--activity-green); font-family: Fredoka, "Segoe UI", sans-serif; }
.agrid div { display: flex; gap: .65rem; align-items: baseline; }
.cert { margin-block-start: 1rem; padding: 1rem; text-align: center; border-color: #ddbf74; }
.cert .ct { font: 600 1.5rem/1.2 Fredoka, "Segoe UI", sans-serif; color: var(--book-blue); }
.cert :is(.cs, .ln) { font-size: .95rem; }
.cert .line input { max-width: 20rem; margin: .6rem auto 0; }

.reader-page :is(.wl, .jl) { display: grid; align-items: start; gap: .25rem; margin-block-start: .65rem; }
.reader-page :is(.wl, .jl, .cert) :is(input[type="text"], textarea) {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    padding: .4rem .6rem;
    border: 1px solid #b8ab92;
    border-radius: .4rem;
    background: #fff;
    color: var(--book-text);
    font: inherit;
}

.jf { width: 100%; justify-content: center; }
.jf img { width: clamp(2.15rem, 8vw, 3.85rem); }
.jbox { padding: .75rem; margin-block: .75rem; }
.jbox canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 760 / 360;
    margin-block: .5rem;
    border: 1px dashed #b8ab92;
    border-radius: .4rem;
    background: white;
    touch-action: none;
    cursor: crosshair;
}

@media (min-width: 39rem) {
    .toc :is(.cols, .end) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1rem; }
    .toc .cols { grid-auto-flow: column; grid-template-rows: repeat(8, auto); }
    .jfaces .row { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 31rem) {
    .qcard .qbody { display: contents; }
    .qcard .qq { align-self: center; }
    .qcard .opts { grid-column: 1 / -1; margin-block-start: .1rem; }
    .qcard .reader-choice { flex: 1 1 100%; }
    .qstar { display: none; }
    .reader-page .pn { padding-block-start: 1.2rem; }
}
