/* ============================================
   LEVEL 7 — THE WITCH'S TOWER
   Pattern lock, cipher deduction, rune sequence,
   gem maths, riddle/anagram, code assembly, spell break
   ============================================ */

/* ── Shared puzzle host ── */
#screen-tower-puzzle {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}
#screen-tower-puzzle.active {
  display: block;
}

.tower-puzzle-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1;
}
.tower-puzzle-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 0%, rgba(0,0,0,0.35) 60%, rgba(0,0,0,0.75) 100%);
  pointer-events: none;
}

.tower-puzzle-content {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2% 4%;
  color: var(--text-light);
  text-shadow: 0 0 6px rgba(0,0,0,0.9);
}

.tower-stage-title {
  font-size: clamp(0.55rem, 1.6vw, 0.9rem);
  color: var(--gold-bright);
  text-shadow: 0 0 8px rgba(218,186,106,0.6), 0 0 2px #000;
  margin-bottom: 1.2em;
  text-align: center;
  line-height: 1.6;
}

.tower-stage-hint {
  font-size: clamp(0.35rem, 1.1vw, 0.55rem);
  color: rgba(234,228,212,0.8);
  margin-top: 1em;
  text-align: center;
}

/* PP-breakthrough hint button */
.tower-hint-btn {
  position: absolute !important;
  bottom: 2%;
  right: 2%;
  z-index: 3;
  font-size: clamp(0.35rem, 1vw, 0.5rem) !important;
  padding: 0.45em 1em !important;
  opacity: 0.65;
  animation: none !important;
}
.tower-hint-btn:hover {
  opacity: 1;
}

/* ══════════════════════════════════════════
   STAGE 1 — TOWER GATE (Pattern Lock)
   ══════════════════════════════════════════ */

.tower-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2em;
}

.tower-gate-sequence-row {
  display: flex;
  gap: 0.8em;
  justify-content: center;
}

/* Arcane socket — recessed witch-stone with a faint purple inner glow */
.tower-gate-slot {
  width: clamp(40px, 6vw, 70px);
  height: clamp(40px, 6vw, 70px);
  border: 2px solid var(--gold);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(106, 58, 138, 0.35) 0%, transparent 70%),
    linear-gradient(160deg, #2c2046 0%, #1a1230 100%);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 3px 8px rgba(0, 0, 0, 0.7),
    inset 0 0 12px rgba(106, 58, 138, 0.4),
    0 0 0 1px rgba(0, 0, 0, 0.7);
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
.tower-gate-slot img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  image-rendering: pixelated;
}
.tower-gate-slot.flashing {
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 20px rgba(255, 220, 120, 0.55),
    0 0 20px rgba(255, 220, 120, 0.9);
  border-color: var(--gold-bright);
  transform: scale(1.1);
}
.tower-gate-slot.filled {
  border-color: #b48ae0;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 3px 8px rgba(0, 0, 0, 0.6),
    inset 0 0 14px rgba(154, 90, 191, 0.55),
    0 0 10px rgba(154, 90, 191, 0.45);
}
.tower-gate-slot.success {
  border-color: var(--success-green);
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 14px rgba(74, 170, 90, 0.5),
    0 0 15px rgba(88, 162, 72, 0.7);
}
.tower-gate-slot.wrong {
  border-color: var(--error-red);
  animation: gate-shake 0.4s;
}

