/* The Music Room: a torn-out pulp cover taped into a case file. Cut paper, tape, ink and one orange. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  overflow: hidden;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, none), var(--ak-bg-art);
  background-size: cover, var(--ak-bg-size);
  background-position: center;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

/* ---------- Shared paper ---------- */

:root {
  --torn-scrap: polygon(1% 9%, 18% 1%, 41% 6%, 63% 0, 84% 5%, 99% 2%, 100% 48%, 98% 93%, 79% 100%, 56% 95%, 33% 100%, 12% 96%, 0 99%, 2% 52%);
  --torn-scrap-2: polygon(0 4%, 22% 0, 47% 5%, 71% 1%, 100% 6%, 98% 51%, 100% 97%, 74% 94%, 49% 100%, 25% 95%, 3% 100%, 1% 47%);
  --torn-sheet: polygon(0 1.2%, 5% 0.3%, 11% 1.4%, 18% 0.2%, 25% 1.1%, 33% 0.4%, 40% 1.5%, 48% 0.3%, 56% 1.2%, 63% 0.2%, 71% 1.3%, 79% 0.4%, 86% 1.4%, 93% 0.3%, 100% 1.1%, 100% 98.9%, 94% 99.7%, 87% 98.6%, 80% 99.6%, 72% 98.5%, 65% 99.5%, 57% 98.7%, 49% 99.7%, 41% 98.6%, 34% 99.5%, 26% 98.5%, 18% 99.6%, 11% 98.7%, 5% 99.5%, 0 98.6%);
  --tape: color-mix(in srgb, var(--ak-accent) 24%, var(--ak-bg));
  --paper-shadow: drop-shadow(0 6px 10px color-mix(in srgb, var(--ak-ink) 55%, transparent));
  --strip-h: clamp(84px, 12dvh, 124px);
}

/* The chrome's note never swallows the tap meant for the strip under it; a tap anywhere still clears it. */
#activity-chrome-toast {
  pointer-events: none;
}

@media (orientation: portrait) {
  html body #activity-chrome-toast[data-at] {
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--strip-h) + 6px);
  }
}

.tape {
  position: absolute;
  width: 64px;
  height: 20px;
  background: var(--tape);
  clip-path: polygon(3% 0, 97% 8%, 100% 100%, 0 92%);
  pointer-events: none;
}

/* Cut-out lettering: every letter clipped from a different page. */
.cut {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
  line-height: 1;
}

.cut > span {
  display: inline-block;
  padding: 2px 3px 3px;
  rotate: var(--r, 0deg);
}

.cut .c0 { background: var(--ak-surface); color: var(--ak-ink); font-family: var(--ak-font-display); }
.cut .c1 { background: var(--ak-btn-fill); color: var(--ak-btn-ink); font-family: var(--ak-font-body); font-weight: 600; text-transform: uppercase; }
.cut .c2 { background: var(--ak-bg); color: var(--ak-ink); font-family: var(--ak-font-display); text-transform: uppercase; }
.cut .c3 { background: var(--ak-surface); color: var(--ak-ink); font-family: var(--ak-font-body); font-weight: 500; font-style: italic; }
.cut .c4 { background: var(--ak-choice-selected-bg); color: var(--ak-choice-selected-ink); font-family: var(--ak-font-display); }
.cut .gap { width: 0.4em; padding: 0; background: none; }

/* ---------- Layout: upright, the room above the notes and the strip ---------- */

.play {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --crop-y: 70;
  --crop-h: 820;
  --top: calc(var(--ac-status-h, 64px) + 12px);
  --desk-min: clamp(200px, 33dvh, 280px);
  --avail-h: calc(100dvh - var(--top) - var(--strip-h) - var(--desk-min) - var(--safe-b) - 30px);
  --sheet-w: min(calc(100dvw - 30px - var(--safe-l) - var(--safe-r)), calc(var(--avail-h) * 768 / var(--crop-h)), 640px);
  --sheet-h: calc(var(--sheet-w) * var(--crop-h) / 768);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, var(--sheet-w));
  grid-template-rows: var(--sheet-h) minmax(0, 1fr) var(--strip-h);
  grid-template-areas: "stage" "desk" "strip";
  justify-content: center;
  row-gap: 10px;
  padding: var(--top) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.stage {
  grid-area: stage;
  position: relative;
  z-index: 2;
  width: var(--sheet-w);
  height: var(--sheet-h);
}

.desk {
  grid-area: desk;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 2px 4px 0;
}

.strip {
  grid-area: strip;
  position: relative;
}

