:root {
  color-scheme: light;
  --ink: #253040;
  --muted: #6e7787;
  --paper: #fffaf1;
  --panel: #ffffff;
  --line: #e7d9c3;
  --orange: #ff7a59;
  --green: #2f9e75;
  --blue: #2487d1;
  --pink: #d05aa1;
  --yellow: #f7c948;
  --active-accent: #ff7a59;
  --shadow: 0 18px 48px rgba(55, 39, 20, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  height: auto;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
}

body {
  margin: 0;
  width: 100%;
  height: auto;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  touch-action: pan-y;
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 12%, rgba(255, 122, 89, 0.18), transparent 24rem),
    radial-gradient(circle at 90% 8%, rgba(47, 158, 117, 0.14), transparent 22rem),
    linear-gradient(135deg, #fff7e4 0%, #f2fbff 48%, #fff1f7 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 18px 0 max(92px, calc(env(safe-area-inset-bottom) + 54px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
}

body.entry-mode .topbar {
  justify-content: center;
}

body.entry-mode #homeBtn,
body.entry-mode #settingsBtn {
  display: none;
}

body.admin-mode #settingsBtn {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  font-size: 1.55rem;
  background: linear-gradient(145deg, var(--active-accent), #d05aa1);
  box-shadow: 0 10px 22px rgba(208, 90, 161, 0.25);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 3vw, 1.8rem);
}

.brand p {
  color: var(--muted);
  margin-top: 2px;
  font-size: 0.95rem;
}

.icon-button,
.tiny-button,
.soft-button,
.primary-button,
.speak-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 42px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.icon-button {
  width: 46px;
  height: 46px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 10px 22px rgba(55, 39, 20, 0.1);
  font-size: 1.35rem;
}

.tiny-button {
  padding: 0 12px;
  min-height: 32px;
  color: var(--ink);
  background: #f4efe5;
}

.soft-button {
  padding: 0 14px;
  color: var(--ink);
  background: #f4efe5;
}

.soft-button.danger {
  color: #a33131;
  background: #ffe8e5;
}

.primary-button,
.speak-button {
  padding: 0 18px;
  color: #fff;
  background: #253040;
  box-shadow: 0 12px 24px rgba(37, 48, 64, 0.18);
}

.speak-button {
  background: var(--active-accent);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
  box-shadow: none;
}

.hero-band {
  position: relative;
  overflow: hidden;
  min-height: 260px;
  border-radius: 8px;
  background: #ffe6c2;
  box-shadow: var(--shadow);
}

.hero-band img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-overlay {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  min-height: 260px;
  padding: 26px;
  background: linear-gradient(90deg, rgba(255, 250, 241, 0.94), rgba(255, 250, 241, 0.62) 44%, rgba(255, 250, 241, 0.1));
}

.eyebrow {
  color: var(--active-accent);
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0;
}

.hero-copy h2 {
  margin-top: 8px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

.hero-copy p:last-child {
  max-width: 520px;
  margin-top: 10px;
  color: #4b5564;
  font-size: clamp(1rem, 2.3vw, 1.18rem);
}

.wallet {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 10px;
  width: min(340px, 100%);
}

.wallet.compact {
  width: min(360px, 100%);
}

.subject-view {
  margin-top: 16px;
}

.entry-view {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  gap: 20px;
  align-items: center;
  justify-items: center;
  min-height: min(560px, calc(100vh - 150px));
  margin-top: 28px;
  padding: clamp(18px, 4vw, 34px);
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(34, 43, 56, 0.88), rgba(34, 43, 56, 0.48) 48%, rgba(34, 43, 56, 0.08)),
    linear-gradient(180deg, rgba(34, 43, 56, 0.05), rgba(34, 43, 56, 0.42)),
    url("assets/pinyin-hero.png") center / cover;
  box-shadow: var(--shadow);
}

.entry-copy {
  display: grid;
  justify-items: center;
  align-self: center;
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  padding: 0;
  color: #fff;
  text-align: center;
  background: transparent;
  box-shadow: none;
}

