.pinyin-view {
  --companion-accent: #9c5b25;
  --companion-accent-strong: #8e5221;
  --companion-accent-soft: #fff0dc;
  --companion-accent-line: #e8cfad;
  --companion-surface: #f7faf9;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  color: #19334d;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 217, 153, .2), transparent 27%),
    radial-gradient(circle at 88% 12%, rgba(178, 226, 211, .22), transparent 28%),
    #f7faf9;
}

.pinyin-topbar {
  position: relative;
  z-index: 2;
  border-bottom: 0;
  background: rgba(247, 250, 249, .94);
}

.pinyin-topbar .companion-identity-mark {
  color: var(--companion-accent);
  background: var(--companion-accent-soft);
}

.pinyin-content {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: clamp(12px, 2.4vw, 28px) clamp(14px, 3vw, 34px) calc(42px + env(safe-area-inset-bottom));
  outline: none;
}

.pinyin-ai-desk {
  display: grid;
  gap: clamp(16px, 2.3vw, 24px);
  width: 100%;
  padding: clamp(18px, 3vw, 34px);
  border: 1px solid rgba(198, 214, 220, .76);
  border-radius: clamp(24px, 3vw, 34px);
  background: rgba(247, 250, 249, .92);
  box-shadow: 0 22px 60px rgba(49, 86, 103, .09);
}

.pinyin-desk-coach {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.pinyin-desk-avatar {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  color: #8e5221;
  border-radius: 20px;
  background: #fff0dc;
  font-size: 1.45rem;
  font-weight: 900;
}

.pinyin-desk-coach p,
.pinyin-desk-coach h1 { margin: 0; }
.pinyin-desk-coach p {
  margin-bottom: 5px;
  color: #8e6746;
  font-size: .88rem;
  font-weight: 800;
}
.pinyin-source-badge {
  display: inline-flex;
  margin-left: 7px;
  padding: 3px 8px;
  align-items: center;
  border-radius: 999px;
  font-size: .72rem;
  line-height: 1.2;
  vertical-align: middle;
}
.pinyin-source-badge.is-ai {
  color: #1b6c5e;
  background: #ddf4ed;
}
.pinyin-source-badge.is-fallback {
  color: #8a5a22;
  background: #fff0d9;
}
.pinyin-desk-coach h1 {
  max-width: 760px;
  font-size: clamp(1.25rem, 2.2vw, 1.75rem);
  line-height: 1.5;
}

.pinyin-desk-board {
  display: grid;
  min-height: clamp(280px, 40vh, 390px);
  gap: 16px;
  padding: clamp(22px, 4vw, 42px);
  border-radius: clamp(24px, 3vw, 32px);
  background: linear-gradient(145deg, #fffaf2, #fff 58%, #f2faf7);
  box-shadow: inset 0 0 0 1px rgba(222, 207, 185, .7);
  transition: opacity .18s ease;
}
.pinyin-desk-board.is-thinking { opacity: .62; }

.pinyin-desk-word {
  align-self: center;
  justify-self: center;
  color: #183854;
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 900;
  letter-spacing: .02em;
}
.pinyin-desk-scene {
  margin-top: -8px;
  color: #82664d;
  font-size: clamp(1rem, 1.7vw, 1.18rem);
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
}

.pinyin-desk-board > p {
  margin: 12px 0 24px;
  text-align: center;
  color: #5e7182;
  font-size: clamp(1rem, 2vw, 1.3rem);
  line-height: 1.5;
}

.pinyin-desk-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 18px);
  align-self: start;
}

