:root {
  --clay-950: #4a241c;
  --clay-900: #652d21;
  --clay-800: #7e3525;
  --clay-700: #a6482f;
  --clay-600: #bc5b3d;
  --clay-500: #d17956;
  --clay-300: #edb497;
  --sand-100: #fff9ed;
  --sand-200: #f9ecd7;
  --sand-300: #efd9ba;
  --sun: #f2bd4b;
  --sun-deep: #bf7720;
  --leaf: #4c785c;
  --leaf-deep: #31563f;
  --berry: #b53d38;
  --ink: #3d251e;
  --muted: #7b5c4e;
  --white: #fffdf8;
  --shadow: rgba(91, 43, 30, 0.2);
  --font-rounded: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--clay-700);
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-rounded);
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 249, 237, 0.2) 0 5px, transparent 6px),
    radial-gradient(circle at 88% 22%, rgba(255, 249, 237, 0.14) 0 8px, transparent 9px),
    linear-gradient(155deg, var(--clay-600), var(--clay-800));
}

body.is-modal-open {
  overflow: hidden;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  isolation: isolate;
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 249, 237, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 249, 237, 0.055) 1px, transparent 1px),
    linear-gradient(155deg, var(--clay-600), var(--clay-800));
  background-size: 24px 24px, 24px 24px, auto;
}

.app-shell::before,
.app-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  pointer-events: none;
}

.app-shell::before {
  width: 190px;
  height: 190px;
  top: -86px;
  right: -72px;
  border: 24px solid rgba(255, 249, 237, 0.09);
}

.app-shell::after {
  width: 130px;
  height: 130px;
  bottom: -72px;
  left: -56px;
  background: rgba(72, 34, 27, 0.12);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  color: var(--sand-100);
}

.mini-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  opacity: 0.92;
}

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--clay-800);
  font-family: Georgia, serif;
  font-size: 17px;
  font-style: italic;
  font-weight: 700;
  background: var(--sand-100);
  border-radius: 50%;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 5px 10px;
  color: var(--sand-100);
  font-size: 11px;
  letter-spacing: 0.04em;
  background: rgba(74, 36, 28, 0.24);
  border: 1px solid rgba(255, 249, 237, 0.32);
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sound-toggle:focus-visible,
.answer-button:focus-visible,
.restart-button:focus-visible,
.badge-book-button:focus-visible,
.badge-book-close:focus-visible,
.badge-card:focus-visible,
.badge-unlock-close:focus-visible {
  outline: 4px solid var(--sun);
  outline-offset: 3px;
}

.sound-toggle[aria-pressed="true"] {
  color: var(--clay-900);
  background: var(--sand-100);
  border-color: var(--sand-100);
}

.game {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.title-block {
  padding: 13px 4px 12px;
  color: var(--sand-100);
  text-align: center;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--sand-300);
  font-size: 11px;
  letter-spacing: 0.16em;
}

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

h1 {
  margin-bottom: 2px;
  font-size: clamp(29px, 9vw, 42px);
  line-height: 1.15;
  letter-spacing: 0.06em;
  text-shadow: 0 3px 0 rgba(74, 36, 28, 0.26);
}

.subtitle {
  margin-bottom: 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

.profile-strip {
  position: relative;
  max-width: 430px;
  margin: 10px auto 0;
  padding: 7px 10px 8px;
  color: var(--sand-100);
  text-align: left;
  background: rgba(74, 36, 28, 0.24);
  border: 1px solid rgba(255, 249, 237, 0.28);
  border-radius: 15px;
}

.profile-heading,
.rank-progress-row,
.finish-rank-heading,
.finish-rank-progress-row {
  display: flex;
  align-items: center;
}

.profile-heading {
  gap: 7px;
  min-height: 42px;
}

.badge-book-button {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 2px 6px 2px 3px;
  color: var(--sand-100);
  text-align: left;
  background: rgba(255, 249, 237, 0.12);
  border: 1px solid rgba(255, 249, 237, 0.28);
  border-radius: 11px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.badge-book-button:active {
  transform: translateY(1px);
}

.current-badge-icon {
  display: grid;
  width: 34px;
  height: 38px;
  place-items: center;
}

.current-badge-icon .title-badge-svg {
  width: 34px;
  height: 38px;
}

.badge-book-button-copy {
  display: grid;
  line-height: 1.08;
}

.badge-book-button-copy > span {
  color: var(--sand-300);
  font-size: 7px;
  white-space: nowrap;
}

.badge-book-button-copy strong {
  color: var(--sun);
  font-size: 10px;
  white-space: nowrap;
}

.rank-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-level {
  color: var(--sun);
  font-size: 11px;
  white-space: nowrap;
}

.crystal-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 0;
  padding: 3px 7px;
  color: var(--clay-950);
  font-size: 10px;
  background: var(--sand-100);
  border-radius: 999px;
  white-space: nowrap;
}

.crystal-pill > span:first-child {
  color: var(--sun-deep);
  font-size: 13px;
}

.rank-progress-row {
  gap: 7px;
  margin-top: 5px;
}

.rank-progress {
  position: relative;
  flex: 1;
  height: 7px;
  overflow: hidden;
  background: rgba(255, 249, 237, 0.25);
  border: 1px solid rgba(255, 249, 237, 0.35);
  border-radius: 999px;
}

.rank-progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--sun), #f8d777);
  border-radius: inherit;
  transition: width 360ms cubic-bezier(0.2, 0.75, 0.25, 1);
}

