:root {
  --ink: #1f1733;
  --muted: #604f74;
  --paper: #fff8ea;
  --panel: #fffdf5;
  --purple: #4e2684;
  --purple-dark: #25143d;
  --orange: #f27b1d;
  --green: #9edc45;
  --blue: #17275a;
  --blue-soft: #dfe9ff;
  --cream: #fff1c7;
  --pink: #fbb6ce;
  --line: rgba(31, 23, 51, 0.18);
  --shadow: 0 18px 40px rgba(13, 11, 36, 0.22);
  --focus: #00a8a8;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 14% 12%, rgba(158, 220, 69, 0.24), transparent 260px),
    radial-gradient(circle at 86% 8%, rgba(242, 123, 29, 0.26), transparent 260px),
    linear-gradient(180deg, #16204a 0, #292563 260px, #f6e5ff 720px, #fff8ea 100%);
}

body,
button,
input,
select {
  font: 16px/1.4 Arial, Helvetica, sans-serif;
}

button,
select,
input {
  color: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
[draggable="true"]:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

.star {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff6b7;
  clip-path: polygon(50% 0, 61% 36%, 98% 36%, 68% 57%, 79% 92%, 50% 70%, 21% 92%, 32% 57%, 2% 36%, 39% 36%);
}

.s1 { left: 10%; top: 70px; }
.s2 { left: 74%; top: 118px; transform: scale(1.5); }
.s3 { left: 88%; top: 42px; transform: scale(.8); }

.mist {
  position: absolute;
  height: 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  filter: blur(10px);
}

.m1 { left: -8%; top: 330px; width: 42%; }
.m2 { right: -10%; top: 430px; width: 54%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px clamp(12px, 3vw, 28px);
  background: rgba(255, 253, 245, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.tracker {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.room-dots,
.letter-slots {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dot,
.letter-slot {
  display: grid;
  place-items: center;
  min-width: 36px;
  min-height: 36px;
  border: 2px solid var(--line);
  background: #fff;
  font-weight: 800;
}

.dot {
  border-radius: 999px;
}

.dot.unlocked {
  border-color: var(--purple);
}

.dot.solved {
  color: #fff;
  background: var(--green);
  border-color: #4f8d1f;
}

.letter-slot {
  border-radius: 8px;
  background: var(--cream);
}

.app-shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 500px);
  gap: 22px;
  align-items: stretch;
}

.intro,
.house-card,
.teacher-guide,
.map-section,
.room-screen,
.final-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 245, 0.95);
  box-shadow: var(--shadow);
}

.intro {
  padding: clamp(22px, 4vw, 42px);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--purple);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.intro h1 {
  max-width: 780px;
  margin-bottom: 16px;
  font-size: clamp(2.6rem, 7vw, 5.8rem);
  line-height: .92;
  letter-spacing: 0;
}

.intro p {
  max-width: 720px;
  color: #47395d;
  font-size: 1.08rem;
}

.house-card {
  overflow: hidden;
  min-height: 340px;
  background: #16204a;
}

.house-card img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 340px;
  object-fit: cover;
}

.home-actions,
.room-actions,
.final-input-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 22px;
}

.next-room-button {
  background: var(--green);
}

.primary-button,
.secondary-button,
.reset-button,
.icon-button,
.small-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--purple);
}

.primary-button:hover {
  background: #351a60;
}

.secondary-button,
.icon-button,
.small-button {
  background: var(--cream);
  border: 2px solid rgba(31, 23, 51, 0.16);
}

.secondary-button:hover,
.icon-button:hover,
.small-button:hover {
  background: #ffe4a3;
}

.reset-button {
  color: #fff;
  background: #b9442c;
}

.teacher-guide,
.map-section {
  margin-top: 22px;
  padding: 24px;
}