/* Rune board — gold double-frame panel over witch-purple stone */
.tower-gate-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6em;
  padding: 1em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.55) 0%, rgba(36, 26, 58, 0.75) 100%),
    rgba(12, 16, 22, 0.88);
  border: 3px solid #c5952e;
  border-radius: 6px;
  max-width: min(55vw, 420px);
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 28px rgba(106, 58, 138, 0.4),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 14px rgba(0, 0, 0, 0.5);
}
.tower-gate-grid.disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* Rune key — dark arcane stone with purple-glow edges */
.tower-rune-btn {
  width: clamp(48px, 7vw, 90px);
  height: clamp(48px, 7vw, 90px);
  background: linear-gradient(155deg, #3a2a5a 0%, #241a3a 100%);
  border: 2px solid #6a4a9a;
  border-radius: 4px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.3),
    inset 0 0 12px rgba(106, 58, 138, 0.45),
    0 3px 0 #14102a,
    0 0 8px rgba(106, 58, 138, 0.35);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.tower-rune-btn:hover, .tower-rune-btn:active {
  background: linear-gradient(155deg, #4c3a72 0%, #302348 100%);
  border-color: var(--gold-bright);
  box-shadow:
    inset 0 1px 0 rgba(200, 165, 245, 0.4),
    inset 0 0 14px rgba(140, 85, 180, 0.55),
    0 3px 0 #14102a,
    0 0 12px rgba(180, 130, 230, 0.5);
  transform: scale(1.05);
}
.tower-rune-btn.wrong {
  border-color: var(--error-red);
  animation: gate-shake 0.4s;
}
.tower-rune-btn img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  image-rendering: pixelated;
}

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ══════════════════════════════════════════
   STAGE 2 — FLOOR 1 CIPHER DEDUCTION
   ══════════════════════════════════════════ */

.tower-cipher {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
  max-width: 90%;
}

.tower-cipher-words {
  display: flex;
  gap: 2em;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.5em;
}

.tower-cipher-word {
  display: flex;
  gap: 0.4em;
}

/* Carved letter cell — arcane stone tablet */
.tower-cipher-cell {
  width: clamp(44px, 4.5vw, 56px);
  height: clamp(44px, 5.5vw, 68px);
  border: 2px solid var(--gold);
  background: linear-gradient(165deg, #3a2a5a 0%, #241a3a 100%);
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.5rem, 1.6vw, 0.9rem);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.2),
    inset 0 0 10px rgba(106, 58, 138, 0.35),
    0 2px 0 #14102a;
}

.tower-cipher-cell.cipher-blank {
  background: linear-gradient(165deg, #4c3066 0%, #2e1c42 100%);
  border-color: var(--purple-witch);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.tower-cipher-cell.cipher-blank:hover,
.tower-cipher-cell.cipher-blank.selected {
  border-color: var(--gold-bright);
  box-shadow:
    inset 0 0 12px rgba(140, 85, 180, 0.5),
    0 2px 0 #14102a,
    0 0 12px rgba(255, 220, 120, 0.6);
  background: linear-gradient(165deg, #5e3c7e 0%, #3a2452 100%);
}
/* Resolved cells glow arcane green */
.tower-cipher-cell.solved {
  border-color: var(--success-green);
  background: linear-gradient(165deg, rgba(74, 170, 90, 0.35) 0%, rgba(30, 60, 36, 0.6) 100%);
  color: #8ee49a;
  box-shadow:
    inset 0 0 10px rgba(74, 170, 90, 0.4),
    0 2px 0 #14102a,
    0 0 12px rgba(74, 170, 90, 0.45);
}
.tower-cipher-cell.wrong {
  border-color: var(--error-red);
  animation: gate-shake 0.4s;
}
.cipher-symbol {
  font-size: 1.4em;
  color: var(--gold-bright);
}
.cipher-resolved {
  font-size: 1em;
  color: var(--gold-bright);
  font-weight: bold;
}

.tower-cipher-instructions {
  font-size: clamp(0.35rem, 1vw, 0.5rem);
  color: rgba(234,228,212,0.85);
  text-align: center;
  margin: 0;
}

/* Keyboard plate — gold double-frame over witch-purple stone */
.tower-cipher-keyboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em;
  justify-content: center;
  max-width: min(80vw, 680px);
  padding: 0.8em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.45) 0%, rgba(36, 26, 58, 0.7) 100%),
    rgba(12, 16, 22, 0.88);
  border: 2px solid #c5952e;
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 22px rgba(106, 58, 138, 0.3),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 12px rgba(0, 0, 0, 0.5);
}
.tower-cipher-keyboard.disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* Letter key — small arcane tile with 3D depth and gold letter */
.tower-cipher-key {
  width: clamp(44px, 3.5vw, 44px);
  height: clamp(44px, 3.5vw, 44px);
  background: linear-gradient(165deg, #3a2a5a 0%, #241a3a 100%);
  border: 2px solid #5a4080;
  color: var(--gold-bright);
  font-family: var(--font-pixel);
  font-size: clamp(0.35rem, 1vw, 0.55rem);
  cursor: pointer;
  border-radius: 3px;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    0 3px 0 #14102a;
  transition: background 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease, transform 0.1s ease;
}
.tower-cipher-key:hover, .tower-cipher-key:active {
  background: linear-gradient(165deg, #4c3a72 0%, #302348 100%);
  border-color: var(--gold-bright);
  box-shadow:
    inset 0 1px 0 rgba(200, 165, 245, 0.35),
    0 3px 0 #14102a,
    0 0 8px rgba(180, 130, 230, 0.45);
  transform: translateY(-1px);
}

/* Symbol legend chip — small gold-framed plaque */
.tower-cipher-legend {
  display: flex;
  gap: 1.5em;
  justify-content: center;
  font-size: clamp(0.4rem, 1.2vw, 0.65rem);
  padding: 0.5em 1em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.35) 0%, rgba(36, 26, 58, 0.55) 100%),
    rgba(12, 16, 22, 0.88);
  border: 2px solid #c5952e;
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 8px rgba(0, 0, 0, 0.4);
}
.legend-item {
  padding: 0.2em 0.5em;
  border-radius: 3px;
  transition: all 0.15s ease;
}
.legend-item.active {
  background: rgba(218, 186, 106, 0.25);
  border: 1px solid var(--gold);
}