.rank-progress-label {
  min-width: 57px;
  color: var(--sand-200);
  font-size: 9px;
  text-align: right;
  white-space: nowrap;
}

.title-badge-svg {
  display: block;
  overflow: visible;
  color: var(--badge-accent);
  filter: drop-shadow(0 3px 0 rgba(74, 36, 28, 0.18));
}

.title-badge-svg .badge-ribbon {
  fill: var(--badge-accent);
  stroke: var(--clay-950);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.title-badge-svg .badge-rim {
  fill: var(--badge-tone);
  stroke: var(--clay-950);
  stroke-width: 4px;
}

.title-badge-svg .badge-disc {
  fill: var(--badge-disc);
  stroke: var(--badge-accent);
  stroke-width: 3px;
}

.title-badge-svg .badge-glyph {
  color: var(--badge-accent);
}

.title-badge-svg.is-locked {
  filter: grayscale(1);
  opacity: 0.34;
}

.quest-card,
.finish-card {
  position: relative;
  padding: 18px 16px 17px;
  background: var(--sand-100);
  border: 3px solid var(--clay-950);
  border-radius: 25px;
  box-shadow:
    0 8px 0 var(--clay-950),
    0 16px 30px rgba(66, 27, 18, 0.2);
}

.quest-card::before,
.finish-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px dashed rgba(166, 72, 47, 0.2);
  border-radius: 17px;
}

.quest-card::after {
  position: absolute;
  inset: 5px;
  z-index: 1;
  content: "";
  pointer-events: none;
  border-radius: 18px;
  opacity: 0;
  background: radial-gradient(circle at 50% 44%, rgba(242, 189, 75, 0.44), transparent 48%);
}

.quest-card.is-correct-impact::after {
  animation: card-flash 900ms ease-out both;
}

.status-row {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 5px 8px;
}

.best-score {
  text-align: right;
}

.status-caption {
  display: block;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.status-value {
  color: var(--clay-800);
  font-size: 16px;
  letter-spacing: 0.03em;
}

.progress-track {
  position: relative;
  height: 12px;
  overflow: hidden;
  background: var(--sand-300);
  border: 2px solid var(--clay-950);
  border-radius: 999px;
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background:
    repeating-linear-gradient(
      135deg,
      var(--sun) 0 10px,
      #f8d777 10px 20px
    );
  border-radius: inherit;
  transition: width 360ms cubic-bezier(0.2, 0.75, 0.25, 1);
}

.tower-progress {
  position: relative;
  margin: 8px 1px 0;
  padding: 6px 1px 1px;
  color: var(--muted);
}

.tower-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 16px;
  font-size: 10px;
  letter-spacing: 0.05em;
}

.tower-reward-legend {
  color: var(--sun-deep);
  font-size: 9px;
  letter-spacing: 0;
  white-space: nowrap;
}

