:root {
  color-scheme: dark;
  --cream: #fff0ce;
  --brass: #e1b86e;
  --ink: #143d39;
  --book: 'Iowan Old Style', Baskerville, 'Palatino Linotype', Georgia, serif;
  --body: ui-rounded, 'Trebuchet MS', system-ui, sans-serif;
  font-family: var(--body);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #102f2c; }
body { color: var(--cream); overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #fff1b4; outline-offset: 4px; }
button, img, .app { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
img { -webkit-user-drag: none; }
button svg, .song svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.definitions { position: absolute; height: 0; width: 0; overflow: hidden; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(100%); white-space: nowrap; }
.app { height: 100vh; height: 100svh; height: 100dvh; min-height: 250px; display: flex; flex-direction: column; overflow: hidden; isolation: isolate; }
.theatre { flex: 1; position: relative; min-height: 0; background: #154a44 url('./art/theatre.webp') center/100% 100% no-repeat; }
.tools { position: absolute; top: max(18px, env(safe-area-inset-top)); right: max(20px,env(safe-area-inset-right)); display: flex; gap: 9px; z-index: 4; }
.round { width: 46px; height: 46px; display: grid; place-items: center; color: #ffe4ac; border: 1px solid #d6b67c92; background: #0e3430ed; border-radius: 50%; box-shadow: 0 2px 6px #041b1b38; }
.round svg { width: 20px; height: 20px; }
.round:active, .baton:active { transform: translateY(1px); }
.marquee { position: absolute; z-index: 1; top: max(7.3%,env(safe-area-inset-top)); left: 8%; right: 8%; text-align: center; pointer-events: none; }
.ornament { display: flex; justify-content: center; align-items: center; gap: 11px; color: var(--brass); font-size: clamp(16px, 2.4vh, 26px); line-height: 1; }
.ornament span { width: clamp(27px,3.5vw,56px); height: 1px; background: linear-gradient(90deg,transparent,var(--brass)); }
.ornament span:last-child { transform: scaleX(-1); }
h1 { margin: .1em 0 .09em; color: #ffedc5; font: 700 clamp(42px, min(5.6vw,9.6vh), 100px)/1.13 var(--book); letter-spacing: -.045em; text-wrap: balance; text-shadow: 0 3px 0 #082c28, 0 4px 15px #06211f6b; }
.marquee p { margin: .25em 0 0; color: #f6e8cf; font-size: clamp(16px,1.5vw,22px); line-height: 1.35; text-shadow: 0 1px 4px #153c37; }
.cast { position: absolute; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: clamp(4px,1.4vw,26px); inset: 36% max(8%,env(safe-area-inset-right)) 4.8% max(8%,env(safe-area-inset-left)); }
.player { isolation: isolate; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; overflow: visible; min-width: 0; min-height: 0; border: 0; padding: 0; background: none; border-radius: 12px; }
.player:before { content: ''; pointer-events: none; position: absolute; z-index: -1; inset: -14% -18% 5%; opacity: 0; background: radial-gradient(ellipse at center 62%,#ffd27040 0, #f7ce6620 42%, transparent 69%); transition: opacity .24s; }
.player[aria-pressed=true]:before { opacity: 1; }
.portrait { position: relative; display: flex; align-items: flex-end; justify-content: center; width: 100%; min-height: 0; flex: 1; pointer-events: none; }
.figure { position: relative; width: 100%; height: 100%; transform-origin: 50% 99%; }
.figure img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; transition: opacity 130ms ease; }
.figure .play { opacity: 0; }
.player[aria-pressed=true] .rest, .player[aria-pressed=false] .play { opacity: 0; }
.player[aria-pressed=true] .play { opacity: 1; }
.player[aria-pressed=true] .figure { animation: sway 1.2s ease-in-out infinite; }
.player:nth-child(even) .figure { animation-direction: reverse; }
.portrait:before { content:''; position:absolute; bottom: .8%; left: 12%; right: 12%; height: 8%; border-radius: 50%; background: radial-gradient(ellipse,#42220965 10%,transparent 72%); }
@keyframes sway { 0%,100% { transform: rotate(-.9deg); } 50% { transform: rotate(1deg) translateY(-1.5px); } }
.label { position: relative; display: inline-flex; align-items:center; justify-content:center; margin-top: clamp(3px,1vh,11px); padding: .28em 1.05em .32em; color: #3a2719; background: linear-gradient(#f2d49d,#dbb172); border: 1px solid #ffe2a4; border-radius: 5px; box-shadow: inset 0 0 0 2px #a976383d,0 2px 0 #6d431f,0 4px 8px #492c1c3d; font: 700 clamp(17px,1.65vw,26px)/1.02 var(--book); white-space: nowrap; }
.label:before,.label:after { content:''; width:3px; height:3px; background:#a77a40; box-shadow:0 1px #ffe0a2; border-radius:50%; position:absolute; top:48%; }
.label:before { left:7px; } .label:after { right:7px; }
.player[aria-pressed=true] .label { background:linear-gradient(#ffe9af,#ecc073); }
.app.frozen .figure { animation-play-state: paused; }
.player.nod .portrait { animation: nod .62s ease-in-out; transform-origin:center bottom; }
.app.frozen .portrait { animation-play-state: paused; }
@keyframes nod { 0%,100% {transform: scaleY(1);} 45% {transform: scale(.99,.964) rotate(1deg);} }
.console { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; column-gap: 12px; padding: clamp(10px,2.25vh,25px) max(6%,env(safe-area-inset-right)) max(clamp(10px,2.25vh,25px),env(safe-area-inset-bottom)) max(6%,env(safe-area-inset-left)); background: #113734; border-top: 2px solid #a7773f; box-shadow: inset 0 3px 0 #0d2c28; }
.song { display: flex; align-items:center; gap:12px; }
.song-icon { color: #e4c08a; width: 40px; height:40px; border:1px solid #baa26d70; border-radius:50%; display:grid; place-items:center; }
.song-icon svg { width:20px; height:20px; }
.caption,.song-title { display:block; }
.caption,.count { font-size: 14px; color:#e4d7bd; }
.song-title { font: 600 clamp(18px,1.55vw,24px)/1.15 var(--book); color:#fbe6bf; margin-top:1px; }
.baton { min-height:48px; display:inline-flex; gap:10px; justify-content:center; align-items:center; padding:10px clamp(16px,2vw,32px); border-radius:40px; border:1px solid #f5dda7; color:#3b2a19; background:linear-gradient(#ffdfa0,#e8b970); box-shadow:inset 0 0 0 2px #ab7b3f4d, 0 3px 0 #7e5d34,0 5px 12px #06272285; font-size:clamp(16px,1.3vw,20px); font-weight:700; white-space:nowrap; touch-action:none; }
.baton svg { width:26px; height:26px; }
.frozen .baton { background:#ebcf8e; transform:translateY(2px); box-shadow:inset 0 2px 3px #87663c88; }
.count { justify-self:end; display:flex; flex-direction:column; align-items:flex-end; gap:7px; }
.lights { display:flex; gap:5px; }
.lights i { width:9px; height:9px; border-radius:50%; border:1px solid #d5b77b99; background:#35514a; }
.lights i.on { background:#f5cd75; box-shadow:0 0 6px #e6bb5a66; }
dialog { border:1px solid #d0b078; color:var(--cream); background:#183e39; border-radius:18px; width:min(90vw,370px); padding:24px; }
dialog::backdrop { background:#071b19b3; }
dialog h2 { margin:0; font:700 29px/1.2 var(--book); }
dialog p { line-height:1.5; } dialog button { background:#f1d197; color:#352919; border:0; padding:12px 18px; border-radius:23px; font-weight:700; }
@media (max-aspect-ratio: 4/5) {
  .tools { top:max(10px,env(safe-area-inset-top)); right:max(13px,env(safe-area-inset-right)); gap:6px; }
  .round { width:44px; height:44px; }
  .marquee { top:calc(max(10px,env(safe-area-inset-top)) + 46px); left:5%; right:5%; }
  .ornament { display:none; }
  h1 { font-size:clamp(29px,7.85vw,53px); margin:0 0 3px; }
  .marquee p { font-size:clamp(15px,3.85vw,20px); }
  .cast { inset:calc(max(10px,env(safe-area-inset-top)) + 60px + clamp(49px,13vw,80px)) 10% 3%; grid-template-columns:repeat(2,minmax(0,1fr)); grid-template-rows:repeat(2,minmax(0,1fr)); column-gap:3%; row-gap:2.6%; }
  .label { margin-top:0; font-size:clamp(16px,4.4vw,22px); }
  .console { padding:11px max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left)); gap:6px; }
  .song-icon { display:none; } .caption,.count { font-size:12px; }
  .song-title { font-size:clamp(15px,3.9vw,20px); } .count { gap:5px; }
  .baton { padding:9px 13px; font-size:15px; gap:5px; }
  .baton svg { width:21px; } .lights { gap:4px; } .lights i { width:7px; height:7px; }
}
@media (orientation:landscape) and (max-height:540px) {
  .marquee { top:max(3%,env(safe-area-inset-top)); }
  .ornament { display:none; }
  h1 { font-size:clamp(27px,7.8vh,42px); margin-top:0; }
  .marquee p { font-size:14px; margin-top:0; }
  .tools { top:max(7px,env(safe-area-inset-top)); right:max(10px,env(safe-area-inset-right)); gap:4px; }
  .round { width:44px; height:44px; }
  .cast { top:25%; bottom:4%; }
  .label { font-size:16px; margin-top:0; }
  .console { padding-top:5px; padding-bottom:max(6px,env(safe-area-inset-bottom)); }
  .baton { min-height:44px; padding:5px 17px; font-size:15px; }
  .caption,.count { font-size:12px; } .song-title { font-size:17px; } .song-icon { width:31px;height:31px; }
}
@media (prefers-reduced-motion:reduce) {
  *,*:before,*:after { animation:none!important; transition:none!important; }
}
[hidden] { display:none!important; }
.retry { pointer-events:auto; background:none; color:var(--cream); font:inherit; border:0; text-decoration:underline; padding:0 .2em; }
.baton { min-width:clamp(170px,16vw,240px); }
@media (max-aspect-ratio:4/5) { .baton { min-width:138px; } }
@media (max-aspect-ratio:4/5) {
  .cast:before { content:''; position:absolute; pointer-events:none; top:calc(48.7% - 25px); left:-5%; right:-5%; height:25px; border-radius:50% 50% 8px 8px / 28% 28% 6px 6px; background:#b88745 url('./art/riser.webp') center/100% 100%; border-bottom:3px solid #754629; box-shadow:0 3px 4px #082a2873; }
}

/* A full row for a wide theatre, with tiered seating on portrait devices. */
.cast { grid-template-columns:repeat(6,minmax(0,1fr)); left:max(5.2%,env(safe-area-inset-left)); right:max(5.2%,env(safe-area-inset-right)); gap:clamp(2px,.7vw,12px); }
.puppet-layer { position:absolute; inset:0; width:100%; height:100%; z-index:2; pointer-events:none; }
.tools { z-index:4; }
.player.puppeteered[aria-pressed=true] .figure { animation:none; }
.player.puppeteered[aria-pressed=true] img.play { opacity:0; transition:none; }
.player .rest { transform-origin:50% 97%; }
.player[aria-pressed=false] .rest { animation:breathe 3.8s ease-in-out infinite; }
.player:nth-child(2n) .rest { animation-delay:-1.8s; }
.player:nth-child(3n) .rest { animation-delay:-2.7s; }
@keyframes breathe { 50% {transform:scale(.996,1.013) rotate(.32deg);} }
.music-spark { position:absolute; right:12%; bottom:65%; color:#f8d797; opacity:0; font:italic 700 clamp(16px,2.1vw,30px)/1 var(--book); pointer-events:none; text-shadow:0 1px 4px #203e35; }
.player[aria-pressed=true] .music-spark { animation:note-rise calc(var(--beat,.6s)*4) ease-out infinite; }
.player:nth-child(even) .music-spark { animation-delay:-.6s; }
@keyframes note-rise { 0%,55%,100% {opacity:0;transform:translate(0,0) rotate(-12deg);} 65% {opacity:.9;} 99% {opacity:0;transform:translate(11px,-22px) rotate(12deg);} }
.app.frozen .figure, .app.frozen .rest, .app.frozen .music-spark {animation-play-state:paused;}
.player[data-part=drum]:not(.puppeteered)[aria-pressed=true] .figure { animation:drum-hop var(--beat,.6s) ease-out infinite; }
.player[data-part=guitar]:not(.puppeteered)[aria-pressed=true] .figure { animation:strum-rock calc(var(--beat,.6s)*2) ease-in-out infinite; }
.player[data-part=trumpet]:not(.puppeteered)[aria-pressed=true] .figure { animation:brass-lift calc(var(--beat,.6s)*2) ease-in-out infinite; }
@keyframes drum-hop { 25% { transform:translateY(-2.3%) scale(.99,1.014); } 60% {transform:scale(1.015,.986);} }
@keyframes strum-rock {0%,100% {transform:rotate(-2deg);} 50% {transform:rotate(3deg) translateY(-1%);} }
@keyframes brass-lift { 40% {transform:rotate(-3.5deg) scale(1.012);} }
.app.frozen .player:not(.puppeteered) .figure {animation-play-state:paused;}
.song { background:none; border:0; color:var(--cream); text-align:left; justify-self:start; min-height:44px; max-width:100%; padding:0 3px; border-radius:7px; }
.song-copy {min-width:0;}
.song-icon {background:#254c43;}
.song-icon svg {fill:currentColor;stroke:none;width:25px;height:25px;}
.song-title {white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.chevron {font-size:20px;color:var(--brass);align-self:center;}
#song-book {width:min(410px,calc(100vw - 28px)); max-height:90dvh; padding:20px; background:#153f3a; box-shadow:0 14px 60px #041b19aa;}
.book-head,.tune-option {display:flex;align-items:center;justify-content:space-between;}
.book-head {margin-bottom:14px;}
.book-head .book-close {min-width:44px;height:44px;color:var(--cream);font:26px/1 var(--body);background:transparent;padding:0;}
#tune-list {display:grid;gap:8px;}
#tune-list .tune-option {width:100%;min-height:66px;text-align:left;padding:8px 14px 8px 8px; gap:12px;border-radius:10px;background:#254e47;color:var(--cream);border:1px solid #cfac6b45;}
#tune-list .tune-option[aria-pressed=true] {background:#2f574b;border-color:#e9c16e;}
.tune-picture {display:grid;place-items:center;flex:0 0 46px;height:46px;border-radius:9px;background:#633b37;color:#ffe1a0;}
.tune-option[data-tune=twinkle] .tune-picture {background:#334368;color:#ffe29c;}
.tune-option[data-tune=joy] .tune-picture {background:#71502b;color:#ffe1a0;}
.tune-picture svg {width:32px;height:32px;stroke:none;fill:currentColor;}
.tune-name {flex:1;font:700 21px/1.12 var(--book);}
.tune-check {color:#ffdc94;visibility:hidden;}
.tune-option[aria-pressed=true] .tune-check {visibility:visible;}
@media (max-aspect-ratio:1/1) {
  .cast {grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));top:26%;bottom:3%;column-gap:2%;row-gap:2%;left:8%;right:8%;}
  .cast:before,.cast:after {content:'';position:absolute;pointer-events:none;top:calc(49% - 20px);left:-3%;right:-3%;height:20px;border-radius:48% 48% 6px 6px / 24% 24% 5px 5px;background:#b88745 url('./art/riser.webp') center/100% 100%;border-bottom:3px solid #754629;box-shadow:0 3px 4px #082a2866;z-index:0;}
  .cast:after {display:none;}
  .player {z-index:1;}
}
@media (max-aspect-ratio:4/5) {
  .cast {inset:calc(max(10px,env(safe-area-inset-top)) + 60px + clamp(49px,13vw,80px)) 8% 2%;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(3,minmax(0,1fr));row-gap:1.8%;column-gap:5%;}
  .cast:before {top:calc(32.13% - 18px);height:18px;}
  .cast:after {display:block;top:calc(66.07% - 18px);height:18px;}
  .label {font-size:clamp(15px,4vw,22px);padding:.21em .94em .27em;}
  .song {gap:4px;}.chevron{font-size:15px;}
  .baton {min-width:0;}
}
@media (orientation:landscape) and (max-height:480px) {
  #song-book {padding:12px 20px;}.book-head {margin-bottom:5px;}
  #tune-list {gap:4px;} #tune-list .tune-option {min-height:48px;padding:3px 9px;}
  .tune-picture {height:36px;flex-basis:36px;} .tune-picture svg {width:25px;height:25px;}
}