.entry-copy h2 {
  margin-top: 8px;
  max-width: min(100%, 980px);
  font-size: clamp(2.4rem, 5.4vw, 4.8rem);
  line-height: 0.98;
  white-space: nowrap;
  text-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.entry-copy p:not(.eyebrow) {
  max-width: 560px;
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 1.08rem;
  line-height: 1.7;
  text-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.entry-card {
  display: grid;
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  width: min(540px, 100%);
  align-content: center;
  gap: 10px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.entry-card label {
  color: rgba(255, 255, 255, 0.94);
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.24);
}

.entry-card input {
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 12px 30px rgba(18, 26, 36, 0.2);
}

.entry-profile-fields {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.entry-help {
  display: none;
}

.entry-card.profile-mode .entry-help {
  display: block;
  color: rgba(255, 255, 255, 0.94);
  text-align: center;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.24);
}

.learner-switcher {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(231, 217, 195, 0.58);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 10px 26px rgba(55, 39, 20, 0.06);
}

.learner-switcher.single-child {
  grid-template-columns: 1fr;
}

.learner-switcher.single-child .child-grid {
  display: none;
}

.current-child-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.current-child-chip h2 {
  margin-top: 2px;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1;
}

.child-summary {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.child-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}

.child-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 7px 8px;
  border: 1px solid rgba(239, 228, 209, 0.72);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 250, 241, 0.74);
}

.child-card.active {
  border-color: var(--active-accent);
  background: #fffaf1;
  box-shadow: 0 6px 14px rgba(55, 39, 20, 0.1);
}

.child-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: var(--child-color, var(--active-accent));
  font-weight: 900;
}

.child-avatar.large {
  width: 50px;
  height: 50px;
  font-size: 1.2rem;
}

.child-card strong,
.child-card span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.child-card span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.subject-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.subject-head h2 {
  margin-top: 8px;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.subject-card {
  position: relative;
  display: grid;
  align-content: end;
  min-height: 390px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 22px;
  color: #fff;
  text-align: left;
  background: var(--subject-color, var(--orange));
  box-shadow: var(--shadow);
}

.subject-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.subject-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(37, 48, 64, 0.02), rgba(37, 48, 64, 0.78));
}

.subject-card > *:not(img) {
  position: relative;
  z-index: 1;
}

.subject-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 50%;
  color: #fff;
  background: var(--subject-color, var(--orange));
  font-size: 1.5rem;
  font-weight: 900;
}

.subject-card strong {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
}

.subject-card span:not(.subject-mark) {
  max-width: 440px;
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.5;
}

.subject-card em {
  width: fit-content;
  margin-top: 18px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #253040;
  background: rgba(255, 255, 255, 0.9);
  font-style: normal;
  font-weight: 800;
}

.wallet > div {
  padding: 14px 12px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  text-align: center;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
}

.wallet-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.wallet strong {
  display: block;
  margin-top: 3px;
  font-size: 1.65rem;
}

.practice-layout {
  display: grid;
  grid-template-columns: 245px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  padding-bottom: max(80px, calc(env(safe-area-inset-bottom) + 48px));
  align-items: start;
  touch-action: pan-y;
  overflow: visible;
}

.stage-panel,
.question-card,
.settings-section,
.modal {
  border: 1px solid rgba(231, 217, 195, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 14px 36px rgba(55, 39, 20, 0.1);
}

.stage-panel {
  padding: 14px;
}

.panel-title,
.question-top,
.modal-head,
.settings-head,
.library-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  font-weight: 800;
}

.stage-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.collection-box {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}

.collection-label {
  color: #4b4236;
  font-weight: 900;
}

.collection-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.collection-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #eadcc8;
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 4px 0 rgba(227, 215, 198, 0.46);
}

