:root {
  font-family: "Clear Sans", system-ui, sans-serif;
  color: #173b30;
  background: #faf6ed;
  --green: #103c30;
  --berry: #9d3046;
  --gold: #f6d38d;
  --line: #d8d7c6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.wrap { width: min(820px, calc(100% - 32px)); margin-inline: auto; }
.masthead { background: var(--green); border-bottom: 3px solid var(--gold); }
.masthead span {
  display: inline-flex; align-items: center; min-height: 47px;
  color: #fff7e9; text-decoration: none; font-weight: 700;
}
main { padding-block: clamp(20px, 5vw, 45px) 36px; }
h1, h2, h3 { margin: 0; font-family: Georgia, serif; }
h1 { font-size: clamp(2rem, 6vw, 3.75rem); line-height: 1.06; letter-spacing: -.035em; margin-bottom: 22px; }
h1 span { display: block; margin-top: 7px; font-size: .55em; color: #81344a; letter-spacing: -.02em; }
h2 { font-size: clamp(1.55rem, 4vw, 2.25rem); }
h3 { font-size: 1.24rem; }
p { line-height: 1.55; }
button { font: inherit; color: inherit; cursor: pointer; }
button, a { touch-action: manipulation; }
:focus-visible { outline: 3px solid #91410b; outline-offset: 3px; }
.masthead :focus-visible { outline-color: var(--gold); }
.paper { background: #fffcf4; border: 1px solid var(--line); border-radius: 20px; padding: clamp(14px, 4vw, 30px); }
.intro { display: grid; grid-template-columns: minmax(90px, 150px) 1fr; gap: 20px; align-items: center; }
.intro img { width: 100%; height: auto; }
.intro p { margin: 0 0 16px; }
.example { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 12px; }
.example strong { display: inline-block; background: #ecf0e6; border-radius: 8px; padding: 5px 11px; letter-spacing: .04em; }
mark { color: #5b280c; background: #f7d37f; border-radius: 3px; }
.primary {
  background: var(--berry); color: #fff; border: 0; border-radius: 11px;
  min-height: 48px; padding: 9px 18px; font-weight: 750;
}
.primary:hover { background: #772034; }
.stage-heading { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 6px; margin-bottom: 13px; }
#count { margin: 0; font-weight: 700; background: #ebeede; border-radius: 12px; padding: 5px 10px; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-bottom: 20px; }
.card {
  position: relative; display: grid; place-items: center; min-width: 0;
  min-height: 64px; height: clamp(64px, 12vw, 105px); padding: 2px;
  container-type: inline-size; background: #174b3d; border: 1px solid #245c4c;
  border-radius: 12px; color: var(--gold);
  box-shadow: inset 0 0 0 3px #ffffff12;
}
.card:not(.open):hover { background: #235e4b; }
.card.open { background: #fffdf6; color: var(--green); border-color: #b9c1ad; box-shadow: none; }
.card.matched { background: #e9efdf; border-color: #9cae89; }
.card-face {
  display: block; font-weight: 850; font-size: clamp(.64rem, 15cqi, 1.5rem);
  line-height: 1; letter-spacing: -.025em; white-space: nowrap;
}
.flake { font-size: 1.65rem; line-height: 1; }
.matched::after { content: "★"; position: absolute; inset: 4px 6px auto auto; color: #97571b; font-size: .85rem; }
.envelopes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px; list-style: none; padding: 0; margin: 10px 0 0; }
.envelope {
  display: grid; place-items: center; position: relative; min-width: 0; aspect-ratio: 1.18;
  background: #efd39e; border: 1px solid #cfad73; border-radius: 7px; overflow: hidden;
}
.envelope::before {
  content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 57%;
  clip-path: polygon(0 0, 100% 0, 50% 100%); background: #dbb978;
  transform-origin: top; transition: transform .25s ease;
}
.envelope.opened::before { transform: scaleY(-1); }
.envelope .seal {
  position: absolute; top: 47%; width: 1em; height: 1em; border-radius: 50%;
  background: var(--berry); box-shadow: 0 0 0 2px #fff3;
}
.envelope .tile { position: relative; width: 85%; aspect-ratio: 1; border-radius: 3px; animation: emerge .35s ease-out both; }
@keyframes emerge { from { opacity: 0; transform: translateY(30%); } }
.next { margin-top: 16px; text-align: center; }
.next p { margin: 0 0 10px; font-weight: 700; }
#puzzle-instructions { margin: 7px 0 12px; }
.puzzle-area { width: min(100%, 600px); margin-inline: auto; }
.frame-wrap { position: relative; overflow: clip; aspect-ratio: 3 / 2; border-radius: 10px; background: #e6ebdf; }
.frame { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.slot, .piece { display: block; width: 100%; aspect-ratio: 1; border: 0; padding: 0; }
.slot {
  background-color: #e9eee3; box-shadow: inset 0 0 0 1px #91a18a;
  color: #52634e; font-weight: 700;
}
.slot:hover:not(.filled) { background-color: #fff4d8; }
.slot:focus-visible, .piece:focus-visible { position: relative; z-index: 1; outline-offset: -4px; }
.tile {
  background-image: var(--scene-image);
  background-size: 300% 200%;
  background-position: var(--tile-x) var(--tile-y);
  background-repeat: no-repeat;
}
.frame .tile { background-color: #e9eee3; }
.slot.filled { cursor: default; transition: box-shadow .45s ease; }
.complete .slot { box-shadow: inset 0 0 0 0 transparent; }
.complete .slot:focus-visible { outline: none; }
.reveal {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  border-radius: inherit; pointer-events: none; animation: reveal .65s ease both;
}
.celebration-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #152326;
  animation: video-appear .35s ease-out both;
}
@keyframes video-appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes reveal {
  from { opacity: 0; transform: scale(1.018); }
  to { opacity: 1; transform: scale(1); }
}
.final-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sound {
  min-height: 48px; padding: 9px 16px; border: 1px solid #b9c1ad; border-radius: 11px;
  background: #e9efdf; font-weight: 700;
}
.sound:hover { background: #dfe9d7; }
.pieces { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.piece { border-radius: 7px; cursor: grab; }
.piece[draggable="true"]:active { cursor: grabbing; }
.piece[aria-pressed="true"] { outline: 3px solid #9d3046; outline-offset: 2px; }
.piece[aria-pressed="true"]:focus-visible { box-shadow: inset 0 0 0 3px #fff; }
.piece.used { visibility: hidden; }
.hint { min-height: 1.6em; margin: 10px 0 0; color: #823649; font-weight: 700; }
.hint:empty { margin: 0; min-height: 0; }
#data-error { color: #8c253b; }
@media (max-width: 550px) {
  .intro { grid-template-columns: 1fr; gap: 7px; }
  .intro img { width: 98px; justify-self: center; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .envelopes, .pieces { gap: 5px; }
  .pieces { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
