:root {
  --ink: #17223b;
  --muted: #6d7890;
  --purple: #6c55e0;
  --purple-dark: #5137c3;
  --purple-soft: #eeeaff;
  --yellow: #ffc73d;
  --yellow-dark: #e9a915;
  --green: #35c58b;
  --red: #f35f75;
  --cream: #fffaf0;
  --white: #ffffff;
  --line: #e9e5f2;
  --shadow: 0 18px 55px rgba(73, 55, 133, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #fbf9ff;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 210, 80, 0.14), transparent 24rem),
    radial-gradient(circle at 88% 82%, rgba(108, 85, 224, 0.1), transparent 28rem),
    linear-gradient(145deg, #fffdf8 0%, #f8f5ff 48%, #f2f7ff 100%);
  font-family: "Noto Sans Thai", system-ui, sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 96px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  transform: rotate(-5deg);
  border: 3px solid #332565;
  border-radius: 15px;
  background: var(--yellow);
  box-shadow: 4px 5px 0 #332565;
}

.brand-mark span {
  transform: rotate(5deg);
  font-size: 21px;
  font-weight: 800;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand-copy strong {
  font-family: "Baloo 2", "Noto Sans Thai", sans-serif;
  font-size: 24px;
  font-weight: 800;
}

.brand-copy small {
  margin-top: 5px;
  color: var(--purple);
  font-family: "Baloo 2", sans-serif;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.topbar-actions,
.score-pills {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  color: #657088;
  font-size: 12px;
  font-weight: 600;
}

.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(53, 197, 139, 0.13);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--white);
  color: var(--purple);
}

.icon-button svg,
.listen-button svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.settings-wrap {
  position: relative;
}

.settings-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 12px);
  right: 0;
  width: 270px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(58, 42, 112, 0.18);
}

.settings-panel[hidden] {
  display: none;
}

.settings-panel > strong {
  display: block;
  margin-bottom: 13px;
  font-size: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
}

.setting-field {
  display: block;
  margin-top: 16px;
}

.setting-row b,
.setting-row small,
.setting-field b,
.setting-field small {
  display: block;
}

.setting-row b,
.setting-field b {
  font-size: 12px;
}

.setting-row small,
.setting-field small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.setting-field select {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
}

.setting-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  flex: 0 0 43px;
  width: 43px;
  height: 25px;
  border-radius: 99px;
  background: #d9d5e3;
  transition: background 0.2s ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(36, 26, 72, 0.22);
  content: "";
  transition: transform 0.2s ease;
}

.setting-row input:checked + .switch {
  background: var(--purple);
}

.setting-row input:checked + .switch::after {
  transform: translateX(18px);
}

.setting-row input:focus-visible + .switch {
  outline: 4px solid rgba(108, 85, 224, 0.2);
  outline-offset: 2px;
}

.parent-stats-button {
  display: flex;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  background: var(--purple-soft);
  color: var(--purple);
  font-size: 11px;
  font-weight: 800;
}

body.icons-hidden .word-emoji,
body.icons-hidden .answer-emoji {
  display: none;
}

body.icons-hidden .answer-card {
  padding-left: 28px;
}

.sound-off-icon {
  display: none;
}

.icon-button.muted .sound-on-icon {
  display: none;
}

.icon-button.muted .sound-off-icon {
  display: block;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: screen-in 0.5s ease both;
}

@keyframes screen-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

.welcome-panel {
  position: relative;
  display: grid;
  min-height: 520px;
  overflow: hidden;
  grid-template-columns: 1fr 1fr;
  border: 1px solid rgba(108, 85, 224, 0.1);
  border-radius: 38px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.97) 0%, rgba(255, 255, 255, 0.92) 48%, transparent 70%),
    linear-gradient(135deg, #f8f5ff, #e9e2ff);
  box-shadow: var(--shadow);
}