.collection-choice span {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collection-choice strong {
  padding: 4px 8px;
  border-radius: 999px;
  color: #607087;
  background: #f4efe5;
  font-size: 0.78rem;
}

.collection-choice.active {
  border-color: rgba(255, 122, 89, 0.55);
  background: linear-gradient(135deg, #fff8ed, #fffdfa);
  box-shadow: 0 7px 18px rgba(255, 122, 89, 0.12);
}

.collection-choice.active strong {
  color: #fff;
  background: var(--orange);
}

.collection-box p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.stage-item {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px;
  border: 1px solid #efe4d1;
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: #fffaf1;
}

.stage-dot {
  width: 12px;
  height: 100%;
  min-height: 30px;
  border-radius: 99px;
  background: var(--stage-color, var(--orange));
}

.stage-item strong,
.stage-item span {
  display: block;
}

.stage-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.stage-item.active {
  border-color: var(--stage-color, var(--orange));
  box-shadow: 0 8px 18px rgba(55, 39, 20, 0.12);
}

.redeem-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.redeem-box p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.question-card {
  position: relative;
  overflow: visible;
  padding: clamp(16px, 3vw, 26px);
  touch-action: pan-y;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--active-accent);
}

.character-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 245px;
  margin: 14px 0;
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255, 122, 89, 0.13), transparent 40%),
    linear-gradient(260deg, rgba(47, 158, 117, 0.13), transparent 42%),
    #fff8ea;
}

.hanzi {
  position: relative;
  z-index: 1;
  font-size: clamp(6rem, 18vw, 11rem);
  line-height: 1;
  color: #222b38;
  text-shadow: 0 10px 0 rgba(247, 201, 72, 0.22);
}

.hanzi.math-problem {
  font-size: clamp(4.5rem, 13vw, 8rem);
  letter-spacing: 0;
  text-shadow: 0 10px 0 rgba(36, 135, 209, 0.16);
}

.hanzi.phrase-problem {
  max-width: min(92%, 700px);
  font-size: clamp(3.8rem, 10vw, 7.2rem);
  letter-spacing: 0;
  text-align: center;
  word-break: keep-all;
}

.hanzi.sentence-problem {
  max-width: min(94%, 760px);
  font-size: clamp(2.45rem, 7vw, 5rem);
  letter-spacing: 0;
  text-align: center;
  word-break: keep-all;
}

.character-zone p {
  position: absolute;
  right: 16px;
  bottom: 14px;
  left: 16px;
  color: var(--muted);
  text-align: center;
}

.sparkle {
  position: absolute;
  width: 24px;
  height: 24px;
  transform: rotate(45deg);
  border-radius: 6px;
  background: var(--yellow);
  animation: floaty 2.7s ease-in-out infinite;
}

.sparkle.one {
  top: 22%;
  left: 19%;
}

.sparkle.two {
  top: 18%;
  right: 22%;
  width: 16px;
  height: 16px;
  background: var(--green);
  animation-delay: 0.35s;
}

.sparkle.three {
  right: 16%;
  bottom: 28%;
  width: 18px;
  height: 18px;
  background: var(--pink);
  animation-delay: 0.75s;
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0) rotate(45deg);
  }
  50% {
    transform: translateY(-10px) rotate(45deg);
  }
}

.answer-form label,
.settings-section label {
  display: grid;
  gap: 7px;
  color: #414b59;
  font-weight: 800;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 8px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #decfb8;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fffdf8;
}

textarea {
  padding: 12px;
  line-height: 1.5;
  resize: vertical;
}

#answerInput {
  min-height: 58px;
  font-size: 1.8rem;
  letter-spacing: 0;
}

.typing-board {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(222, 207, 184, 0.9);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 250, 241, 0.96), rgba(247, 252, 244, 0.94)),
    #fffaf1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.84), 0 10px 24px rgba(88, 68, 42, 0.08);
}

.pinyin-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
  margin-bottom: 11px;
}

.pinyin-progress:empty {
  display: none;
}

.pinyin-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid #eadcc8;
  border-radius: 999px;
  color: #607087;
  background: rgba(255, 253, 248, 0.86);
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(227, 215, 198, 0.55);
}

.pinyin-chip strong {
  color: #253040;
  font-size: 1.02rem;
}

.pinyin-chip em {
  font-style: normal;
}

