.escape-shell {
  --quest-brass: #e7bf79;
  --quest-tone: #4c392c;
  --quest-ink: #37251a;
}

.escape-shell[data-era="moyen-age"] { --quest-brass: #e3b883; --quest-tone: #523344; }
.escape-shell[data-era="renaissance"] { --quest-brass: #c7d6aa; --quest-tone: #274642; }
.escape-shell[data-era="baroque"] { --quest-brass: #f0bc88; --quest-tone: #55342c; }
.escape-shell[data-era="classicisme"] { --quest-brass: #cbd8ed; --quest-tone: #304360; }
.escape-shell[data-era="romantisme"] { --quest-brass: #f1bec4; --quest-tone: #563449; }
.escape-shell[data-era="modernites"] { --quest-brass: #d9c7f4; --quest-tone: #3b3d60; }
.escape-shell[data-era="interpretes"] { --quest-brass: #dec1ed; --quest-tone: #473656; }
.escape-shell[data-era="jazz"] { --quest-brass: #f5c77e; --quest-tone: #64422a; }
.escape-shell[data-era="trad"] { --quest-brass: #b9dbc1; --quest-tone: #344c3c; }

.escape-shell .locks { grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.3fr); }
.escape-shell .lock { flex-direction: column; gap: 4px; }
.escape-shell .lock span { display: block; font-size: clamp(9px, .7vw, 12px); text-align: center; line-height: 1; }
.escape-shell .lock::after { content: none; }
.escape-shell .lock.unlocked { border-color: #638e75; }

.lock-symbol {
  position: relative;
  width: 21px;
  height: 10px;
  margin-top: 4px;
  border: 1px solid currentColor;
  border-radius: 2px;
}

.lock-symbol::before {
  position: absolute;
  inset: -5px -1px auto;
  height: 5px;
  border: 1px solid currentColor;
  border-radius: 5px 5px 0 0;
  content: "";
}

.lock.open .lock-symbol::before, .lock.unlocked .lock-symbol::before {
  transform: translateY(-2px) rotate(-14deg);
  transform-origin: left bottom;
}

.lock[data-prop="door"] .lock-symbol {
  width: 17px;
  height: 21px;
  margin: 0;
  border-width: 2px 2px 1px;
  border-radius: 9px 9px 1px 1px;
}

.lock[data-prop="door"] .lock-symbol::before { content: none; }
.lock[data-prop="door"] .lock-symbol::after {
  position: absolute;
  inset: 2px 3px 0;
  border: 1px solid currentColor;
  border-radius: 5px 5px 0 0;
  content: "";
}
.lock[data-prop="door"].unlocked .lock-symbol::after {
  background: currentColor;
  opacity: .5;
}

.key-rack {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #d9d5c9;
  border-radius: 10px;
  background: #f7f4eb;
}

.key-rack-count {
  color: #514333;
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.key-slots {
  display: flex;
  align-items: center;
  gap: 1px;
  width: min(100%, 157px);
  min-height: 30px;
}

.key-slot { color: #bcb29f; }
.key-slot .key-part { color: currentColor; }
.key-slot.collected { color: #785022; }
.key-slot:nth-child(2) { flex: 1; }
.key-slot .key-part[data-part="1"] { width: 29px; height: 29px; border-width: 6px; }
.key-slot .key-part[data-part="2"] { width: 100%; height: 8px; border-radius: 1px; }
.key-slot .key-part[data-part="3"] { width: 12px; height: 17px; border-width: 4px; }
.key-slot .key-part[data-part="4"] { width: 25px; height: 19px; transform: translateY(5px); }

.key-part {
  position: relative;
  display: block;
  width: 17px;
  height: 12px;
  color: #b5843d;
}

.key-part[data-part="1"] {
  width: 13px;
  height: 13px;
  border: 3px solid currentColor;
  border-radius: 50%;
}
.key-part[data-part="2"] { height: 5px; margin-block: 4px; border-radius: 3px; background: currentColor; }
.key-part[data-part="3"] {
  width: 10px;
  height: 13px;
  border: 2px solid currentColor;
  border-inline-width: 3px;
  border-radius: 3px;
}
.key-part[data-part="4"] {
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 100% 87%, 76% 87%, 76% 48%, 58% 48%, 58% 100%, 32% 100%, 32% 44%, 0 44%);
}

.escape-collect {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}
.escape-collect:has([data-escape-next][hidden]) { display: none; }
.escape-collect .primary { min-height: 42px; padding: 8px 12px; }
.escape-collect .primary:focus-visible { outline-offset: 3px; }

.treasure-finale { display: grid; gap: 14px; width: 100%; }
.treasure-stage { text-align: center; }
.treasure-stage > p { margin-bottom: 0; }
.treasure-reward {
  min-width: 0;
  padding: clamp(12px, 2vw, 28px);
  border: 1px solid #d8c39a;
  border-radius: 13px;
  background: #fff9ed;
  color: #2c3240;
  text-align: left;
}
.reward-layout {
  display: grid;
  grid-template-columns: clamp(58px, 10vw, 146px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(10px, 1.3vw, 21px);
}
.reward-image { background: #eee2ce; border-color: #ded0b7; }
.reward-image img { aspect-ratio: 4 / 5; object-fit: contain; }
.reward-image .zoom-badge { display: none; }
.treasure-reward h3 { margin: 7px 0 2px; color: #2a3445; font-size: clamp(20px, 2.2vw, 36px); line-height: 1.1; }
.treasure-reward p { margin: 6px 0 8px; color: #4f4d49; font-size: 14px; }
.treasure-reward .reward-author { margin-top: 0; color: #6c4b25; font-weight: 750; }
.reward-challenge {
  margin: 9px 0 11px;
  padding: 7px 10px;
  border-left: 3px solid #c49d65;
  border-radius: 0 6px 6px 0;
  background: #f5ebd8;
  color: #5c431f;
}
.reward-challenge strong { font-size: 12px; }
.reward-challenge p { margin: 2px 0 0; }
.reward-score { margin-top: 12px; }
.reward-score summary { width: fit-content; cursor: pointer; color: #173f70; font-size: 13px; font-weight: 800; }
.reward-score .music-box { margin-top: 8px; }
.victory-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

@media (max-width: 760px) {
  .escape-shell .lock { height: 37px; }
  .escape-shell .escape-header h1 { font-size: clamp(22px, 6.5vw, 29px); }
  .escape-shell .escape-header p { margin-top: 4px; }
  .key-rack { padding-block: 6px; }
  .escape-shell.escape-complete { display: block; }
  .escape-collect .primary { flex: 1; }
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
  .escape-shell .escape-header { gap: 10px; padding: clamp(15px, 1.7vw, 28px); }
  .escape-header .archive-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(59px, 7vw, 114px);
    gap: clamp(8px, 1.3vw, 20px);
    align-items: center;
    width: 100%;
  }
  .escape-header h1 { margin: 7px 0; font-size: clamp(27px, 2.7vw, 46px); }
  #app .escape-header .eyebrow { max-width: 100%; white-space: normal; color: var(--quest-brass); }
  .escape-header .archive-art::after {
    background: linear-gradient(130deg, #101825f5, color-mix(in srgb, var(--quest-tone) 74%, transparent) 58%, #101825f7);
  }
  .archive-portrait[hidden] {
    display: block !important;
    padding: 4px;
    border: 1px solid var(--quest-brass);
    border-radius: 8px;
    background: #121a27;
    box-shadow: 0 4px 16px #03060b80;
  }
  .archive-portrait img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    object-position: center 22%;
    border-radius: 4px;
  }
  .archive-stage[hidden] {
    position: relative;
    display: grid !important;
    place-items: center;
    flex: 1;
    width: 100%;
    min-height: clamp(110px, 19vh, 185px);
    padding-top: 18px;
  }
  .archive-stage::before {
    position: absolute;
    inset: 35% 4% -8%;
    content: "";
    background: radial-gradient(ellipse at center, color-mix(in srgb, var(--quest-brass) 34%, transparent), transparent 65%);
    pointer-events: none;
  }
  .archive-stage .archive-chest { width: clamp(120px, 11vw, 173px); }
  .archive-key {
    position: absolute;
    z-index: 3;
    width: 58px;
    height: 24px;
    color: #ffe0a1;
    filter: drop-shadow(0 2px 3px #25190c);
    pointer-events: none;
  }
  .archive-key::before {
    position: absolute;
    inset: 2px auto auto 0;
    width: 20px;
    height: 20px;
    border: 5px solid currentColor;
    border-radius: 50%;
    content: "";
  }
  .archive-key::after {
    position: absolute;
    inset: 6px 0 2px 17px;
    background: currentColor;
    clip-path: polygon(0 20%, 100% 20%, 100% 100%, 83% 100%, 83% 67%, 73% 67%, 73% 93%, 58% 93%, 58% 58%, 0 58%);
    content: "";
  }
  .chest-key { top: 42%; left: 16%; opacity: 0; transform-origin: right center; }
  .chest-fragment {
    position: absolute;
    z-index: 2;
    top: 2%;
    left: calc(50% - 8px);
    opacity: 0;
    color: #ffe6a2;
    transform: translateY(-11px) scale(1.75);
    filter: drop-shadow(0 0 4px #f4b85d);
  }
  .chest-sparks {
    position: absolute;
    z-index: 2;
    inset: -52% -32% 30%;
    background:
      radial-gradient(circle at 15% 58%, #ffe6ae 0 2px, transparent 3px),
      radial-gradient(circle at 33% 30%, #ffd57c 0 2px, transparent 3px),
      radial-gradient(circle at 49% 12%, #ffe6ae 0 3px, transparent 4px),
      radial-gradient(circle at 62% 49%, #fff4cb 0 2px, transparent 3px),
      radial-gradient(circle at 73% 18%, #ffd57c 0 2px, transparent 3px),
      radial-gradient(circle at 85% 52%, #ffe6ae 0 2px, transparent 3px);
    opacity: 0;
    pointer-events: none;
  }
  .is-unlocking .chest-lid { transform: translateY(-16%) rotate(-17deg); }
  .is-unlocking .chest-fragment, .is-unlocking .chest-glow { opacity: 1; }
  .key-rack {
    padding: 9px 11px;
    margin: 0;
    border-color: color-mix(in srgb, var(--quest-brass) 48%, #212c3b);
    background: #111a27ec;
  }
  .key-rack-count { color: #f2e6cd; font-size: 13px; }
  .key-slot { color: #6c716f; }
  .key-slot.collected { color: var(--quest-brass); filter: drop-shadow(0 1px 4px #e9bd5342); }
  .escape-shell .lock[data-prop="door"] { color: var(--quest-brass); }
  .escape-shell .puzzle-footer .feedback { min-height: 48px; }
  .escape-shell .puzzle-footer:has([data-escape-next]:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
  }
  .escape-collect {
    display: grid;
    justify-items: stretch;
    gap: 3px;
    text-align: center;
  }
  .escape-collect .primary {
    background: #e8c584;
    color: #32271c;
    border-color: #c59a57;
  }
  .escape-collect .primary:hover { background: #f3d79f; }
  .escape-shell.escape-complete { min-height: 0; }
  .escape-shell .victory {
    display: grid;
    align-content: center;
    gap: 13px;
    min-height: min(630px, calc(100dvh - 145px));
    padding: clamp(18px, 3vw, 45px);
  }
  .treasure-finale {
    grid-template-columns: minmax(230px, .82fr) minmax(0, 1.18fr);
    gap: clamp(16px, 2.6vw, 42px);
    align-items: center;
  }
  .treasure-stage { display: grid; justify-items: center; padding: 15px 0 12px; }
  .treasure-stage > p { color: #f2e9db; font-size: 16px; }
  .treasure-stage h2 { margin: 0 0 4px; color: #ffe2a5; font-size: clamp(34px, 4.2vw, 62px); }
  .treasure-reward .chip { border-color: #d2c5ad; background: #f5ead4; color: #594628; }
  .treasure-reward .chip .glossary-term { color: #694f27; border-color: #98764c; }
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) and (max-height: 740px) {
  .archive-stage[hidden] { min-height: 100px; padding-top: 10px; }
  .archive-stage .archive-chest { width: clamp(100px, 10vw, 136px); }
  .escape-header .archive-portrait { max-width: 74px; justify-self: end; }
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .is-unlocking .chest-key { animation: quest-key-turn .56s ease-in-out both; }
  .is-unlocking .chest-lid { animation: quest-lid .48s .35s ease-out both; }
  .is-unlocking .chest-glow { animation: quest-glow .65s .36s ease-out both; }
  .is-unlocking .chest-fragment { animation: quest-fragment .65s .44s cubic-bezier(.18,.7,.33,1) both; }
  .chest-fragment[data-part="1"] { --fragment-turn: -190deg; --fragment-shift: -15px; }
  .chest-fragment[data-part="2"] { --fragment-turn: 105deg; --fragment-shift: 23px; }
  .chest-fragment[data-part="3"] { --fragment-turn: -85deg; --fragment-shift: -28px; }
  .chest-fragment[data-part="4"] { --fragment-turn: 235deg; --fragment-shift: 12px; }
  .is-unlocking .chest-sparks { animation: quest-sparks .85s .4s ease-out both; }
  .is-unlocking .escape-collect { animation: quest-reveal .28s ease-out both; }
  .key-slot.latest { animation: quest-fragment-seat .42s ease-out both; }
  [data-escape-step="5"] .key-slot { animation: quest-fragment-seat .7s ease-out both; }
  [data-escape-step="5"] .key-slot:nth-child(2) { animation-delay: .07s; }
  [data-escape-step="5"] .key-slot:nth-child(3) { animation-delay: .14s; }
  [data-escape-step="5"] .key-slot:nth-child(4) { animation-delay: .21s; }
  .joined-key { animation: quest-key-assemble .72s .25s ease-out both; }
  .victory .treasure-reward { animation: quest-reveal .46s .72s ease-out both; }
}

@keyframes quest-key-turn {
  0% { opacity: 0; transform: translate(-44px, -18px) rotate(-30deg); }
  45% { opacity: 1; transform: translate(-10px, 0); }
  67% { opacity: 1; transform: translate(2px, 2px) rotate(14deg); }
  100% { opacity: 0; transform: translate(2px, 2px) rotate(14deg); }
}
@keyframes quest-lid { from { transform: none; } }
@keyframes quest-glow { from { opacity: 0; transform: scale(.42); } }
@keyframes quest-fragment {
  from { opacity: 0; transform: translate(var(--fragment-shift), 25px) scale(.55) rotate(var(--fragment-turn)); }
}
@keyframes quest-sparks {
  0% { opacity: 0; transform: translateY(12px) scale(.52); }
  33% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-22px) scale(1.18); }
}
@keyframes quest-reveal { from { opacity: 0; transform: translateY(7px); } }
@keyframes quest-fragment-seat {
  40% { transform: translateY(-3px); filter: drop-shadow(0 0 6px #f3d48b); }
}
@keyframes quest-key-assemble {
  0% { opacity: 0; transform: translate(-30px, 18px) rotate(-95deg) scale(.65); }
  70% { opacity: 1; transform: rotate(-20deg) scale(1.43); }
}