/* ══════════════════════════════════════════
   STAGES 3 & 5 — RUNE SEQUENCE (Stairway)
   ══════════════════════════════════════════ */

.tower-runes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2em;
}

/* Stairway housing — gold double-frame over deep witch-stone */
.tower-rune-stairs {
  display: flex;
  gap: 1.2em;
  padding: 1.5em 2em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.45) 0%, rgba(36, 26, 58, 0.7) 100%),
    rgba(12, 16, 22, 0.88);
  border: 3px solid #c5952e;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 30px rgba(106, 58, 138, 0.4),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 14px rgba(0, 0, 0, 0.5);
}
.tower-rune-stairs.disabled {
  pointer-events: none;
}

.tower-stair-rune {
  width: clamp(60px, 9vw, 110px);
  height: clamp(60px, 9vw, 110px);
  background: linear-gradient(160deg, #3a2a5a 0%, #241a3a 100%);
  border: 3px solid #5a4080;
  border-radius: 6px;
  cursor: pointer;
  padding: 6px;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    inset 0 0 14px rgba(106, 58, 138, 0.4),
    0 4px 0 #14102a;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.tower-stair-rune img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0.55;
  transition: opacity 0.2s ease, filter 0.2s ease;
}
.tower-stair-rune.glow,
.tower-stair-rune.pressed {
  border-color: var(--gold-bright);
  background: rgba(255, 232, 136, 0.25);
  box-shadow: 0 0 30px rgba(255, 232, 136, 0.9), inset 0 0 15px rgba(255, 232, 136, 0.5);
  transform: scale(1.1);
}
.tower-stair-rune.glow img,
.tower-stair-rune.pressed img {
  opacity: 1;
  filter: brightness(1.6) drop-shadow(0 0 6px rgba(255, 220, 120, 0.8));
}
.tower-stair-rune.wrong {
  border-color: var(--error-red);
  background: rgba(202, 90, 72, 0.3);
  animation: gate-shake 0.4s;
}
.tower-stair-rune.all-lit {
  border-color: var(--success-green);
  background: rgba(88, 162, 72, 0.2);
  box-shadow: 0 0 20px rgba(88, 162, 72, 0.6);
}
.tower-stair-rune.all-lit img {
  opacity: 1;
  filter: brightness(1.4);
}

/* ══════════════════════════════════════════
   STAGE 4 — FLOOR 2 GEM MATHS
   ══════════════════════════════════════════ */

.tower-gems {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8em;
  max-width: 95%;
}

/* Gem-value legend chip — small gold-framed plaque */
.tower-gem-values {
  font-size: clamp(0.75rem, 2vw, 1.05rem);
  color: rgba(234,228,212,0.9);
  padding: 0.5em 1em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.4) 0%, rgba(36, 26, 58, 0.6) 100%),
    rgba(12, 16, 22, 0.88);
  border: 2px solid #c5952e;
  border-radius: 4px;
  letter-spacing: 0.02em;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 8px rgba(0, 0, 0, 0.4);
}