.pinyin-chip::before {
  content: "☆";
  color: #c9a96b;
}

.pinyin-chip.correct {
  border-color: rgba(47, 158, 117, 0.4);
  color: #1d7858;
  background: #effaf3;
  box-shadow: 0 4px 0 rgba(47, 158, 117, 0.14);
}

.pinyin-chip.correct::before {
  content: "★";
  color: #2f9e75;
}

.pinyin-chip.typing {
  border-color: rgba(240, 167, 47, 0.5);
  color: #9a650c;
  background: #fff8df;
}

.pinyin-chip.wrong {
  border-color: rgba(230, 90, 141, 0.42);
  color: #b9406c;
  background: #fff1f6;
}

.keyboard {
  display: grid;
  gap: 7px;
}

.keyboard-row {
  display: grid;
  grid-template-columns: repeat(var(--key-count), minmax(0, 1fr));
  gap: 7px;
}

.keyboard.pinyin .keyboard-row:nth-child(2) {
  width: 94%;
  margin-inline: auto;
}

.keyboard.pinyin .keyboard-row:nth-child(3) {
  width: 86%;
  margin-inline: auto;
}

.keyboard.pinyin .pinyin-actions {
  width: 84%;
  margin-inline: auto;
}

.keyboard-row.math {
  width: min(390px, 100%);
  margin-inline: auto;
}

.key {
  min-width: 0;
  min-height: 44px;
  border: 1px solid #ded1bf;
  border-radius: 8px;
  color: #243044;
  background: linear-gradient(180deg, #fffefb, #fff8ec);
  box-shadow: 0 4px 0 #e4d5bf;
  font-weight: 800;
}

.keyboard-row.math .key {
  min-height: 54px;
  font-size: 1.35rem;
}

.key.wide {
  grid-column: span 2;
}

.key.super-wide {
  grid-column: span 3;
}

.key:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e3d7c6;
}

.helper-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.feedback {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 13px 14px;
  border-radius: 8px;
  background: #f4efe5;
}

.feedback strong {
  font-size: 1.05rem;
}

.feedback span {
  white-space: pre-line;
  line-height: 1.55;
}

.feedback.good {
  color: #12553a;
  background: #def7e8;
}

.feedback.try {
  color: #7a3c1b;
  background: #fff0d6;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
}

dd {
  margin: 3px 0 0;
  font-weight: 800;
  line-height: 1.45;
}

.settings-view {
  margin-top: 18px;
}

.settings-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.settings-head h2 {
  margin-top: 4px;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.settings-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-actions,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  min-height: 44px;
  border: 1px solid rgba(231, 217, 195, 0.88);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
  font-weight: 900;
}

.tab-button.active {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
  box-shadow: 0 10px 22px rgba(37, 48, 64, 0.16);
}

.settings-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-card {
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 13px 14px;
  border: 1px solid rgba(231, 217, 195, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-card span,
.summary-card em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
  font-weight: 900;
}

.summary-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.25rem;
}

.settings-section {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.settings-section.wide {
  grid-column: 1 / -1;
}

.settings-note {
  color: var(--muted);
  line-height: 1.55;
}

.settings-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: #7a3c1b;
  background: #fff0d6;
  font-weight: 900;
}

.family-settings-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
  gap: 14px;
}

.settings-subpanel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(43, 36, 26, 0.1);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.62);
}

.settings-subpanel h4 {
  margin: 0;
  font-size: 1.05rem;
}

.child-manager {
  display: grid;
  gap: 8px;
}

.child-manager-row,
.add-child-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.child-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.child-actions .remove-child {
  color: #a33131;
}

.tiny-button.danger {
  color: #a33131;
  border-color: rgba(163, 49, 49, 0.28);
  background: #fff3f0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  color: #12553a;
  background: #def7e8;
  font-weight: 900;
}

