[data-pickup-magpie-key],
[data-unlock-magpie-chest],
.shelf-chest-open {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.magpie-key[data-pickup-magpie-key] { pointer-events: auto; }
.shelf-chest[data-unlock-magpie-chest] { pointer-events: auto; }
[data-pickup-magpie-key] img,
[data-unlock-magpie-chest] img,
.shelf-chest-open img {
  display: block;
  width: 100%;
  height: auto;
}
[data-pickup-magpie-key]::before {
  content: '';
  position: absolute;
  inset: -8px;
}
[data-magpie-puzzle="collected"] [data-pickup-magpie-key],
[data-magpie-puzzle="opened"] [data-pickup-magpie-key],
[data-magpie-puzzle="opened"] [data-unlock-magpie-chest] { display: none; }
.shelf-chest-open {
  display: none;
  margin-bottom: .6%;
  clip-path: polygon(2.2% .8%, 98.2% .8%, 99.7% 12%, 94.4% 45%, 99.7% 64%, 99.7% 98%, 98.5% 99.4%, 1.2% 99.4%, .5% 98%, .5% 64%, 6% 45%, .4% 13%);
}
[data-magpie-puzzle="opened"] .shelf-chest-open { display: block; }

.key-inventory,
.key-status {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  z-index: 18;
  box-sizing: border-box;
  border: 1px solid #ad915d;
  border-radius: 5px;
  background: #22281fed;
  color: #f2e9d7;
  font: .87rem/1.3 Georgia, serif;
}
.key-inventory {
  top: 50%;
  transform: translateY(-50%);
  padding: 8px;
  text-align: center;
}
.key-inventory button {
  display: block;
  width: 48px;
  min-height: 44px;
  margin: 5px auto 0;
  padding: 5px;
  border: 1px solid #aa926d80;
  border-radius: 3px;
  background: #0f150eb0;
  cursor: pointer;
}
.key-inventory button[aria-pressed="true"] { border-color: #ffdfa2; background: #695331; }
.key-inventory button:disabled { opacity: .72; cursor: default; }
.key-inventory img { display: block; width: 100%; height: auto; }
.key-status {
  bottom: max(64px, env(safe-area-inset-bottom));
  max-width: min(22rem, calc(100% - 24px));
  margin: 0;
  padding: 8px 12px;
  pointer-events: none;
}
.key-status:empty { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); }
.key-cursor {
  position: fixed;
  z-index: 19;
  width: 45px;
  height: auto;
  transform: translate(9px, 9px) rotate(-23deg);
  filter: drop-shadow(0 1px 2px #140e08);
  pointer-events: none;
}
[data-pickup-magpie-key]:focus-visible,
[data-unlock-magpie-chest]:focus-visible,
.key-inventory button:focus-visible {
  outline: 2px solid #f8dc91;
  outline-offset: 4px;
}
body.reading .key-inventory,
body.reading .key-cursor { display: none; }

.shelf-chest.shelf-chest-open { pointer-events: auto; }
.shelf-chest-open:hover { filter: brightness(1.08) drop-shadow(1px 3px 2px #1a100cd0); }
.shelf-chest-open:focus-visible { filter: brightness(1.25) drop-shadow(0 0 4px #f8dc91); }
.shelf-chest-open::after {
  content: '';
  position: absolute;
  left: 28%;
  top: 48%;
  width: 44%;
  height: 12%;
  border-radius: 12% / 38%;
  background:
    linear-gradient(90deg, #3a2115 0 12%, transparent 14% 86%, #3a2115 88%),
    linear-gradient(#4d2e18a0, transparent 32% 63%, #362011b8),
    repeating-linear-gradient(90deg, #996a37 0 3%, #e6ca94 4% 17%);
  box-shadow: 0 2px 4px #170d07;
}

.cryptex-dialog {
  --brass: linear-gradient(#654324, #c69756 10%, #60401f 24%, #3c2718 43%, #a17340 53%, #5e3b20 72%, #c39657 88%, #442916);
  box-sizing: border-box;
  width: min(36rem, calc(100% - 1.5rem));
  padding: clamp(12px, 4vw, 27px);
  border: 1px solid #b79359;
  border-radius: 8px;
  background: radial-gradient(ellipse at 45% 30%, #543820, #2e2118 75%);
  color: #f4e6ca;
  box-shadow: 0 16px 62px #110a06cc, inset 0 0 24px #170d08a0;
  font: 1rem/1.4 Georgia, serif;
}
.cryptex-dialog::backdrop { background: #130e0ad1; }
.cryptex-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
}
.cryptex-dialog h2 { margin: 0; font: bold clamp(1.25rem, 5vw, 1.65rem)/1.2 Georgia, serif; }
.cryptex-close {
  padding: .45rem .7rem;
  border: 1px solid #b79359;
  border-radius: 4px;
  color: inherit;
  background: #38291c;
  font: inherit;
  cursor: pointer;
}
.cryptex-instructions { margin: .75rem 0 0; color: #e0cca8; }
.cryptex-stage { padding: 1.55rem 0 1.35rem; }
.cryptex {
  display: flex;
  place-items: center;
  width: 84%;
  max-width: 26rem;
  height: clamp(77px, 23vw, 126px);
  margin: auto;
  filter: drop-shadow(0 8px 8px #180e08);
}
.cryptex-body {
  display: flex;
  align-items: center;
  flex: 1;
  height: 100%;
  min-width: 0;
  transition: transform .55s ease;
}
.cryptex-cap {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 14%;
  height: 100%;
  box-sizing: border-box;
  border: 3px double #b7894b;
  border-radius: 36% 10% 10% 36% / 24% 7% 7% 24%;
  color: #e5bc7f;
  background:
    repeating-linear-gradient(135deg, #140c0540 0 2px, transparent 2px 6px),
    var(--brass);
  font: bold clamp(1rem, 5vw, 1.7rem)/1 Georgia, serif;
  text-shadow: 0 1px 2px #190e07;
}
.cryptex-cap-right {
  flex-basis: 12%;
  z-index: -1;
  border-radius: 10% 36% 36% 10% / 7% 24% 24% 7%;
  transition: transform .55s ease;
}
.cryptex-cap-right::before {
  content: '';
  position: absolute;
  top: 22%;
  right: 98%;
  width: 160%;
  height: 56%;
  border-radius: 5px 0 0 5px;
  box-shadow: inset 3px 0 4px #1d1008;
  background: linear-gradient(#593a22, #b98d52 21%, #dbc18b 48%, #73502c 94%);
}
.cryptex-wheels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  flex: 1;
  gap: 2px;
  height: 92%;
  padding: 0 2px;
  border-radius: 3px;
  background: var(--brass);
}
.cryptex-wheel {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  align-items: stretch;
  min-width: 0;
  padding: 0;
  border: 1px solid #6f512d;
  border-radius: 4px / 9px;
  color: #352417;
  background: linear-gradient(#896c4d, #e6d5ae 23%, #fcf1d4 49%, #e8d4ae 76%, #896c4d);
  font: bold clamp(.76rem, 4.7vw, 1.55rem)/1 Georgia, serif;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}
.cryptex-wheel span {
  display: grid;
  place-items: center;
  pointer-events: none;
}
.cryptex-wheel span:nth-child(2) {
  border-block: 1px solid #977747;
  background: #ffedbb65;
  color: #241509;
}
.cryptex-wheel span:first-child,
.cryptex-wheel span:last-child { opacity: .76; font-size: .8em; }
.cryptex-wheel:focus-visible,
.cryptex-close:focus-visible { outline: 2px solid #ffde94; outline-offset: 3px; z-index: 1; }
.cryptex-wheel:disabled { cursor: default; opacity: 1; }
.cryptex-dialog.is-open .cryptex-body { transform: translateX(-6%); }
.cryptex-dialog.is-open .cryptex-cap-right { transform: translateX(56%); }
.cryptex-dialog.is-open .cryptex-instructions { display: none; }
.cryptex-note {
  width: fit-content;
  box-sizing: border-box;
  margin: 0 auto .35rem;
  padding: .9rem 1.2rem;
  color: #362315;
  background: radial-gradient(ellipse at 40% 40%, #f9eacc, #dabb83);
  box-shadow: 1px 5px 9px #150d07b0, inset 0 0 8px #9c6b4b60;
  font: italic 1.13rem/1.45 Georgia, serif;
  text-align: center;
  animation: cryptex-reveal .45s .3s both;
}
.cryptex-note:focus { outline: none; }
@keyframes cryptex-reveal {
  from { opacity: 0; transform: translateY(-.7rem); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .cryptex-body, .cryptex-cap-right { transition: none; }
  .cryptex-note { animation: none; }
}

html:not([data-cryptex-tried]) .cryptex-question { display: none; }
