@font-face {
  font-family: "Tibetan Uchen";
  src: url("./noto-serif-tibetan-regular.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+0F00-0FFF, U+25CC;
}

:root {
  color-scheme: light;
  --ink: #24333a;
  --muted: #697a80;
  --paper: #fffefd;
  --cream: #fff8e9;
  --mint: #dff4ee;
  --mint-strong: #62b7a3;
  --sky: #dceff4;
  --blue: #315ba8;
  --blue-soft: #8da8d2;
  --red: #b94235;
  --red-soft: #f7ddd5;
  --gold: #ddaa45;
  --line: #d7e0df;
  --guide: #9fb7cf;
  --shadow: 0 24px 70px rgba(43, 69, 77, 0.13);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 28px 18px 42px;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.8), transparent 23%),
    radial-gradient(circle at 92% 9%, rgba(255, 226, 167, 0.36), transparent 24%),
    linear-gradient(160deg, #eaf8f4 0%, #e5f3f6 48%, #f7f1e8 100%);
  overflow-x: hidden;
}

body:has(dialog[open]) {
  overflow: hidden;
}

button {
  font: inherit;
}

button:focus-visible,
canvas:focus-visible {
  outline: 4px solid rgba(49, 91, 168, 0.2);
  outline-offset: 3px;
}

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

.sky-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(1px);
  pointer-events: none;
}

.sky-shape--one {
  top: -100px;
  left: -80px;
  width: 300px;
  height: 300px;
  background: rgba(255, 255, 255, 0.48);
}

.sky-shape--two {
  top: 36%;
  right: -120px;
  width: 340px;
  height: 340px;
  background: rgba(175, 224, 218, 0.25);
}

