.mip-game {
  --mip-plum: #362147;
  --mip-purple: #613989;
  --mip-muted: #614f6c;
  --mip-cream: #fffbf3;
  --mip-line: #dccbeb;
  --mip-focus: #6628a1;
  width: min(100%, 960px);
  margin-inline: auto;
  padding: clamp(14px, 3.5vw, 34px);
  border: 1px solid var(--mip-line);
  border-radius: clamp(20px, 3vw, 32px);
  color: var(--mip-plum);
  background: linear-gradient(155deg, #f7edff 0%, var(--mip-cream) 47%);
  box-shadow: 0 5px 0 #d8c5ef68, 0 10px 26px #51336e10;
}

.mip-game *, .mip-game *::before, .mip-game *::after { box-sizing: border-box; }
.mip-game h1, .mip-game h2, .mip-game p { margin: 0; }
.mip-game button { font-family: inherit; font-size: inherit; }
.mip-game button:focus-visible {
  outline: 3px solid var(--mip-focus);
  outline-offset: 3px;
}

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

.mip-exit, .mip-action {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.38em;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  touch-action: manipulation;
}

.mip-exit {
  margin-bottom: clamp(12px, 2vw, 20px);
  padding: 0.3em 0.75em;
  border-color: #cfbce1;
  color: var(--mip-purple);
  background: #fffcff;
}

.mip-exit svg { width: 1.15em; height: 1.15em; }
.mip-exit:hover { background: #eee0fb; }

.mip-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 8px 20px;
}

.mip-game .mip-term {
  margin-bottom: 0.25em;
  color: var(--mip-muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.mip-heading h1 {
  font-size: clamp(1.35rem, 4.2vw, 2.55rem);
  line-height: 1.23;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.mip-progress {
  min-width: 78px;
  flex: none;
  display: grid;
  justify-items: center;
  padding: 0.38em 0.65em;
  border: 1px solid #e1ceef;
  border-radius: 12px;
  color: #59367b;
  background: #f1e4fa;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.35;
}

.mip-progress strong {
  font-size: 1.13rem;
  font-variant-numeric: tabular-nums;
}

.mip-game .mip-rule {
  margin-top: 0.6em;
  color: var(--mip-muted);
  font-size: clamp(0.94rem, 2vw, 1.06rem);
  line-height: 1.55;
}

.mip-play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(215px, 0.45fr);
  align-items: start;
  gap: clamp(14px, 3vw, 26px);
  margin-top: clamp(15px, 2.7vw, 24px);
}

.mip-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 1.6vw, 15px);
}

.mip-card {
  position: relative;
  display: grid;
  container-type: inline-size;
  min-width: 44px;
  min-height: 88px;
  aspect-ratio: 1.18;
  place-items: center;
  padding: 0;
  border: 2px solid #623d88;
  border-radius: clamp(12px, 2vw, 18px);
  color: #fbdfef;
  background: radial-gradient(ellipse at 25% 8%, #8b58ac 0, #68418f 57%, #563479);
  box-shadow: 0 4px 0 #46247132;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.mip-card:not([aria-disabled]):hover {
  border-color: #452269;
  box-shadow: 0 4px 0 #52278564;
}

.mip-card[aria-disabled="true"] { cursor: default; }

.mip-card-back {
  position: absolute;
  inset: clamp(5px, 1vw, 10px);
  display: grid;
  place-items: center;
  border: 1px dashed #edd3efaa;
  border-radius: clamp(7px, 1vw, 11px);
  background: radial-gradient(circle, #fff5 1px, transparent 1.5px) 0 0 / 12px 12px;
  pointer-events: none;
}

.mip-card-back svg {
  display: block;
  width: min(63%, 88px);
  height: auto;
  filter: drop-shadow(0 3px 4px #3d255541);
}

.mip-card--open {
  border-color: #9162b7;
  color: var(--mip-plum);
  background: #fffdf6;
  box-shadow: 0 4px 0 #9562b42d;
}

.mip-card--different {
  border-color: #a66b21;
  background: #fff9e9;
  box-shadow: 0 4px 0 #b3732433;
}

.mip-card--matched {
  border-color: #638b70;
  background: #f0faef;
  box-shadow: 0 4px 0 #638b702e;
}

.mip-card-check {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  width: clamp(16px, 13cqw, 23px);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #406e50;
}

.mip-card-check svg { width: 70%; }

.mip-face {
  display: grid;
  width: 100%;
  min-width: 0;
  place-items: center;
  padding: clamp(8px, 11cqw, 15px) 3px clamp(6px, 6cqw, 10px);
  animation: mip-reveal 160ms ease-out both;
}

@keyframes mip-reveal {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.mip-number, .mip-expression {
  font-weight: 900;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.mip-number { font-size: clamp(1.85rem, 30cqw, 3.65rem); }
.mip-number small { margin-inline-start: 0.2em; font-size: 0.43em; }
.mip-expression { font-size: clamp(1.18rem, 21cqw, 2.35rem); }

.mip-stars {
  display: grid;
  grid-template-columns: repeat(var(--mip-columns), auto);
  gap: 5px 1px;
  color: #885495;
  font-size: clamp(0.88rem, 16cqw, 1.7rem);
  line-height: 1;
}

.mip-blocks {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: clamp(3px, 4cqw, 10px);
}

.mip-block-group {
  display: grid;
  justify-items: center;
  align-items: end;
  gap: 3px;
  color: #4c3b60;
  font-size: clamp(0.62rem, 10cqw, 0.87rem);
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.mip-rods, .mip-cubes {
  display: grid;
  align-content: end;
  gap: 2px;
}

.mip-rods { grid-auto-flow: column; }
.mip-cubes { grid-template-columns: repeat(3, auto); }

.mip-rods i {
  display: grid;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  width: clamp(5px, 6cqw, 10px);
  height: clamp(35px, 44cqw, 70px);
  border: 1px solid #65558e;
  border-radius: 1px;
  background: #b9a7eb;
}

.mip-rods i b + b { border-top: 1px solid #65558e; }

.mip-cubes i {
  display: block;
  width: clamp(7px, 8cqw, 12px);
  aspect-ratio: 1;
  border: 1px solid #a65e43;
  border-radius: 2px;
  background: #ffd4af;
}

.mip-coins {
  --mip-coin-size: clamp(25px, 27cqw, 42px);
  display: flex;
  flex-wrap: wrap;
  width: calc(2 * var(--mip-coin-size) + 3px);
  justify-content: center;
  gap: 3px;
}

.mip-coin {
  display: grid;
  flex: none;
  width: var(--mip-coin-size);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid #8f602b;
  border-radius: 50%;
  color: #563a1b;
  background: #f6d3a3;
  box-shadow: inset 0 0 0 2px #fff8;
  font-size: clamp(0.82rem, 12cqw, 1.2rem);
  font-style: normal;
  font-weight: 900;
}

.mip-coin--5 { border-color: #817a88; color: #494051; background: #e5e0e9; }
.mip-coin--10 { border-color: #6c7781; color: #32424e; background: #d8e4e9; }

.mip-sidebar { display: grid; gap: 10px; min-width: 0; }

.mip-note {
  padding: clamp(12px, 2vw, 17px);
  border: 1px solid #e0cde9;
  border-radius: 15px;
  background: #f8f0fd;
}

.mip-note[data-kind="different"] { border-color: #e8ca94; background: #fff3da; }
.mip-note[data-kind="matched"] { border-color: #cbdcc7; background: #f1f8ed; }
.mip-note-title { font-weight: 900; }
.mip-note .mip-note-text { margin-top: 4px; color: #56405e; font-size: 0.94rem; line-height: 1.58; }

.mip-action {
  padding: 0.45em 0.9em;
  color: #fff;
  background: var(--mip-purple);
  box-shadow: 0 3px 0 #42206440;
}

.mip-action:hover { background: #4d2a76; }
.mip-action[hidden] { display: none; }
.mip-action[aria-disabled="true"] { cursor: default; }
.mip-note .mip-action { width: 100%; margin-top: 10px; }

.mip-side-art, .mip-reward {
  display: grid;
  justify-items: center;
  align-items: center;
  background: radial-gradient(ellipse at 50% 52%, #f2ddfbc7 0 37%, #f7e5dc80 38% 55%, transparent 56%);
}

.mip-side-art img, .mip-reward img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 18px;
  object-fit: contain;
  filter: drop-shadow(0 7px 6px #7a56832d);
}

.mip-result {
  display: grid;
  grid-template-columns: minmax(0, 0.65fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(14px, 3vw, 26px);
  margin-top: 16px;
  padding: clamp(14px, 3vw, 30px);
  border: 1px solid #e4d1ec;
  border-radius: 20px;
  background: #fffcf8;
}

.mip-result h2 { font-size: clamp(1.3rem, 3.8vw, 2rem); line-height: 1.25; }
.mip-result h2:focus { outline: none; }
.mip-result p { margin-top: 0.55em; color: var(--mip-muted); }
.mip-result .mip-result-explanation { color: #385c46; font-weight: 750; }
.mip-result .mip-action { margin-top: 0.9rem; }

@media (max-width: 700px) {
  .mip-play { grid-template-columns: minmax(0, 1fr); }
  .mip-side-art { display: none; }
}

@media (max-width: 460px) {
  .mip-result { grid-template-columns: minmax(0, 1fr); text-align: center; }
  .mip-reward img { width: 142px; }
  .mip-result .mip-action { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .mip-card { transition: none; }
  .mip-face { animation: none; }
}