.welcome-copy {
  position: relative;
  z-index: 2;
  align-self: center;
  padding: 62px 0 62px 70px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.eyebrow::before {
  width: 19px;
  height: 3px;
  border-radius: 2px;
  background: var(--yellow);
  content: "";
}

h1 {
  max-width: 540px;
  margin: 20px 0 17px;
  font-size: clamp(42px, 5vw, 68px);
  font-weight: 800;
  letter-spacing: -2.5px;
  line-height: 1.08;
}

h1 span {
  position: relative;
  color: var(--purple);
}

h1 span::after {
  position: absolute;
  right: 2px;
  bottom: -2px;
  left: 2px;
  height: 6px;
  transform: rotate(-1deg);
  border-radius: 50%;
  background: var(--yellow);
  content: "";
  opacity: 0.8;
}

.welcome-copy p {
  max-width: 460px;
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.primary-button,
.secondary-button,
.next-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 54px;
  padding: 0 27px;
  cursor: pointer;
  border: 0;
  border-radius: 17px;
  font-weight: 800;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.primary-button {
  background: var(--purple);
  box-shadow: 0 8px 0 var(--purple-dark), 0 14px 25px rgba(108, 85, 224, 0.22);
  color: var(--white);
}

.primary-button:hover,
.next-button:hover {
  transform: translateY(-2px);
}

.primary-button:active,
.next-button:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 var(--purple-dark);
}

.primary-button span {
  font-size: 21px;
}

.hero-art {
  position: relative;
  min-height: 520px;
}

.orbit {
  position: absolute;
  border: 2px dashed rgba(108, 85, 224, 0.13);
  border-radius: 50%;
}

.orbit-one {
  width: 430px;
  height: 430px;
  top: 44px;
  left: 30px;
}

.orbit-two {
  width: 310px;
  height: 310px;
  top: 105px;
  left: 90px;
}

.mascot {
  position: absolute;
  top: 118px;
  left: 142px;
  width: 220px;
  height: 310px;
  filter: drop-shadow(0 22px 20px rgba(69, 48, 137, 0.18));
  animation: mascot-float 4s ease-in-out infinite;
}

@keyframes mascot-float {
  50% {
    transform: translateY(-12px) rotate(1deg);
  }
}

.mascot-head {
  position: absolute;
  z-index: 3;
  top: 35px;
  left: 25px;
  width: 170px;
  height: 158px;
  border: 4px solid #352864;
  border-radius: 47% 47% 44% 44%;
  background: #fff;
}

.mascot-ear {
  position: absolute;
  z-index: 2;
  top: 15px;
  width: 70px;
  height: 75px;
  border: 4px solid #352864;
  background: #fff;
}

.mascot-ear.left {
  left: 17px;
  transform: rotate(-20deg);
  border-radius: 60% 20% 45% 35%;
}

.mascot-ear.right {
  right: 17px;
  transform: rotate(20deg);
  border-radius: 20% 60% 35% 45%;
}

.mascot-ear::after {
  position: absolute;
  inset: 17px;
  border-radius: inherit;
  background: #f8c9d9;
  content: "";
}

.mascot-eye {
  position: absolute;
  top: 64px;
  width: 12px;
  height: 18px;
  border-radius: 50%;
  background: #352864;
}

.mascot-eye::after {
  position: absolute;
  top: 2px;
  left: 3px;
  width: 4px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  content: "";
}

.mascot-eye.left {
  left: 47px;
}

.mascot-eye.right {
  right: 47px;
}

.mascot-cheek {
  position: absolute;
  top: 91px;
  width: 25px;
  height: 12px;
  border-radius: 50%;
  background: #ffc6d6;
  opacity: 0.75;
}

.mascot-cheek.left {
  left: 24px;
}

.mascot-cheek.right {
  right: 24px;
}

.mascot-nose {
  position: absolute;
  top: 86px;
  left: 77px;
  width: 16px;
  height: 12px;
  border-radius: 60% 60% 50% 50%;
  background: #f19a9f;
}

.mascot-mouth {
  position: absolute;
  top: 98px;
  left: 70px;
  width: 30px;
  height: 24px;
  border-bottom: 3px solid #352864;
  border-radius: 50%;
}

.mascot-body {
  position: absolute;
  z-index: 2;
  top: 171px;
  left: 45px;
  display: grid;
  width: 130px;
  height: 125px;
  place-items: center;
  border: 4px solid #352864;
  border-radius: 43% 43% 34% 34%;
  background: var(--purple);
}

.body-star {
  color: var(--yellow);
  font-size: 42px;
  text-shadow: 0 3px 0 rgba(54, 40, 100, 0.3);
}

.mascot-arm {
  position: absolute;
  z-index: 1;
  top: 186px;
  width: 42px;
  height: 92px;
  border: 4px solid #352864;
  border-radius: 50%;
  background: var(--purple);
}

.mascot-arm.left {
  left: 16px;
  transform: rotate(35deg);
}

.mascot-arm.right {
  right: 16px;
  transform: rotate(-35deg);
}

.floating-card {
  position: absolute;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 15px 30px rgba(67, 47, 130, 0.13);
  backdrop-filter: blur(8px);
}

.card-hello {
  top: 82px;
  right: 31px;
  width: 118px;
  height: 104px;
  transform: rotate(6deg);
}

.card-hello strong {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 28px;
}

.floating-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.card-apple {
  bottom: 56px;
  left: 36px;
  width: 105px;
  height: 98px;
  transform: rotate(-7deg);
}

.card-apple span {
  font-size: 34px;
}

.hero-spark {
  position: absolute;
  z-index: 5;
  color: var(--yellow-dark);
  font-size: 30px;
}

.spark-a {
  top: 60px;
  left: 115px;
}

.spark-b {
  right: 50px;
  bottom: 105px;
  color: var(--purple);
  font-size: 20px;
}

.how-to-grid {
  display: grid;
  max-width: 850px;
  margin: 30px auto 0;
  grid-template-columns: repeat(3, 1fr);
  gap: 25px;
}

.how-to-grid article {
  display: flex;
  align-items: center;
  gap: 13px;
}

.how-to-grid strong,
.how-to-grid small {
  display: block;
}

.how-to-grid strong {
  font-size: 13px;
}

.how-to-grid small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.step-icon {
  display: grid;
  flex: 0 0 45px;
  width: 45px;
  height: 45px;
  place-items: center;
  border-radius: 14px;
  font-family: "Baloo 2", sans-serif;
  font-size: 21px;
  font-weight: 800;
}

.step-icon.hear {
  background: #eeeaff;
  color: var(--purple);
}

.step-icon.choose {
  background: #fff1d0;
  color: #df9c00;
}

.step-icon.win {
  background: #ddf9ee;
  color: var(--green);
}

.game-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.progress-area {
  width: min(670px, 70%);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
}

.progress-label strong {
  color: var(--purple);
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 99px;
  background: #e8e4f0;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), #9c83ff);
  box-shadow: inset 0 -2px 0 rgba(61, 41, 148, 0.2);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.score-pill {
  display: flex;
  min-width: 75px;
  height: 45px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 7px 18px rgba(70, 52, 124, 0.07);
}

.score-pill span {
  font-size: 18px;
}

.score-pill strong {
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
}

.star-pill strong {
  color: #d99900;
}

.prompt-copy {
  margin: 34px 0 24px;
  text-align: center;
}

.prompt-copy .eyebrow::before {
  display: none;
}

.prompt-copy h2 {
  margin: 6px 0 0;
  font-size: 24px;
}

.challenge-layout {
  display: grid;
  align-items: stretch;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 32px;
}

.word-card {
  position: relative;
  display: flex;
  min-height: 405px;
  overflow: hidden;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  border: 2px solid rgba(108, 85, 224, 0.16);
  border-radius: 32px;
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 199, 61, 0.18), transparent 110px),
    linear-gradient(150deg, #fff 0%, #f7f3ff 100%);
  box-shadow: var(--shadow);
}

.word-card::before,
.word-card::after {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid rgba(108, 85, 224, 0.08);
  border-radius: 24px;
  content: "";
}

.word-card::before {
  top: -30px;
  left: -30px;
  transform: rotate(25deg);
}

.word-card::after {
  right: -30px;
  bottom: -35px;
  transform: rotate(-18deg);
}

.card-shine {
  position: absolute;
  top: 18px;
  right: 22px;
  color: var(--yellow);
}

.card-shine::after {
  content: "✦";
  font-size: 24px;
}

.word-emoji {
  display: grid;
  width: 84px;
  height: 84px;
  place-items: center;
  border-radius: 50%;
  background: #fff4d8;
  font-size: 47px;
  box-shadow: 0 9px 20px rgba(207, 154, 29, 0.13);
}

.chinese-word {
  margin-top: 19px;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 68px;
  line-height: 1.15;
}

.pinyin {
  color: var(--purple);
  font-family: "Baloo 2", sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1.4px;
}

.listen-button {
  display: inline-flex;
  min-height: 40px;
  margin-top: 21px;
  padding: 0 16px;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  border: 1px solid #ddd6fa;
  border-radius: 12px;
  background: #fff;
  color: var(--purple);
  font-size: 11px;
  font-weight: 700;
}

.word-actions {
  display: flex;
  margin-top: 21px;
  gap: 7px;
}

.word-actions .listen-button {
  margin-top: 0;
}

.writing-button {
  min-height: 40px;
  padding: 0 12px;
  cursor: pointer;
  border: 1px solid #ddd6fa;
  border-radius: 12px;
  background: #fff;
  color: var(--purple);
  font-size: 11px;
  font-weight: 700;
}

.writing-button:hover {
  border-color: #b7a9f4;
  background: #f7f3ff;
}

.listen-button.speaking svg {
  animation: sound-pulse 0.55s ease infinite alternate;
}

@keyframes sound-pulse {
  to {
    transform: scale(1.22);
  }
}

.answers {
  display: grid;
  padding: 10px;
  grid-template-columns: 1fr;
  gap: 8px;
  border: 1px solid rgba(108, 85, 224, 0.09);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.42);
}