.tower-gem-progress {
  display: flex;
  gap: 0.8em;
  margin-bottom: 0.5em;
}
/* Witch-lock socket — dark circular keyhole that glows green with the ✓ */
.tower-gem-slot {
  width: clamp(24px, 3.5vw, 40px);
  height: clamp(24px, 3.5vw, 40px);
  border: 2px solid #5a4080;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, rgba(106, 58, 138, 0.4) 0%, transparent 70%),
    linear-gradient(160deg, #2c2046 0%, #181028 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  color: #8ee49a;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.7),
    inset 0 0 8px rgba(106, 58, 138, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.7);
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}
.tower-gem-slot.filled {
  border-color: var(--success-green);
  background:
    radial-gradient(circle at 50% 40%, rgba(74, 170, 90, 0.45) 0%, transparent 75%),
    linear-gradient(160deg, #1e3424 0%, #122016 100%);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    inset 0 0 8px rgba(74, 170, 90, 0.5),
    0 0 10px rgba(88, 162, 72, 0.6);
}

/* Equation plaque — gold double-frame with purple inner glow */
.tower-gem-problem {
  padding: 1em 1.5em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.45) 0%, rgba(36, 26, 58, 0.7) 100%),
    rgba(12, 16, 22, 0.88);
  border: 2px solid #c5952e;
  border-radius: 8px;
  min-height: 3em;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 20px rgba(106, 58, 138, 0.3),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 12px rgba(0, 0, 0, 0.5);
}

.gem-equation {
  font-size: clamp(0.65rem, 2vw, 1.1rem);
  display: flex;
  align-items: center;
  gap: 0.3em;
  color: var(--text-light);
}
.gem-equation .mystery {
  color: var(--purple-witch);
  font-weight: bold;
  background: rgba(106, 58, 138, 0.3);
  padding: 0.1em 0.5em;
  border-radius: 6px;
  border: 2px dashed var(--purple-witch);
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  min-width: 1.2em;
  justify-content: center;
}
.tower-gem {
  display: inline-block;
  vertical-align: middle;
}

.tower-gem-input {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
  align-items: center;
  margin-top: 0.5em;
}