.sky-shape--three {
  bottom: -160px;
  left: 18%;
  width: 420px;
  height: 420px;
  background: rgba(242, 206, 159, 0.14);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

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

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.brand small,
.brand strong {
  display: block;
}

.brand small {
  color: var(--blue);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.brand strong {
  margin-top: 2px;
  font-family: "Songti SC", SimSun, serif;
  font-size: 25px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 5px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.profile-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  font-size: 22px;
  background: linear-gradient(145deg, #fff4d8, #e6f4f0);
  border-radius: 50%;
  place-items: center;
}

.profile-chip small,
.profile-chip strong {
  display: block;
}

.profile-chip small {
  color: var(--muted);
  font-size: 8px;
}

.profile-chip strong {
  max-width: 80px;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.soft-button,
.primary-button {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  color: var(--blue);
  font-size: 22px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(156, 183, 190, 0.5);
  border-radius: 50%;
  place-items: center;
}

.soft-button {
  min-height: 40px;
  padding: 8px 15px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(156, 183, 190, 0.5);
  border-radius: 999px;
}

.primary-button {
  min-height: 46px;
  padding: 10px 22px;
  color: #fff;
  font-weight: 800;
  background: var(--red);
  border-radius: 13px;
  box-shadow: 0 10px 22px rgba(185, 66, 53, 0.22);
}

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

.soft-button:hover {
  color: var(--blue);
  background: #fff;
}

.primary-button:hover {
  background: #9f3027;
}

.hero {
  position: relative;
  display: grid;
  min-height: 320px;
  grid-template-columns: minmax(0, 1.07fr) minmax(300px, 0.93fr);
  overflow: hidden;
  padding: clamp(26px, 4.5vw, 48px);
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.96), rgba(255, 252, 244, 0.82));
  border: 1px solid rgba(196, 214, 211, 0.86);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.hero::after {
  position: absolute;
  right: 32%;
  bottom: -80px;
  width: 210px;
  height: 210px;
  background: rgba(225, 239, 229, 0.6);
  border-radius: 50%;
  content: "";
}

.hero-copy {
  position: relative;
  z-index: 2;
}

.eyebrow,
.section-kicker {
  color: var(--red);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.14em;
}

.section-kicker[lang="bo"],
.brand small[lang="bo"] {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  letter-spacing: 0;
}

.eyebrow {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 17px;
  letter-spacing: 0;
}

.hero h1 {
  max-width: 570px;
  margin: 10px 0 12px;
  font-family: "Songti SC", SimSun, serif;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.06;
  letter-spacing: 0.02em;
}

.hero h1 em {
  color: var(--red);
  font-style: normal;
}

.hero-copy > p {
  max-width: 510px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 25px;
}

.stat-card {
  display: flex;
  min-width: 104px;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.stat-icon {
  display: grid;
  width: 30px;
  height: 30px;
  color: var(--red);
  font-size: 19px;
  background: var(--cream);
  border-radius: 10px;
  place-items: center;
}

.stat-card small,
.stat-card strong {
  display: block;
}

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

.stat-card strong {
  margin-top: 1px;
  font-size: 16px;
}

.mascot-scene {
  position: relative;
  z-index: 1;
  min-height: 250px;
}

.mountain {
  position: absolute;
  bottom: 28px;
  width: 0;
  height: 0;
  border-right: 115px solid transparent;
  border-bottom: 165px solid #d6ebe3;
  border-left: 115px solid transparent;
}

.mountain::after {
  position: absolute;
  top: 40px;
  left: 47px;
  width: 61px;
  height: 38px;
  background: #fff;
  clip-path: polygon(0 100%, 35% 10%, 50% 42%, 65% 0, 100% 100%);
  content: "";
}

.mountain--back {
  right: 35px;
  opacity: 0.72;
  transform: scale(0.8);
}

.mountain--front {
  right: 160px;
  border-bottom-color: #a9d8c9;
}

.mascot {
  position: absolute;
  right: 80px;
  bottom: 38px;
  width: 154px;
  height: 176px;
  animation: float 3.4s ease-in-out infinite;
}

.mascot-face {
  position: absolute;
  top: 23px;
  left: 20px;
  width: 115px;
  height: 118px;
  background: #fff;
  border: 4px solid #2e4c66;
  border-radius: 50% 50% 45% 45%;
  box-shadow: inset 0 -10px 0 #e8f4f2;
}

.mascot-ear {
  position: absolute;
  top: 8px;
  width: 49px;
  height: 58px;
  background: #fff;
  border: 4px solid #2e4c66;
  transform: rotate(-24deg);
}

.mascot-ear::after {
  position: absolute;
  inset: 9px 10px 12px;
  background: #f2c7bd;
  border-radius: 50%;
  content: "";
}

.mascot-ear--left {
  left: 13px;
  border-radius: 70% 30% 55% 45%;
}

.mascot-ear--right {
  right: 9px;
  border-radius: 30% 70% 45% 55%;
  transform: rotate(24deg);
}

.mascot-eye {
  position: absolute;
  top: 47px;
  width: 9px;
  height: 12px;
  background: #2e4c66;
  border-radius: 50%;
}

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

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

.mascot-nose {
  position: absolute;
  top: 67px;
  left: 50%;
  width: 12px;
  height: 9px;
  background: #bc645f;
  border-radius: 50% 50% 60% 60%;
  transform: translateX(-50%);
}

.mascot-smile {
  position: absolute;
  top: 76px;
  left: 50%;
  width: 25px;
  height: 12px;
  border-bottom: 2px solid #2e4c66;
  border-radius: 50%;
  transform: translateX(-50%);
}

.mascot-scarf {
  position: absolute;
  right: 17px;
  bottom: 29px;
  left: 17px;
  height: 30px;
  background: var(--red);
  border-radius: 16px 16px 8px 8px;
}

.mascot-scarf::after {
  position: absolute;
  top: 19px;
  right: 7px;
  width: 22px;
  height: 45px;
  background: #d65a4a;
  border-radius: 4px 4px 12px 12px;
  transform: rotate(-9deg);
  content: "";
}

.speech-bubble {
  position: absolute;
  top: 16px;
  right: 8px;
  width: 175px;
  padding: 12px 15px;
  color: #405861;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  background: #fffdf5;
  border: 1px solid #ded6c3;
  border-radius: 15px 15px 5px 15px;
  box-shadow: 0 9px 20px rgba(53, 80, 83, 0.08);
}

.spark {
  position: absolute;
  color: var(--gold);
  animation: twinkle 2.4s ease-in-out infinite;
}

.spark--one {
  top: 25px;
  left: 22%;
}

.spark--two {
  right: 18px;
  bottom: 115px;
  animation-delay: 0.7s;
}

.spark--three {
  bottom: 70px;
  left: 12%;
  font-size: 12px;
  animation-delay: 1.3s;
}

.mode-tabs {
  display: grid;
  width: min(760px, 100%);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 22px auto;
  padding: 6px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(150, 180, 182, 0.46);
  border-radius: 18px;
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 66px;
  padding: 8px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 13px;
  cursor: pointer;
}

.mode-tab.is-active {
  color: var(--ink);
  background: #fff;
  border-color: #b6d4cb;
  box-shadow: 0 7px 18px rgba(65, 104, 98, 0.1);
}

.mode-tab strong,
.mode-tab small {
  display: block;
}

.mode-tab strong {
  font-size: 13px;
}

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

.mode-icon {
  display: grid;
  width: 37px;
  height: 37px;
  flex: none;
  color: var(--red);
  font-size: 20px;
  background: var(--red-soft);
  border-radius: 11px;
  place-items: center;
}

.mode-icon--cards {
  color: var(--blue);
  background: #e4ecf8;
}

.mode-icon--stack {
  color: #a36d12;
  font-size: 16px;
  font-weight: 900;
  background: #fff2cc;
}

.game-panel {
  padding: clamp(20px, 3.8vw, 34px);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(173, 199, 198, 0.55);
  border-radius: 27px;
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.panel-heading h2 {
  margin: 5px 0 0;
  font-family: "Songti SC", SimSun, serif;
  font-size: clamp(23px, 3vw, 32px);
}

.trace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(230px, 0.7fr);
  gap: clamp(20px, 4vw, 42px);
  align-items: center;
}

.trace-stage {
  padding: 17px;
  background: #f2f6f5;
  border-radius: 22px;
}

.trace-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #fff;
  border: 1.5px solid #aac2d8;
  border-radius: 12px;
  touch-action: none;
}

.trace-guides,
#guide-canvas,
#ink-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.trace-guides line {
  stroke: var(--guide);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.trace-guides .trace-guide--bottom {
  opacity: 0.65;
}

#guide-canvas {
  pointer-events: none;
}

#ink-canvas {
  z-index: 2;
  cursor: crosshair;
}

.trace-start-dot {
  position: absolute;
  z-index: 3;
  width: 13px;
  height: 13px;
  background: var(--red);
  border: 4px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(185, 66, 53, 0.15);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: pulse 1.8s ease-in-out infinite;
}

.trace-tip {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.trace-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.letter-feature {
  display: grid;
  min-height: 154px;
  align-content: center;
  justify-items: center;
  color: var(--red);
  background:
    radial-gradient(circle at 80% 20%, rgba(255, 218, 168, 0.42), transparent 28%),
    #fffaf1;
  border: 1px solid #f0dfc7;
  border-radius: 20px;
}

.letter-feature span,
.letter-feature small {
  color: var(--muted);
  font-size: 9px;
}

.letter-feature .letter-example {
  margin: 2px 0 9px;
  color: #7b6b55;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 10px;
}

.letter-feature strong {
  margin: 7px 0 4px;
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 81px;
  font-weight: 400;
  line-height: 0.9;
}

.listen-button {
  min-height: 34px;
  padding: 6px 13px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  background: #eef4fb;
  border: 1px solid #c7d8eb;
  border-radius: 999px;
  cursor: pointer;
}

.stroke-reference-strip {
  display: grid;
  width: 100%;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 10px 13px;
  color: var(--ink);
  text-align: left;
  background: #fffdf7;
  border: 1px dashed #ddcfad;
  border-radius: 14px;
  cursor: zoom-in;
}

.stroke-reference-strip img {
  width: 72px;
  height: 58px;
  object-fit: contain;
}

.stroke-reference-strip strong,
.stroke-reference-strip small {
  display: block;
}

.stroke-reference-strip strong {
  font-size: 11px;
}

.stroke-reference-strip small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.meter-label strong {
  color: var(--blue);
}

.meter-label b {
  display: inline-block;
  margin-right: 3px;
  font-size: 14px;
  transform-origin: center;
}

.meter-label em {
  font-style: normal;
  font-weight: 800;
}

.meter-track {
  height: 9px;
  overflow: hidden;
  margin-top: 8px;
  background: #e5eeeb;
  border-radius: 999px;
}

.meter-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #75c6b2, #315ba8);
  border-radius: inherit;
  transition: width 100ms linear;
}

.action-stack {
  display: grid;
  gap: 8px;
}

.gentle-tip {
  min-height: 34px;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
  text-align: center;
}

.gentle-tip.is-happy {
  color: #267860;
  font-weight: 800;
}

.gentle-tip.is-wiggle {
  color: var(--red);
}

.letter-pool-section,
.garden-section {
  margin-top: 27px;
  padding-top: 20px;
  border-top: 1px dashed #cadad5;
}

.subheading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.subheading strong {
  font-size: 13px;
}

.subheading span {
  color: var(--muted);
  font-size: 10px;
}

.subheading-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.subheading-actions em {
  font-style: normal;
}

.mini-action {
  padding: 5px 9px;
  color: var(--blue);
  font-size: 9px;
  font-weight: 800;
  background: #eef4fb;
  border: 1px solid #d2dfed;
  border-radius: 999px;
  cursor: pointer;
}

.letter-pool {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  gap: 5px;
}

.letter-seed {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  padding: 0;
  color: #63777d;
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: clamp(16px, 2.1vw, 24px);
  background: #f6f9f7;
  border: 1px solid #dfe8e5;
  border-radius: 9px;
  cursor: pointer;
  place-items: center;
}

.letter-seed:hover {
  color: var(--blue);
  border-color: #abc7d6;
}

.letter-seed.is-current {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.letter-seed.is-done {
  color: #2c8c71;
  background: #e4f6ef;
  border-color: #b8e2d3;
}

.letter-seed.is-done::after {
  position: absolute;
  width: 4px;
  height: 4px;
  margin-top: 20px;
  margin-left: 20px;
  background: var(--gold);
  border-radius: 50%;
  content: "";
}

.garden-bed {
  position: relative;
  display: flex;
  min-height: 84px;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  padding: 13px 17px 17px;
  background: linear-gradient(transparent 66%, #d5ebdf 66%, #c8e2d7 100%);
  border: 1px solid #d9e9e2;
  border-radius: 16px;
}

.garden-empty {
  color: #8ba197;
  font-size: 11px;
}

.garden-flower {
  position: relative;
  display: grid;
  width: 52px;
  height: 52px;
  flex: none;
  font-size: 34px;
  place-items: center;
  animation: flower-pop 550ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.garden-flower span {
  position: absolute;
  color: #566f66;
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 9px;
}

.round-pill {
  padding: 9px 14px;
  color: var(--muted);
  font-size: 11px;
  background: #fff8ea;
  border: 1px solid #ecd9ad;
  border-radius: 999px;
}

.round-pill strong {
  color: var(--red);
}

.match-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.65fr);
  gap: clamp(20px, 4vw, 42px);
  align-items: center;
}

.match-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.match-card {
  position: relative;
  aspect-ratio: 0.9;
  padding: 0;
  background: transparent;
  border: 0;
  perspective: 700px;
  cursor: pointer;
}

.match-card-inner {
  position: absolute;
  inset: 0;
  transition: transform 360ms ease;
  transform-style: preserve-3d;
}

.match-card.is-open .match-card-inner,
.match-card.is-matched .match-card-inner {
  transform: rotateY(180deg);
}

.match-face {
  position: absolute;
  inset: 0;
  display: grid;
  border-radius: 17px;
  backface-visibility: hidden;
  place-items: center;
}

.match-front {
  color: rgba(255, 255, 255, 0.9);
  font-size: 24px;
  background:
    radial-gradient(circle at 35% 22%, rgba(255, 255, 255, 0.25), transparent 25%),
    linear-gradient(145deg, #315ba8, #6b8fc7);
  border: 1px solid #7695c4;
}

.match-back {
  color: var(--ink);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: clamp(44px, 7vw, 72px);
  background: #fffdf8;
  border: 2px solid #b5cec8;
  transform: rotateY(180deg);
}

.match-card.is-matched .match-back {
  color: #24775f;
  background: #e7f8f0;
  border-color: #78bea7;
  animation: match-glow 500ms ease;
}

.match-side {
  padding: 22px;
  background: #f6faf8;
  border: 1px solid #dbe7e2;
  border-radius: 20px;
}

.match-mascot {
  display: grid;
  width: 48px;
  height: 48px;
  color: var(--blue);
  font-size: 25px;
  background: #e4eef8;
  border-radius: 15px;
  place-items: center;
}

.match-side h3 {
  margin: 14px 0 7px;
  font-family: "Songti SC", SimSun, serif;
  font-size: 22px;
}

.match-side p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.match-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 17px;
  padding-top: 15px;
  border-top: 1px dashed #cddbd5;
}

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

.match-score strong {
  color: var(--red);
  font-size: 18px;
}

.match-message {
  margin-top: 18px;
  padding: 10px 12px;
  background: #fff;
  border-radius: 10px;
}

.stack-layout {
  display: grid;
  grid-template-columns: minmax(250px, 0.72fr) minmax(0, 1.28fr);
  gap: clamp(20px, 4vw, 42px);
  align-items: center;
}

.stack-stage {
  display: grid;
  min-height: 330px;
  align-content: center;
  justify-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 80% 16%, rgba(255, 222, 159, 0.36), transparent 28%),
    #f9fcfa;
  border: 1px solid #d7e7e1;
  border-radius: 23px;
}

.stack-face {
  font-size: 38px;
  transition: transform 180ms ease;
}

.stack-result {
  min-height: 128px;
  margin: 8px 0;
  color: var(--red);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 102px;
  line-height: 1.2;
}

.stack-stage.is-wrong .stack-result {
  animation: wiggle 340ms ease;
}

.stack-stage p {
  max-width: 290px;
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
  text-align: center;
}

.stack-controls {
  display: grid;
  gap: 12px;
}

.stack-step {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 13px;
  background: #f7faf8;
  border: 1px solid #dde8e3;
  border-radius: 15px;
}

.stack-step > span {
  display: grid;
  width: 27px;
  height: 27px;
  color: #fff;
  font-size: 11px;
  font-weight: 850;
  background: var(--blue);
  border-radius: 50%;
  place-items: center;
}

.stack-step strong {
  display: block;
  margin: 5px 0 9px;
  font-size: 12px;
}

.stack-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stack-option {
  min-width: 38px;
  min-height: 38px;
  padding: 4px 9px;
  color: var(--ink);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 22px;
  background: #fff;
  border: 1px solid #d7e3df;
  border-radius: 10px;
  cursor: pointer;
}

.stack-option:hover {
  border-color: var(--mint-strong);
}

.stack-option.is-active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.stack-help {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.profile-dialog,
.ranking-dialog,
.stroke-help-dialog {
  width: min(440px, calc(100vw - 26px));
  max-height: calc(100vh - 26px);
  margin: auto;
  padding: 28px;
  color: var(--ink);
  background: #fffef9;
  border: 1px solid #e2d9c7;
  border-radius: 23px;
  box-shadow: 0 32px 90px rgba(40, 60, 63, 0.28);
}

.profile-dialog::backdrop,
.ranking-dialog::backdrop,
.stroke-help-dialog::backdrop {
  background: rgba(30, 47, 49, 0.5);
  backdrop-filter: blur(4px);
}

.profile-dialog h2,
.ranking-dialog h2,
.stroke-help-dialog h2 {
  margin: 6px 0 17px;
  font-family: "Songti SC", SimSun, serif;
  font-size: 27px;
}

.stroke-help-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 150px);
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  font-size: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  place-items: center;
}