.answer-card {
  position: relative;
  display: flex;
  min-height: 112px;
  padding: 15px 22px;
  align-items: center;
  gap: 20px;
  cursor: pointer;
  border: 2px solid #e5e1ec;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 4px 12px rgba(65, 49, 118, 0.055);
  color: var(--ink);
  text-align: left;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.answer-card:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: #b7a9f4;
  box-shadow: 0 12px 25px rgba(87, 65, 166, 0.13);
}

.answer-card:focus-visible {
  outline: 4px solid rgba(108, 85, 224, 0.2);
  outline-offset: 2px;
}

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

.answer-index {
  display: grid;
  flex: 0 0 39px;
  width: 39px;
  height: 39px;
  place-items: center;
  border-radius: 12px;
  background: var(--purple-soft);
  color: var(--purple);
  font-family: "Baloo 2", sans-serif;
  font-size: 17px;
  font-weight: 800;
}

.answer-emoji {
  display: grid;
  flex: 0 0 55px;
  width: 55px;
  height: 55px;
  place-items: center;
  border-radius: 17px;
  background: #f8f6fc;
  font-size: 31px;
}

.answer-copy {
  display: flex;
  flex-direction: column;
}

.answer-copy strong {
  font-size: 21px;
  font-weight: 700;
}

.answer-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.answer-state {
  display: none;
  width: 32px;
  height: 32px;
  margin-left: auto;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}