.tower-gem-pick {
  width: clamp(60px, 8vw, 90px);
  height: clamp(60px, 8vw, 90px);
  background: linear-gradient(160deg, #3a2a5a 0%, #241a3a 100%);
  border: 3px solid #5a4080;
  border-radius: 8px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    inset 0 0 12px rgba(106, 58, 138, 0.4),
    0 4px 0 #14102a;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tower-gem-pick:hover, .tower-gem-pick:active {
  transform: scale(1.08);
  border-color: var(--gold-bright);
}
.tower-gem-pick.correct {
  border-color: var(--success-green);
  background: rgba(88, 162, 72, 0.3);
}
.tower-gem-pick.wrong {
  border-color: var(--error-red);
  animation: gate-shake 0.4s;
}

/* Answer readout — recessed witch-glass display */
.gem-number-display {
  min-width: 2em;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: var(--gold-bright);
  padding: 0.3em 0.6em;
  border: 2px solid var(--gold);
  background:
    radial-gradient(ellipse at 50% 30%, rgba(106, 58, 138, 0.35) 0%, transparent 70%),
    rgba(8, 6, 16, 0.85);
  border-radius: 4px;
  text-align: center;
  margin-right: 0.8em;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 3px 8px rgba(0, 0, 0, 0.7),
    inset 0 0 12px rgba(106, 58, 138, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.7);
}
.gem-number-display.correct {
  border-color: var(--success-green);
  color: var(--success-green);
}
.gem-number-display.wrong {
  border-color: var(--error-red);
  color: var(--error-red);
  animation: gate-shake 0.4s;
}

.gem-number-pad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.45em;
  max-width: min(72vw, 640px);
}
/* Number key — arcane tile with 3D ledge and gold digit */
.gem-num-key {
  padding: 0.9em 0.6em;
  background: linear-gradient(165deg, #3a2a5a 0%, #241a3a 100%);
  border: 2px solid #5a4080;
  color: var(--gold-bright);
  font-family: var(--font-pixel);
  font-size: clamp(0.85rem, 2.5vw, 1.3rem);
  cursor: pointer;
  border-radius: 4px;
  min-height: 2.4em;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    0 3px 0 #14102a;
  transition: background 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease;
}
.gem-num-key:hover, .gem-num-key:active {
  background: linear-gradient(165deg, #4c3a72 0%, #302348 100%);
  border-color: var(--gold-bright);
  box-shadow:
    inset 0 1px 0 rgba(200, 165, 245, 0.35),
    0 3px 0 #14102a,
    0 0 8px rgba(180, 130, 230, 0.45);
}
.gem-num-key.num-go {
  background: linear-gradient(165deg, #2e5a32 0%, #1c3a22 100%);
  border-color: var(--success-green);
  color: var(--gold-bright);
  box-shadow:
    inset 0 1px 0 rgba(140, 220, 150, 0.3),
    0 3px 0 #0e2012,
    0 0 8px rgba(74, 170, 90, 0.35);
}
.gem-num-key.num-del {
  background: linear-gradient(165deg, #5a2a3a 0%, #381a26 100%);
  border-color: #7a4a5a;
  box-shadow:
    inset 0 1px 0 rgba(220, 150, 170, 0.25),
    0 3px 0 #200e16;
}

.tower-gem-feedback {
  min-height: 1.2em;
  font-size: clamp(0.4rem, 1.1vw, 0.55rem);
  margin: 0.3em 0 0;
}
.tower-gem-feedback.success { color: var(--success-green); }
.tower-gem-feedback.error   { color: var(--error-red); }

/* ══════════════════════════════════════════
   STAGE 6 — FLOOR 3 RIDDLE / ANAGRAM
   ══════════════════════════════════════════ */

.tower-riddle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
  max-width: 92%;
}

/* Riddle scroll-plaque — gold double-frame over witch-purple stone */
.tower-riddle-text {
  font-size: clamp(0.45rem, 1.2vw, 0.7rem);
  line-height: 2;
  color: var(--text-light);
  text-align: center;
  padding: 1.2em 1.8em;
  background:
    linear-gradient(160deg, rgba(58, 42, 90, 0.45) 0%, rgba(36, 26, 58, 0.7) 100%),
    rgba(12, 16, 22, 0.88);
  border: 2px solid #c5952e;
  border-radius: 6px;
  max-width: min(70vw, 640px);
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 22px rgba(106, 58, 138, 0.3),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 0 12px rgba(0, 0, 0, 0.5);
}
.tower-riddle-text strong {
  color: var(--gold-bright);
}

.tower-anagram-slots {
  display: flex;
  gap: 0.6em;
}
/* Anagram socket — recessed arcane stone awaiting its letter tile */
.tower-anagram-slot {
  width: clamp(46px, 6vw, 80px);
  height: clamp(54px, 7vw, 96px);
  border: 3px dashed var(--gold);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(106, 58, 138, 0.35) 0%, transparent 70%),
    linear-gradient(160deg, #2c2046 0%, #1a1230 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.6rem, 2vw, 1.1rem);
  color: var(--gold-bright);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.6),
    inset 0 0 12px rgba(106, 58, 138, 0.4);
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}
.tower-anagram-slot.filled {
  border-style: solid;
  background: linear-gradient(160deg, #4c3066 0%, #2e1c42 100%);
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    inset 0 0 12px rgba(140, 85, 180, 0.45),
    0 0 8px rgba(154, 90, 191, 0.35);
}
.tower-anagram-slot.correct {
  border-color: var(--success-green);
  background: linear-gradient(160deg, rgba(74, 170, 90, 0.35) 0%, rgba(30, 60, 36, 0.6) 100%);
  box-shadow:
    inset 0 0 12px rgba(74, 170, 90, 0.4),
    0 0 15px rgba(88, 162, 72, 0.55);
}
.tower-anagram-slot.wrong {
  border-color: var(--error-red);
  animation: gate-shake 0.4s;
}

.tower-anagram-tiles {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
  justify-content: center;
}
/* Letter tile — arcane stone with 3D ledge and gold letter */
.tower-anagram-tile {
  width: clamp(44px, 5.5vw, 72px);
  height: clamp(44px, 5.5vw, 72px);
  background: linear-gradient(165deg, #3a2a5a 0%, #241a3a 100%);
  border: 3px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--font-pixel);
  font-size: clamp(0.55rem, 1.6vw, 0.9rem);
  cursor: pointer;
  border-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(180, 140, 230, 0.25),
    inset 0 0 10px rgba(106, 58, 138, 0.35),
    0 3px 0 #14102a;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.tower-anagram-tile:hover, .tower-anagram-tile:active {
  transform: scale(1.1) translateY(-3px);
  background: linear-gradient(165deg, #4c3a72 0%, #302348 100%);
  box-shadow:
    inset 0 1px 0 rgba(200, 165, 245, 0.35),
    0 3px 0 #14102a,
    0 4px 12px rgba(255, 220, 120, 0.4);
}

/* ══════════════════════════════════════════
   STAGE 7 — CODE ASSEMBLY
   ══════════════════════════════════════════ */

.tower-assembly {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}

/* The final lock housing — the most ornate frame in the tower */
.tower-assembly-frame {
  padding: 1.5em 2em;
  background:
    linear-gradient(135deg, rgba(58, 42, 90, 0.5), rgba(36, 26, 58, 0.5)),
    rgba(12, 16, 22, 0.88);
  border: 4px solid #c5952e;
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 2px rgba(8, 10, 16, 0.85),
    inset 0 0 0 4px #8a6518,
    inset 0 0 26px rgba(106, 58, 138, 0.45),
    0 0 0 2px rgba(0, 0, 0, 0.8),
    0 0 30px rgba(255, 220, 120, 0.3);
}

.tower-assembly-slots {
  display: flex;
  gap: 0.7em;
  align-items: center;
  justify-content: center;
}
/* Final-lock socket — gold double-frame with an inner purple glow */
.tower-assembly-slot {
  min-width: clamp(60px, 8vw, 100px);
  height: clamp(60px, 8vw, 100px);
  border: 3px dashed var(--gold);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(106, 58, 138, 0.4) 0%, transparent 70%),
    linear-gradient(160deg, #2c2046 0%, #181028 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 2.4vw, 1.4rem);
  color: var(--gold-bright);
  padding: 0 0.6em;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px rgba(138, 101, 24, 0.6),
    inset 0 3px 8px rgba(0, 0, 0, 0.6),
    inset 0 0 16px rgba(106, 58, 138, 0.45);
  transition: border-color 0.4s ease, background 0.4s ease, box-shadow 0.4s ease, color 0.4s ease;
}
.tower-assembly-slot[data-double="1"] {
  min-width: clamp(80px, 11vw, 140px);
}
/* Filled: the socket burns bright gold */
.tower-assembly-slot.filled {
  border-style: solid;
  border-color: var(--gold-bright);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 232, 136, 0.18) 0%, transparent 75%),
    linear-gradient(160deg, #4c3066 0%, #2e1c42 100%);
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 14px rgba(255, 220, 120, 0.35),
    0 0 14px rgba(255, 220, 120, 0.55);
}
.tower-assembly-slot.snap {
  animation: assembly-snap 0.4s ease;
}
.tower-assembly-slot.complete {
  border-color: var(--success-green);
  background:
    radial-gradient(ellipse at 50% 40%, rgba(120, 210, 110, 0.25) 0%, transparent 75%),
    linear-gradient(160deg, rgba(74, 170, 90, 0.35) 0%, rgba(30, 60, 36, 0.6) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    inset 0 0 14px rgba(74, 170, 90, 0.4),
    0 0 18px rgba(255, 220, 120, 0.7);
  color: var(--gold-bright);
}
@keyframes assembly-snap {
  0%   { transform: scale(1.3); }
  60%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.tower-assembly-instructions {
  font-size: clamp(0.4rem, 1.1vw, 0.55rem);
  color: rgba(234,228,212,0.8);
  text-align: center;
  margin: 0;
}

.tower-assembly-fragments {
  display: flex;
  gap: 0.8em;
  flex-wrap: wrap;
  justify-content: center;
}
/* Code fragment — glowing arcane tile, ready to drop into the lock */
.tower-fragment-btn {
  min-width: clamp(60px, 8vw, 110px);
  height: clamp(50px, 7vw, 80px);
  padding: 0 0.8em;
  background: linear-gradient(160deg, #4c3066 0%, #2e1c42 100%);
  border: 3px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--font-pixel);
  font-size: clamp(0.7rem, 2vw, 1.2rem);
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, background 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(200, 165, 245, 0.3),
    inset 0 0 12px rgba(140, 85, 180, 0.4),
    0 3px 0 #14102a,
    0 0 12px rgba(255, 220, 120, 0.3);
}
.tower-fragment-btn:hover, .tower-fragment-btn:active {
  transform: scale(1.08) translateY(-3px);
  background: linear-gradient(160deg, #5e3c7e 0%, #3a2452 100%);
  box-shadow:
    inset 0 1px 0 rgba(210, 180, 250, 0.4),
    inset 0 0 14px rgba(160, 100, 210, 0.5),
    0 3px 0 #14102a,
    0 6px 20px rgba(255, 220, 120, 0.6);
}
.tower-fragment-btn.placed {
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0.85);
}

/* Fragment reveal animation (F, RE, E flashes after each puzzle) */
.tower-fragment-reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  background: radial-gradient(ellipse at 50% 50%, rgba(255,220,120,0.25) 0%, rgba(0,0,0,0.7) 70%);
  z-index: 5;
  animation: fragment-fade-in 0.5s ease;
  pointer-events: none;
}
.tower-fragment-reveal p {
  font-size: clamp(0.45rem, 1.2vw, 0.65rem);
  color: var(--text-light);
  text-align: center;
}
.tower-fragment-letter {
  font-size: clamp(4rem, 14vw, 10rem);
  color: var(--gold-bright);
  text-shadow:
    0 0 20px rgba(255, 220, 120, 0.9),
    0 0 40px rgba(255, 220, 120, 0.6),
    0 0 6px #000;
  font-family: var(--font-pixel);
  animation: fragment-pulse 1.2s ease infinite;
  display: inline-block;
  padding: 0 0.2em;
}
.tower-fragment-reveal .tower-fragment-letter + .tower-fragment-letter {
  animation-delay: 0.3s;
}
.tower-fragment-reveal.floating-out {
  animation: fragment-float-out 0.9s ease forwards;
}
@keyframes fragment-fade-in {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes fragment-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@keyframes fragment-float-out {
  to {
    opacity: 0;
    transform: translateY(-40%) scale(0.5);
  }
}

/* ══════════════════════════════════════════
   STAGE 8 — SPELL BREAKS (screen crack + witch dissolve)
   ══════════════════════════════════════════ */

.spell-crack-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transform: scale(0.3);
  transition: opacity 0.8s ease, transform 0.8s ease;
  mix-blend-mode: screen;
}
.spell-crack-overlay img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(1.4);
}
/* Staged spread: the crack creeps across the screen in three jolts */
.spell-crack-overlay.stage-1 {
  opacity: 0.45;
  transform: scale(0.55) rotate(-2deg);
}
.spell-crack-overlay.stage-2 {
  opacity: 0.75;
  transform: scale(0.82) rotate(1deg);
}
.spell-crack-overlay.active {
  opacity: 1;
  transform: scale(1);
}
.spell-crack-overlay.fading {
  opacity: 0;
  transition: opacity 1.4s ease;
}

.spell-light-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 49;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%,
    rgba(255, 255, 240, 0.95) 0%,
    rgba(255, 220, 120, 0.7) 20%,
    rgba(255, 180, 80, 0.3) 40%,
    transparent 70%);
  transition: opacity 0.6s ease;
}
.spell-light-burst.active {
  opacity: 0.7;
  animation: light-burst-pulse 2.5s ease infinite;
}
.spell-light-burst.fading {
  opacity: 0;
  transition: opacity 2s ease;
}
@keyframes light-burst-pulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 0.95; }
}

