:root {
  color-scheme: dark;
  --bg: #131c23;
  --panel: #1c2932;
  --ink: #f3eee4;
  --muted: #a9b7be;
  --gold: #e8ba76;
  --line: #40505b;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: radial-gradient(ellipse at top, #24333e, var(--bg) 70%);
  color: var(--ink);
  font:
    16px/1.6 system-ui,
    sans-serif;
  min-height: 100vh;
}
header {
  max-width: 850px;
  margin: auto;
  padding: 25px 24px;
  display: flex;
  justify-content: space-between;
  letter-spacing: 0.22em;
  font-size: 13px;
}
a {
  color: inherit;
  text-decoration: none;
}
header span {
  color: var(--muted);
}
main {
  max-width: 740px;
  margin: 20px auto;
  padding: 0 22px;
  text-align: center;
}
h1 {
  font:
    normal clamp(32px, 6vw, 46px)/1.2 Georgia,
    serif;
  margin: 10px 0 14px;
}
p {
  color: var(--muted);
  max-width: 510px;
  margin: 10px auto 24px;
}
.eyebrow {
  color: var(--gold);
  letter-spacing: 0.2em;
  font-size: 12px;
  text-transform: uppercase;
}
.surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  margin: 24px auto;
  box-shadow: 0 16px 60px #0003;
}
button,
input {
  font: inherit;
}
button,
.button {
  border: 1px solid var(--line);
  background: #273a46;
  color: var(--ink);
  padding: 11px 20px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 46px;
}
button:hover {
  border-color: var(--gold);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}