.tower-path {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 2px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.tower-path::before {
  position: absolute;
  top: 11px;
  right: 4%;
  left: 4%;
  height: 4px;
  content: "";
  background: var(--sand-300);
  border-radius: 999px;
}

.tower-node {
  position: relative;
  z-index: 2;
  min-width: 0;
  color: #a78e7e;
  font-size: 8px;
  line-height: 1;
  text-align: center;
}

.tower-node-marker {
  display: grid;
  width: 23px;
  height: 23px;
  margin: 0 auto 2px;
  place-items: center;
  color: var(--muted);
  font-size: 9px;
  background: var(--sand-100);
  border: 2px solid #c9b2a1;
  border-radius: 50%;
  transition:
    transform 180ms ease,
    color 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.tower-node-label {
  display: block;
  color: inherit;
}

.tower-node.is-complete {
  color: var(--leaf-deep);
}

.tower-node.is-complete .tower-node-marker {
  color: var(--white);
  background: var(--leaf);
  border-color: var(--leaf-deep);
}

.tower-node.is-current .tower-node-marker {
  color: var(--clay-950);
  background: var(--sun);
  border-color: var(--sun-deep);
  box-shadow: 0 0 0 3px rgba(242, 189, 75, 0.25);
  transform: scale(1.12);
}

.tower-node.is-milestone .tower-node-marker {
  color: var(--clay-900);
  border-color: var(--sun-deep);
}

.tower-node.is-milestone.is-complete .tower-node-marker {
  color: var(--clay-900);
  background: var(--sun);
  box-shadow: 0 2px 0 var(--sun-deep);
}

.streak-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 35px;
  padding: 8px 3px 0;
}

.streak-chip {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 11px;
  background: var(--sand-200);
  border-radius: 999px;
}

.streak-chip.is-hot {
  color: var(--clay-900);
  background: #f6d589;
}

.first-try-score {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--sun-deep);
  font-size: 15px;
}

.problem-area {
  position: relative;
  z-index: 2;
  display: grid;
  min-height: 145px;
  place-content: center;
  text-align: center;
}