/* ---------- Sideways: the notes on the left; the room on the right, the strip under it ---------- */

@media (orientation: landscape) {
  .play {
    --crop-y: 120;
    --crop-h: 560;
    --side-w: clamp(260px, 38dvw, 420px);
    --strip-h: clamp(72px, 20dvh, 104px);
    --sheet-w: min(calc(100dvw - var(--side-w) - 22px - 84px - 12px - var(--safe-l) - var(--safe-r)), calc((100dvh - 24px - var(--strip-h) - 8px - var(--safe-t) - var(--safe-b)) * 768 / var(--crop-h)), 800px);
    grid-template-columns: var(--side-w) var(--sheet-w);
    grid-template-rows: var(--sheet-h) var(--strip-h);
    grid-template-areas: "desk stage" "desk strip";
    align-content: center;
    column-gap: 22px;
    row-gap: 8px;
    padding: max(12px, var(--safe-t)) calc(var(--safe-r) + 72px) max(12px, var(--safe-b)) calc(var(--safe-l) + 12px);
  }

  .desk {
    align-self: stretch;
    padding-top: calc(var(--ac-status-h, 64px) - max(12px, var(--safe-t)) + 8px);
  }

  .hint-note,
  .taped-desk {
    font-size: 16px;
  }

  .spot-label {
    font-size: 14px;
  }

  /* Once the bench is open her page has done its work; sideways, its room goes to the notes. */
  .page-wrap.is-done {
    display: none;
  }
}

/* ---------- The room: the torn cover, taped to the page ---------- */

.sheet-wrap {
  position: absolute;
  inset: 0;
  rotate: -1.5deg;
  filter: var(--paper-shadow);
}

.sheet {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--ak-ink);
  clip-path: var(--torn-sheet);
}

.room {
  position: absolute;
  left: 0;
  width: 100%;
  top: calc(var(--crop-y) / var(--crop-h) * -100%);
  height: calc(1024 / var(--crop-h) * 100%);
}

.room-art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: filter 0.8s ease;
}

:root.ac-lights-up .play .room-art,
:root.ac-lights-up .closeup {
  filter: brightness(1.18) contrast(0.96);
}

.play[data-dusk="1"] .room-art {
  filter: brightness(0.9) saturate(0.95);
}

.play[data-dusk="2"] .room-art {
  filter: brightness(0.8) saturate(0.9);
}

.at {
  position: absolute;
  left: calc(var(--x) / 768 * 100%);
  top: calc(var(--y) / 1024 * 100%);
  width: calc(var(--w) / 768 * 100%);
  height: calc(var(--h) / 1024 * 100%);
}

.logo {
  position: absolute;
  top: -3%;
  left: 37%;
  width: 26%;
  height: auto;
  rotate: -2deg;
  pointer-events: none;
}

.sheet-wrap::before,
.sheet-wrap::after {
  content: '';
  position: absolute;
  z-index: 2;
  width: 18%;
  height: 4.5%;
  background: var(--tape);
  clip-path: polygon(3% 0, 97% 10%, 100% 100%, 0 90%);
  pointer-events: none;
}

.sheet-wrap::before {
  top: -1.5%;
  right: -4%;
  rotate: 38deg;
}

.sheet-wrap::after {
  bottom: -1.5%;
  left: -4%;
  rotate: 34deg;
}

/* Sprites: one cell of a strip of pictures, cropped by its box. */
.cell {
  position: absolute;
  overflow: hidden;
}

.cell img {
  position: absolute;
  top: 0;
  height: 100%;
  max-width: none;
  width: calc(var(--sheet) / var(--cw) * 100%);
  left: calc(var(--cx) / var(--cw) * -100%);
  pointer-events: none;
}

/* The girl in the empty frame. One layer per stage so her page eases down between them. */
.girl {
  background: var(--ak-bg);
}

.girl .cell {
  top: 2%;
  bottom: 0;
  left: 50%;
  height: 98%;
  aspect-ratio: 76.8 / 296;
  translate: -50% 0;
  opacity: 0;
}

.girl .cell.is-on {
  opacity: 1;
}

.box-piece .cell {
  inset: 0;
}

.box-piece .cell.is-off {
  opacity: 0;
}

/* Opened locks, drawn over the room. */
.bench-lid {
  background: var(--ak-ink);
  opacity: 0;
  transform-origin: left bottom;
}

.is-open-bench .bench-lid {
  opacity: 1;
  rotate: -7deg;
}

