/* The Triwizard remix: the boards the new division challenges draw.
   ------------------------------------------------------------------------
   Everything js/remix-triwizard.js mounts into the stage panel: picture
   cards to choose between, the fair-shares judge, the Goblet round, the
   fact-family house, Gringotts vaults, the hedge maze, the balance, the
   halving chain, the fact ladder and the boats at the dock.

   House rules kept from css/style.css and css/division.css: every size is a
   clamp(), nothing scrolls, a phone held sideways sizes from the height, and
   every animation is short and switched off under prefers-reduced-motion. */

@keyframes rtw-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-2deg); }
  45% { transform: translateX(7px) rotate(2deg); }
  70% { transform: translateX(-4px); }
}
@keyframes rtw-pop {
  0% { transform: scale(0.7); opacity: 0.2; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes rtw-arrive {
  from { transform: translateY(-26px) scale(0.5); opacity: 0; }
}
@keyframes rtw-glow {
  0%, 100% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.16), 0 0 0 0 rgba(255, 201, 74, 0.9); }
  50% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.16), 0 0 0 12px rgba(255, 201, 74, 0); }
}
@keyframes rtw-flicker {
  0%, 100% { transform: scale(1) rotate(-2deg); }
  50% { transform: scale(1.12) rotate(2deg); }
}

.rtw-shake { animation: rtw-shake 0.45s ease; }
.rtw-pop { animation: rtw-pop 0.35s ease; }

/* Printed only, never spoken: the sum being worked, a running note. */
.rtw-lead {
  margin: 0;
  text-align: center;
  font-size: clamp(1.05rem, 3.6vw, 1.6rem);
  font-weight: bold;
  color: var(--gold-deep);
  letter-spacing: 0.02em;
}
.rtw-note {
  margin: 0;
  text-align: center;
  font-size: clamp(0.85rem, 2.8vw, 1.15rem);
  color: var(--ink);
  opacity: 0.85;
  min-height: 1.3em;
}
.solved > .rtw-note { color: var(--green); opacity: 1; font-weight: bold; }

/* The big fact in the middle of the Goblet round and the maze. */
.rtw-fact {
  font-size: clamp(2.2rem, 10vw, 4.4rem);
  color: var(--gold-deep);
  letter-spacing: 0.05em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
  line-height: 1.1;
}

.rtw-goblet, .rtw-maze, .rtw-fair, .rtw-house, .rtw-vault, .rtw-balance,
.rtw-chain, .rtw-ladder, .rtw-dock, .rtw-cardwrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1.4vh, 12px);
  width: 100%;
}

/* Answer tiles laid into the controls row by a multi-step board. */
.choices.stage-controls .rtw-tile { flex: 0 0 auto; }
.choices.stage-controls .rtw-tile.word { min-width: clamp(90px, 22vw, 170px); font-size: clamp(1.1rem, 4.2vw, 1.8rem); }
.choices.stage-controls .rtw-door { font-size: clamp(1.2rem, 4.6vw, 2.1rem); white-space: nowrap; }
.choices.stage-controls .rtw-door.wrong { font-size: clamp(0.8rem, 2.6vw, 1.1rem); }
.stage-step.chosen { outline: 4px solid var(--gold-deep); outline-offset: 2px; }
.stage-step.glow { animation: rtw-glow 1.1s ease-in-out infinite; }
.stage-step:disabled { opacity: 0.5; }