.problem-area.is-correct-impact .equation {
  animation: equation-impact 760ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.question-label {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.09em;
}

.equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(13px, 5vw, 25px);
  color: var(--clay-950);
  font-family: "Arial Rounded MT Bold", var(--font-rounded);
  font-size: clamp(60px, 20vw, 92px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.04em;
}

.operator {
  color: var(--clay-600);
  font-size: 0.62em;
  transform: translateY(2px);
}

.feedback {
  position: relative;
  z-index: 2;
  min-height: 29px;
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.feedback.is-correct {
  color: var(--leaf-deep);
}

.feedback.is-wrong {
  color: var(--berry);
}

.answers {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.reward-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 7;
  display: grid;
  width: min(78%, 260px);
  min-height: 106px;
  padding: 13px 14px 11px;
  place-content: center;
  gap: 2px;
  color: var(--clay-950);
  text-align: center;
  background: rgba(255, 253, 248, 0.97);
  border: 3px solid var(--sun-deep);
  border-radius: 20px;
  box-shadow:
    0 7px 0 var(--clay-950),
    0 12px 28px rgba(74, 36, 28, 0.3),
    0 0 0 7px rgba(242, 189, 75, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.7) rotate(-2deg);
}

.reward-banner.is-visible {
  animation: reward-in 920ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.reward-kicker {
  color: var(--clay-600);
  font-family: Georgia, serif;
  font-size: 12px;
  letter-spacing: 0.16em;
}

.reward-copy {
  font-size: clamp(17px, 5vw, 24px);
  line-height: 1.25;
}

.reward-crystals {
  color: var(--sun-deep);
  font-size: 12px;
}

.reward-milestone {
  color: var(--leaf-deep);
  font-size: 10px;
}

.reward-milestone:empty {
  display: none;
}

.answer-button {
  min-width: 0;
  min-height: 82px;
  padding: 8px 3px 11px;
  color: var(--clay-950);
  font-family: "Arial Rounded MT Bold", var(--font-rounded);
  font-size: clamp(29px, 10vw, 43px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: var(--white);
  border: 3px solid var(--clay-800);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--clay-800);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 100ms ease,
    box-shadow 100ms ease,
    background-color 130ms ease,
    border-color 130ms ease,
    color 130ms ease;
}

.answer-button:hover {
  background: var(--sand-200);
}

.answer-button:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--clay-800);
}

.answer-button.is-correct {
  color: var(--white);
  background: var(--leaf);
  border-color: var(--leaf-deep);
  box-shadow: 0 6px 0 var(--leaf-deep);
  animation: answer-pop 720ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.answer-button.is-wrong {
  color: var(--white);
  background: var(--berry);
  border-color: #7c2b29;
  box-shadow: 0 3px 0 #7c2b29;
  animation: answer-shake 310ms ease both;
}

.answer-button:disabled {
  cursor: default;
}

.answer-button:disabled:not(.is-correct):not(.is-wrong) {
  color: #9d877a;
  background: #eee4d6;
  border-color: #b9a494;
  box-shadow: 0 4px 0 #b9a494;
}

.finish-card {
  min-height: 505px;
  padding: 20px 18px 21px;
  text-align: center;
}

.finish-medal {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 124px;
  height: 66px;
  margin: 0 auto 7px;
  color: #c9b5a3;
  border: 3px solid var(--clay-950);
  border-radius: 36px;
  background: var(--sand-200);
  box-shadow: 0 5px 0 var(--sand-300);
  animation: medal-in 560ms cubic-bezier(0.2, 1.2, 0.35, 1) both;
}

.finish-star {
  display: inline-block;
  color: #c9b5a3;
  font-size: 30px;
  line-height: 1;
  opacity: 0.5;
  transform: translateY(3px) scale(0.88);
}

.finish-star:nth-child(2) {
  font-size: 38px;
  transform: translateY(0) scale(0.88);
}

.finish-star.is-filled {
  color: var(--sun);
  opacity: 1;
  text-shadow: 0 2px 0 var(--sun-deep);
  animation: star-pop 560ms cubic-bezier(0.2, 1.2, 0.35, 1) both;
}

.finish-kicker {
  position: relative;
  margin-bottom: 3px;
  color: var(--clay-600);
  font-size: 12px;
  letter-spacing: 0.13em;
}

.finish-card h2 {
  position: relative;
  margin-bottom: 4px;
  color: var(--clay-950);
  font-size: clamp(29px, 9vw, 40px);
  line-height: 1.2;
}

.finish-message {
  position: relative;
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 13px;
}

.result-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 10px;
}

.result-item {
  padding: 8px 5px 7px;
  background: var(--sand-200);
  border: 2px solid var(--sand-300);
  border-radius: 15px;
}

.result-item > span {
  display: block;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.05em;
}

.result-item strong {
  display: block;
  color: var(--clay-800);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.result-item small {
  font-size: 11px;
}

.finish-rank {
  position: relative;
  margin: 0 0 8px;
  padding: 8px 10px 9px;
  color: var(--clay-900);
  text-align: left;
  background: #f8e5c5;
  border: 2px solid #e5c58e;
  border-radius: 14px;
}

.finish-rank-heading {
  justify-content: space-between;
  gap: 8px;
  font-size: 9px;
}

.finish-rank-heading > span {
  color: var(--muted);
}

.finish-rank-heading strong {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finish-rank-progress-row {
  gap: 7px;
  margin-top: 6px;
}

.finish-rank .rank-progress {
  background: rgba(166, 72, 47, 0.16);
  border-color: rgba(166, 72, 47, 0.24);
}

.finish-rank .rank-progress-label {
  color: var(--muted);
}

.best-message {
  position: relative;
  min-height: 20px;
  margin-bottom: 8px;
  color: var(--leaf-deep);
  font-size: 12px;
}

.restart-button {
  position: relative;
  width: 100%;
  min-height: 62px;
  padding: 10px 18px 14px;
  color: var(--white);
  font-size: 19px;
  letter-spacing: 0.04em;
  background: var(--clay-600);
  border: 3px solid var(--clay-950);
  border-radius: 17px;
  box-shadow: 0 6px 0 var(--clay-950);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.restart-button:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--clay-950);
}

.gentle-note {
  margin: 18px 4px 0;
  color: var(--sand-100);
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
  letter-spacing: 0.03em;
  opacity: 0.9;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  width: 9px;
  height: 16px;
  top: 42%;
  left: 50%;
  border-radius: 3px;
  animation: confetti-burst 720ms cubic-bezier(0.12, 0.7, 0.25, 1) forwards;
}

.confetti-piece.is-round {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.badge-book-layer,
.badge-unlock-layer {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: end center;
}

.badge-book-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: rgba(47, 20, 14, 0.7);
  border: 0;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.badge-book-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  max-height: min(88svh, 790px);
  padding: 17px 14px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 5%, rgba(242, 189, 75, 0.2), transparent 26%),
    var(--sand-100);
  border: 3px solid var(--clay-950);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 42px rgba(47, 20, 14, 0.35);
  animation: badge-sheet-in 340ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
  -webkit-overflow-scrolling: touch;
}

.badge-book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.badge-book-kicker {
  margin-bottom: 1px;
  color: var(--clay-600);
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: 0.16em;
}

.badge-book-header h2 {
  margin-bottom: 0;
  color: var(--clay-950);
  font-size: 27px;
  line-height: 1.15;
}

.badge-book-close {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0 0 4px;
  place-items: center;
  color: var(--white);
  font-size: 28px;
  line-height: 1;
  background: var(--clay-600);
  border: 2px solid var(--clay-950);
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--clay-950);
  cursor: pointer;
  touch-action: manipulation;
}