.cab-open {
  opacity: 0;
  background:
    linear-gradient(90deg, transparent 0 50%, var(--ak-ink) 50% 52%, color-mix(in srgb, var(--ak-ink) 82%, var(--ak-accent)) 52% 100%);
}

.is-open-cabinet .cab-open {
  opacity: 0.9;
}

.door-hall {
  background:
    linear-gradient(180deg, var(--ak-ink) 0 62%, color-mix(in srgb, var(--ak-accent) 45%, var(--ak-ink)) 100%);
  opacity: 0;
}

.door-leaf {
  position: absolute;
  inset: 0;
  background-image: url("./art/music-room.jpg");
  background-size: calc(768 / 66 * 100%) calc(1024 / 458 * 100%);
  background-position: calc(702 / (768 - 66) * 100%) calc(168 / (1024 - 458) * 100%);
  transform-origin: right center;
}

.is-open-door .door-hall {
  opacity: 1;
}

.is-open-door .door-leaf {
  transform: scaleX(0.16);
}

/* Hot spots: plain tap areas with a cut-out label each. */
.spot {
  min-width: 48px;
  min-height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

/* The door sits at the very edge, so its tap area hangs off the sheet instead of eating the cabinet. */
.spot-door {
  position: absolute;
  z-index: 1;
  top: calc((156 - var(--crop-y)) / var(--crop-h) * 100%);
  right: -22px;
  width: max(calc(74 / 768 * 100% + 22px), 56px);
  height: calc(474 / var(--crop-h) * 100%);
}

/* The painted room carries the scene. A pencilled label shows only for the spot just tapped, and
   on every spot while something is in hand, so you can see where it might go. */
.spot-label {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 1;
  padding: 3px 9px 4px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 15px;
  font-style: italic;
  font-weight: 500;
  white-space: nowrap;
  clip-path: var(--torn-scrap);
  translate: -50% calc(-100% - 10px);
  rotate: var(--lr, -2deg);
  visibility: hidden;
  opacity: 0;
}

.spot.is-picked .spot-label,
.play.is-holding .spot-label {
  visibility: visible;
  opacity: 1;
}

.spot[data-spot="bench"] .spot-label,
.spot[data-spot="music-box"] .spot-label {
  top: auto;
  bottom: 0;
  translate: -50% 40%;
}

.spot[data-spot="door"] .spot-label {
  top: 22%;
  left: auto;
  right: 2px;
  translate: 0 0;
}

/* The line taped into the scene when a lock opens. */
.taped {
  position: absolute;
  left: 50%;
  bottom: 3%;
  z-index: 3;
  width: max-content;
  max-width: 88%;
  margin: 0;
  padding: 9px 14px 10px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: clamp(14px, 2.1dvh, 17px);
  font-style: italic;
  line-height: 1.3;
  text-align: center;
  clip-path: var(--torn-scrap);
  translate: -50% 0;
  rotate: 1.5deg;
}

/* Sideways the room has no bare floor to spare, so the line is taped into the notes instead. */
.taped-desk {
  display: none;
  margin: 0;
  padding: 10px 14px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 16px;
  font-style: italic;
  line-height: 1.3;
  clip-path: var(--torn-scrap);
  rotate: 1.2deg;
}

@media (orientation: landscape) {
  .taped {
    display: none;
  }

  .taped-desk:not([hidden]) {
    display: block;
  }
}

/* ---------- Close looks: a clipping pasted over the room ---------- */

.is-close .logo,
.is-close .taped,
.is-close .spot-label {
  visibility: hidden;
}

.closeup {
  position: absolute;
  inset: 2.5% 2.5% 3%;
  z-index: 4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  padding: 10px 10px 12px;
  background: var(--ak-surface);
  clip-path: var(--torn-scrap-2);
  rotate: 1deg;
}

.closeup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
}

.back-tab {
  position: relative;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: 15px;
  font-weight: 600;
  rotate: -2deg;
}

.back-tab:active {
  background: var(--ak-btn-active);
}

.closeup-title {
  margin: 0;
  font-size: 15px;
}

.closeup-title .cut {
  flex-wrap: nowrap;
}

/* While the guide points at the back tab, its arrow takes the title's place. */
.back-tab.is-guided {
  z-index: 3;
}

.back-tab.is-guided ~ .closeup-title {
  visibility: hidden;
}

.closeup-body {
  position: relative;
  container-type: size;
  min-height: 0;
}

.closeup-line {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-style: italic;
  line-height: 1.35;
}

/* Her portrait, close. */
.look-portrait {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 4%;
  height: 100%;
}