.child-manager-row {
  padding: 9px 10px;
  border: 1px solid rgba(43, 36, 26, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.child-manager-row strong {
  display: block;
}

.child-manager-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

.backend-status {
  display: grid;
  gap: 8px;
}

.backend-status div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid rgba(43, 36, 26, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.backend-status strong {
  color: #4b4236;
}

.backend-status span {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  line-height: 1.45;
}

.admin-view {
  margin-top: 18px;
}

.admin-login-view {
  display: grid;
  place-items: center;
  min-height: min(620px, calc(100vh - 120px));
  margin-top: 22px;
}

.admin-login-card {
  display: grid;
  gap: 14px;
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid rgba(231, 217, 195, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.admin-login-card h2 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.admin-dashboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  display: grid;
  gap: 8px;
  min-height: 92px;
  padding: 14px;
  border: 1px solid rgba(231, 217, 195, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.stat-card span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.stat-card strong {
  font-size: 2rem;
  line-height: 1;
}

.admin-table {
  overflow-x: auto;
}

.admin-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  padding: 11px 10px;
  border-bottom: 1px solid rgba(43, 36, 26, 0.1);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.admin-table th {
  color: #4b4236;
  background: rgba(255, 250, 241, 0.8);
}

.admin-table td {
  color: var(--muted);
  font-weight: 800;
}

.admin-table .tiny-button {
  min-width: 58px;
  white-space: nowrap;
}

.admin-editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(231, 217, 195, 0.88);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.56);
}

.admin-editor .wide-field {
  grid-column: span 2;
}

.admin-editor .check-field {
  align-self: end;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid rgba(231, 217, 195, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.admin-editor .check-field input {
  width: auto;
}

.admin-editor-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.admin-question-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed rgba(43, 36, 26, 0.16);
}

.admin-question-panel h4 {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 1.05rem;
}

.question-editor-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.library-table,
.question-table {
  margin-top: 10px;
}

.redeem-editor {
  display: grid;
  gap: 10px;
}

.redeem-edit-row {
  display: grid;
  grid-template-columns: 1.4fr 0.72fr 0.72fr 44px;
  gap: 8px;
  align-items: end;
}

.question-editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.question-editor .primary-button {
  align-self: stretch;
}

.library-actions {
  justify-content: start;
  flex-wrap: wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(37, 48, 64, 0.42);
}

#rewardModal {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-items: center;
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgba(37, 48, 64, 0.34);
}

.modal {
  width: min(620px, 100%);
  padding: 20px;
}

#rewardModal .modal {
  position: fixed;
  top: var(--reward-modal-top, 50vh);
  left: var(--reward-modal-left, 50vw);
  transform: translate(-50%, -50%);
  width: min(560px, calc(var(--reward-modal-width, 100vw) - 36px));
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px);
  max-height: var(--reward-modal-max-height, calc(100dvh - 36px));
  margin: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 2.4vw, 22px);
  border: 2px solid rgba(255, 205, 92, 0.82);
  background: linear-gradient(135deg, rgba(255, 249, 222, 0.97), rgba(255, 255, 255, 0.97) 54%, rgba(255, 239, 248, 0.97));
  box-shadow: 0 24px 56px rgba(37, 48, 64, 0.22), 0 8px 0 rgba(255, 214, 102, 0.2);
}

#rewardModal .modal::before {
  content: "★";
  position: absolute;
  top: 14px;
  left: 16px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #ff7a59, #e65a8d);
  box-shadow: 0 14px 24px rgba(230, 90, 141, 0.24);
}

#rewardModal .eyebrow {
  min-height: 42px;
  padding-left: 52px;
  display: flex;
  align-items: center;
}

.modal.compact-modal {
  width: min(440px, 100%);
}

.modal h2 {
  margin-top: 5px;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
}

#rewardModal .modal h2 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.1;
}

.pin-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.reward-choice {
  display: grid;
  gap: 8px;
  min-height: 124px;
  padding: 16px;
  border: 2px solid rgba(232, 218, 198, 0.95);
  border-radius: 8px;
  text-align: left;
  background: #fffaf1;
}

#rewardModal .reward-choice {
  align-content: center;
  min-height: 112px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 6px 0 rgba(227, 215, 198, 0.5);
}

#rewardModal .reward-choice:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(227, 215, 198, 0.6);
}