.badge-book-guide {
  min-height: 20px;
  margin: 7px 0 8px;
  color: var(--muted);
  font-size: 11px;
}

.badge-book-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 6px 10px;
  color: var(--clay-900);
  background: #f8e5c5;
  border: 2px solid #e5c58e;
  border-radius: 12px;
}

.badge-book-summary strong {
  color: var(--clay-700);
  font-size: 16px;
  white-space: nowrap;
}

.badge-book-summary > span {
  min-width: 0;
  overflow: hidden;
  font-size: 9px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 9px;
  margin-top: 10px;
}

.badge-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 127px;
  padding: 7px 4px 8px;
  align-items: center;
  flex-direction: column;
  color: var(--clay-950);
  background: var(--white);
  border: 2px solid var(--sand-300);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--sand-300);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.badge-card:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--sand-300);
}

.badge-card.is-selected {
  background: #fff4cf;
  border-color: var(--sun-deep);
  box-shadow: 0 4px 0 var(--sun-deep), 0 0 0 3px rgba(242, 189, 75, 0.2);
}

.badge-card.is-locked {
  color: #8e8178;
  background: #eee7dc;
  border-color: #cec0b3;
  box-shadow: none;
  cursor: default;
}

.badge-card-graphic {
  display: grid;
  width: 56px;
  height: 62px;
  place-items: center;
}

.badge-card-graphic .title-badge-svg {
  width: 56px;
  height: 62px;
}

.badge-card-title {
  display: grid;
  min-height: 29px;
  place-items: center;
  font-size: 9px;
  line-height: 1.35;
  text-align: center;
}

.badge-card-condition {
  display: inline-flex;
  min-height: 18px;
  margin-top: auto;
  padding: 2px 7px;
  align-items: center;
  color: var(--muted);
  font-size: 8px;
  background: var(--sand-200);
  border-radius: 999px;
}

.badge-card.is-selected .badge-card-condition {
  color: var(--clay-950);
  background: var(--sun);
}

.badge-unlock-layer {
  z-index: 80;
  place-items: center;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: rgba(47, 20, 14, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.badge-unlock-card {
  position: relative;
  isolation: isolate;
  width: min(100%, 350px);
  padding: 22px 20px 20px;
  overflow: hidden;
  color: var(--ink);
  text-align: center;
  background:
    radial-gradient(circle at 50% 30%, #fffdf8 0 23%, #fff3d2 54%, #f4d28f 100%);
  border: 4px solid var(--clay-950);
  border-radius: 28px;
  box-shadow:
    0 9px 0 var(--clay-950),
    0 20px 60px rgba(28, 10, 7, 0.45),
    0 0 0 7px rgba(242, 189, 75, 0.28);
  animation: badge-unlock-in 500ms cubic-bezier(0.2, 1.15, 0.3, 1) both;
}

.badge-unlock-rays {
  position: absolute;
  z-index: -1;
  width: 260px;
  height: 260px;
  top: -25px;
  left: 50%;
  opacity: 0.55;
  background: repeating-conic-gradient(from 0deg, rgba(242, 189, 75, 0.42) 0 10deg, transparent 10deg 22deg);
  border-radius: 50%;
  transform: translateX(-50%);
  animation: badge-rays-spin 8s linear infinite;
}

.badge-unlock-kicker {
  margin-bottom: 4px;
  color: var(--clay-600);
  font-family: Georgia, serif;
  font-size: 13px;
  letter-spacing: 0.18em;
}

.badge-unlock-icon {
  display: grid;
  width: 126px;
  height: 138px;
  margin: 0 auto -4px;
  place-items: center;
  animation: badge-float 1200ms ease-in-out infinite alternate;
}

.badge-unlock-icon .title-badge-svg {
  width: 126px;
  height: 138px;
  filter: drop-shadow(0 7px 0 rgba(74, 36, 28, 0.2));
}

.badge-unlock-label {
  margin-bottom: 3px;
  color: var(--sun-deep);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.badge-unlock-card h2 {
  margin-bottom: 5px;
  color: var(--clay-950);
  font-size: clamp(24px, 8vw, 33px);
  line-height: 1.25;
}

.badge-unlock-message {
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 12px;
}

.badge-unlock-close {
  width: 100%;
  min-height: 54px;
  padding: 8px 16px 11px;
  color: var(--white);
  font-size: 18px;
  background: var(--clay-600);
  border: 3px solid var(--clay-950);
  border-radius: 15px;
  box-shadow: 0 5px 0 var(--clay-950);
  cursor: pointer;
  touch-action: manipulation;
}

.badge-unlock-close:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--clay-950);
}

.badge-symbols {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

@keyframes answer-pop {
  0% { transform: scale(1); }
  25% { transform: translateY(-7px) scale(1.12); box-shadow: 0 10px 0 var(--leaf-deep), 0 0 20px rgba(76, 120, 92, 0.42); }
  55% { transform: translateY(1px) scale(0.98); }
  100% { transform: scale(1); }
}

@keyframes answer-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@keyframes medal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.65) rotate(-12deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes star-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.25) rotate(-20deg); }
  65% { opacity: 1; transform: translateY(-2px) scale(1.12) rotate(4deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes card-flash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes equation-impact {
  0% { transform: scale(1); }
  30% { filter: drop-shadow(0 0 9px rgba(242, 189, 75, 0.78)); transform: scale(1.08); }
  100% { filter: none; transform: scale(1); }
}

@keyframes reward-in {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7) rotate(-2deg); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(1deg); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.96) rotate(0); }
}

