/* ============================================================================
   The Lost Ring of Schloss Eller — escape-room easter egg styles
   Loads after css/theme.css (design tokens assumed). All selectors are
   prefixed `er-` so nothing leaks into the invitation page.
   Mobile-first; flawless at 360 px.
   ========================================================================== */

/* ---------------------------------------------------------------- */
/* Trigger shake (applied to the hidden hibiscus on the invite page) */
/* ---------------------------------------------------------------- */

.er-shake {
  animation: er-wiggle 0.5s ease;
  transform-origin: 50% 60%;
}

@keyframes er-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-11deg) scale(1.06); }
  40% { transform: rotate(9deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}

/* ---------------------------------------------------------------- */
/* Overlay, backdrop, modal shell                                    */
/* ---------------------------------------------------------------- */

body.er-scroll-lock {
  overflow: hidden;
}

.er-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  color: var(--ink);
}

.er-overlay.er-open {
  display: flex;
}

.er-overlay.er-closing {
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: none;
}

.er-backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(90% 60% at 78% 12%, rgba(247, 239, 201, 0.14), transparent 55%),
    linear-gradient(180deg, #141a38 0%, #232b54 58%, #2e3763 100%);
}

.er-open .er-backdrop {
  animation: er-fade-in 0.35s ease both;
}

.er-backdrop svg {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: min(920px, 135%);
  height: auto;
}

.er-moon {
  position: absolute;
  top: 7%;
  right: 12%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #f7efc9;
  box-shadow: 0 0 40px 12px rgba(247, 239, 201, 0.35);
}

.er-castle-win path {
  animation: er-flicker 3.2s ease-in-out infinite;
}

.er-castle-win path:nth-child(2) { animation-delay: 1.1s; }
.er-castle-win path:nth-child(3) { animation-delay: 2.2s; }

@keyframes er-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes er-fade-in {
  from { opacity: 0; }
}

.er-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(201, 162, 39, 0.08), transparent 60%),
    linear-gradient(180deg, var(--cream-50), var(--cream-100) 55%, var(--cream-200));
  box-shadow: var(--shadow-soft);
  -webkit-user-select: none;
  user-select: none;
}

/* inner gold parchment frame */
.er-modal::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: calc(var(--radius) - 8px);
  pointer-events: none;
  z-index: 20;
}

.er-open .er-modal {
  animation: er-modal-in 0.4s ease both;
}

@keyframes er-modal-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
}

@media (min-width: 640px) {
  .er-overlay {
    padding: 24px;
  }
  .er-modal {
    width: min(580px, 94vw);
    height: auto;
    min-height: min(640px, 88vh);
    max-height: 92vh;
    border: 1px solid var(--gold-soft);
    border-radius: var(--radius);
  }
}

/* ---------------------------------------------------------------- */
/* Header                                                            */
/* ---------------------------------------------------------------- */

.er-header {
  position: relative;
  z-index: 10;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--gold-soft);
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.1), rgba(201, 162, 39, 0.02));
}

.er-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.er-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(0.92rem, 3.4vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.er-timer {
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--gold);
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  padding: 3px 10px;
}

.er-close {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.25s ease, background-color 0.2s ease;
}

.er-close:hover {
  background: rgba(201, 162, 39, 0.15);
  transform: rotate(90deg);
}

.er-progress {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 8px;
}

.er-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: transparent;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.er-dot-active {
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25);
  animation: er-dot-pulse 1.8s ease-in-out infinite;
}

.er-dot-done {
  background: var(--gold);
}

@keyframes er-dot-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25); }
  50% { box-shadow: 0 0 0 6px rgba(201, 162, 39, 0.1); }
}

/* ---------------------------------------------------------------- */
/* Body, stage, castle doors                                         */
/* ---------------------------------------------------------------- */

.er-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.er-watermark {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
}

.er-watermark svg {
  width: min(420px, 88%);
  height: auto;
}

.er-stage {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 26px;
}

.er-scene {
  max-width: 480px;
  margin: 0 auto;
  animation: er-scene-in 0.45s ease both;
}