.pinyin-desk-options button {
  min-width: 0;
  min-height: 82px;
  padding: 14px 10px;
  color: #193a58;
  border: 2px solid #d9e5eb;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 9px 20px rgba(66, 97, 112, .07);
  font: inherit;
  font-size: clamp(1.45rem, 4vw, 2.35rem);
  font-weight: 900;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.pinyin-desk-options button:hover,
.pinyin-desk-options button:focus-visible {
  border-color: #d28a45;
  background: #fff8ef;
  outline: none;
  transform: translateY(-2px);
}
.pinyin-desk-options button.is-wrong {
  color: #9b7066;
  border-color: #ead2cc;
  background: #fff6f3;
  opacity: .66;
}

.pinyin-desk-listen {
  display: inline-flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  justify-self: center;
  min-width: 210px;
  padding: 0 24px;
  color: #fff;
  border: 0;
  border-radius: 20px;
  background: #a45e24;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}
.pinyin-desk-listen.is-inside {
  min-width: 164px;
  min-height: 48px;
  justify-self: start;
  padding: 0 18px;
  border-radius: 16px;
  background: #a96831;
}
.pinyin-desk-listen:disabled { cursor: wait; opacity: .68; }

.pinyin-desk-wave {
  display: inline-flex;
  height: 22px;
  align-items: center;
  gap: 3px;
}
.pinyin-desk-wave i {
  width: 3px;
  height: 9px;
  border-radius: 3px;
  background: currentColor;
}
.pinyin-desk-wave i:nth-child(2),
.pinyin-desk-wave i:nth-child(4) { height: 17px; }
.pinyin-desk-wave i:nth-child(3) { height: 22px; }

.pinyin-desk-note {
  margin: -8px 0 0;
  text-align: center;
  color: #7d8d99;
  font-size: .88rem;
}

.pinyin-desk-skip {
  align-self: center;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #64748b;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.pinyin-desk-secondary {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pinyin-build-area {
  display: grid;
  gap: 18px;
}

.pinyin-build-recovery {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 20px;
  color: #6f7e8d;
  border: 1px dashed #d8c3a7;
  border-radius: 18px;
  background: rgba(255, 249, 239, .82);
}

.pinyin-build-recovery p { margin: 0; }
.pinyin-build-recovery button {
  min-height: 46px;
  padding: 0 22px;
  color: #fff;
  border: 0;
  border-radius: 15px;
  background: #a96831;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.pinyin-build-slots,
.pinyin-build-pieces,
.pinyin-build-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pinyin-build-slot {
  display: grid;
  width: clamp(66px, 12vw, 94px);
  min-height: 68px;
  place-items: center;
  color: #9aa8b2;
  border: 2px dashed #cbd9df;
  border-radius: 20px;
  background: rgba(255, 255, 255, .74);
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  font-weight: 900;
}
.pinyin-build-slot.is-filled {
  color: #193a58;
  border-style: solid;
  border-color: #e2b47e;
  background: #fff7e9;
}
.pinyin-build-plus { color: #9a7a58; font-size: 1.4rem; font-weight: 900; }

.pinyin-build-pieces button,
.pinyin-build-actions button {
  min-height: 48px;
  padding: 0 20px;
  color: #193a58;
  border: 1px solid #d9e5eb;
  border-radius: 16px;
  background: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}
.pinyin-build-pieces button { min-width: 76px; font-size: 1.55rem; }
.pinyin-build-pieces button:disabled { opacity: .32; cursor: default; }
.pinyin-build-actions .pinyin-build-check { color: #fff; border-color: #a96831; background: #a96831; }
.pinyin-build-actions button:disabled { opacity: .42; cursor: default; }

.pinyin-home-board { min-height: 0; }

.pinyin-start-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  width: min(100%, 680px);
  margin: 0 auto;
}

.pinyin-start-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 78px;
  align-content: center;
  align-items: center;
  gap: 3px 18px;
  padding: 14px 18px;
  color: #19334d;
  text-align: left;
  border: 1px solid #d9e5eb;
  border-radius: 18px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 7px 18px rgba(66, 97, 112, .05);
  font: inherit;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.pinyin-start-card::after {
  grid-column: 2;
  grid-row: 1 / span 2;
  color: #9b7a5b;
  content: "›";
  font-size: 1.75rem;
  line-height: 1;
}

.pinyin-start-card:hover,
.pinyin-start-card:focus-visible {
  border-color: #d28a45;
  background: #fff8ef;
  outline: none;
  transform: translateY(-2px);
}
.pinyin-start-card strong { font-size: clamp(1.1rem, 2.5vw, 1.4rem); }
.pinyin-start-card span { color: #748392; font-size: .9rem; line-height: 1.4; }
.pinyin-start-card strong,
.pinyin-start-card span { grid-column: 1; }

.pinyin-loading-stage { min-height: 220px; align-content: center; }
.pinyin-desk-error {
  width: min(100%, 620px);
  margin: 16px auto 0 !important;
  padding: 12px 16px;
  color: #8b493d;
  background: #fff3ef;
  border: 1px solid #efc8bd;
  border-radius: 14px;
  font-size: .95rem !important;
  text-align: center;
}

.pinyin-feedback-stage {
  min-height: clamp(360px, 62vh, 650px);
  align-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 234, 166, .34), transparent 35%),
    rgba(255, 255, 255, .94);
}
.pinyin-feedback-stage.is-incorrect {
  background:
    radial-gradient(circle at 50% 40%, rgba(190, 229, 214, .34), transparent 35%),
    rgba(255, 255, 255, .94);
}
.pinyin-feedback-label { margin: 4px 0 0; color: #9c632f; font-weight: 900; }
.pinyin-feedback-stage.is-incorrect .pinyin-feedback-label { color: #3f8168; }
.pinyin-feedback-stage h1 { max-width: 700px; margin: 0; color: #173653; font-size: clamp(1.45rem, 4vw, 2.4rem); line-height: 1.35; }
.pinyin-feedback-stage > p:last-of-type { margin: 0; color: #708094; }
.pinyin-feedback-burst { position: relative; display: grid; width: 92px; height: 92px; place-items: center; }
.pinyin-feedback-burst > span { position: relative; z-index: 2; color: #f1b941; font-size: 3.75rem; filter: drop-shadow(0 8px 12px rgba(184, 125, 35, .16)); animation: pinyin-feedback-pop .5s cubic-bezier(.2, .9, .28, 1.2) both; }
.pinyin-feedback-stage.is-incorrect .pinyin-feedback-burst > span { color: #56a685; }
.pinyin-feedback-burst i { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: #f0bd52; animation: pinyin-feedback-spark .65s ease-out infinite; }
.pinyin-feedback-burst i:nth-child(2) { transform: translate(-42px, -22px); animation-delay: .12s; }
.pinyin-feedback-burst i:nth-child(3) { transform: translate(44px, -12px); animation-delay: .28s; }
.pinyin-feedback-burst i:nth-child(4) { transform: translate(32px, 38px); animation-delay: .44s; }
.pinyin-feedback-loading { display: flex; gap: 7px; height: 18px; align-items: center; }
.pinyin-feedback-loading i { width: 8px; height: 8px; border-radius: 50%; background: #d79b55; animation: pinyin-feedback-dot .85s ease-in-out infinite alternate; }
.pinyin-feedback-loading i:nth-child(2) { animation-delay: .16s; }
.pinyin-feedback-loading i:nth-child(3) { animation-delay: .32s; }
.pinyin-feedback-retry { min-height: 48px; padding: 0 24px; color: #fff; border: 0; border-radius: 16px; background: #a96831; font: inherit; font-weight: 900; cursor: pointer; }
@keyframes pinyin-feedback-pop { from { opacity: 0; transform: scale(.55) rotate(-12deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes pinyin-feedback-spark { 0%, 100% { opacity: .25; scale: .6; } 50% { opacity: 1; scale: 1; } }
@keyframes pinyin-feedback-dot { from { transform: translateY(3px); opacity: .35; } to { transform: translateY(-3px); opacity: 1; } }

@media (max-width: 620px) {
  .pinyin-view { height: 100dvh; overflow: hidden; }
  .pinyin-content { height: calc(100dvh - 58px - env(safe-area-inset-top)); padding: 8px 10px max(24px, calc(16px + env(safe-area-inset-bottom))); overflow-y: auto; }
  .pinyin-ai-desk { gap: 14px; margin-bottom: max(10px, env(safe-area-inset-bottom)); padding: 10px 2px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .pinyin-desk-coach { grid-template-columns: 48px minmax(0, 1fr); gap: 10px; }
  .pinyin-desk-avatar { width: 48px; height: 48px; border-radius: 16px; font-size: 1.2rem; }
  .pinyin-desk-coach h1 { font-size: 1.12rem; line-height: 1.45; }
  .pinyin-desk-board { min-height: min(47vh, 360px); gap: 12px; padding: 16px 14px; border-radius: 20px; }
  .pinyin-desk-board > p { margin: 8px 0 18px; font-size: .96rem; }
  .pinyin-desk-options { grid-template-columns: 1fr; gap: 10px; }
  .pinyin-start-options { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .pinyin-start-card { min-height: 72px; padding: 12px 15px; border-radius: 16px; }
  .pinyin-start-card strong { font-size: 1.02rem; }
  .pinyin-start-card span { font-size: .78rem; }
  .pinyin-desk-options button { min-height: 62px; border-radius: 18px; font-size: 1.7rem; }
  .pinyin-desk-listen { width: 100%; min-height: 56px; }
  .pinyin-desk-listen.is-inside { width: auto; min-height: 46px; justify-self: center; }
  .pinyin-build-slot { min-height: 58px; }
  .pinyin-desk-note { font-size: .8rem; }
  .pinyin-feedback-stage { min-height: min(58vh, 500px); padding-inline: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .pinyin-feedback-burst > span,
  .pinyin-feedback-burst i,
  .pinyin-feedback-loading i { animation: none; }
}