.answer-card.correct {
  border-color: var(--green);
  background: #f0fff9;
  animation: correct-pop 0.42s ease;
}

.answer-card.correct .answer-index,
.answer-card.correct .answer-state {
  display: grid;
  background: var(--green);
  color: #fff;
}

.answer-card.wrong {
  border-color: var(--red);
  background: #fff5f6;
  animation: wrong-shake 0.42s ease;
}

.answer-card.wrong .answer-index,
.answer-card.wrong .answer-state {
  display: grid;
  background: var(--red);
  color: #fff;
}

.answer-card.dimmed {
  opacity: 0.48;
}

@keyframes correct-pop {
  50% {
    transform: scale(1.03);
  }
}

@keyframes wrong-shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.feedback-panel {
  display: flex;
  max-height: 0;
  margin-top: 0;
  overflow: hidden;
  align-items: center;
  gap: 14px;
  border: 0 solid transparent;
  border-radius: 22px;
  opacity: 0;
  transition: max-height 0.35s ease, margin 0.35s ease, padding 0.35s ease, opacity 0.25s ease;
}

.feedback-panel.visible {
  max-height: 110px;
  margin-top: 20px;
  padding: 14px 16px;
  border-width: 1px;
  opacity: 1;
}

.feedback-panel.success {
  border-color: #b9efd9;
  background: #effcf7;
}

.feedback-panel.try-again {
  border-color: #ffd2d8;
  background: #fff5f6;
}

.feedback-icon {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 21px;
  font-weight: 800;
}

.try-again .feedback-icon {
  background: var(--red);
}

.feedback-copy {
  display: flex;
  flex-direction: column;
}

.feedback-copy strong {
  color: #18845e;
  font-size: 15px;
}

.try-again .feedback-copy strong {
  color: #c74258;
}

.feedback-copy span {
  color: var(--muted);
  font-size: 11px;
}

.next-button {
  min-height: 45px;
  margin-left: auto;
  padding: 0 20px;
  border-radius: 14px;
  background: var(--purple);
  box-shadow: 0 5px 0 var(--purple-dark);
  color: white;
  font-size: 12px;
}