.primary,
.next {
  background: var(--gold);
  color: #19212a;
  border: 0;
}
.next {
  display: inline-block;
  margin: 18px;
}
.status {
  min-height: 28px;
  color: var(--gold);
  margin-top: 16px;
}
input {
  background: #111c23;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 12px;
  width: 180px;
  text-align: center;
  letter-spacing: 0.2em;
}
form {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
footer {
  text-align: center;
  color: #82929a;
  font: italic 16px Georgia;
  padding: 35px;
}
.row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.key-board {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 30px 0;
}
.slot {
  padding: 0;
  width: 90px;
  height: 95px;
  border: 2px dashed var(--line);
}
.key-parts button {
  padding: 0;
  width: 90px;
  height: 95px;
}
.selected {
  outline: 2px solid var(--gold);
}
svg {
  max-width: 100%;
}
.photo {
  position: relative;
  aspect-ratio: 1;
  max-width: 440px;
  margin: auto;
  background: #3b2924;
}
.photo img,
.photo canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo canvas {
  touch-action: none;
}
.books {
  display: flex;
  height: 265px;
  align-items: end;
  justify-content: center;
  gap: 3px;
  margin-bottom: 20px;
}
.book {
  position: relative;
  width: 12%;
  height: 235px;
  border: 1px solid #ffffff35;
  border-radius: 5px 5px 2px 2px;
  padding: 0;
  overflow: hidden;
  box-shadow:
    inset 5px 0 #ffffff12,
    inset -5px 0 #0003;
}
.book:nth-child(even) {
  height: 249px;
}
.book svg {
  position: absolute;
  left: 0;
  bottom: 65px;
  width: 100%;
  height: 85px;
}
.book span {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  font-size: 13px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.card {
  height: 102px;
  padding: 5px;
  font-size: 14px;
  line-height: 1.15;
  transition: background 0.2s;
}
.card .motif {
  display: block;
  font-size: 27px;
  margin-bottom: 7px;
}
.card.back {
  color: var(--gold);
  font-size: 30px;
  background: repeating-linear-gradient(
    45deg,
    #22323d,
    #22323d 8px,
    #293b47 8px,
    #293b47 9px
  );
}
.card.matched {
  background: #345347;
  border-color: #90b8a3;
}
.clock-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.clock {
  width: min(100%, 340px);
  touch-action: none;
}
.frame {
  padding: 12px;
  border: 7px ridge #b38e57;
  background: #f4e9d5;
  color: #543c35;
  font-size: 38px;
  min-width: 90px;
}
.clock-controls {
  margin-top: 20px;
  display: flex;
  gap: 20px;
  justify-content: center;
}
.clock-controls button {
  padding: 5px 13px;
}
.clock-controls strong {
  display: inline-block;
  min-width: 32px;
}
canvas.maze {
  max-width: 100%;
  width: 450px;
  touch-action: none;
  background: #17252f;
  border-radius: 8px;
}
.history {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}
.history th,
.history td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.history td:first-child {
  letter-spacing: 0.18em;
  font-size: 18px;
}
.symbol {
  font-size: 120px;
  color: var(--gold);
  line-height: 1.4;
  margin: 30px;
}
.review {
  display: grid;
  gap: 10px;
  text-align: left;
}
.review a {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
@media (max-width: 480px) {
  main {
    margin-top: 8px;
    padding: 0 15px;
  }
  .surface {
    padding: 16px;
  }
  .clock-layout {
    gap: 8px;
  }
  .frame {
    font-size: 28px;
    min-width: 65px;
    padding: 6px;
  }
  .card {
    height: 95px;
    font-size: 12px;
  }
  .clock-controls {
    gap: 12px;
  }
  .books {
    height: 250px;
  }
}

.key-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 500/420;
  touch-action: none;
  overflow: hidden;
}
.key-fragment {
  position: absolute;
  width: 16%;
  height: 20.238%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
  border-radius: 0;
}
.key-fragment:hover {
  background: #ffffff07;
}
.key-fragment:active {
  cursor: grabbing;
}
.key-fragment svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.lock-target {
  position: absolute;
  left: 68%;
  top: 57.14%;
  width: 20%;
  height: 28.57%;
}
.assembled .key-fragment {
  filter: drop-shadow(0 0 7px #e8ba7655);
}
.unlocked #shackle {
  transform: translateY(-12px);
  transition: transform 0.4s;
}
.unlocked .key-fragment {
  opacity: 0.25;
  transition: opacity 0.4s;
}
.status:empty {
  display: none;
}
.books .book:nth-child(even) {
  height: 235px;
}
.book svg {
  overflow: hidden;
}
input {
  max-width: 100%;
}

.puzzle-only header,
.puzzle-only footer,
.puzzle-only .eyebrow {
  display: none;
}
.puzzle-only main {
  margin-top: 28px;
}

/* Contiguous equal-width slices keep split glyphs on one shared baseline. */
.books {
  gap: 0;
}
.books .book {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  border: 0;
  height: 235px;
  box-shadow:
    inset 1px 0 #ffffff35,
    inset -1px 0 #0005;
}
.books .book svg {
  display: block;
  left: 0;
  bottom: 65px;
  width: 100%;
  height: 85px;
}

.combination-lock {
  width: min(100%, 470px);
  margin: 8px auto 0;
}
.combo-shackle {
  display: block;
  width: 120px;
  height: 70px;
  margin: 0 auto -4px;
  transition: transform 0.35s;
}
.combo-body {
  position: relative;
  background: linear-gradient(140deg, #aa8146, #70522e);
  padding: 22px 12px 16px;
  border-radius: 16px;
  border: 1px solid #e8ba7677;
  box-shadow:
    inset 0 2px #efce9855,
    0 9px 28px #0003;
}
.combo-wheels {
  display: flex;
  gap: 5px;
  justify-content: center;
  position: relative;
  margin-bottom: 18px;
}
.number-wheel {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  height: 132px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  border-radius: 7px;
  background: linear-gradient(#111a21, #354651 45%, #354651 55%, #111a21);
  touch-action: pan-y;
  color: #f8eddb;
  box-shadow: inset 0 0 0 1px #0008;
}
.number-wheel::-webkit-scrollbar {
  display: none;
}
.wheel-digits {
  padding: 44px 0;
}
.wheel-digit {
  height: 44px;
  line-height: 44px;
  text-align: center;
  scroll-snap-align: center;
  font: 28px/44px monospace;
  user-select: none;
}
.combo-wheels:after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 44px;
  height: 44px;
  border-top: 1px solid #e8ba76;
  border-bottom: 1px solid #e8ba76;
  pointer-events: none;
}
.combo-submit {
  width: 100%;
}
.open .combo-shackle {
  transform: translateY(-16px) rotate(-10deg);
}
.open .number-wheel {
  pointer-events: none;
}
.lock-feedback {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 24px;
}
.lock-feedback strong {
  display: block;
  font: 32px Georgia;
  color: var(--gold);
}
.lock-feedback span {
  font-size: 14px;
  color: var(--muted);
}
.clock {
  cursor: grab;
}
.clock:active {
  cursor: grabbing;
}

/* Plain title-only spines inside a wooden shelf. Code is printed on each spine. */
.wooden-shelf {
  margin: 8px auto 28px;
  padding: 25px 14px 0;
  max-width: 620px;
  border: 12px solid #583c28;
  border-bottom: 22px solid #795235;
  border-radius: 3px;
  background: linear-gradient(180deg, #100f0d, #211b16);
  box-shadow:
    inset 0 12px 25px #0009,
    0 10px 20px #0005;
  position: relative;
}
.wooden-shelf:after {
  content: "";
  position: absolute;
  left: -12px;
  right: -12px;
  bottom: -22px;
  height: 6px;
  background: #a2774b;
  border-top: 1px solid #c0986955;
}
.books.plain-books {
  height: auto;
  align-items: stretch;
  gap: 0;
  margin: 0;
}
.books.plain-books .plain-book {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: clamp(310px, 60vw, 440px);
  padding: 0;
  background:
    linear-gradient(
      90deg,
      #0004,
      transparent 12%,
      #ffffff08 45%,
      transparent 90%,
      #0005
    ),
    var(--spine);
  border: 0;
  border-radius: 4px 4px 0 0;
  overflow: visible;
  box-shadow:
    inset 1px 0 #ffffff18,
    inset -1px 0 #0006;
  transition:
    transform 0.15s,
    filter 0.15s;
}
.books.plain-books .plain-book.selected {
  outline: 2px solid #e8ba76;
  outline-offset: 1px;
  z-index: 2;
  transform: translateY(-12px);
  filter: brightness(1.12);
}
.books.plain-books .book-title {
  position: absolute;
  top: 24px;
  bottom: 126px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font:
    16px/1.15 Georgia,
    serif;
  letter-spacing: 1px;
  color: #f8ecd5;
  text-transform: uppercase;
  text-shadow: 0 1px 1px #0008;
}
.books.plain-books .spine-code {
  position: absolute;
  display: block;
  left: 0;
  bottom: 48px;
  width: 100%;
  height: 56px;
  overflow: hidden;
  background: none;
  border: 0;
  opacity: 0.88;
}
.plain-book:focus-visible {
  z-index: 3;
}
@media (max-width: 400px) {
  .wooden-shelf {
    padding: 22px 7px 0;
    border-left-width: 8px;
    border-right-width: 8px;
  }
  .wooden-shelf:after {
    left: -8px;
    right: -8px;
  }
  .books.plain-books .book-title {
    font-size: 14px;
    letter-spacing: 0.7px;
  }
}

/* Supplied matching artwork: complete images, without visible captions. */
.card:not(.back) {
  background: #eeeae2;
  padding: 7px;
  overflow: hidden;
}
.card .card-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}
.card.matched:disabled {
  opacity: 1;
  border-color: #90b8a3;
  box-shadow: inset 0 0 0 2px #90b8a3;
}

/* Keep decoded faces mounted behind the cover; reveal with no transition. */
.card {
  position: relative;
  overflow: hidden;
  transition: none;
}
.card .card-art {
  opacity: 1;
  transition: none;
}
.card.back .card-art {
  opacity: 0;
}
.card .card-cover {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}
.card.back .card-cover {
  display: flex;
}