@keyframes confetti-burst {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.7) rotate(0deg);
  }
  to {
    opacity: 0;
    transform: translate(var(--confetti-x), var(--confetti-y)) scale(var(--confetti-scale, 1)) rotate(var(--confetti-r));
  }
}

@keyframes badge-sheet-in {
  from { opacity: 0; transform: translateY(38px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes badge-unlock-in {
  from { opacity: 0; transform: translateY(18px) scale(0.68) rotate(-4deg); }
  70% { opacity: 1; transform: translateY(-3px) scale(1.04) rotate(1deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes badge-rays-spin {
  from { transform: translateX(-50%) rotate(0deg); }
  to { transform: translateX(-50%) rotate(360deg); }
}

@keyframes badge-float {
  from { transform: translateY(1px) rotate(-1deg); }
  to { transform: translateY(-7px) rotate(1deg); }
}

@media (max-width: 360px) {
  .app-shell {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .quest-card,
  .finish-card {
    padding-right: 12px;
    padding-left: 12px;
  }

  .answers {
    gap: 7px;
  }

  .answer-button {
    min-height: 76px;
    border-radius: 15px;
  }

  .profile-strip {
    margin-top: 8px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .profile-heading {
    gap: 5px;
  }

  .badge-book-button {
    padding-right: 4px;
  }

  .badge-book-button-copy > span {
    display: none;
  }

  .crystal-pill {
    padding-right: 5px;
    padding-left: 5px;
    font-size: 9px;
  }

  .badge-grid {
    gap: 7px;
  }

  .tower-heading {
    font-size: 9px;
  }

  .tower-reward-legend {
    font-size: 8px;
  }

  .tower-node-marker {
    width: 21px;
    height: 21px;
    font-size: 8px;
  }
}

@media (max-height: 640px) {
  .title-block {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .subtitle {
    display: none;
  }

  .quest-card {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .problem-area {
    min-height: 112px;
  }

  .tower-progress {
    margin-top: 6px;
  }

  .profile-strip {
    margin-top: 7px;
  }

  .badge-book-button-copy > span {
    display: none;
  }

  .gentle-note {
    margin-top: 13px;
  }
}

@media (min-width: 700px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .app-shell {
    min-height: auto;
    border: 1px solid rgba(255, 249, 237, 0.26);
    border-radius: 34px;
    box-shadow: 0 30px 80px rgba(61, 22, 15, 0.3);
  }
}

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

  .confetti-layer {
    display: none;
  }

  .reward-banner {
    transform: translate(-50%, -50%);
  }

  .badge-unlock-rays,
  .badge-unlock-icon {
    animation: none;
  }
}