/* ============================================================ picture cards */
.rtw-cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 2.2vw, 18px);
  width: 100%;
}
.rtw-card {
  font: inherit;
  cursor: pointer;
  flex: 1 1 0;
  min-width: clamp(96px, 26vw, 150px);
  max-width: 240px;
  min-height: clamp(90px, 18vh, 170px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(6px, 1.4vw, 12px);
  background: linear-gradient(180deg, #fffdf6, var(--parchment));
  border: 4px solid var(--parchment-edge);
  border-radius: 18px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.16);
  transition: transform 0.09s ease, opacity 0.25s ease;
}
.rtw-card:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.16); }
.rtw-card.correct { border-color: var(--green); background: linear-gradient(180deg, #eaffef, #c7f5d8); animation: rtw-pop 0.4s ease; }
.rtw-card.wrong { opacity: 0.35; filter: grayscale(0.85); animation: rtw-shake 0.4s ease; box-shadow: none; }
.rtw-card.glow { border-color: var(--gold-deep); animation: rtw-glow 1.1s ease-in-out infinite; }

/* Groups and leftovers: 13 in fours. */
.rtw-mini-groups {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.rtw-g {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 1px;
  padding: 3px 5px;
  border: 3px solid var(--gold-deep);
  border-radius: 12px;
  background: rgba(255, 201, 74, 0.16);
}
.rtw-g i { font-style: normal; font-size: clamp(0.95rem, 3.2vw, 1.5rem); line-height: 1.1; }
.rtw-g.rtw-left {
  border-style: dotted;
  border-color: var(--red);
  background: rgba(226, 87, 76, 0.08);
}

/* A mini array: equal rows, or not. */
.rtw-mini-array { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.rtw-row { display: flex; gap: 4px; }
.rtw-row i {
  width: clamp(9px, 2.4vw, 15px);
  height: clamp(9px, 2.4vw, 15px);
  border-radius: 50%;
  background: var(--sea);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

/* A mini bar model. */
.rtw-mini-bar { display: flex; flex-direction: column; align-items: stretch; width: 100%; gap: 3px; }
.rtw-mini-bar > b { text-align: center; color: var(--gold-deep); font-size: clamp(1rem, 3.4vw, 1.4rem); }
.rtw-bar-body {
  display: flex;
  height: clamp(28px, 6vh, 44px);
  border: 3px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
  background: var(--parchment-2);
}
.rtw-bar-body i { border-right: 3px solid var(--ink); background: rgba(255, 201, 74, 0.35); }
.rtw-bar-body i:nth-child(even) { background: rgba(255, 201, 74, 0.6); }
.rtw-bar-body i:last-child { border-right: 0; }

/* ======================================================== fair or not? */
.rtw-holders {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(6px, 1.8vw, 14px);
}
.rtw-holder {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: clamp(64px, 16vw, 110px);
  padding: 6px 6px 4px;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid var(--parchment-edge);
  border-radius: 16px;
  color: var(--ink);
}
.rtw-holder:disabled { opacity: 1; cursor: default; }
.rtw-fair.fixing .rtw-holder { cursor: pointer; border-color: var(--gold-deep); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14); }
.rtw-holder.glow { animation: rtw-glow 1.1s ease-in-out infinite; }
.rtw-h-e { font-size: clamp(1.4rem, 5vw, 2.2rem); line-height: 1; }
.rtw-h-items {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 1px;
  min-height: 2.2em;
  justify-content: center;
}
.rtw-it { font-size: clamp(0.95rem, 3.4vw, 1.5rem); line-height: 1.1; }
.rtw-it.rtw-arrive { animation: rtw-arrive 0.45s ease; }
.rtw-h-n {
  font-weight: bold;
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: var(--gold-deep);
}
.rtw-fair.solved .rtw-holder { border-color: var(--green); }
.rtw-fair.solved .rtw-h-n { color: var(--green); }

/* ======================================================= the Goblet round */
.rtw-flames { display: flex; gap: clamp(4px, 1.6vw, 12px); }
.rtw-flame {
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  filter: grayscale(1) brightness(1.4);
  opacity: 0.35;
  transition: filter 0.3s ease, opacity 0.3s ease;
}
.rtw-flame.lit {
  filter: hue-rotate(185deg) saturate(1.6);
  opacity: 1;
  animation: rtw-flicker 1.4s ease-in-out infinite;
}

/* ================================================== the fact-family house */
.rtw-roof {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 3vw, 22px);
  width: min(100%, 420px);
  padding: clamp(18px, 5vh, 34px) 12px 8px;
  background: linear-gradient(180deg, #b0452f, #8a2f20);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  color: #fff6e0;
  font-weight: bold;
  font-size: clamp(1.2rem, 4.4vw, 1.9rem);
}
.rtw-roof .big { font-size: 1.25em; color: #ffe08a; }
.rtw-windows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(5px, 1.4vw, 10px);
  width: min(100%, 420px);
  padding: clamp(6px, 1.4vw, 10px);
  background: var(--parchment-2);
  border: 4px solid var(--wood);
  border-top: 0;
  border-radius: 0 0 12px 12px;
}
.rtw-win {
  text-align: center;
  padding: 6px 4px;
  border: 3px solid var(--parchment-edge);
  border-radius: 10px;
  background: #fffdf6;
  font-size: clamp(1rem, 3.6vw, 1.5rem);
  white-space: nowrap;
}
.rtw-win.now { border-color: var(--gold-deep); box-shadow: 0 0 0 4px rgba(255, 201, 74, 0.45); }
.rtw-win.done { border-color: var(--green); background: #eaffef; }
.rtw-win .gap { color: var(--gold-deep); }

/* ============================================================ the vaults */
.rtw-pool, .rtw-v-in {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 3px;
}
.rtw-pool {
  min-height: clamp(34px, 7vh, 54px);
  max-width: min(100%, 560px);
  padding: 6px 10px;
  border: 3px dashed var(--parchment-edge);
  border-radius: 14px;
}
.rtw-empty { opacity: 0.5; font-style: italic; }
.rtw-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(12px, 2.8vw, 18px);
  height: clamp(36px, 8vh, 54px);
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  writing-mode: vertical-rl;
  font-weight: bold;
  color: #6b4200;
  background: linear-gradient(90deg, #ffe08a, var(--gold), #e3a72a);
  border: 2px solid var(--gold-deep);
  border-radius: 3px;
}
.rtw-coin {
  width: clamp(10px, 2.4vw, 15px);
  height: clamp(10px, 2.4vw, 15px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2b8, var(--gold) 60%, #c98a14);
  border: 1px solid var(--gold-deep);
}
.rtw-vaults {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(5px, 1.6vw, 12px);
}
.rtw-v {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: clamp(58px, 14vw, 96px);
  max-width: 130px;
  padding: 4px;
  border: 3px solid var(--wood);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}
.rtw-v-e { font-size: clamp(1.1rem, 4vw, 1.7rem); line-height: 1; }
.rtw-v-in { min-height: clamp(22px, 5vh, 40px); }
.rtw-v-n { font-weight: bold; color: var(--gold-deep); font-size: clamp(0.9rem, 3vw, 1.2rem); }
.rtw-vault.solved .rtw-v { border-color: var(--green); }

/* ============================================================== the maze */
.rtw-path {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  max-width: 100%;
  padding: 6px 10px;
  background: linear-gradient(180deg, #4f8a3a, #2f6a24);
  border-radius: 999px;
}
.rtw-j {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(30px, 8vw, 50px);
  height: clamp(30px, 8vw, 50px);
  border-radius: 50%;
  background: #cfe9b5;
  font-size: clamp(1rem, 3.6vw, 1.6rem);
  border: 3px solid #1f4a18;
}
.rtw-j.done { background: #eaffef; color: var(--green); font-weight: bold; }
.rtw-j.now { background: #fff3c4; box-shadow: 0 0 0 4px rgba(255, 201, 74, 0.7); }
.rtw-j.goal { background: #ffe08a; }
.rtw-hedge { width: clamp(10px, 4vw, 34px); height: 6px; background: #cfe9b5; opacity: 0.7; }

/* =========================================================== the balance */
.rtw-scale {
  --t: 0;
  position: relative;
  width: min(100%, 440px);
  height: clamp(110px, 24vh, 180px);
}
.rtw-beam {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 22%;
  height: 8px;
  border-radius: 4px;
  background: var(--wood);
  transform: rotate(calc(var(--t) * 12deg));
  transition: transform 0.4s ease;
}
.rtw-post {
  position: absolute;
  left: calc(50% - 6px);
  top: 22%;
  bottom: 0;
  width: 12px;
  background: var(--wood);
  border-radius: 6px 6px 0 0;
}
.rtw-post::after {
  content: "";
  position: absolute;
  left: -30px;
  right: -30px;
  bottom: 0;
  height: 10px;
  border-radius: 6px;
  background: var(--wood);
}
.rtw-pan {
  position: absolute;
  top: calc(22% + 18px);
  width: 34%;
  min-height: 44%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px;
  border: 3px solid var(--wood);
  border-top: 0;
  border-radius: 0 0 50% 50% / 0 0 30% 30%;
  background: rgba(255, 255, 255, 0.55);
  transition: transform 0.4s ease;
}
/* The pans hang under the beam at ±29% of the width, so they rise and fall
   by about what the beam does there when it tilts twelve degrees. */
.rtw-pan::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -16px;
  width: 3px;
  height: 16px;
  margin-left: -1.5px;
  background: var(--wood);
}
.rtw-pan.left { left: 4%; transform: translateY(calc(var(--t) * -26px)); }
.rtw-pan.right { right: 4%; transform: translateY(calc(var(--t) * 26px)); }
.rtw-weight {
  padding: 2px 10px;
  border-radius: 8px;
  background: #5b5b66;
  color: #fff;
  font-weight: bold;
  font-size: clamp(1.1rem, 4vw, 1.7rem);
}
.rtw-bags { display: flex; flex-wrap: wrap-reverse; justify-content: center; gap: 2px; }
.rtw-bag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(20px, 5vw, 30px);
  height: clamp(20px, 5vw, 30px);
  padding: 0 3px;
  border-radius: 8px 8px 12px 12px;
  background: #a0703a;
  color: #fff6e0;
  font-weight: bold;
  font-size: clamp(0.7rem, 2.4vw, 1rem);
  animation: rtw-arrive 0.3s ease;
}
.rtw-scale.level .rtw-beam { background: var(--green); }
.rtw-scale.tipped .rtw-beam { background: var(--red); }

/* ====================================================== the halving chain */
.rtw-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.2vw, 10px);
}
.rtw-link {
  min-width: clamp(52px, 13vw, 86px);
  padding: 6px 10px;
  text-align: center;
  border: 4px solid var(--parchment-edge);
  border-radius: 14px;
  background: #fffdf6;
  font-size: clamp(1.4rem, 5.4vw, 2.4rem);
  font-weight: bold;
  color: var(--ink);
}
.rtw-link.last { border-color: var(--green); animation: rtw-pop 0.35s ease; }
.rtw-link.empty { color: var(--gold-deep); border-style: dashed; }
.rtw-link.empty.now { border-color: var(--gold-deep); box-shadow: 0 0 0 4px rgba(255, 201, 74, 0.45); }
.rtw-arrow { color: var(--gold-deep); font-weight: bold; font-size: clamp(0.9rem, 3vw, 1.3rem); white-space: nowrap; }
.rtw-chain.solved .rtw-link.last { background: #eaffef; }

/* ======================================================= the fact ladder */
.rtw-climb { display: flex; align-items: baseline; gap: clamp(8px, 2.6vw, 20px); flex-wrap: wrap; justify-content: center; }
.rtw-now { font-size: clamp(1.6rem, 6.4vw, 3rem); font-weight: bold; color: var(--ink); }
.rtw-goal { font-size: clamp(1.3rem, 5vw, 2.3rem); color: var(--gold-deep); font-weight: bold; }
.rtw-rungs {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
  width: min(86vw, 540px);
}
.rtw-rung {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 0;
  border: 3px solid var(--wood);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  min-height: clamp(38px, 8vh, 56px);
  justify-content: space-between;
}
.rtw-rung b { font-size: clamp(0.72rem, 2.5vw, 1.05rem); min-height: 1.2em; }
.rtw-rung i { font-style: normal; font-size: clamp(0.6rem, 1.9vw, 0.8rem); opacity: 0.6; }
.rtw-rung.known { background: #eaf4ff; }
.rtw-rung.seen b { color: var(--ink); }
.rtw-rung.now { border-color: var(--gold-deep); background: #fff3c4; transform: translateY(-4px); box-shadow: 0 0 0 3px rgba(255, 201, 74, 0.5); }
.rtw-ladder.solved .rtw-rung.now { border-color: var(--green); background: #eaffef; }

/* ========================================================== the dock */
.rtw-boxes, .rtw-wait { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.rtw-boxes { min-height: clamp(36px, 8vh, 60px); }
.rtw-box {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border: 3px solid var(--sea-deep);
  border-radius: 14px;
  background: rgba(127, 208, 242, 0.25);
  animation: rtw-pop 0.35s ease;
}
.rtw-box-e { font-size: clamp(1rem, 3.6vw, 1.6rem); }
.rtw-box-in i { font-style: normal; font-size: clamp(0.95rem, 3.2vw, 1.45rem); }
.rtw-wait i { font-style: normal; font-size: clamp(1.1rem, 3.9vw, 1.8rem); }
.rtw-wait {
  max-width: min(100%, 520px);
  padding: 5px 10px;
  border-top: 5px solid var(--wood);
  min-height: clamp(30px, 6vh, 48px);
}
.rtw-wait.left { border-top-color: var(--red); background: rgba(226, 87, 76, 0.08); border-radius: 0 0 12px 12px; }

/* Rule sentences sort better big: they are sums, not stories. */
.drag-item.story.rtw-sum .text { font-size: clamp(1rem, 3.6vw, 1.5rem); white-space: nowrap; }

/* ========================================== a phone held sideways */
@media (max-height: 520px) {
  .rtw-goblet, .rtw-maze, .rtw-fair, .rtw-house, .rtw-vault, .rtw-balance,
  .rtw-chain, .rtw-ladder, .rtw-dock, .rtw-cardwrap { gap: 3px; }
  .rtw-fact { font-size: clamp(1.4rem, 10vh, 2.4rem); }
  .rtw-roof { padding: 6px 10px 3px; width: min(100%, 360px); }
  .rtw-windows { grid-template-columns: repeat(4, auto); width: auto; padding: 4px; gap: 4px; }
  .rtw-boxes { min-height: 0; }
  .rtw-box-in i { font-size: clamp(0.75rem, 4.4vh, 1.1rem); }
  .rtw-wait { min-height: 0; padding: 2px 8px; }
  .rtw-wait i { font-size: clamp(0.85rem, 5.4vh, 1.3rem); }
  .rtw-flames .rtw-flame { font-size: clamp(1rem, 7vh, 1.5rem); }
  .rtw-lead { font-size: clamp(0.9rem, 5vh, 1.2rem); }
  .rtw-note { font-size: clamp(0.75rem, 4vh, 0.95rem); }
  .rtw-card { min-height: clamp(70px, 26vh, 120px); }
  .rtw-g i { font-size: clamp(0.7rem, 4vh, 1rem); }
  .rtw-flame { font-size: clamp(1.2rem, 9vh, 1.8rem); }
  .rtw-roof { padding-top: 12px; font-size: clamp(1rem, 6vh, 1.4rem); }
  .rtw-win { font-size: clamp(0.85rem, 5vh, 1.15rem); padding: 3px; }
  .rtw-scale { height: clamp(90px, 34vh, 130px); }
  .rtw-bar { height: clamp(26px, 10vh, 38px); }
  .rtw-link { font-size: clamp(1.1rem, 8vh, 1.8rem); padding: 3px 8px; }
  .rtw-now { font-size: clamp(1.2rem, 9vh, 2rem); }
  .rtw-goal { font-size: clamp(1rem, 7vh, 1.6rem); }
  .rtw-rung { min-height: clamp(28px, 11vh, 40px); }
  .rtw-it { font-size: clamp(0.8rem, 5vh, 1.15rem); }
  .rtw-h-e { font-size: clamp(1.1rem, 7vh, 1.6rem); }
  .rtw-j { width: clamp(26px, 10vh, 38px); height: clamp(26px, 10vh, 38px); }
}

@media (prefers-reduced-motion: reduce) {
  .rtw-shake, .rtw-pop, .rtw-card.correct, .rtw-card.wrong, .rtw-card.glow, .rtw-it.rtw-arrive,
  .rtw-flame.lit, .rtw-bag, .rtw-link.last, .rtw-box, .rtw-holder.glow, .stage-step.glow {
    animation: none;
  }
  .rtw-beam, .rtw-pan, .rtw-flame { transition: none; }
}

/* A number line or a bar as the picture of a tap puzzle (hops left,
   explain the model). The stimulus box shrinks to its content, and neither
   has a width of its own, so they are given the panel's. */
.play-screen .stimulus:has(> .numberline),
.play-screen .stimulus:has(> .barstage) { width: 100%; }

/* A whole number sentence as the picture ("31 ÷ 6 = 4 r 7"): one line,
   sized to fit, rather than the single-word card size that wraps it. */
.wordcard .rtw-sum-card {
  display: inline-block;
  white-space: nowrap;
  font-size: clamp(1.8rem, 7.4vw, 3.6rem);
  letter-spacing: 0.03em;
}
@media (max-height: 520px) {
  .wordcard .rtw-sum-card { font-size: clamp(1.4rem, 11vh, 2.6rem); }
}
