:root {
  color-scheme: light;
  --bg: #f3eadc;
  --bg-2: #fff7ea;
  --ink: #2a2118;
  --muted: #6f5b49;
  --card: #fffaf3;
  --line: #eadfce;
  --dash: #c3b19a;
  --pine: #2d6a4f;
  --pine-dark: #214e3a;
  --sand: #f3ddb4;
  --amber: #e39b2d;
  --ghost: #b7a08c;
  --shadow: 0 10px 28px rgba(80, 52, 24, 0.08);
  --radius: 24px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background:
    radial-gradient(900px 420px at 50% -80px, var(--bg-2), transparent 70%),
    var(--bg);
}

button, input { font: inherit; color: inherit; }

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--pine);
  outline-offset: 3px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.start {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.start-card {
  width: min(440px, 100%);
  text-align: center;
}

.mark {
  width: min(220px, 70%);
  margin: 0 auto 8px;
}

h1 {
  margin: 8px 0 8px;
  font-size: clamp(32px, 8vw, 48px);
  font-weight: 760;
  letter-spacing: 0;
  line-height: 1.2;
}

.lead {
  margin: 0 0 22px;
  font-size: 20px;
}

.btn-primary {
  appearance: none;
  width: min(100%, 320px);
  min-height: 76px;
  border: 0;
  border-radius: 999px;
  background: var(--pine);
  color: #fffaf3;
  font-size: 28px;
  font-weight: 750;
  box-shadow: 0 8px 0 var(--pine-dark);
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 6px 0 var(--pine-dark);
}

.adult {
  margin: 22px 0 0;
  padding: 14px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--muted);
  font-size: 16px;
  text-align: left;
}

.adult strong,
.who {
  color: var(--ink);
  font-weight: 700;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: max(4px, env(safe-area-inset-top));
}

.top-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 48px;
  margin-right: auto;
}

.top-char {
  font-size: 36px;
  line-height: 1;
  font-weight: 700;
}

.top-py {
  font-size: 20px;
  color: var(--muted);
}

.top-py,
.card .py,
.py,
.pinyin-lg {
  font-family: "Liberation Serif", "Nimbus Roman", "Times New Roman", "Songti SC", "PMingLiU", serif;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  min-height: 52px;
  padding: 0 16px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--card);
  font-size: 18px;
}

.btn:active { background: #fff1dc; }

.btn-speak[data-state="speaking"] {
  border-color: var(--pine);
  background: #e7f3ec;
}

.picker-head {
  margin: 18px 0 12px;
}

.picker-head h2 {
  margin: 0;
  font-size: 28px;
}

.picker-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.card {
  min-height: 132px;
  border-radius: 22px;
  border: 2px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px;
}

.card:active { background: #fff4e4; }

.card .hz {
  font-size: 64px;
  line-height: 1;
  font-weight: 700;
}

.card .py {
  font-size: 18px;
  color: var(--muted);
}

.silent {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--sand);
  color: var(--ink);
  font-size: 16px;
}

.hint {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.hint p {
  margin: 0;
  font-size: 17px;
}

.who {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: var(--muted);
}

.instruction {
  min-height: 32px;
  margin: 12px 0;
  text-align: center;
  font-size: 18px;
  color: var(--muted);
}

.build {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage-wrap { width: min(100%, 460px); margin: 0 auto; }

.stage.stage--done {
  width: min(100%, 200px);
  margin-inline: auto;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 300 / 320;
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage svg { width: 100%; height: 100%; display: block; }

.ink { color: var(--ink); }
.ghost { color: var(--ghost); }

.slot {
  position: absolute;
  border: 3px dashed var(--dash);
  border-radius: 18px;
  background: transparent;
  padding: 0;
}

.stage.is-armed .slot {
  border-color: var(--pine);
  background: rgba(45, 106, 79, 0.06);
}

.slot.is-wiggle {
  animation: wiggle 0.45s ease;
  background: rgba(243, 221, 180, 0.7);
  border-color: #c8923a;
}

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-7px); }
  70% { transform: translateX(7px); }
}

.tray {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
}

.part {
  min-height: 128px;
  border-radius: 20px;
  border: 4px solid transparent;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.part svg {
  width: 100%;
  height: 84px;
}

.part span {
  font-size: 16px;
  color: var(--muted);
}

.part[aria-pressed="true"] {
  border-color: var(--amber);
  background: #fff6e4;
}

.part:disabled {
  opacity: 0.38;
  box-shadow: none;
}

.done { text-align: center; }

.kicker {
  margin: 8px 0 4px;
  font-size: 28px;
  font-weight: 750;
}

.pinyin-lg {
  margin: 4px 0;
  font-size: 36px;
  letter-spacing: 0.04em;
}

.scene {
  margin: 16px 0 8px;
  background: var(--card);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
  text-align: left;
}

.scene svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fffaf3;
}

.scene figcaption {
  margin: 0;
  padding: 10px 14px 4px;
  font-size: 20px;
  line-height: 1.45;
}

.scene-note,
.silent-line {
  margin: 0;
  padding: 0 16px 14px;
  color: var(--muted);
  font-size: 15px;
}

.silent-line {
  padding: 0 0 8px;
  text-align: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.actions .btn { min-width: 140px; font-size: 20px; min-height: 60px; }

#floater {
  position: fixed;
  z-index: 40;
  width: 112px;
  height: 112px;
  margin-left: -56px;
  margin-top: -64px;
  pointer-events: none;
  filter: drop-shadow(0 10px 14px rgba(60, 40, 20, 0.18));
}

#floater[hidden] { display: none; }

.noscript {
  margin: 24px auto;
  max-width: 440px;
  padding: 16px;
}

@media (max-width: 899px) {
  .fit {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .fit .hint {
    flex: 0 0 auto;
  }

  .fit .silent {
    margin: 8px 0;
    padding: 8px 10px;
  }

  .fit .instruction {
    margin: 4px 0 6px;
    font-size: 16px;
  }

  .fit .build {
    flex: 1 1 auto;
  }

  .fit .stage-wrap {
    width: min(100%, 280px);
  }

  .fit .tray {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 6px 0 calc(4px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 70%, rgba(243, 234, 220, 0));
  }

  .fit .part {
    min-height: 104px;
  }

  .fit .part svg {
    height: 62px;
  }

  .fit .btn {
    min-height: 48px;
  }
}

@media (max-width: 899px) and (max-height: 700px) {
  .fit .stage-wrap { width: min(100%, 210px); }
}

@media (max-width: 899px) and (min-height: 860px) {
  .fit .stage-wrap { width: min(100%, 320px); }
}

@media (min-width: 720px) {
  .picker { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .card { min-height: 148px; }
  .card .hz { font-size: 68px; }
}

@media (min-width: 900px) {
  .build {
    display: grid;
    grid-template-columns: minmax(0, 460px) minmax(260px, 1fr);
    align-items: center;
    gap: 22px;
  }
  .stage-wrap { width: 100%; }
  .tray { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .part { min-height: 160px; }
  .part svg { height: 108px; }
}

@media (prefers-reduced-motion: reduce) {
  .slot.is-wiggle { animation: none; }
  .btn-primary:active { transform: none; }
}