.reward-choice strong {
  font-size: 1.8rem;
}

.reward-choice span {
  color: var(--muted);
  line-height: 1.45;
}

.redeem-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.redeem-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #efe4d1;
  border-radius: 8px;
  background: #fffaf1;
}

.redeem-item p {
  color: var(--muted);
  margin-top: 3px;
}

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: min(520px, calc(100% - 32px));
  min-width: min(280px, calc(100% - 32px));
  min-height: 52px;
  padding: 11px 20px 11px 13px;
  border: 2px solid rgba(255, 205, 92, 0.82);
  border-radius: 999px;
  color: #253040;
  background: linear-gradient(135deg, rgba(255, 249, 222, 0.96), rgba(255, 255, 255, 0.96) 52%, rgba(255, 239, 248, 0.96));
  box-shadow: 0 18px 42px rgba(37, 48, 64, 0.16), 0 8px 0 rgba(255, 214, 102, 0.2);
  backdrop-filter: blur(16px);
  opacity: 0;
  transform: translate(-50%, -14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  visibility: hidden;
  pointer-events: none;
  text-align: center;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

body.entry-mode .toast {
  top: 86px;
}

.toast::before {
  content: "★";
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #ff7a59, #e65a8d);
  box-shadow: 0 10px 20px rgba(230, 90, 141, 0.24);
  font-size: 1rem;
}

.toast::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255, 153, 102, 0.5);
  border-radius: inherit;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
}

.toast.show::before {
  animation: toast-star-hop 0.58s ease;
}

@keyframes toast-star-hop {
  0% {
    transform: scale(0.74) rotate(-14deg);
  }

  55% {
    transform: scale(1.12) rotate(10deg);
  }

  100% {
    transform: scale(1) rotate(0deg);
  }
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 4px;
  animation: fall 850ms ease-in forwards;
}

@keyframes fall {
  to {
    transform: translateY(105vh) rotate(480deg);
    opacity: 0;
  }
}

[hidden] {
  display: none !important;
}

@media (max-width: 1180px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
  }

  .app-shell {
    min-height: max-content;
    padding-bottom: max(118px, calc(env(safe-area-inset-bottom) + 86px));
  }

  .practice-layout {
    grid-template-columns: 1fr;
    min-height: max-content;
    padding-bottom: max(118px, calc(env(safe-area-inset-bottom) + 86px));
    overflow: visible;
  }

  .stage-panel {
    order: 2;
    padding: 12px;
    margin-bottom: 0;
  }

  .question-card {
    order: 1;
    min-height: max-content;
  }

  .stage-list {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
  }

  .collection-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
  }

  .app-shell {
    min-height: max-content;
    padding-bottom: max(96px, calc(env(safe-area-inset-bottom) + 72px));
  }

  .entry-view {
    grid-template-columns: 1fr;
  }

  .entry-copy {
    grid-column: 1;
    grid-row: 1;
    min-height: 160px;
  }

  .entry-copy h2 {
    font-size: clamp(2rem, 8.6vw, 3.2rem);
  }

  .entry-card {
    grid-column: 1;
    grid-row: 2;
  }

  .admin-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .subject-head {
    align-items: stretch;
    flex-direction: column;
  }

  .subject-grid {
    grid-template-columns: 1fr;
  }

  .subject-card {
    min-height: 330px;
  }

  .hero-overlay {
    align-items: stretch;
    flex-direction: column;
    justify-content: end;
  }

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

  #rewardModal {
    place-items: center;
    padding: 18px;
  }

  #rewardModal .modal {
    width: min(540px, calc(100vw - 36px));
  }

  #rewardModal .choice-grid {
    gap: 10px;
    margin-top: 12px;
  }

  #rewardModal .reward-choice {
    min-height: 96px;
    padding: 14px 15px;
  }

  .stage-list {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
  }

  .stage-item {
    min-height: 48px;
    padding: 9px;
  }

  .collection-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-grid,
  .question-editor {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
    padding-bottom: max(72px, calc(env(safe-area-inset-bottom) + 56px));
  }

  .brand p {
    display: none;
  }

  .settings-head {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .admin-dashboard {
    grid-template-columns: 1fr;
  }

  .admin-editor,
  .question-editor-grid {
    grid-template-columns: 1fr;
  }

  .admin-editor .wide-field {
    grid-column: auto;
  }

  .hero-band,
  .hero-overlay {
    min-height: 330px;
  }

  .hero-overlay {
    padding: 16px;
    background: linear-gradient(180deg, rgba(255, 250, 241, 0.25), rgba(255, 250, 241, 0.94) 58%);
  }

  .wallet {
    grid-template-columns: repeat(3, 1fr);
  }

  .stage-list,
  .collection-picker,
  .helper-strip,
  .choice-grid,
  .redeem-edit-row,
  .redeem-item {
    grid-template-columns: 1fr;
  }

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

  .keyboard-row {
    gap: 5px;
  }

  .key {
    min-height: 42px;
  }

  #rewardModal .choice-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 12px;
  }

  #rewardModal .reward-choice {
    min-height: 86px;
    padding: 13px 15px;
  }

  .toast {
    top: 78px;
    bottom: auto;
    left: 50%;
    max-width: none;
    min-width: auto;
    width: calc(100% - 24px);
    border-radius: 18px;
    text-align: center;
    transform: translate(-50%, -12px);
  }

  .toast.show {
    transform: translate(-50%, 0);
  }
}