@keyframes er-scene-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* Castle doors that close/open between chambers */
.er-doors {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.er-doors-closed .er-door {
  pointer-events: auto;
}

.er-door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.5%;
  background:
    repeating-linear-gradient(90deg,
      rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 26px),
    linear-gradient(90deg, #5d4228 0%, #7d5b38 35%, #6e4f30 70%, #5d4228 100%);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.55s cubic-bezier(0.65, 0, 0.35, 1);
  will-change: transform;
}

.er-door-l {
  left: 0;
  transform: translateX(-102%);
  border-right: 3px solid #3f2c18;
}

.er-door-r {
  right: 0;
  transform: translateX(102%);
  border-left: 3px solid #3f2c18;
}

/* iron ring handles */
.er-door::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 26px;
  height: 26px;
  border: 4px solid #c9a227;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.er-door-l::after { right: 12px; transform: translateY(-50%); }
.er-door-r::after { left: 12px; transform: translateY(-50%); }

.er-doors-closed .er-door-l,
.er-doors-closed .er-door-r {
  transform: translateX(0);
}

/* ---------------------------------------------------------------- */
/* Shared scene typography & controls                                */
/* ---------------------------------------------------------------- */

.er-ch-label {
  margin: 4px 0 2px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.er-h {
  margin: 2px 0 8px;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5.4vw, 1.85rem);
  line-height: 1.15;
  color: var(--ink);
}

.er-ornament {
  display: block;
  width: 120px;
  height: 12px;
  margin: 0 auto 12px;
}

.er-story,
.er-note {
  margin: 0 auto 14px;
  max-width: 42ch;
  text-align: center;
  line-height: 1.55;
}

.er-story { color: var(--ink); }

.er-note {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.er-riddle {
  margin: 0 auto 14px;
  max-width: 40ch;
  padding: 12px 14px;
  text-align: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-line;
  background: rgba(201, 162, 39, 0.07);
  border-top: 1px solid var(--gold-soft);
  border-bottom: 1px solid var(--gold-soft);
  border-radius: 10px;
}

.er-status {
  min-height: 1.5em;
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.er-center {
  display: flex;
  justify-content: center;
}

.er-btn {
  display: inline-block;
  margin: 6px auto 0;
  padding: 13px 26px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--cream-50);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.er-btn-gold {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  box-shadow: 0 4px 14px rgba(201, 162, 39, 0.35);
}

.er-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(201, 162, 39, 0.45);
}

.er-btn:active {
  transform: scale(0.97);
}

.er-btn:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.er-intro {
  text-align: center;
}

.er-intro-castle svg {
  display: block;
  width: min(300px, 74%);
  height: auto;
  margin: 4px auto 10px;
}

/* screen-reader-only helper */
.er-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* focus visibility */
.er-overlay button:focus-visible {
  outline: 2px solid var(--batik-indigo);
  outline-offset: 2px;
}

/* the dialog container receives programmatic focus on open — no ring needed */
.er-modal:focus {
  outline: none;
}

/* ---------------------------------------------------------------- */
/* Chamber I — room + clickable objects                              */
/* ---------------------------------------------------------------- */

.er-room-wrap {
  margin: 0 auto;
  max-width: 460px;
}

.er-room {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
  background: #eadfc6;
}

.er-obj {
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transition: filter 0.2s ease;
}

.er-obj:hover {
  filter: brightness(1.07) drop-shadow(0 1px 3px rgba(62, 52, 40, 0.3));
}

.er-hit {
  fill: none;
  stroke: none;
  pointer-events: all;
}

.er-obj:focus-visible .er-hit {
  stroke: var(--gold);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
}

.er-obj.er-found {
  cursor: default;
  pointer-events: none;
  filter: drop-shadow(0 0 6px rgba(201, 162, 39, 0.95));
  animation: er-found-pop 0.45s ease;
}

@keyframes er-found-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.er-obj.er-wrong {
  animation: er-shake-x 0.4s ease;
}

@keyframes er-shake-x {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.er-slots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.er-slot {
  min-width: 78px;
  padding: 6px 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  border: 1.5px dashed var(--gold-soft);
  border-radius: 999px;
  background: rgba(255, 255, 242, 0.6);
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.er-slot-filled {
  border-style: solid;
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.15);
  color: var(--ink);
  font-weight: 600;
}

/* ---------------------------------------------------------------- */
/* Chamber II — Simon tiles                                          */
/* ---------------------------------------------------------------- */

.er-round {
  margin: 0 0 10px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.er-simon {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: min(320px, 82vw);
  margin: 0 auto;
}

.er-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(62, 52, 40, 0.25);
  border-radius: 16px;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  touch-action: manipulation;
  transition: filter 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  will-change: transform, filter;
}

.er-tile svg {
  width: 44%;
  height: 44%;
}

.er-tile-indigo { background: radial-gradient(120% 120% at 30% 25%, #3a5cb0, var(--batik-indigo)); }
.er-tile-red    { background: radial-gradient(120% 120% at 30% 25%, #ef4a82, var(--hibiscus)); }
.er-tile-yellow { background: radial-gradient(120% 120% at 30% 25%, #ffd23f, var(--spanish-yellow)); }
.er-tile-teal   { background: radial-gradient(120% 120% at 30% 25%, #12967e, var(--malaysia-teal)); }

.er-tile-yellow { color: rgba(90, 70, 0, 0.5); }

.er-tile:active {
  transform: scale(0.96);
}

.er-tile.er-lit {
  filter: brightness(1.45) saturate(1.15);
  transform: scale(1.05);
}

.er-tile-indigo.er-lit { box-shadow: 0 0 24px rgba(58, 92, 176, 0.9); }
.er-tile-red.er-lit    { box-shadow: 0 0 24px rgba(216, 30, 91, 0.9); }
.er-tile-yellow.er-lit { box-shadow: 0 0 24px rgba(241, 191, 0, 0.9); }
.er-tile-teal.er-lit   { box-shadow: 0 0 24px rgba(11, 110, 92, 0.9); }

.er-tiles-locked .er-tile {
  pointer-events: none;
  cursor: default;
}

.er-simon-fail {
  animation: er-shake-x 0.4s ease;
}

/* ---------------------------------------------------------------- */
/* Chamber III — date lock                                           */
/* ---------------------------------------------------------------- */

.er-lock-wrap {
  width: 104px;
  margin: 0 auto 10px;
}

.er-lock-svg {
  display: block;
  width: 100%;
  height: auto;
}

.er-shackle {
  transform-box: fill-box;
  transform-origin: 15% 100%;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.er-unlocked .er-shackle {
  transform: translate(-2px, -12px) rotate(-26deg);
}

.er-unlocked .er-lock-svg {
  filter: drop-shadow(0 0 12px rgba(201, 162, 39, 0.85));
  animation: er-lock-hop 0.55s ease;
}

@keyframes er-lock-hop {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-8px); }
  65% { transform: translateY(2px); }
}

.er-lock-shake {
  animation: er-shake-x 0.4s ease;
}

.er-dials {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.er-dial {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.er-dial-btn {
  width: 46px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  background: var(--cream-100);
  color: var(--gold);
  font-size: 0.8rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.er-dial-btn:hover {
  background: rgba(201, 162, 39, 0.16);
}

.er-dial-btn:active {
  transform: scale(0.94);
}

.er-dial-window {
  width: 52px;
  height: 62px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff9e8;
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  box-shadow: inset 0 3px 8px rgba(62, 52, 40, 0.18);
}

.er-digit {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.er-digit-tick {
  animation: er-digit-roll 0.22s ease;
}

@keyframes er-digit-roll {
  from {
    transform: translateY(-55%);
    opacity: 0;
  }
}

.er-dial-hint {
  margin: 0 0 12px;
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------------- */
/* Win screen — ring, sparkles, confetti                             */
/* ---------------------------------------------------------------- */

.er-win {
  text-align: center;
}

.er-ring-wrap {
  position: relative;
  width: min(210px, 58vw);
  margin: 6px auto 4px;
  animation: er-ring-in 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.er-ring-wrap::before {
  content: "";
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 162, 39, 0.3), transparent 65%);
  animation: er-halo 2.4s ease-in-out infinite;
}

@keyframes er-halo {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.07); }
}

@keyframes er-ring-in {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-14deg);
  }
}

.er-ring-svg {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
}

.er-spark {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: er-sparkle 1.7s ease-in-out infinite;
  opacity: 0;
}

.er-spark:nth-child(2) { animation-delay: 0.55s; }
.er-spark:nth-child(3) { animation-delay: 1.1s; }

@keyframes er-sparkle {
  0%, 100% { opacity: 0; transform: scale(0.5); }
  50% { opacity: 1; transform: scale(1); }
}

.er-win-time {
  margin: 2px 0 10px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
}

.er-confetti {
  position: absolute;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.er-confetti i {
  position: absolute;
  top: -26px;
  display: block;
  animation-name: er-confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: both;
  will-change: transform, opacity;
}

@keyframes er-confetti-fall {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  90% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--er-dx, 0px), 106vh, 0) rotate(var(--er-rot, 540deg));
  }
}

/* ---------------------------------------------------------------- */
/* Reduced motion — keep essential state, drop the theatre           */
/* ---------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .er-shake,
  .er-obj.er-wrong,
  .er-obj.er-found,
  .er-simon-fail,
  .er-lock-shake,
  .er-digit-tick,
  .er-scene,
  .er-ring-wrap,
  .er-ring-wrap::before,
  .er-spark,
  .er-dot-active,
  .er-castle-win path,
  .er-confetti i,
  .er-open .er-modal,
  .er-open .er-backdrop {
    animation: none !important;
  }

  .er-spark {
    opacity: 1;
    transform: none;
  }

  .er-overlay.er-closing {
    transition: none;
  }

  .er-door,
  .er-shackle,
  .er-close,
  .er-btn,
  .er-tile,
  .er-dial-btn {
    transition: none !important;
  }
}