.avatar-preview {
  display: grid;
  width: 104px;
  height: 104px;
  margin: 0 auto 10px;
  font-size: 61px;
  background: linear-gradient(145deg, #fff0cb, #e4f5f0);
  border: 4px solid #fff;
  border-radius: 50%;
  box-shadow: 0 12px 28px rgba(56, 90, 87, 0.14);
  place-items: center;
}

.profile-dialog > .soft-button {
  display: block;
  margin: 0 auto 18px;
}

.profile-name-field {
  display: block;
  margin-bottom: 16px;
}

.profile-name-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.profile-name-field input {
  width: 100%;
  height: 43px;
  padding: 8px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.profile-dialog > .primary-button {
  width: 100%;
}

.ranking-tip {
  margin: -7px 0 15px;
  color: var(--muted);
  font-size: 10px;
}

.ranking-list {
  display: grid;
  gap: 8px;
  max-height: 55vh;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-row {
  display: grid;
  grid-template-columns: 30px 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  background: #f7faf8;
  border: 1px solid #dde8e3;
  border-radius: 12px;
}

.ranking-row:first-child {
  background: #fff8e5;
  border-color: #ecd394;
}

.ranking-place {
  color: var(--muted);
  font-weight: 850;
  text-align: center;
}

.ranking-avatar {
  font-size: 25px;
  text-align: center;
}

.ranking-name {
  overflow: hidden;
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-score {
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
}

.ranking-empty {
  padding: 25px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 20px 9px 0;
  color: #6d817d;
  font-size: 10px;
}

.page-footer span:first-child {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 14px;
}

.celebrate-dialog {
  width: min(420px, calc(100vw - 28px));
  margin: auto;
  padding: 34px 28px 28px;
  overflow: hidden;
  color: var(--ink);
  text-align: center;
  background: #fffef9;
  border: 1px solid #ecd6ad;
  border-radius: 24px;
  box-shadow: 0 35px 100px rgba(41, 58, 61, 0.3);
}

.celebrate-dialog::backdrop {
  background: rgba(29, 50, 53, 0.46);
  backdrop-filter: blur(4px);
}

.celebration-rays {
  position: absolute;
  top: -100px;
  left: 50%;
  width: 280px;
  height: 280px;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(240, 193, 94, 0.22) 0 9deg,
    transparent 9deg 20deg
  );
  border-radius: 50%;
  transform: translateX(-50%);
}

.celebration-star {
  position: relative;
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 13px;
  color: #fff;
  font-size: 34px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 10px 26px rgba(202, 149, 46, 0.3);
  place-items: center;
}

.celebrate-dialog h2 {
  position: relative;
  margin: 0;
  font-family: "Songti SC", SimSun, serif;
  font-size: 28px;
}

.celebrate-dialog p {
  position: relative;
  margin: 9px 0 20px;
  color: var(--muted);
  font-size: 12px;
}

.confetti-canvas {
  position: fixed;
  z-index: 20;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.8) rotate(0); }
  50% { opacity: 1; transform: scale(1.2) rotate(12deg); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 5px rgba(185, 66, 53, 0.12); }
  50% { box-shadow: 0 0 0 12px rgba(185, 66, 53, 0); }
}

@keyframes flower-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.5); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes match-glow {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.07); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-4deg); }
  70% { transform: rotate(4deg); }
}

