:root {
  color-scheme: light;
  --page: #ffffff;
  --surface: #ffffff;
  --surface-strong: #fff7f2;
  --ink: #23322d;
  --muted: #697a73;
  --line: #e4ebe7;
  --grid: #f58b73;
  --accent: #f46f51;
  --accent-strong: #ce4b34;
  --teal: #2d9c89;
  --yellow: #f5be45;
  --shadow: none;
  --radius: 8px;
  font-family:
    ui-rounded,
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  background: var(--page);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  margin: 0;
  padding: 0;
  line-height: 1;
}

svg {
  display: block;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  max-width: 980px;
  margin: 0 auto 12px;
}

h1,
h2,
p {
  margin: 0;
}

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

.search input {
  width: 94px;
  min-width: 0;
  height: 56px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 36px;
  font-weight: 800;
  text-align: center;
  outline: 0;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(244, 111, 81, 0.16);
}

.primary-button,
.icon-button,
.sound-button,
.stroke-item {
  -webkit-tap-highlight-color: transparent;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 96px;
  height: 56px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: none;
}

.primary-button:active,
.icon-button:active,
.sound-button:active,
.stroke-item:active {
  transform: translateY(1px);
}

.button-icon {
  font-size: 28px;
  line-height: 1;
}

.learning-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
  max-width: 980px;
  margin: 0 auto;
}

.writer-zone {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: var(--shadow);
}

.writer-zone {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 0;
}

.writer-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
}

.pronunciation-strip {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  --pinyin-guide-solid: var(--line);
  --pinyin-guide-dot: #e3ebe7;
  width: min(46vw, 380px);
  height: 96px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 18px;
  min-width: 0;
}

.pronunciation-strip::before,
.pronunciation-strip::after {
  position: absolute;
  top: 13px;
  right: 0;
  left: 0;
  height: 72px;
  content: "";
  pointer-events: none;
  z-index: 0;
}

.pronunciation-strip::before {
  background-image:
    linear-gradient(var(--pinyin-guide-solid), var(--pinyin-guide-solid)),
    linear-gradient(var(--pinyin-guide-solid), var(--pinyin-guide-solid));
  background-position:
    0 0,
    0 100%;
  background-repeat: no-repeat;
  background-size:
    100% 2px,
    100% 2px;
}

.pronunciation-strip::after {
  background-image:
    radial-gradient(circle at 1px 33.333%, var(--pinyin-guide-dot) 0 0.9px, transparent 1.05px),
    radial-gradient(circle at 1px 66.666%, var(--pinyin-guide-dot) 0 0.9px, transparent 1.05px);
  background-repeat: repeat-x;
  background-size: 5px 100%;
}