/* Witch dissolve into pixels */
.scene-character.witch-dissolving {
  animation: witch-dissolve 1.8s ease forwards;
}
@keyframes witch-dissolve {
  0%   { opacity: 1; filter: none; transform: scale(1); }
  30%  { opacity: 1; filter: hue-rotate(40deg) contrast(1.4) saturate(1.5); transform: translateX(-6px) scale(1.02); }
  45%  { filter: hue-rotate(-40deg) contrast(1.6) saturate(1.2); transform: translateX(6px) scale(1.04); }
  60%  { filter: brightness(1.6) blur(3px); transform: scale(1.1); opacity: 0.85; }
  80%  { filter: blur(10px) brightness(2); transform: scale(1.25); opacity: 0.4; }
  100% { filter: blur(30px) brightness(3); transform: scale(1.5); opacity: 0; }
}

/* ══════════════════════════════════════════
   SPELL BREAK — witch pixel-shatter, white-out, PP entrance
   ══════════════════════════════════════════ */

/* Field for the Witch's shattered pixels (spawned + animated from JS) */
.witch-shatter-field {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 51;
  overflow: hidden;
}
.witch-pixel {
  position: absolute;
  image-rendering: pixelated;
  box-shadow: 0 0 6px rgba(216, 176, 255, 0.7);
}