.look-portrait .girl-big {
  position: relative;
  flex: none;
  height: 100%;
  aspect-ratio: 76.8 / 296;
  max-width: 30%;
  background: var(--ak-bg);
}

.look-portrait .girl-big .cell {
  inset: 0;
}

.look-portrait .page-big {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.page-big svg {
  width: 100%;
  height: auto;
  max-height: 60cqh;
}

/* The piano, close: wider than the room so every key is a real target. The back tab and the card
   on the stand share the top row, the keys take the rest. */
.closeup.is-piano {
  --wide-w: min(calc(100dvw - 12px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)), 600px);
  padding-inline: 4px;
  left: calc((var(--sheet-w) - max(var(--wide-w), var(--sheet-w))) / 2);
  right: auto;
  width: max(var(--wide-w), var(--sheet-w));
  top: 1%;
  bottom: 1%;
}

@media (orientation: landscape) {
  /* Sideways the room is short, so the keys borrow the strip's height under it too. */
  .closeup.is-piano {
    left: 0;
    right: auto;
    top: 0;
    bottom: auto;
    width: var(--sheet-w);
    height: calc(var(--sheet-h) + 8px + var(--strip-h));
  }
}

.look-piano {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  height: 100%;
}

.piano-line {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-style: italic;
  line-height: 1.3;
  text-align: center;
}

@media (orientation: landscape), (max-height: 800px) {
  .piano-line {
    display: none;
  }
}