@media (max-width: 800px) {
  body {
    padding: 18px 12px 28px;
  }

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

  .mascot-scene {
    min-height: 235px;
  }

  .mascot {
    right: calc(50% - 158px);
  }

  .speech-bubble {
    top: 2px;
    right: 5px;
  }

  .trace-layout,
  .match-layout,
  .stack-layout {
    grid-template-columns: 1fr;
  }

  .trace-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .trace-side .action-stack,
  .trace-side .gentle-tip {
    grid-column: 1 / -1;
  }

  .letter-pool {
    grid-template-columns: repeat(10, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  .topbar {
    align-items: flex-start;
  }

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

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
  }

  .profile-chip {
    order: 3;
  }

  #reset-progress {
    display: none;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .soft-button {
    padding: 8px 11px;
  }

  .hero {
    padding: 25px 20px;
    border-radius: 22px;
  }

  .hero h1 {
    font-size: 38px;
  }

  .stat-card {
    min-width: 0;
    flex: 1 1 auto;
  }

  .mode-tabs {
    margin: 14px auto;
  }

  .mode-tab {
    min-height: 56px;
    justify-content: flex-start;
    padding: 7px;
  }

  .mode-tab small {
    display: none;
  }

  .game-panel {
    padding: 18px;
    border-radius: 20px;
  }

  .panel-heading {
    align-items: flex-start;
  }

  .trace-side {
    grid-template-columns: 1fr;
  }

  .letter-feature {
    min-height: 120px;
  }

  .letter-feature strong {
    font-size: 64px;
  }

  .letter-pool {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .match-board {
    gap: 7px;
  }

  .match-face {
    border-radius: 12px;
  }

  .match-back {
    font-size: 45px;
  }

  .stack-stage {
    min-height: 260px;
  }

  .stack-result {
    font-size: 78px;
  }

  .page-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