/* Full-screen white-out while colour floods back into the world */
.finale-white-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  background: #fffdf2;
  opacity: 0;
  animation: finale-white-flash 3s ease-in-out forwards;
}
@keyframes finale-white-flash {
  0%   { opacity: 0; }
  30%  { opacity: 1; }
  55%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Column of golden light Princess Pumpkin materializes inside */
.pp-light-pillar {
  position: absolute;
  bottom: 0;
  left: 42%;
  transform: translateX(-50%) scaleY(0);
  transform-origin: 50% 100%;
  width: 24%;
  height: 92%;
  pointer-events: none;
  z-index: 4;
  background: linear-gradient(to top,
    rgba(255, 240, 190, 0.85) 0%,
    rgba(255, 226, 140, 0.55) 35%,
    rgba(255, 220, 120, 0.25) 70%,
    transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 50% 100% at 50% 100%, #000 55%, transparent 100%);
  mask-image: radial-gradient(ellipse 50% 100% at 50% 100%, #000 55%, transparent 100%);
  animation: pillar-rise 1s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  transition: opacity 0.9s ease;
}
@keyframes pillar-rise {
  to { transform: translateX(-50%) scaleY(1); }
}
.pp-light-pillar.fading {
  opacity: 0;
}

/* ══════════════════════════════════════════
   FINALE — Fireworks (launch streak → burst → falling sparks; JS-driven)
   ══════════════════════════════════════════ */

.celebration-fireworks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

/* Rising launch streak */
.fw-streak {
  position: absolute;
  width: 4px;
  height: 9%;
  border-radius: 2px;
  background: linear-gradient(to top, transparent 0%, currentColor 70%, #fff 100%);
  filter: drop-shadow(0 0 6px currentColor);
  will-change: transform, opacity;
}

/* Bloom flash at the burst point */
.fw-flash {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, #fff 0%, currentColor 45%, transparent 70%);
  filter: drop-shadow(0 0 18px currentColor);
  will-change: transform, opacity;
}

/* Individual spark with a glowing trail */
.fw-spark {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: currentColor;
  box-shadow:
    0 0 6px 1px currentColor,
    0 0 14px 3px rgba(255, 255, 255, 0.25);
  will-change: transform, opacity;
}

/* ══════════════════════════════════════════
   MOBILE / TABLET RESPONSIVE TWEAKS
   ══════════════════════════════════════════ */

@media (max-width: 900px) {
  .tower-cipher-words { gap: 1em; }
  .tower-cipher-keyboard { max-width: 85vw; }
  .tower-rune-stairs { gap: 0.8em; padding: 1em 1.2em; }
  .gem-number-pad { grid-template-columns: repeat(6, 1fr); max-width: 80vw; }
}