.result-card {
  position: relative;
  max-width: 770px;
  margin: 20px auto 0;
  padding: 42px 55px;
  overflow: hidden;
  border: 1px solid rgba(108, 85, 224, 0.12);
  border-radius: 36px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
  text-align: center;
}

.trophy {
  position: relative;
  display: grid;
  width: 100px;
  height: 100px;
  margin: 0 auto 20px;
  place-items: center;
  transform: rotate(-4deg);
  border: 4px solid #352864;
  border-radius: 32px;
  background: var(--yellow);
  box-shadow: 7px 8px 0 #352864;
}

.trophy span {
  color: #fff;
  font-size: 53px;
  text-shadow: 0 4px 0 #d89900;
}

.result-card .eyebrow::before {
  display: none;
}

.result-card h2 {
  margin: 7px 0 2px;
  font-size: 39px;
}

.result-card > p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.result-score {
  display: flex;
  margin: 28px 0;
  align-items: center;
  justify-content: center;
  gap: 42px;
}

.score-ring {
  position: relative;
  display: grid;
  width: 125px;
  height: 125px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--purple) 0deg, var(--purple) var(--score-angle, 360deg), #e9e5f3 var(--score-angle, 360deg));
}

.score-ring::before {
  position: absolute;
  width: 101px;
  height: 101px;
  border-radius: 50%;
  background: #fff;
  content: "";
}

.score-ring div {
  position: relative;
  z-index: 1;
}

.score-ring strong {
  font-family: "Baloo 2", sans-serif;
  font-size: 44px;
  line-height: 1;
}

.score-ring span {
  color: var(--muted);
  font-size: 13px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-stats div {
  display: grid;
  min-width: 115px;
  padding: 14px;
  border-radius: 18px;
  background: #f8f6fc;
  grid-template-columns: 32px 1fr;
  text-align: left;
}

.result-stats span {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 23px;
}

.result-stats small {
  color: var(--muted);
  font-size: 9px;
}

.result-stats strong {
  font-family: "Baloo 2", sans-serif;
  font-size: 21px;
  line-height: 1;
}

.learned-words {
  display: flex;
  max-height: 0;
  overflow: hidden;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.3s ease;
}

.learned-words.open {
  max-height: 280px;
  margin-bottom: 28px;
  opacity: 1;
}

.learned-chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 11px;
}

.learned-chip strong {
  margin-right: 5px;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 15px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 13px;
}

.secondary-button {
  border: 1px solid #ddd6ef;
  background: #fff;
  color: var(--purple);
}

.confetti i {
  position: absolute;
  width: 8px;
  height: 15px;
  transform: rotate(25deg);
  border-radius: 3px;
  background: var(--yellow);
}

.confetti i:nth-child(1) { top: 45px; left: 65px; background: var(--purple); }
.confetti i:nth-child(2) { top: 90px; left: 115px; transform: rotate(-34deg); background: var(--green); }
.confetti i:nth-child(3) { top: 42px; right: 80px; transform: rotate(56deg); background: var(--red); }
.confetti i:nth-child(4) { top: 125px; right: 125px; background: var(--yellow); }
.confetti i:nth-child(5) { bottom: 75px; left: 55px; transform: rotate(70deg); background: var(--red); }
.confetti i:nth-child(6) { bottom: 115px; right: 45px; background: var(--purple); }
.confetti i:nth-child(7) { top: 200px; left: 35px; background: var(--yellow); }
.confetti i:nth-child(8) { top: 230px; right: 30px; transform: rotate(-48deg); background: var(--green); }

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

.stats-modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
}

.stats-modal[hidden] {
  display: none;
}

.writing-modal {
  position: fixed;
  z-index: 110;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
}

.writing-modal[hidden] {
  display: none;
}

.writing-dialog {
  position: relative;
  z-index: 1;
  width: min(680px, 100%);
  padding: 26px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(20, 13, 50, 0.3);
}

.writing-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.writing-header h2 {
  margin: 4px 0 0;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 42px;
  line-height: 1;
}

.writing-header h2 small {
  color: var(--purple);
  font-family: "Baloo 2", sans-serif;
  font-size: 17px;
}

.writing-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.writing-header .icon-button {
  flex: 0 0 42px;
  color: var(--ink);
  font-size: 25px;
}