/* What you have played so far: one slot per note on her page. */
.slots {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.slots li {
  display: grid;
  place-items: center;
  width: 30px;
  height: 32px;
  border-bottom: 3px solid var(--ak-ink);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 20px;
  font-weight: 600;
}

.slot-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.slot-say {
  margin: 0;
  min-height: 1.2em;
  padding: 0 4px;
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  font-size: 15px;
  font-weight: 600;
}

.slot-say.is-count {
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.slots li.is-right {
  border-bottom-color: var(--ak-accent);
}

.slot-say:empty {
  background: none;
}

.slots li.is-wrong {
  color: var(--ak-ink);
  background: var(--ak-choice-selected-bg);
  text-decoration: line-through 2px;
}

.keys-cell {
  container-type: size;
  min-height: 0;
}

.keys {
  position: relative;
  top: 50%;
  translate: 0 -50%;
  margin: 0 auto;
  width: min(100cqw, 100cqh * 348 / 198);
  aspect-ratio: 348 / 198;
  overflow: hidden;
}

.keys > img {
  position: absolute;
  max-width: none;
  width: calc(376 / 348 * 100%);
  height: calc(384 / 198 * 100%);
  left: calc(-14 / 348 * 100%);
  top: calc(-170 / 198 * 100%);
  pointer-events: none;
}

.key {
  position: absolute;
  left: calc(var(--x) / 348 * 100%);
  top: calc(var(--y) / 198 * 100%);
  width: calc(var(--w) / 348 * 100%);
  height: calc(var(--h) / 198 * 100%);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.key.is-black {
  z-index: 1;
}

.key .press {
  position: absolute;
  inset: 0;
  background: var(--ak-ink);
  opacity: 0;
  pointer-events: none;
}

.key.is-black .press {
  left: 28%;
  right: 28%;
  background: var(--ak-bg);
}

.key.is-down .press {
  background: var(--ak-accent);
  opacity: 0.45;
}

/* After a wrong note, the key that note really wanted wears a ring until the next press. */
.key.is-answer {
  z-index: 2;
  outline: 4px solid var(--ak-accent);
  outline-offset: -4px;
  box-shadow: inset 0 0 0 6px var(--ak-ink);
}

.key.is-wrong .press {
  opacity: 0.32;
  background: var(--ak-accent);
}

/* The music box, close. */
.look-box {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  justify-items: center;
  gap: 8px;
  height: 100%;
}

.box-big {
  position: relative;
  height: 100%;
  aspect-ratio: 192 / 302;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.box-big .cell {
  inset: 0;
}

.box-big .crank-in {
  position: absolute;
  inset: auto;
  left: 86%;
  top: 52%;
  width: 26%;
  aspect-ratio: 128 / 264;
  opacity: 0;
  transform-origin: 30% 50%;
}

.box-big.is-winding .crank-in {
  opacity: 1;
}

.bars {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bars li {
  width: 14px;
  height: 22px;
  border-bottom: 2px solid var(--ak-ink-muted);
}

.bars li::before {
  content: '';
  display: block;
  width: 10px;
  height: 8px;
  margin: 12px 0 0 2px;
  border-radius: 50%;
  background: var(--ak-ink);
  rotate: -20deg;
  opacity: 0.15;
}

.bars li.is-played::before {
  background: var(--ak-accent);
  box-shadow: 0 0 0 1.5px var(--ak-ink);
  opacity: 1;
}

/* ---------- The notes: her page, the guide, the hint ladder ---------- */

.guide {
  position: relative;
  margin: 0;
  padding: 8px 14px 8px 46px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  clip-path: var(--torn-scrap-2);
  rotate: -0.8deg;
}

.guide::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  width: 24px;
  height: 28px;
  translate: 0 -50%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M12 1 L22 13 H16 V27 H8 V13 H2 Z' fill='%23FF5A1F' stroke='%23171311' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

@media (orientation: landscape) {
  .guide::before {
    rotate: 90deg;
  }
}

/* When the guide points at her page, its arrow turns down to it. */
.guide[data-point="down"]::before {
  rotate: 180deg;
}

.guide,
.taped-desk,
.desk-foot {
  flex: none;
}

/* Her page gives way first when the notes run short of room; Hint and the save line never do. */
.page-wrap {
  display: flex;
  flex: 0 1 auto;
  min-height: 92px;
}

.page-wrap .page-scrap {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.page-staff {
  flex: 1 1 auto;
  min-height: 0;
}

.page-wrap {
  position: relative;
}

.desk-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 0;
}

.page-scrap {
  position: relative;
  margin: 0;
  padding: 4px 8px 6px;
  background: var(--ak-bg);
  clip-path: var(--torn-scrap);
  rotate: 1.2deg;
}

.page-scrap.is-fresh {
  background: color-mix(in srgb, var(--ak-accent) 14%, var(--ak-bg));
}

.scrap-label {
  margin: 0 0 2px 4px;
  font-family: var(--ak-font-display);
  font-size: 13px;
  color: var(--ak-ink-muted);
}

.page-staff svg {
  display: block;
  width: 100%;
  height: 100%;
  max-height: clamp(76px, 15dvh, 150px);
}

.page-unseen {
  margin: 8px 0 4px;
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-style: italic;
  line-height: 1.3;
}

.hint-tab {
  flex: none;
  min-width: 88px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  clip-path: var(--torn-scrap-2);
  rotate: 2deg;
}

.hint-tab:active {
  background: var(--ak-btn-active);
}

.hint-note {
  flex: 0 1 auto;
  min-height: 2.8em;
  overflow-y: auto;
  overflow-y: auto;
  margin: 0;
  padding: 8px 10px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 15px;
  line-height: 1.35;
  clip-path: var(--torn-scrap-2);
  rotate: -0.6deg;
}

@media (orientation: portrait) and (max-height: 780px) {
  .hint-note {
    font-size: 14px;
    line-height: 1.3;
  }
}

.hint-note.is-fresh {
  outline: 3px solid var(--ak-accent);
  outline-offset: -3px;
}

.hint-note .next {
  font-weight: 600;
}

.hint-note .rung {
  display: inline;
  margin-right: 8px;
  color: var(--ak-ink-muted);
  font-size: 12px;
  font-variant: small-caps;
  letter-spacing: 0.1em;
}

.kept {
  margin: 0;
  padding: 2px 8px;
  background: var(--ak-bg);
  color: var(--ak-ink-muted);
  font-size: 13px;
  font-style: italic;
}

.kept.is-error {
  color: var(--ak-ink);
  font-style: normal;
}

/* ---------- The strip: a long torn piece of cream paper ---------- */

.strip::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--ak-surface);
  clip-path: polygon(0 10%, 6% 3%, 14% 9%, 23% 1%, 31% 8%, 40% 2%, 49% 9%, 58% 3%, 67% 10%, 76% 2%, 85% 8%, 93% 1%, 100% 7%, 100% 92%, 94% 99%, 86% 93%, 77% 100%, 68% 92%, 59% 99%, 50% 93%, 41% 100%, 32% 92%, 23% 99%, 14% 93%, 6% 100%, 0 94%);
  rotate: -0.6deg;
  filter: var(--paper-shadow);
}

.items {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4%;
  height: 100%;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
}

.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--strip-h) - 14px);
  min-width: 64px;
  margin: 0;
  padding: 0 8px 0 0;
  border: 0;
  background: none;
  rotate: var(--tilt, 2deg);
}

.item .cell {
  position: relative;
  height: 100%;
  aspect-ratio: 128 / 264;
}