@media (orientation: landscape) and (max-height: 820px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
  }

  .app-shell {
    padding-top: 8px;
    padding-bottom: max(160px, calc(env(safe-area-inset-bottom) + 128px));
  }

  .topbar {
    min-height: 48px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    font-size: 1.35rem;
  }

  .brand p {
    font-size: 0.86rem;
  }

  .hero-band,
  .hero-overlay {
    min-height: 160px;
  }

  .hero-overlay {
    padding: 18px 26px;
  }

  .hero-copy h2 {
    font-size: clamp(2rem, 4vw, 3rem);
  }

  .wallet {
    width: min(340px, 38vw);
  }

  .wallet > div {
    padding: 10px 12px;
  }

  .wallet strong {
    font-size: 1.45rem;
  }

  .practice-layout {
    gap: 12px;
    margin-top: 12px;
    padding-bottom: max(160px, calc(env(safe-area-inset-bottom) + 128px));
    overflow: visible;
  }

  .stage-panel {
    padding: 12px;
  }

  .question-card {
    padding: 18px;
    overflow: visible;
  }

  .character-zone {
    min-height: 210px;
    margin: 10px 0;
  }

  .hanzi {
    font-size: clamp(5rem, 12vw, 8rem);
  }

  .hanzi.phrase-problem {
    font-size: clamp(3.7rem, 7.2vw, 6rem);
  }

  .hanzi.sentence-problem {
    font-size: clamp(2.6rem, 5.4vw, 4.2rem);
  }

  #answerInput {
    min-height: 52px;
    font-size: 1.58rem;
  }

  .typing-board {
    padding: 10px;
  }

  .keyboard,
  .keyboard-row {
    gap: 6px;
  }

  .key {
    min-height: 38px;
  }

  .helper-strip {
    margin-top: 10px;
  }

  #rewardModal {
    padding-block: 14px;
  }

  #rewardModal .modal {
    top: var(--reward-modal-top, 50vh);
    left: var(--reward-modal-left, 50vw);
    transform: translate(-50%, -50%);
    width: min(660px, calc(var(--reward-modal-width, 100vw) - 36px));
    max-height: calc(100vh - 28px);
    max-height: calc(100dvh - 28px);
    max-height: var(--reward-modal-max-height, calc(100dvh - 28px));
    padding: 16px;
  }

  #rewardModal .modal h2 {
    font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  }

  #rewardModal .choice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
  }

  #rewardModal .reward-choice {
    min-height: 88px;
    padding: 12px 14px;
  }

  #rewardModal .reward-choice strong {
    font-size: 1.45rem;
  }
}
