:root {
  color-scheme: dark;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  background: #181417;
  color: #f3deb5;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: radial-gradient(ellipse at 50% 40%, #352228 0%, #181417 64%);
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
canvas:focus-visible {
  outline: 2px solid #f1bc79;
  outline-offset: 4px;
}

.theatre {
  --theatre-art: url("./assets/theatre.jpg");
  --toolbar-size: min(12.5%, 47px);
  position: relative;
  width: min(100vw, 56.25vh, 530px);
  width: min(100vw, 56.25dvh, 530px);
  aspect-ratio: 9 / 16;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  background: #5c2830;
  box-shadow: 0 11px 54px #0d090bd9;
}

.scenery {
  position: absolute;
  inset: 0;
  background: var(--theatre-art) center / 100% 100% no-repeat;
}

.scenery::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 13.45%;
  background: linear-gradient(180deg, #39322a, #262022 91%, #4c3b33);
}

.stage-paper {
  position: absolute;
  inset: 13.1% 0 15.9%;
  background: var(--theatre-art) center 45.1724% / 112% 140.8451% no-repeat;
}

.stage-frame {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4.2%;
  background: var(--theatre-art) left top / 2380.95% 100% no-repeat;
}

.stage-frame-left { left: 0; }
.stage-frame-right { right: 0; transform: scaleX(-1); }

.has-wall-seam .stage-frame-left::after {
  content: "";
  position: absolute;
  top: 80.5%;
  left: 66%;
  width: 3px;
  height: 20px;
  background: linear-gradient(90deg, #211a1ee8 0 44%, #9a817ba3 48% 70%, #292025ae 74%);
  clip-path: polygon(0 0, 74% 0, 74% 43%, 100% 55%, 100% 100%, 26% 100%, 26% 58%, 0 44%);
}

.has-right-wall-seam .stage-frame-right::after,
.has-return-right .stage-frame-right::after,
.has-return-left .stage-frame-left::after {
  content: "";
  position: absolute;
  top: 43.3%;
  left: 66%;
  width: 3px;
  height: 20px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, #211a1ee8 0 44%, #9a817ba3 48% 70%, #292025ae 74%);
  clip-path: polygon(0 0, 74% 0, 74% 43%, 100% 55%, 100% 100%, 26% 100%, 26% 58%, 0 44%);
}

.has-return-right .stage-frame-right::after,
.has-return-left .stage-frame-left::after { top: clamp(15%, var(--return-position), 82.5%); }

.stage-number {
  position: absolute;
  z-index: 4;
  left: 4.6%;
  top: 1%;
  background: linear-gradient(123deg, #b89a6b, #e7c48d 42%, #cfab78);
  color: #32231c;
  display: grid;
  place-items: start center;
  width: 12%;
  height: 7.2%;
  border: 0;
  padding-top: 1%;
  font: 700 clamp(22px, 6.2dvh, 40px) / 1.12 Georgia, serif;
  font-size: min(6.7vw, 4dvh, 36px);
  text-shadow: 0 1px #f2d7ab8c;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 81%, 0 100%);
}

.backstage .stage-number span { transform: scaleX(-1); }

.stage-number:focus-visible { box-shadow: inset 0 0 0 3px #6c462e; }

.toolbar-button {
  position: absolute;
  top: .6%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: var(--toolbar-size);
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 4px;
  background: transparent;
  color: #e9cda1;
  font: clamp(17px, 3.05dvh, 25px) / 1 Georgia, serif;
  text-shadow: 0 2px 2px #1a1216;
}

.restart-stage { left: 17.6%; }
.settings-open { right: 4.3%; }
.help-open { right: calc(5.3% + var(--toolbar-size)); }
.settings-open svg {
  width: 69%;
  aspect-ratio: 1;
  filter: drop-shadow(0 2px 2px #1a1216);
}

.attempts {
  display: flex;
  gap: 5px;
}

.attempts i {
  width: clamp(6px, 1.45dvh, 11px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #edd0a1, #c99c69);
  box-shadow: 0 2px 3px #150d10ae, inset 0 1px #ffefd39e;
  transition: background-color .2s, opacity .2s, transform .2s;
}

.attempts .spent {
  opacity: .32;
  transform: scale(.82);
  background: #382225;
  box-shadow: inset 0 0 0 1px #deb78d;
}

.playing-area {
  position: absolute;
  inset: 13.1% 4.2% 15.9%;
  touch-action: none;
  -webkit-touch-callout: none;
}

.playing-area::before {
  content: "";
  position: absolute;
  top: -5px;
  left: -1px;
  right: -1px;
  height: 6px;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(#62514d, #332d2c 24%, #262123 82%);
  box-shadow: 0 2px 3px #271419a8;
}

.curtain-tie:not([hidden]) {
  position: absolute;
  z-index: 2;
  top: -6%;
  left: var(--curtain-tie-x);
  width: clamp(.8px, .17dvh, 1.5px);
  height: calc(6% + 1px);
  transform: translateX(-50%);
  background-color: #b2987472;
  pointer-events: none;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.paper-target {
  position: absolute;
  z-index: 2;
  top: 1.7%;
  left: 58.5%;
  display: grid;
  place-items: center;
  width: 10%;
  height: 5.6%;
  padding: 0;
  background: transparent;
  border: 0;
}

.paper-target[hidden] { display: none; }

.paper-target img:not(.paper-target-glyph) {
  grid-area: 1 / 1;
  width: clamp(16px, 3.1dvh, 27px);
  filter: drop-shadow(1px 2px 1px #271519c7);
}

.paper-target .paper-target-glyph {
  grid-area: 1 / 1;
  width: clamp(8px, 1.5dvh, 13px);
  z-index: 1;
  pointer-events: none;
}

.paper-target[aria-pressed="true"] img:not(.paper-target-glyph) {
  filter: drop-shadow(0 0 4px #ffbe7aac);
}

.curtains {
  position: absolute;
  z-index: 3;
  inset: 0 0 auto;
  height: 13.4%;
  pointer-events: none;
  filter: drop-shadow(0 3px 2px #261a1bbf);
}

.curtains::before {
  content: "";
  position: absolute;
  inset: -1px 0 auto;
  height: 3px;
  background: #4e4137;
  box-shadow: inset 0 1px #74604e;
}

.curtain-panel {
  display: block;
  position: absolute;
  top: 0;
  width: 50.35%;
  height: 100%;
  transition: transform .55s cubic-bezier(.24,.78,.32,1);
}

.curtain-panel:first-child { left: 0; transform-origin: left top; }
.curtain-panel:last-child { right: 0; transform-origin: right top; }

.curtain-open .curtain-panel { transform: translateY(-4%) scaleX(.33); }

.backstage .curtains { visibility: visible; }

.clear-recall {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: min(13%, 46px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: transparent;
}

.clear-recall[hidden] { display: none; }

.clear-recall::after {
  content: "";
  width: clamp(10px, 2dvh, 15px);
  aspect-ratio: 1;
  transform: rotate(45deg);
  background: #e0b77b;
  border: 1px solid #bf9863;
  box-shadow: 0 0 8px #f0c58370;
}

.status {
  position: absolute;
  inset: auto 0 8%;
  display: block;
  width: max-content;
  max-width: 96%;
  margin: auto;
  padding: .45em .7em;
  pointer-events: none;
  border-radius: 3px;
  background-color: #271b1ce8;
  font-size: clamp(12px, 2dvh, 17px);
  text-align: center;
}

.status:empty { display: none; }

.controls {
  position: absolute;
  inset: 85.4% 22.55% 2.8%;
  display: grid;
  grid-template-columns: 1.28fr 1.65fr 1.28fr;
  align-items: center;
  justify-items: center;
}

.controls button {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 34px;
  min-height: 34px;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  touch-action: none;
  -webkit-touch-callout: none;
}

.reverse-group {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
  justify-items: center;
  align-items: center;
}

.controls .reverse {
  z-index: 1;
  width: 91%;
  height: 100%;
  border-radius: 9%;
  background: linear-gradient(118deg, #d9b484, #e9c997 55%, #cfa574);
  color: #332720;
  border: 1px solid #e8c99b;
  box-shadow: 0 5px 0 #77583e, 0 7px 10px #150e10;
}

.reverse img {
  width: 47%;
  height: 69%;
  object-fit: contain;
}

.reverse:active,
.reverse.pressed {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #77583e, 0 4px 6px #150e10;
}

.reverse.unavailable {
  opacity: .64;
}

.triangle {
  width: 44%;
  height: 44%;
  background: linear-gradient(140deg, #ffe0aa, #c7a071);
  filter: drop-shadow(2px 2px 1px #2b1a17);
  clip-path: polygon(10% 2%, 97% 50%, 10% 98%);
}

.triangle.left { transform: scaleX(-1); }
.direction:active .triangle,
.direction.pressed .triangle { filter: brightness(1.24); }

dialog {
  width: min(87vw, 360px);
  max-height: 84dvh;
  padding: 0;
  color: #362725;
  border: 1px solid #a67c61;
  border-radius: 4px;
  background-color: #ecce9f;
  background-image: radial-gradient(ellipse at 25% 13%, #f8dfb5, #dfb887 145%);
  box-shadow: 0 5px 0 #6c4e3d, 0 16px 36px #1a1015a8;
}

dialog::backdrop { background: #221619b5; }

.dialog-inner {
  padding: 26px clamp(19px, 6vw, 32px) 25px;
}

.dialog-inner h1,
.dialog-inner h2 {
  margin: 0 0 .65em;
  font-size: clamp(21px, 5.6vw, 28px);
  font-weight: 750;
  letter-spacing: .025em;
}

.dialog-inner p {
  margin: 0 0 .65em;
  line-height: 1.65;
  font-size: 15px;
}

.close {
  float: right;
  margin: 3px;
  color: #593b37;
  width: 39px;
  height: 39px;
  background: transparent;
  border: 0;
  font: 26px / 1 sans-serif;
}

.paper-button {
  display: block;
  min-height: 42px;
  padding: 8px 18px;
  margin: 18px auto 2px;
  color: #ffe5b7;
  letter-spacing: .03em;
  background: #583138;
  border: 1px solid #49272e;
  border-radius: 3px;
  box-shadow: 0 3px #3f2529;
}

.paper-button[hidden] { display: none; }

.share {
  text-decoration: none;
  background-color: #1e181a;
  color: #fff7e7;
  width: max-content;
  margin-top: 14px;
}

.sound-settings {
  display: grid;
  grid-template-columns: auto auto minmax(56px, 1fr);
  gap: .65em;
  align-items: center;
  padding-bottom: .55em;
  font-size: 14px;
}

.sound-toggle {
  min-height: 42px;
  border: 1px solid #8c6547;
  border-radius: 4px;
  background: #ebcb98;
}

.sound-toggle[aria-pressed="true"] { background: #583138; color: #ffe4ba; }
.sound-settings input { width: 100%; min-height: 38px; touch-action: manipulation; accent-color: #71444b; }
.menu-link {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: .65em 0;
  text-align: left;
  text-decoration: none;
  border: 0;
  border-top: 1px solid #8c654747;
  background: transparent;
  color: #41292b;
}
.menu-link small { display: block; margin-top: .3em; font-size: 12px; line-height: 1.5; }
.dialog-inner .menu-note { margin: .8em 0 0; font-size: 12px; color: #6f4b3c; }
.dialog-actions { display: flex; gap: 12px; }
.record-output dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: .65em .8em;
  margin: 1em 0;
}
.record-output dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.stage-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 12px 0 2px;
}

.stage-choices .paper-button {
  width: 100%;
  padding: 8px;
  margin: 0;
  font: 700 22px / 1 Georgia, serif;
}

.stage-choices .paper-button[aria-current="step"] {
  box-shadow: inset 0 0 0 1px #eaca97, 0 3px #3f2529;
}

.stage-choices .paper-button:disabled {
  opacity: .42;
  cursor: default;
}

.hidden-stage-choice span { display: inline-block; transform: scaleX(-1); }
.stage-choices .hidden-stage-choice { grid-row: 2; }
.hidden-stage-choice[data-hidden-stage="0"] { grid-column: 1; }
.hidden-stage-choice[data-hidden-stage="1"] { grid-column: 2; }
.hidden-stage-choice[data-hidden-stage="2"] { grid-column: 3; }

#curtainCall { text-align: center; }
.clear-star { color: #9c632e; display: block; font-size: 29px; }
.dialog-inner .clear-number { color: #6e463a; letter-spacing: .15em; font: 700 11px / 1.7 Georgia, serif; }

@media (prefers-reduced-motion: reduce) {
  .attempts i, .curtain-panel { transition: none; }
}