.pinyin-scroll {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.pinyin-scroll::-webkit-scrollbar {
  display: none;
}

.pinyin-track {
  display: flex;
  width: 100%;
  height: 100%;
}

.pinyin-slide {
  display: grid;
  min-width: 100%;
  height: 100%;
  flex: 0 0 100%;
  place-items: center;
  scroll-snap-align: center;
  text-align: center;
}

.pinyin-spelling {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-size: clamp(42px, 6vw, 58px);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  font-variant-ligatures: none;
}

.pinyin-index {
  position: absolute;
  right: 0;
  bottom: -2px;
  left: 0;
  z-index: 2;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

.pinyin-inline-initial {
  color: #1f8f7d;
}

.pinyin-inline-final {
  color: #ce4b34;
}

.pinyin-inline-empty {
  color: var(--muted);
  font-size: 0.58em;
}

.sound-button,
.icon-button {
  display: inline-flex;
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    transform 120ms ease;
}

.sound-button {
  position: relative;
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  overflow: visible;
}

.sound-button svg {
  position: relative;
  z-index: 1;
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-button::after {
  position: absolute;
  inset: 5px;
  border: 2px solid rgba(45, 156, 137, 0.45);
  border-radius: inherit;
  content: "";
  opacity: 0;
  transform: scale(0.85);
}

.sound-button.is-speaking::after {
  animation: sound-pulse 780ms ease-out infinite;
}

.sound-button.is-speaking svg {
  animation: sound-icon-play 560ms ease-in-out infinite;
}

.sound-button.is-speaking svg path:nth-child(2) {
  animation: sound-wave 560ms ease-in-out infinite;
}

.sound-button.is-speaking svg path:nth-child(3) {
  animation: sound-wave 560ms ease-in-out 110ms infinite;
}

@keyframes sound-pulse {
  0% {
    opacity: 0.7;
    transform: scale(0.85);
  }

  100% {
    opacity: 0;
    transform: scale(1.45);
  }
}

@keyframes sound-icon-play {
  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(-1px);
  }
}

@keyframes sound-wave {
  0%,
  100% {
    opacity: 0.45;
    transform: translateX(-1px);
  }

  50% {
    opacity: 1;
    transform: translateX(1px);
  }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button[aria-pressed="true"],
.icon-button.active,
.icon-button.is-active {
  border-color: rgba(244, 111, 81, 0.7);
  background: var(--surface-strong);
  color: var(--accent-strong);
}

.icon-button svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg path:not([d="M8 5v14l11-7z"]) {
  fill: none;
}

.writer-stage {
  display: grid;
  flex: 1;
  min-height: 470px;
  place-items: center;
  padding: 6px 0 18px;
}

.tianzige {
  position: relative;
  width: min(82vw, 560px);
  max-width: 100%;
  aspect-ratio: 1;
  border: 3px solid var(--grid);
  border-radius: var(--radius);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M50 0V100M0 50H100' fill='none' stroke='%23f46f51' stroke-opacity='.5' stroke-width='.9' stroke-linecap='round' stroke-dasharray='.1 2.4'/%3E%3C/svg%3E"),
    #fffdfb;
  background-size: 100% 100%;
  overflow: hidden;
  touch-action: none;
}

#writer-target,
.fallback-glyph {
  position: absolute;
  inset: 0;
}

.writer-host {
  width: 100%;
  height: 100%;
}

#writer-target svg {
  width: 100%;
  height: 100%;
}

.fallback-glyph {
  display: grid;
  place-items: center;
  color: rgba(35, 50, 45, 0.72);
  font-size: clamp(210px, 46vw, 430px);
  font-weight: 800;
  line-height: 1;
  animation: glyph-write 1.2s ease both;
}

@keyframes glyph-write {
  from {
    clip-path: inset(0 100% 0 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

.quiz-score {
  display: flex;
  width: min(82vw, 560px);
  max-width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: -4px auto 12px;
  color: var(--teal);
  font-size: 15px;
  font-weight: 800;
}

.quiz-score[hidden] {
  display: none;
}

.quiz-score strong {
  color: var(--accent-strong);
  font-size: 34px;
  line-height: 1;
}

.quiz-score[data-level="excellent"] strong,
.quiz-score[data-level="great"] strong {
  color: var(--teal);
}

.quiz-score[data-level="again"] strong {
  color: var(--accent-strong);
}

.stroke-panel {
  margin-top: 2px;
}

.stroke-summary {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--teal);
  font-size: 15px;
  font-weight: 800;
}

.stroke-summary strong {
  color: var(--muted);
  font-size: 13px;
}

.stroke-list {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  margin-top: 10px;
  max-height: none;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 10px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.stroke-item {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 20px;
  gap: 6px;
  flex: 0 0 clamp(132px, 16vw, 168px);
  min-width: 0;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  overflow: visible;
  scroll-snap-align: start;
}

.stroke-item.active {
  color: var(--accent-strong);
}

.stroke-grid {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M50 0V100M0 50H100' fill='none' stroke='%23e3ebe7' stroke-width='1.8' stroke-linecap='round' stroke-dasharray='.1 2.7'/%3E%3C/svg%3E"),
    #fffdfb;
  background-size: 100% 100%;
  overflow: hidden;
}

.stroke-item.active .stroke-grid {
  border-color: var(--accent);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M50 0V100M0 50H100' fill='none' stroke='%23f46f51' stroke-opacity='.55' stroke-width='1.8' stroke-linecap='round' stroke-dasharray='.1 2.7'/%3E%3C/svg%3E"),
    var(--surface-strong);
}

.stroke-grid svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.stroke-number {
  position: static;
  display: block;
  align-self: center;
  justify-self: center;
  min-width: 0;
  height: auto;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  font-weight: 900;
  box-shadow: none;
}

.stroke-item.active .stroke-number {
  color: var(--accent-strong);
}

.site-credit {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
}

.toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(35, 50, 45, 0.12);
  border-radius: var(--radius);
  background: rgba(35, 50, 45, 0.92);
  color: #fff;
  padding: 11px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (max-width: 980px) {
  .topbar,
  .learning-layout {
    max-width: 760px;
  }

  .writer-zone {
    min-height: auto;
  }

  .stroke-list {
    display: flex;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
  }

  .search {
    width: 100%;
    justify-content: flex-end;
  }

  .search input {
    flex: 1;
    width: auto;
    height: 48px;
    font-size: 31px;
  }

  .primary-button {
    flex: 0 0 94px;
    height: 48px;
  }

  .writer-zone {
    padding: 10px;
  }

  .writer-topline {
    gap: 8px;
    margin-bottom: 10px;
  }

  .pronunciation-strip {
    width: min(46vw, 300px);
    height: 82px;
    padding: 0 12px;
  }

  .pronunciation-strip::before,
  .pronunciation-strip::after {
    top: 11px;
    height: 60px;
  }

  .pinyin-spelling {
    font-size: 40px;
  }

  .sound-button,
  .icon-button {
    width: 42px;
    height: 42px;
  }

  .writer-stage {
    min-height: 320px;
    padding: 12px 0;
  }

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

  .stroke-panel {
    min-height: 0;
  }

  .stroke-list {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 12px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 10px;
  }

  .stroke-item {
    flex-basis: calc((100% - 24px) / 4);
    width: calc((100% - 24px) / 4);
    height: auto;
    max-height: none;
  }

  .stroke-number {
    font-size: 11px;
  }
}

@media (max-width: 420px) {
  .search input,
  .primary-button {
    height: 52px;
  }

  .primary-button {
    flex-basis: 88px;
  }

  .button-icon {
    display: none;
  }

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

  .toolbar {
    justify-content: flex-end;
    gap: 6px;
  }

  .pronunciation-strip {
    width: min(43vw, 190px);
  }

  .stroke-item {
    flex-basis: calc((100% - 24px) / 4);
  }
}