.writing-board-wrap {
  height: min(48vh, 380px);
  min-height: 260px;
  margin-top: 18px;
  overflow: hidden;
  border: 2px dashed #cfc5f5;
  border-radius: 20px;
  background-color: #fcfbff;
  background-image: linear-gradient(#ebe7fa 1px, transparent 1px), linear-gradient(90deg, #ebe7fa 1px, transparent 1px);
  background-position: center;
  background-size: 50% 50%;
}

#writing-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.writing-actions {
  display: flex;
  margin-top: 16px;
  justify-content: flex-end;
  gap: 9px;
}

.writing-actions .secondary-button,
.writing-actions .primary-button {
  min-height: 42px;
  padding: 0 14px;
  font-size: 11px;
}

.stats-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 18, 48, 0.55);
  backdrop-filter: blur(5px);
}

.stats-dialog {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  padding: 30px;
  overflow-y: auto;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(20, 13, 50, 0.3);
}

.stats-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.stats-header h2 {
  margin: 5px 0 2px;
  font-size: 27px;
}

.stats-header p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.stats-header .icon-button {
  flex: 0 0 42px;
  color: var(--ink);
  font-size: 25px;
}

.stats-empty {
  display: flex;
  min-height: 280px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.stats-empty > span {
  font-size: 52px;
}

.stats-empty strong {
  margin-top: 12px;
}

.stats-empty p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.stats-summary {
  display: grid;
  margin-top: 26px;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stats-summary article {
  display: grid;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #faf9fd;
  grid-template-columns: 32px 1fr;
}

.stats-summary article > span {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 23px;
}

.stats-summary strong {
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  line-height: 1;
}

.stats-summary small {
  color: var(--muted);
  font-size: 9px;
}

.stats-section {
  margin-top: 26px;
}

.stats-section h3 {
  margin: 0 0 11px;
  font-size: 14px;
}

.practice-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.practice-word {
  display: inline-flex;
  padding: 7px 11px;
  align-items: center;
  gap: 7px;
  border-radius: 11px;
  background: #fff3f5;
  color: #b63e53;
  font-size: 10px;
}

.practice-word strong {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 16px;
}

.session-history {
  display: grid;
  gap: 8px;
}

.history-row {
  display: grid;
  padding: 12px 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  grid-template-columns: 1fr auto auto;
  gap: 18px;
}

.history-row strong,
.history-row small {
  display: block;
}

.history-row strong {
  font-size: 11px;
}

.history-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.history-score {
  color: var(--purple);
  font-family: "Baloo 2", sans-serif;
  font-size: 18px;
  font-weight: 800;
}

.history-duration {
  min-width: 52px;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.burst-star {
  position: absolute;
  top: var(--start-y);
  left: var(--start-x);
  color: var(--burst-color);
  font-size: var(--burst-size);
  animation: burst 0.9s ease-out forwards;
}

@keyframes burst {
  to {
    transform: translate(var(--move-x), var(--move-y)) rotate(180deg) scale(0.2);
    opacity: 0;
  }
}

.sky-decoration {
  position: fixed;
  pointer-events: none;
}

.cloud {
  width: 120px;
  height: 35px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.65);
  filter: blur(1px);
}

.cloud::before,
.cloud::after {
  position: absolute;
  border-radius: 50%;
  background: inherit;
  content: "";
}

.cloud::before {
  width: 55px;
  height: 55px;
  top: -26px;
  left: 22px;
}

.cloud::after {
  width: 42px;
  height: 42px;
  top: -17px;
  right: 16px;
}

.cloud-one {
  top: 150px;
  left: -55px;
}

.cloud-two {
  right: -40px;
  bottom: 100px;
  transform: scale(1.3);
}

.star {
  color: rgba(108, 85, 224, 0.14);
  font-size: 34px;
}

.star-one {
  top: 120px;
  right: 5%;
}

.star-two {
  bottom: 70px;
  left: 5%;
  color: rgba(255, 183, 21, 0.25);
  font-size: 22px;
}

@media (max-width: 850px) {
  .welcome-panel {
    grid-template-columns: 1fr;
  }

  .welcome-copy {
    padding: 55px;
  }

  .hero-art {
    display: none;
  }

  .challenge-layout {
    grid-template-columns: 1fr;
  }

  .word-card {
    min-height: 260px;
  }

  .word-emoji {
    width: 66px;
    height: 66px;
    font-size: 38px;
  }

  .chinese-word {
    margin-top: 8px;
    font-size: 54px;
  }

  .listen-button {
    margin-top: 12px;
  }

  .answers {
    grid-template-columns: repeat(3, 1fr);
    padding: 8px;
    gap: 8px;
  }

  .answer-card {
    min-height: 160px;
    padding: 13px;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    text-align: center;
  }

  .answer-index {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 29px;
    height: 29px;
  }

  .answer-emoji {
    flex-basis: 50px;
    width: 50px;
    height: 50px;
  }

  .answer-state {
    position: absolute;
    top: 10px;
    right: 10px;
    margin: 0;
  }

  .result-card {
    padding: 38px 30px;
  }
}

@media (max-width: 600px) {
  .writing-modal {
    padding: 12px;
  }

  .writing-dialog {
    padding: 19px;
    border-radius: 22px;
  }

  .writing-board-wrap {
    height: min(46vh, 330px);
    min-height: 220px;
  }

  .writing-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .writing-actions .secondary-button {
    flex: 1 1 42%;
  }

  .writing-actions .primary-button {
    width: 100%;
  }

  .app-shell {
    width: min(100% - 24px, 1120px);
  }

  .topbar {
    height: 76px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .brand-copy strong {
    font-size: 20px;
  }

  .session-pill {
    display: none;
  }

  .welcome-panel {
    min-height: calc(100vh - 120px);
    border-radius: 28px;
  }

  .welcome-copy {
    padding: 38px 27px;
  }

  h1 {
    font-size: 42px;
  }

  .primary-button {
    width: 100%;
  }

  .how-to-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 0 18px;
  }

  .game-status {
    align-items: flex-end;
  }

  .progress-area {
    width: calc(100% - 100px);
  }

  .score-pills {
    gap: 5px;
  }

  .score-pill {
    min-width: 43px;
    height: 38px;
    gap: 3px;
    border-radius: 12px;
  }

  .score-pill span {
    font-size: 14px;
  }

  .score-pill strong {
    font-size: 16px;
  }

  .prompt-copy {
    margin: 25px 0 15px;
  }

  .prompt-copy h2 {
    font-size: 19px;
  }

  .challenge-layout {
    gap: 14px;
  }

  .word-card {
    min-height: 235px;
    border-radius: 25px;
  }

  .chinese-word {
    font-size: 49px;
  }

  .answers {
    grid-template-columns: 1fr;
    padding: 7px;
    gap: 5px;
    border-radius: 20px;
  }

  .answer-card {
    min-height: 76px;
    padding: 10px 14px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    border-radius: 18px;
    text-align: left;
  }

  .answer-index {
    position: static;
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .answer-emoji {
    flex-basis: 46px;
    width: 46px;
    height: 46px;
    font-size: 25px;
  }

  .answer-copy strong {
    font-size: 17px;
  }

  .answer-state {
    position: static;
    margin-left: auto;
  }

  .feedback-panel.visible {
    max-height: 160px;
    flex-wrap: wrap;
  }

  .feedback-copy {
    max-width: calc(100% - 58px);
  }

  .next-button {
    width: 100%;
    margin: 2px 0 0;
  }

  .result-card {
    margin-top: 0;
    padding: 30px 18px;
    border-radius: 27px;
  }

  .result-card h2 {
    font-size: 31px;
  }

  .result-score {
    flex-direction: column;
    gap: 20px;
  }

  .result-actions {
    flex-direction: column-reverse;
  }

  .result-actions button {
    width: 100%;
  }

  .stats-modal {
    padding: 10px;
  }

  .stats-dialog {
    max-height: calc(100vh - 20px);
    padding: 22px 16px;
    border-radius: 22px;
  }

  .stats-summary {
    grid-template-columns: 1fr 1fr;
  }

  .history-row {
    grid-template-columns: 1fr auto;
  }

  .history-duration {
    display: none;
  }
}

/* Keep the complete question and Next action inside a phone viewport. */
@media (max-width: 600px) {
  body.game-active {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  body.game-active .app-shell {
    display: flex;
    height: 100dvh;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: column;
  }

  body.game-active .topbar {
    flex: 0 0 54px;
    height: 54px;
  }

  body.game-active .brand-mark {
    width: 34px;
    height: 34px;
    border-width: 2px;
    box-shadow: 3px 3px 0 #332565;
  }

  body.game-active .brand-mark span {
    font-size: 16px;
  }

  body.game-active .brand-copy strong {
    font-size: 17px;
  }

  body.game-active .brand-copy small,
  body.game-active .session-pill {
    display: none;
  }

  body.game-active .topbar-actions {
    gap: 7px;
  }

  body.game-active .icon-button {
    width: 36px;
    height: 36px;
  }

  body.game-active .game-screen.active {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
  }

  body.game-active .game-status {
    flex: 0 0 35px;
    margin-top: 0;
  }

  body.game-active .progress-label {
    margin-bottom: 4px;
    font-size: 9px;
  }

  body.game-active .progress-track {
    height: 8px;
  }

  body.game-active .score-pill {
    height: 32px;
  }

  body.game-active .prompt-copy {
    flex: 0 0 37px;
    margin: 5px 0 4px;
  }

  body.game-active .prompt-copy .eyebrow {
    display: none;
  }

  body.game-active .prompt-copy h2 {
    margin: 0;
    font-size: 17px;
    line-height: 37px;
  }

  body.game-active .challenge-layout {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: 7px;
  }

  body.game-active .word-card {
    display: grid;
    min-height: 0;
    height: auto;
    padding: 10px 18px;
    flex: 3 1 0;
    border-radius: 20px;
    grid-template-columns: 62px 1fr auto;
    grid-template-rows: 1fr 1fr;
    column-gap: 13px;
  }

  body.game-active .word-emoji {
    width: 58px;
    height: 58px;
    grid-row: 1 / 3;
    align-self: center;
    font-size: 32px;
  }

  body.game-active .chinese-word {
    margin: 0;
    align-self: end;
    font-size: clamp(35px, 11vw, 47px);
    line-height: 1;
  }

  body.game-active .pinyin {
    align-self: start;
    font-size: 15px;
  }

  body.game-active .word-actions {
    margin: 0;
    align-self: center;
    grid-column: 3;
    grid-row: 1 / 3;
    flex-direction: column;
    gap: 4px;
  }

  body.game-active .listen-button,
  body.game-active .writing-button {
    display: grid;
    width: 36px;
    min-height: 36px;
    padding: 0;
    place-items: center;
    font-size: 0;
  }

  body.game-active .listen-button svg {
    width: 22px;
  }

  body.game-active .writing-button > span {
    font-size: 16px;
  }

  body.game-active .answers {
    min-height: 0;
    padding: 5px;
    flex: 2 1 0;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 4px;
    border-radius: 17px;
  }

  body.game-active .answer-card {
    min-height: 0;
    height: auto;
    max-height: 67px;
    padding: 6px 11px;
    border-radius: 12px;
    gap: 9px;
  }

  body.game-active .answer-index {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 14px;
  }

  body.game-active .answer-emoji {
    flex-basis: 38px;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 22px;
  }

  body.game-active .answer-copy strong {
    font-size: 15px;
    line-height: 1.2;
  }

  body.game-active .answer-copy small {
    display: none;
  }

  body.game-active .answer-state {
    width: 27px;
    height: 27px;
  }

  body.game-active .feedback-panel.visible {
    display: grid;
    max-height: 75px;
    min-height: 65px;
    margin-top: 7px;
    padding: 7px 8px;
    flex: 0 0 65px;
    grid-template-columns: 34px 1fr auto;
    gap: 8px;
  }

  body.game-active .feedback-icon {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  body.game-active .feedback-copy {
    min-width: 0;
    max-width: none;
  }

  body.game-active .feedback-copy strong,
  body.game-active .feedback-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.game-active .feedback-copy strong {
    font-size: 12px;
  }

  body.game-active .feedback-copy span {
    font-size: 9px;
  }

  body.game-active .next-button {
    width: auto;
    min-height: 39px;
    margin: 0;
    padding: 0 13px;
    white-space: nowrap;
  }

  body.game-active.icons-hidden .word-card {
    grid-template-columns: 1fr auto;
  }

  body.game-active.icons-hidden .chinese-word,
  body.game-active.icons-hidden .pinyin {
    grid-column: 1;
  }

  body.game-active.icons-hidden .listen-button {
    grid-column: 2;
  }
}

@media (max-width: 600px) and (max-height: 700px) {
  body.game-active .topbar {
    flex-basis: 46px;
    height: 46px;
  }

  body.game-active .prompt-copy {
    display: none;
  }

  body.game-active .word-card {
    height: auto;
    flex-basis: 0;
  }

  body.game-active .feedback-panel.visible {
    min-height: 58px;
    flex-basis: 58px;
  }
}

@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;
  }
}
