:root {
  color-scheme: light;
  --page: #f7f7f5;
  --paper: #fff;
  --ink: #1d252e;
  --muted: #59616b;
  --line: #d8dbde;
  --blue: #2454c4;
  --blue-dark: #193f9d;
  --green: #157249;
  --red: #a13532;
  font: 16px/1.4 Arial, Helvetica, sans-serif;
  background: var(--page);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, input { -webkit-tap-highlight-color: transparent; }
:where(button, input, [tabindex]):focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }

.stage {
  min-height: 100svh;
  padding: 24px 16px 52px;
  display: grid;
  place-items: center;
}
.stage-stack { width: min(100%, 414px); position: relative; }
#game { min-width: 0; }
#game > .challenge { animation: arrive 160ms ease-out both; }
@keyframes arrive {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}
.history-link {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
.history-link:hover, .text-button:hover { color: var(--blue-dark); }

.check-widget {
  display: flex;
  align-items: center;
  gap: 13px;
  width: min(100%, 324px);
  min-height: 78px;
  padding: 14px 17px;
  margin-inline: auto;
  border: 1px solid #d5d7da;
  border-radius: 4px;
  background: #fcfcfc;
  color: #252a30;
  box-shadow: 0 1px 3px #1822340a;
  text-align: left;
  font-size: 15px;
}
.check-widget:hover .check-box { border-color: #858c96; }
.check-box {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 2px solid #a9afb7;
  border-radius: 2px;
  background: var(--paper);
  color: var(--green);
  transition: border-color 120ms, background 120ms;
}
.check-widget[aria-checked="true"] .check-box { border-color: #b7d8c9; background: #eef8f2; }
.check-box svg { width: 20px; height: 20px; }
.widget-mark {
  margin-left: auto;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 6px);
  grid-auto-rows: 6px;
  align-content: center;
  justify-content: center;
  gap: 2px;
}
.widget-mark i { background: #b4bcc6; border-radius: 1px; }
.widget-mark i:nth-child(3n+1) { background: #7b8ba0; }
.widget-mark i:nth-child(5), .widget-mark i:nth-child(9) { background: #57749b; }
.widget-mark i:nth-child(3) { background: #d5dce4; }

.challenge {
  overflow: hidden;
  border: 1px solid #cfd3d8;
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 8px 24px #222c3a0a, 0 1px 2px #222c3a0a;
  container-type: inline-size;
}
.challenge-header {
  position: relative;
  background: var(--blue);
  color: white;
  padding: 14px 16px 15px;
}
.challenge-header h2 {
  margin: 0;
  color: white;
  font-size: 20px;
  line-height: 1.16;
  letter-spacing: -.022em;
  font-weight: 700;
}
.challenge-header h2 span { display: block; margin-bottom: 3px; font-size: 13px; line-height: 1.2; letter-spacing: 0; font-weight: 400; }
.challenge-header p { margin: 6px 0 0; font-size: 12px; color: #f0f4ff; }
.challenge-body { padding: 9px; }
.challenge-body.padded { padding: 14px; }
.challenge-footer {
  min-height: 59px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid #e3e5e8;
}
.challenge-footer > button:last-child { margin-left: auto; }
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}
.icon-button:hover { background: #f0f2f5; color: var(--ink); }
.icon-button svg { width: 19px; height: 19px; }
.primary {
  min-width: 84px;
  min-height: 38px;
  padding: 8px 15px;
  border: 1px solid var(--blue);
  border-radius: 3px;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.primary:hover { background: var(--blue-dark); }
.primary:disabled { border-color: #e4e8ee; background: #e4e8ee; color: #596578; }
.text-button {
  min-height: 36px;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}
.status[data-tone="error"] { color: var(--red); }
.status[data-tone="good"] { color: var(--green); }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  padding: 0;
  background: #e4e5df;
}
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 140ms ease, opacity 140ms ease; }
.tile:focus-visible { outline-offset: -4px; z-index: 1; }
.tile[aria-pressed="true"] { background: #e9f0ff; }
.tile[aria-pressed="true"] img { transform: scale(.80); }
.tile[aria-pressed="true"]::after {
  content: '✓';
  position: absolute;
  display: grid;
  place-items: center;
  top: 3px;
  left: 3px;
  width: 23px;
  height: 23px;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 700;
}
.tile[data-wrong] { box-shadow: inset 0 0 0 3px var(--red); }
.tile[data-wrong] img { opacity: .62; }
.tile[data-new] img { animation: refresh 220ms ease-out; }
@keyframes refresh { from { opacity: .25; } to { opacity: 1; } }
.timer-bar { position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; transform-origin: left; background: #a8c2ff; }

.sample {
  display: grid;
  place-items: center;
  position: relative;
  height: 88px;
  border: 1px solid #dadddf;
  overflow: hidden;
  background: repeating-linear-gradient(168deg, #f3f2eb, #f3f2eb 5px, #ecebe1 6px, #f3f2eb 7px);
}
.sample::after {
  content: '';
  pointer-events: none;
  position: absolute;
  left: -5%;
  top: 55%;
  width: 110%;
  height: 12px;
  border-top: 1px solid #86887f;
  border-radius: 50%;
  transform: rotate(-7deg);
}
.code-glyphs {
  display: flex;
  gap: .14em;
  align-items: center;
  font: italic 700 clamp(35px, 13cqw, 48px)/1 Georgia, serif;
  color: #343e43;
  user-select: none;
}
.code-glyphs span:nth-child(1) { transform: rotate(-14deg) translateY(2px); }
.code-glyphs span:nth-child(2) { transform: rotate(15deg) scaleY(.85); color: #566365; }
.code-glyphs span:nth-child(3) { transform: rotate(-11deg) scaleX(.84) translateY(-2px); }
.code-glyphs span:nth-child(4) { transform: rotate(13deg) translateY(3px); color: #565952; }
.code-glyphs .zero { position: relative; }
.code-glyphs .zero::after {
  content: '';
  position: absolute;
  top: 48%;
  left: 31%;
  width: 44%;
  height: 2px;
  transform: rotate(-47deg);
  background: currentColor;
}
.code-input {
  width: 100%;
  height: 42px;
  margin-top: 11px;
  padding: 6px 10px;
  border: 1px solid #bfc6cf;
  border-radius: 3px;
  color: var(--ink);
  background: white;
}
.fall-field {
  position: relative;
  height: clamp(135px, 48cqw, 182px);
  margin: 9px 0 7px;
  overflow: hidden;
  border: 1px solid #dce2eb;
  background: repeating-linear-gradient(90deg, #f8faff, #f8faff calc(20% - 1px), #e8edf7 calc(20% - 1px), #e8edf7 20%);
}
.fall-field[hidden] { display: none; }
.fall-glyph {
  position: absolute;
  top: 0;
  width: clamp(34px, 12cqw, 44px);
  height: 38px;
  padding: 0;
  border: 1px solid #becdec;
  border-radius: 3px;
  background: white;
  color: #233f78;
  font: 700 22px/1 Georgia, serif;
  will-change: transform;
}
.fall-glyph:focus-visible { z-index: 1; outline-offset: -3px; }
.fall-glyph:hover { background: #eaf0ff; }
.fall-glyph[data-miss] { background: #ffeded; border-color: #ba635d; }
.catch-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 9px; margin-top: 8px; }
.catch-slots { display: flex; gap: 5px; }
.catch-slots span {
  display: grid;
  place-items: center;
  width: 31px;
  height: 33px;
  border: 1px dashed #bcc7d6;
  border-radius: 3px;
  font: 700 18px/1 Georgia, serif;
}
.catch-slots span:not(:empty) { border-style: solid; background: #edf5ff; color: #244880; }

.puzzle-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 3/2;
  overflow: hidden;
  border-radius: 2px;
  background: #d7d9c9 var(--puzzle-image) center / cover;
}
.cutout {
  position: absolute;
  top: 37%;
  width: 17%;
  aspect-ratio: 1;
  clip-path: polygon(0 15%, 36% 15%, 36% 0, 62% 0, 62% 15%, 100% 15%, 100% 41%, 84% 41%, 84% 64%, 100% 64%, 100% 100%, 0 100%);
}
.cutout-hole { left: 63%; background: #121721bd; }
.cutout-piece {
  left: var(--piece-left, 3%);
  background: var(--puzzle-image) 75.9% 49.67% / 588.235% auto;
  box-shadow: inset 0 0 0 2px #fffe;
}
.puzzle-photo[data-aligned] .cutout-piece { box-shadow: inset 0 0 0 3px #a3f3cb; }
.slide-range { display: block; width: 100%; height: 38px; margin: 8px 0 0; accent-color: var(--blue); }
.tilt-wrap { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 17px 0 7px; }
.tilt-rail {
  position: relative;
  display: flex;
  align-items: center;
  height: 35px;
  touch-action: none;
  cursor: ns-resize;
}
.rail {
  width: 100%;
  position: relative;
  height: 8px;
  border-radius: 5px;
  background: #e1e7f2;
  transform: rotate(var(--tilt, 0deg));
}
.rail::after {
  content: '';
  position: absolute;
  top: -3px;
  left: 79%;
  height: 14px;
  width: 2px;
  background: #8aa4df;
}
.rail i {
  position: absolute;
  z-index: 1;
  left: var(--rail-knob, 0%);
  width: 16px;
  height: 16px;
  top: -4px;
  transform: translateX(-50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 1px #92a4c6;
}
.tilt-button {
  width: 40px;
  height: 34px;
  border: 1px solid #cbd3e0;
  border-radius: 3px;
  background: #f7f9fd;
  color: #24427e;
  touch-action: none;
}
.tilt-button:active { background: #dce8ff; }
.tilt-help { margin: 1px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

#history {
  width: min(930px, calc(100vw - 24px));
  max-height: calc(100svh - 28px);
  padding: 0;
  overflow: auto;
  border: 1px solid #cdd2da;
  border-radius: 7px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 18px 70px #15223e36;
}
#history::backdrop { background: #1c26374d; }
.history-head {
  padding: 10px 15px 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.history-head h1 { margin: 0; font-size: 18px; }
.history-nav { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.history-nav button {
  padding: 6px 9px;
  border: 1px solid #d6dce6;
  border-radius: 4px;
  background: white;
  color: #475366;
  font-size: 12px;
}
.history-nav button[aria-pressed="true"] { border-color: #8ca8e8; background: #e9f0ff; color: #193f9d; }
#history-content { padding: 12px 16px 16px; }
.exhibit-note { margin: 0 0 13px; max-width: 68ch; color: #4c5767; font-size: 13px; }
.exhibits { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.exhibit { min-width: 0; }
.exhibit h2 { margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.exhibit .challenge-header h2 { color: white; font-size: 19px; font-weight: 700; }
.exhibit .challenge-footer { min-height: 52px; }
.replay-result { padding: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
.replay-result p { margin: 0 0 6px; color: var(--green); font-size: 13px; }
.history-foot { padding: 4px 16px; border-top: 1px solid var(--line); background: var(--paper); }

@media (max-width: 620px) {
  .exhibits { grid-template-columns: 1fr; }
  .exhibit { width: min(100%, 414px); }
}
@media (max-width: 380px) {
  .stage { padding-inline: 11px; }
  .challenge-header { padding-inline: 12px; }
  .challenge-body { padding: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.rotation-shell {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.rotation-card {
  width: 100%;
  transition: rotate 240ms ease;
}
.rotation-window {
  width: clamp(78px, calc(100cqw - 205px), 195px);
  aspect-ratio: 1;
  overflow: hidden;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #e4e5df;
}
.rotation-window img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: rotate 240ms ease;
}
.rotation-controls, .cursor-choices {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-top: 9px;
}
.rotate-button, .cursor-choices button {
  min-width: 44px;
  min-height: 38px;
  padding: 4px 8px;
  border: 1px solid #cbd3e0;
  border-radius: 3px;
  background: #f7f9fd;
  color: #24427e;
}
.rotate-button { font-size: 21px; line-height: 1; }
.rotate-button small { font-size: 11px; vertical-align: 2px; }
.rotate-button:hover, .cursor-choices button:not(:disabled):hover { background: #e8effe; }
.cursor-choices button { font-size: 13px; font-weight: 700; }
.cursor-choices button:disabled { opacity: .5; }
.cursor-choices button[aria-pressed="true"] { border-color: var(--blue); background: #e1eaff; color: var(--blue-dark); }

.cursor-field {
  position: relative;
  height: clamp(132px, 47cqw, 183px);
  overflow: hidden;
  border: 1px solid #c8d3e3;
  border-radius: 2px;
  background-color: #f6f8fc;
  background-image: radial-gradient(#c6d1e3 1px, transparent 1px);
  background-size: 13px 13px;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
.cursor-field.tracking { cursor: none; }
.cursor-marker {
  position: absolute;
  display: flex;
  align-items: flex-end;
  gap: 1px;
  pointer-events: none;
}
.cursor-marker svg {
  width: 18px;
  height: 21px;
  fill: #2d3c50;
  stroke: white;
  stroke-width: 1.3;
  stroke-linejoin: round;
}
.cursor-marker span {
  padding: 0 3px;
  border: 1px solid #cbd3e0;
  border-radius: 2px;
  background: white;
  color: #27384e;
  font-size: 10px;
  font-weight: 700;
}
.cursor-marker[data-selected] { z-index: 1; }
.cursor-marker[data-selected] svg { fill: var(--blue); }
.cursor-marker[data-selected] span { border-color: var(--blue); color: var(--blue-dark); }