.item .item-name {
  font-size: 14px;
  font-weight: 600;
}

.item[aria-pressed="true"] {
  translate: 0 -6px;
  rotate: 0deg;
}

.item[aria-pressed="true"] .item-name {
  padding: 4px 6px;
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
}

.item[aria-pressed="true"]::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 4px;
  z-index: 1;
  width: 40px;
  height: 14px;
  background: var(--ak-accent);
  clip-path: polygon(3% 0, 97% 10%, 100% 100%, 0 90%);
  rotate: -12deg;
}

.strip-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 18px;
  text-align: center;
  color: var(--ak-ink-muted);
  font-size: 15px;
  font-style: italic;
  pointer-events: none;
}

/* On a narrow phone the status label stays on one line, so the room keeps its height. */
@media (max-width: 400px) {
  html body #activity-chrome-status.site-shriversify {
    gap: 10px;
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* ---------- The guided first move: a ring, an arrow, a caption that waits ---------- */

.is-guided::after {
  content: '';
  position: absolute;
  inset: -5px;
  z-index: 2;
  border: 3px solid var(--ak-accent);
  border-radius: 12px;
  box-shadow: 0 0 0 2px var(--ak-ink), inset 0 0 0 2px var(--ak-ink);
  pointer-events: none;
}

.is-guided::before {
  content: '';
  position: absolute;
  z-index: 3;
  width: 34px;
  height: 40px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 34 40'%3E%3Cpath d='M17 38 L2 20 H11 V2 H23 V20 H32 Z' fill='%23FF5A1F' stroke='%23171311' stroke-width='3' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  pointer-events: none;
}

.is-guided[data-arrow="above"]::before {
  left: 50%;
  bottom: calc(100% + 10px);
  translate: -50% 0;
}

.is-guided[data-arrow="right"]::before {
  left: calc(100% + 10px);
  top: 50%;
  translate: 0 -50%;
  rotate: 90deg;
}

.is-guided[data-arrow=""]::before {
  content: none;
}

.is-guided[data-arrow="left"]::before {
  right: calc(100% + 8px);
  top: 50%;
  translate: 0 -50%;
  rotate: -90deg;
}

.is-guided[data-arrow="below"]::before {
  left: 50%;
  top: calc(100% + 10px);
  translate: -50% 0;
  rotate: 180deg;
}

/* ---------- Her page in the ending's keepsake and the chrome's ending, taped on ---------- */

#activity-chrome-ending.site-shriversify .ac-card {
  position: relative;
  rotate: -1.5deg;
}

#activity-chrome-ending.site-shriversify .ac-card::before,
#activity-chrome-ending.site-shriversify .ac-card::after {
  content: '';
  position: absolute;
  width: 92px;
  height: 26px;
  background: var(--tape);
  clip-path: polygon(3% 0, 97% 10%, 100% 100%, 0 90%);
}

#activity-chrome-ending.site-shriversify .ac-card::before {
  top: -10px;
  left: -18px;
  rotate: -32deg;
}

#activity-chrome-ending.site-shriversify .ac-card::after {
  top: -10px;
  right: -18px;
  rotate: 28deg;
}

#activity-chrome-ending.site-shriversify .ac-work {
  clip-path: var(--torn-scrap);
  border: 0;
}

/* The turned page always fits: it starts at the top when it is taller than the screen, never cut off. */
html body #activity-chrome-ending.site-shriversify {
  justify-content: safe center;
}

html body #activity-chrome-ending.site-shriversify .ac-work img {
  max-height: 22dvh;
  width: auto;
  margin: 0 auto;
}

/* The second line is the room's own: set apart, in ink. */
html body #activity-chrome-ending.site-shriversify .ac-line:nth-child(2) {
  color: var(--ak-ink);
}

@media (orientation: landscape) and (max-height: 560px) {
  html body #activity-chrome-ending.site-shriversify {
    padding: 10px 84px 10px 16px;
  }

  /* Sideways the page lies on its side: the words on the left, her page and the buttons on the right. */
  html body #activity-chrome-ending.site-shriversify .ac-card {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-areas: "number work" "verdict work" "lines actions";
    align-items: center;
    column-gap: 22px;
    width: min(100%, 760px);
    padding: 18px 22px 14px;
  }

  html body #activity-chrome-ending.site-shriversify .ac-number { grid-area: number; margin: 0; }
  html body #activity-chrome-ending.site-shriversify .ac-verdict { grid-area: verdict; margin: 0 0 6px; padding-bottom: 6px; font-size: 24px; }
  html body #activity-chrome-ending.site-shriversify .ac-lines { grid-area: lines; align-self: start; font-size: 15px; line-height: 1.35; }
  html body #activity-chrome-ending.site-shriversify .ac-work { grid-area: work; margin: 0; }
  html body #activity-chrome-ending.site-shriversify .ac-work img { max-height: 30dvh; }
  html body #activity-chrome-ending.site-shriversify .ac-actions { grid-area: actions; margin-top: 0; }
}