.teacher-guide h2,
.map-section h2 {
  margin-bottom: 16px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-grid article,
details,
.password-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

details {
  margin-top: 12px;
}

summary {
  font-weight: 900;
  cursor: pointer;
}

.password-panel {
  display: grid;
  gap: 10px;
  max-width: 560px;
}

.password-panel p {
  margin-bottom: 0;
}

.password-panel label {
  font-weight: 900;
}

.teacher-password-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.teacher-password-row input {
  max-width: 260px;
}

.auth-feedback {
  min-height: 1.4em;
  color: #b9442c;
  font-weight: 800;
}

.room-map {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.room-card {
  display: grid;
  gap: 12px;
  min-height: 190px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.room-card.unlocked {
  border-color: var(--purple);
}

.room-card.solved {
  border-color: #5b941f;
  background: #f4ffe6;
}

.room-card svg {
  width: 100%;
  max-height: 88px;
}

.room-card img.room-map-trapdoor {
  display: block;
  width: min(220px, 68%);
  height: 112px;
  object-fit: contain;
  justify-self: center;
  align-self: center;
  margin: 0 auto;
}

.room-card strong {
  font-size: 1.1rem;
}

.room-card span {
  color: var(--muted);
  font-weight: 700;
}

.room-screen {
  padding: clamp(18px, 4vw, 34px);
}

.room-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.room-header h2,
.final-card h2 {
  margin-bottom: 8px;
  font-size: clamp(1.8rem, 4vw, 3.3rem);
  line-height: 1;
}

.hint-box,
.feedback-box {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: #fff;
}

.feedback-box:empty {
  display: none;
}

.feedback-box.success {
  border-color: #5b941f;
  background: #f4ffe6;
}

.feedback-box.error {
  border-color: #b9442c;
  background: #fff0ed;
}

.side-reveal-slot {
  margin-top: 14px;
}

.side-room-reveal {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 240px;
  margin: 0 auto;
  padding: 10px;
  border: 2px solid rgba(158, 220, 69, 0.34);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(158, 220, 69, 0.28), transparent 72%),
    #25143d;
  box-shadow: 0 12px 24px rgba(31, 23, 51, 0.18);
  animation: reveal-pop 420ms ease both;
}

.side-room-reveal img {
  display: block;
  width: 100%;
  border-radius: 8px;
}

.side-room-reveal figcaption {
  color: #fff6b7;
  font-size: 0.95rem;
  font-weight: 900;
}

.pumpkin-reveal-panel {
  align-self: start;
}

.pumpkin-workshop-reveal {
  max-width: 260px;
}

.activity-layout {
  display: grid;
  grid-template-columns: minmax(280px, .95fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: start;
}

.scene-panel,
.work-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.grid-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: 6px;
  width: min(100%, 480px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid rgba(31, 23, 51, 0.16);
  border-radius: 8px;
  background: #ecf5ff;
}

.cell:nth-child(even) {
  background: #f5f0ff;
}

.cell svg,
.cell img.grid-icon-image {
  width: 78%;
  height: 78%;
}

.cell img.grid-icon-image {
  object-fit: contain;
}

.cell img.grid-character-image {
  width: 78%;
  height: 78%;
  object-fit: contain;
  border-radius: 50%;
}

.room-card img.grid-icon-image {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.room-card img.grid-icon-image.room-map-trapdoor {
  width: min(220px, 68%);
  height: 112px;
}

.cell-label {
  position: absolute;
  left: 6px;
  top: 4px;
  color: rgba(31, 23, 51, 0.58);
  font-size: .72rem;
  font-weight: 900;
}

.commands {
  display: grid;
  gap: 10px;
}

.arrow-card,
.code-card,
.pattern-card,
.choice-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.arrow-symbol {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  color: #fff;
  background: var(--orange);
  font-size: 2rem;
  font-weight: 900;
}

.arrow-card label,
.code-card label,
.pattern-card label {
  font-weight: 900;
}

.path-layout .commands {
  gap: 10px;
}

.path-layout .arrow-card {
  grid-template-columns: auto minmax(108px, 0.42fr) minmax(160px, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 74px;
  padding: 10px 12px;
}

.path-layout .arrow-symbol {
  width: 42px;
  height: 42px;
  font-size: 1.45rem;
}

.path-layout .arrow-card label {
  margin: 0;
}

.path-layout .arrow-card select {
  min-height: 40px;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
}

.card-bank,
.drop-zone,
.sequence-list {
  display: grid;
  gap: 10px;
}

.sequence-wrap {
  display: grid;
  grid-template-columns: minmax(220px, .58fr) minmax(0, 1fr) minmax(220px, .62fr);
  gap: 16px;
}

.room-hero-banner {
  margin: 0 0 16px;
  overflow: hidden;
  border: 2px solid rgba(78, 38, 132, 0.16);
  border-radius: 8px;
  background: #fff8ea;
  box-shadow: 0 10px 22px rgba(33, 19, 49, 0.08);
}

.potion-room-banner {
  width: calc(100% + (clamp(18px, 4vw, 34px) * 2));
  max-width: none;
  margin: 0 calc(clamp(18px, 4vw, 34px) * -1) 18px;
  border-right: 0;
  border-left: 0;
  border-radius: 0;
}

.room-hero-banner img {
  display: block;
  width: 100%;
  height: clamp(160px, 22vw, 275px);
  object-fit: cover;
  object-position: center;
}

.pumpkin-sequence-wrap {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.42fr);
}

.pumpkin-sequence-wrap.reveal-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.recipe-guide {
  align-self: start;
  padding: 16px;
  border: 2px solid rgba(78, 38, 132, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 241, 199, 0.9), rgba(255, 253, 245, 0.96)),
    var(--cream);
}

.recipe-guide h3 {
  margin-bottom: 8px;
  color: var(--purple);
}

.recipe-guide p {
  color: #47395d;
}

.recipe-guide ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  font-weight: 800;
}

.recipe-guide li::marker {
  color: var(--purple);
  font-weight: 900;
}

.recipe-guide .guide-note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--purple-dark);
  background: #f3e9ff;
  font-weight: 900;
}

