:root {
  --paper: #faf7f0;
  --ink: #362d29;
  --muted: #685e55;
  --red: #912d38;
  --stock: #efeae1;
  --rail: #ddd5c9;
  color-scheme: light;
}
* { box-sizing: border-box; min-width: 0 }
html { scroll-behavior: smooth; scroll-padding-top: 24px }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.55 "Helvetica Neue", Arial, sans-serif; overflow-x: clip }
main, .screen { width: min(1120px, 92%); margin-inline: auto }
/* Header, title, player and step text always share one window height. */
.screen { height: 100vh; height: 100dvh; min-height: 460px; display: flex; flex-direction: column; padding-bottom: clamp(10px, 2vh, 20px) }
header, .brand, .buttons { display: flex; align-items: center }
header { justify-content: space-between; padding: clamp(8px, 2vh, 20px) 0; position: relative; z-index: 4 }
a { color: inherit; text-underline-offset: .22em }
.brand { gap: 9px; font: 600 clamp(17px, 2.4vw, 23px)/1.1 Georgia, serif }
.brand img { width: 23px; height: auto }
.picker { position: relative; font-size: 14px }
.picker summary { cursor: pointer; color: var(--red); padding: 8px 0 }
.patterns { position: absolute; right: 0; top: 100%; width: max-content; padding: 8px; background: var(--paper); box-shadow: 0 6px 25px #422b201c; border-radius: 6px }
.patterns a { display: block; padding: 8px 14px; text-decoration: none }
.patterns a:hover, .patterns [aria-current] { background: var(--stock); color: var(--red) }
h1,h2,h3,p,figure { margin: 0 }
h1,h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; line-height: 1.08; letter-spacing: -.045em; text-wrap: balance }
h1 { font-size: clamp(28px, min(5vw, 6.5vh), 64px); text-align: center }
h2 { font-size: clamp(30px,3.6vw,46px) }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: transparent; padding: 6px 9px; border-radius: 4px }
button:hover { color: var(--red); background: #e6dfd5 }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px }

.player { --bar-h: 86px; position: relative; width: min(100%, 980px); margin: clamp(6px, 1.6vh, 18px) auto 0; flex: 1; min-height: 0; display: flex; flex-direction: column }
.stage { position: relative; flex: 1; min-height: 150px; background: var(--stock); border-radius: 8px; overflow: hidden; isolation: isolate; cursor: grab; touch-action: none; user-select: none }
.stage:active { cursor: grabbing }
.layer { position: absolute; inset: 0 0 calc(var(--bar-h) / 2) 0; width: 100%; height: calc(100% - var(--bar-h) / 2); overflow: visible; filter: drop-shadow(0 7px 5px #50391e14) }
.caption { position: absolute; bottom: calc(var(--bar-h) + 6px); left: 50%; transform: translateX(-50%); max-width: 92%; width: max-content; padding: 3px 10px; font-size: 14px; color: var(--muted); text-shadow: 0 0 4px var(--stock), 0 0 2px var(--stock); pointer-events: none; z-index: 1 }
.reset { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; font-size: 18px; background: #f3eee5eb; z-index: 1 }
.zoom { position: absolute; top: 56px; right: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 1 }
.zoom button { width: 40px; height: 40px; font-size: 20px; line-height: 1; background: #f3eee5eb }
.layer { transform-origin: 50% 50%; transition: transform .25s ease-out }
.stage.pinching .layer { transition: none }
@media (prefers-reduced-motion: reduce) { .layer { transition: none } }
.bigplay { position: absolute; left: 50%; top: 50%; width: 84px; height: 84px; margin: -42px 0 0 -42px; border-radius: 50%; background: var(--red); color: #fff; box-shadow: 0 8px 28px #5a1d2440; z-index: 2; transition: opacity .35s, transform .35s }
.bigplay svg { width: 40px; height: 40px; fill: currentColor; display: block; margin: 0 auto; translate: 3px 0 }
.bigplay:hover { background: #7c2430; color: #fff; transform: scale(1.05) }
.stage.playing .bigplay { opacity: 0; transform: scale(.85); pointer-events: none }

/* The controls float over the bottom of the animation, so the drawing can use the whole player. */
.bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; background: linear-gradient(#f3eee500, #f3eee5e6 45%); border-radius: 0 0 8px 8px; padding: 4px 12px 8px }
.track { position: relative; padding: 12px 0; cursor: pointer; touch-action: none }
.segs { display: flex; gap: 3px; height: 5px; transition: height .15s }
.track:hover .segs, .track.hover .segs, .track:focus-visible .segs { height: 9px }
.seg { position: relative; background: var(--rail); border-radius: 2px; overflow: hidden }
.seg i { position: absolute; inset: 0; background: var(--red); transform: scaleX(0); transform-origin: left }
.tip { position: absolute; bottom: 100%; transform: translateX(-50%); padding: 3px 8px; font-size: 13px; white-space: nowrap; color: #fff; background: var(--ink); border-radius: 4px; opacity: 0; pointer-events: none }
.track.hover .tip { opacity: 1 }
.buttons { gap: 4px; flex-wrap: wrap }
.buttons button { width: 44px; height: 44px; padding: 10px }
.buttons svg { width: 24px; height: 24px; fill: currentColor; display: block }
.time { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; margin-inline: 6px 2px }
.chapname { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 }
.chapname::before { content: "·"; color: var(--muted); margin-right: 8px }

.step { width: min(100%, 980px); margin: clamp(8px, 2vh, 20px) auto 0; flex: none }
.stepnum { font-size: 14px; color: var(--muted) }
.step h2 { font-size: clamp(22px, min(3vw, 4vh), 34px); margin: 2px 0 6px }
.step p:last-child { max-width: 72ch; min-height: 4.65em; color: var(--muted) }
main p a { color: var(--red) }

.chapters { width: min(100%, 940px); margin: clamp(36px,5vw,64px) auto 0 }
.chapters h2 { font-size: clamp(24px,2.4vw,32px); margin-bottom: 12px }
.chapters ol { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 4px 16px }
.chapters button { width: 100%; display: flex; gap: 12px; text-align: left; padding: 10px; min-height: 44px }
.chapters .when { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.6em }
.chapters [aria-current] { background: var(--stock); color: var(--red) }

#materials { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; width: min(100%, 940px); margin: clamp(48px,7vw,88px) auto 36px }
#materials h2 { font-size: clamp(24px,2.4vw,32px) }
#materials li { color: var(--muted) }
ul { padding-left: 1.2em; margin: 0 }
li+li { margin-top: 10px }
li small { display: block }
#credit { width: min(100%, 940px); margin: 0 auto 32px; color: var(--muted); font-size: 13px }

/* Page entrance: the finished star first, the play button a beat later. */
@keyframes rise { from { opacity: 0; transform: translateY(10px) } }
@keyframes appear { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: scale(.7) } }
.enter { animation: rise .8s .1s cubic-bezier(.2,.7,.2,1) backwards }
.stage { animation: appear 1.1s .25s ease-out backwards }
.bar { animation: appear .7s 1.1s ease-out backwards }
.bigplay { animation: pop .6s 1.3s cubic-bezier(.2,.9,.3,1.3) backwards }
.step { animation-delay: .9s }
.chapters, #materials, #credit { animation-delay: 1.1s }

@media(max-width:640px) {
  .step p:last-child { font-size: 15px; line-height: 1.45; min-height: 5.8em }
  #materials { grid-template-columns: 1fr; gap: 14px }
  .player { --bar-h: 116px }
  .bar { padding-inline: 6px }
  .bigplay { width: 68px; height: 68px; margin: -34px 0 0 -34px }
  .chapname { flex-basis: 100%; padding-left: 10px }
  .chapname::before { content: none }
}
@media(prefers-reduced-motion:reduce) {
  html { scroll-behavior: auto }
  .enter, .stage, .bar, .bigplay { animation: none }
  .bigplay, .segs { transition: none }
}