/* ---------- The opening: the letter itself, pinned over the dark room, sealed in orange wax ----------
   start.js draws this screen; these rules only dress its own parts for this room. */

#activity-start.site-shriversify.is-scene {
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background-color: var(--ak-ink);
}

#activity-start.site-shriversify.is-scene::before {
  background-image:
    radial-gradient(ellipse at center, color-mix(in srgb, var(--ak-ink) 55%, transparent) 30%, var(--ak-ink) 100%),
    url("./art/music-room.jpg");
  background-size: cover, cover;
  background-position: center, center;
}

#activity-start.site-shriversify.is-scene::after {
  display: none;
}

#activity-start.site-shriversify.is-scene .ak-scene {
  position: relative;
  justify-content: flex-start;
  gap: 18px;
  width: min(100%, 500px);
  min-height: 0;
  margin: 0 auto;
  padding: 40px 26px 24px;
  border: 1px solid var(--ak-outline);
  background-color: var(--ak-surface);
  background-image:
    radial-gradient(circle at 14% 22%, color-mix(in srgb, var(--ak-ink-muted) 14%, transparent) 0 18px, transparent 46px),
    radial-gradient(circle at 82% 64%, color-mix(in srgb, var(--ak-ink-muted) 11%, transparent) 0 26px, transparent 64px),
    radial-gradient(circle at 36% 90%, color-mix(in srgb, var(--ak-ink-muted) 10%, transparent) 0 12px, transparent 36px);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
  rotate: -0.8deg;
}

/* The pin that holds the letter up. */
#activity-start.site-shriversify.is-scene .ak-scene::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
  translate: -50% 0;
}

#activity-start.site-shriversify.is-scene .ak-scene .ak-head {
  width: 100%;
  padding-bottom: 14px;
  border-bottom: 3px double var(--ak-outline);
}

#activity-start.site-shriversify.is-scene .ak-scene .ak-logo {
  display: block;
  max-height: min(110px, 16dvh);
  width: auto;
  margin: 0 auto;
}

#activity-start.site-shriversify.is-scene .ak-scene-lines {
  gap: 12px;
  max-width: 34ch;
}

#activity-start.site-shriversify.is-scene .ak-scene-line {
  color: var(--ak-ink);
  font-size: clamp(17px, 2.6dvh, 21px);
  text-shadow: none;
}

#activity-start.site-shriversify.is-scene .ak-scene-line:last-child {
  color: var(--ak-ink-muted);
}

/* The wax seal you break to go in. */
#activity-start.site-shriversify.is-scene .ak-scene .ak-go {
  width: 112px;
  height: 112px;
  border: 3px solid var(--ak-btn-active);
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--ak-ink) 18%, transparent), 0 4px 10px rgba(0, 0, 0, 0.5);
  rotate: -6deg;
}

#activity-start.site-shriversify.is-scene .ak-scene .ak-jump {
  color: var(--ak-ink);
}

/* Sideways the letter lies on its side: the lines on the left, the seal on the right. */
@media (orientation: landscape) and (max-height: 560px) {
  #activity-start.site-shriversify.is-scene .ak-scene {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "head actions" "lines actions";
    align-items: center;
    column-gap: 28px;
    row-gap: 10px;
    width: min(100%, 760px);
    padding: 30px 28px 18px;
  }

  #activity-start.site-shriversify.is-scene .ak-scene .ak-head {
    grid-area: head;
    padding-bottom: 8px;
  }

  #activity-start.site-shriversify.is-scene .ak-scene .ak-logo {
    max-height: 56px;
  }

  #activity-start.site-shriversify.is-scene .ak-scene-lines {
    grid-area: lines;
    max-width: none;
    gap: 8px;
  }

  #activity-start.site-shriversify.is-scene .ak-scene-line {
    font-size: 17px;
  }

  #activity-start.site-shriversify.is-scene .ak-scene-actions {
    grid-area: actions;
  }
}

/* ---------- Motion: slow, and only when it is welcome ---------- */