.sortable-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sortable-card[aria-grabbed="true"] {
  border-color: var(--focus);
  background: #e9fffb;
}

.card-number {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #fff;
  background: var(--purple);
  font-weight: 900;
}

.move-buttons {
  display: flex;
  gap: 5px;
}

.move-buttons button {
  min-width: 36px;
  min-height: 36px;
  border-radius: 8px;
  background: var(--blue-soft);
  font-weight: 900;
}

.drop-zone {
  min-height: 170px;
  padding: 12px;
  border: 2px dashed rgba(31, 23, 51, 0.28);
  border-radius: 8px;
  background: #fff9ec;
}

.drop-zone.drag-over {
  border-color: var(--focus);
  background: #e9fffb;
}

.drop-title {
  margin: 0;
  font-weight: 900;
}

.pattern-row {
  display: grid;
  grid-template-columns: repeat(9, minmax(80px, 1fr));
  gap: 10px;
}

.pattern-card {
  text-align: center;
}

.pattern-card svg {
  width: 58px;
  height: 58px;
  margin: 0 auto;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice-card {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  text-align: left;
}

.choice-card input {
  width: 22px;
  height: 22px;
}

.choice-card:has(input:checked) {
  border-color: var(--purple);
  background: #f3e9ff;
}

.final-screen {
  position: relative;
}

.final-card {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  padding: clamp(22px, 5vw, 42px);
  text-align: center;
}

.final-card label {
  display: block;
  margin-bottom: 8px;
  font-weight: 900;
}

.final-input-row {
  justify-content: center;
}

.final-input-row input {
  max-width: 260px;
  text-transform: uppercase;
}

.front-door {
  position: relative;
  width: 170px;
  height: 230px;
  margin: 26px auto 10px;
  border: 8px solid var(--purple-dark);
  border-radius: 82px 82px 8px 8px;
  overflow: hidden;
  background: #fff6b7;
  perspective: 600px;
}

.door-panel {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: left center;
  border-radius: 70px 70px 0 0;
  background: linear-gradient(120deg, #7430a9, #f27b1d);
  transition: transform 700ms ease;
}

.door-panel::after {
  content: "";
  position: absolute;
  right: 28px;
  top: 118px;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: #fff6b7;
}

.front-door.open .door-panel {
  transform: rotateY(-68deg);
}

.final-celebration-popup {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: 50%;
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(88vw, 820px);
  padding: clamp(12px, 2vw, 18px);
  border: 3px solid #fff6b7;
  border-radius: 8px;
  background: rgba(15, 20, 52, 0.96);
  box-shadow: 0 26px 70px rgba(9, 8, 26, 0.45);
  opacity: 0;
  transform: translate(-50%, -46%) scale(0.94);
  transition: opacity 320ms ease, transform 320ms ease;
}

.final-celebration-popup.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.final-celebration-popup img {
  display: block;
  width: 100%;
  max-height: min(72vh, 620px);
  object-fit: contain;
  border-radius: 8px;
}

.final-celebration-popup button {
  background: #fff6b7;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: hidden;
}

.celebration span {
  position: absolute;
  left: var(--x);
  top: -48px;
  color: var(--color);
  font-size: 28px;
  animation: confetti-fall var(--duration) linear var(--delay) forwards;
}

@keyframes confetti-fall {
  from {
    opacity: 0;
    transform: translateY(-40px) rotate(0deg) scale(var(--scale));
  }
  12% {
    opacity: 1;
  }
  to {
    transform: translate(var(--drift), 110vh) rotate(var(--turn)) scale(var(--scale));
    opacity: 0;
  }
}

@keyframes reveal-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .home-grid,
  .activity-layout,
  .sequence-wrap {
    grid-template-columns: 1fr;
  }

  .room-map {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pattern-row {
    grid-template-columns: repeat(3, minmax(80px, 1fr));
  }

  .guide-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1200px);
  }

  .room-map {
    grid-template-columns: 1fr;
  }

  .room-header {
    display: grid;
  }

  .intro h1 {
    font-size: clamp(2.2rem, 16vw, 4rem);
  }

  .sortable-card {
    grid-template-columns: 1fr;
  }

  .pumpkin-workshop-reveal {
    max-width: 260px;
  }

  .path-layout .arrow-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .path-layout .arrow-card select {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