@media (prefers-reduced-motion: no-preference) {
  #activity-start.site-shriversify.is-scene .scene-crawl .ak-scene-lines {
    animation: none;
  }

  :root:not(.ac-still) #activity-start.site-shriversify.is-scene .scene-crawl .ak-scene-line {
    animation: mr-ink 1.6s ease-out both;
    animation-delay: calc(0.3s + var(--ak-line, 0) * 0.9s);
  }

  #activity-start.site-shriversify.is-scene .scene-crawl .ak-scene-actions {
    animation-delay: 2.6s;
  }

  :root:not(.ac-still) .girl .cell {
    transition: opacity 1.6s ease-in-out, translate 1.6s ease-in-out;
  }

  :root:not(.ac-still) .girl .cell:not(.is-on) {
    translate: -50% 3%;
  }

  :root:not(.ac-still) .bench-lid {
    transition: opacity 0.6s ease, rotate 1.4s ease-out;
  }

  :root:not(.ac-still) .cab-open {
    transition: opacity 1.4s ease-in-out;
  }

  :root:not(.ac-still) .door-hall {
    transition: opacity 0.6s ease;
  }

  :root:not(.ac-still) .door-leaf {
    transition: transform 0.9s cubic-bezier(0.45, 0, 0.25, 1);
  }

  :root:not(.ac-still) .box-piece .cell {
    transition: opacity 1.2s ease;
  }

  :root:not(.ac-still) .taped-desk.is-new {
    animation: mr-tape-desk 1.4s ease-out both;
  }

  :root:not(.ac-still) .taped.is-new {
    animation: mr-tape 1.4s ease-out both;
  }

  :root:not(.ac-still) .item.is-new {
    animation: mr-drop 1.1s ease-out both;
  }

  :root:not(.ac-still) .closeup.is-new {
    animation: mr-paste 0.9s ease-out both;
  }

  :root:not(.ac-still) .page-scrap.is-fresh {
    transition: background-color 2.4s ease;
  }

  :root:not(.ac-still) .is-guided::after {
    animation: mr-ring 2.2s ease-in-out infinite alternate;
  }

  :root:not(.ac-still) .spot-label {
    transition: opacity 0.6s ease, visibility 0s linear 0.6s;
  }

  :root:not(.ac-still) .spot.is-picked .spot-label,
  :root:not(.ac-still) .play.is-holding .spot-label {
    transition: opacity 0.6s ease, visibility 0s;
  }

  :root:not(.ac-still) .slots li.is-fresh {
    animation: mr-settle 0.6s ease-out both;
  }

  :root:not(.ac-still) .key .press {
    transition: opacity 0.35s ease;
  }

  :root:not(.ac-still) .box-big.is-winding .crank-in {
    animation: mr-turn 1.8s linear infinite;
  }

  :root:not(.ac-still) .bars li::before {
    transition: opacity 0.5s ease, background-color 0.5s ease;
  }

  :root:not(.ac-still) .note-sung {
    animation: mr-settle 0.9s ease-out both;
    animation-delay: calc(var(--i, 0) * 180ms);
  }

  :root:not(.ac-still) .box-piece.is-playing {
    animation: mr-hum 0.9s ease-in-out 2;
  }

  :root:not(.ac-still) .item,
  :root:not(.ac-still) .hint-note {
    transition: translate 0.4s ease, rotate 0.4s ease;
  }
}

@keyframes mr-ink {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes mr-tape {
  from { opacity: 0; rotate: -4deg; translate: -50% 12px; }
  to { opacity: 1; rotate: 1.5deg; translate: -50% 0; }
}

@keyframes mr-tape-desk {
  from { opacity: 0; rotate: -3deg; }
  to { opacity: 1; rotate: 1.2deg; }
}

@keyframes mr-drop {
  from { opacity: 0; translate: 0 -48px; rotate: -10deg; }
  70% { opacity: 1; translate: 0 2px; }
  to { opacity: 1; translate: 0 0; rotate: var(--tilt, 2deg); }
}

@keyframes mr-paste {
  from { opacity: 0; rotate: -2deg; }
  to { opacity: 1; rotate: 1deg; }
}

@keyframes mr-ring {
  from { opacity: 0.55; inset: -4px; }
  to { opacity: 1; inset: -9px; }
}

@keyframes mr-turn {
  from { rotate: 0deg; }
  to { rotate: 360deg; }
}

@keyframes mr-settle {
  from { opacity: 0.2; translate: 0 -6px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes mr-hum {
  0%, 100% { rotate: 0deg; }
  50% { rotate: 1.5deg; }
}
