:root {
  --bg: #ffe8c2;
  --ink: #3b2410;
  --accent: #ff6b4a;
  --card: #fffaf1;
  --soft: rgba(59, 36, 16, 0.12);
  --shadow: 0 22px 50px rgba(90, 40, 10, 0.16);
  --radius: 36px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Fredoka", "Nunito", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  transition: background 0.55s ease;
}

.app {
  min-height: 100%;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(12px, env(safe-area-inset-top)) 20px max(14px, env(safe-area-inset-bottom));
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.blobs,
.blob,
.star {
  pointer-events: none;
}

.blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.55;
  animation: drift 14s ease-in-out infinite;
}

.b1 {
  width: 280px;
  height: 280px;
  left: -70px;
  top: -50px;
  background: radial-gradient(circle, #fff7 0%, #fff0 70%);
}

.b2 {
  width: 340px;
  height: 340px;
  right: -90px;
  bottom: -80px;
  background: radial-gradient(circle, #fff6 0%, #fff0 68%);
  animation-delay: -4s;
}

.b3 {
  width: 160px;
  height: 160px;
  right: 18%;
  top: 12%;
  background: radial-gradient(circle, #ffffffaa 0%, #fff0 70%);
  animation-delay: -8s;
}

.star {
  position: absolute;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
  animation: twinkle 3.4s ease-in-out infinite;
}

.s1 { left: 8%; top: 22%; font-size: 22px; }
.s2 { right: 10%; top: 30%; font-size: 18px; animation-delay: -1.2s; }
.s3 { left: 16%; bottom: 16%; font-size: 16px; animation-delay: -2s; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 2;
  width: 100%;
  min-width: 0;
}

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

.logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  font-size: 22px;
  box-shadow: 0 8px 0 var(--soft);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
  opacity: 0.7;
  font-family: "Nunito", sans-serif;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
}

.seg-btn,
.icon-btn,
.speak,
.nav {
  font: inherit;
  border: 0;
  cursor: pointer;
  color: inherit;
}

.seg-btn {
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 14px;
  min-width: 0;
}

.seg-btn.is-on {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 65%, #3b2410);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 18px;
}

.icon-btn.is-on {
  background: var(--accent);
  color: #fff;
}

.stage {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  width: 100%;
  max-width: 760px;
  height: 100%;
  max-height: min(640px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 36px 88px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  user-select: none;
  container-type: size;
}

.card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 28px;
  border: 3px dashed color-mix(in srgb, var(--accent) 35%, transparent);
  pointer-events: none;
}

.badge {
  position: absolute;
  top: 22px;
  left: 28px;
  background: color-mix(in srgb, var(--accent) 16%, white);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
}

.glyph-row {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.glyph {
  font-size: min(11rem, 42cqh, 28cqi);
  font-weight: 700;
  line-height: 0.85;
  color: var(--accent);
  text-shadow: 0 10px 0 color-mix(in srgb, var(--accent) 22%, white);
  animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.lower {
  font-size: min(4.4rem, 16cqh, 11cqi);
  font-weight: 650;
  color: color-mix(in srgb, var(--accent) 70%, #3b2410);
  margin-bottom: 0.08em;
  animation: pop 0.55s 0.04s both cubic-bezier(0.2, 1.4, 0.4, 1);
}

.meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding-bottom: 6px;
}

.picture {
  font-size: clamp(2.4rem, 7vmin, 3.6rem);
  margin: 0 0 2px;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.05));
  animation: floaty 2.8s ease-in-out infinite;
}

.word {
  font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  font-weight: 700;
  margin-top: 2px;
  line-height: 1.15;
}

.word-zh {
  font-size: 1.2rem;
  opacity: 0.72;
  margin-top: 2px;
  line-height: 1.3;
}

.speak {
  margin-top: 14px;
  flex-shrink: 0;
  min-width: 180px;
  height: 60px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--accent) 70%, #3b2410);
  transition: transform 0.12s ease;
}

.speak:hover { transform: translateY(-2px); }
.speak:active { transform: translateY(3px); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 70%, #3b2410); }
.icon-btn:active,
.seg-btn:active {
  transform: translateY(2px);
}

.speak.is-talking {
  animation: pulse 0.9s ease-in-out infinite;
}

.speak-wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
}

.speak-wave i {
  display: block;
  width: 4px;
  height: 8px;
  border-radius: 99px;
  background: #fff;
}

.speak.is-talking .speak-wave i:nth-child(1) { animation: bar 0.7s 0s ease-in-out infinite; }
.speak.is-talking .speak-wave i:nth-child(2) { animation: bar 0.7s 0.12s ease-in-out infinite; }
.speak.is-talking .speak-wave i:nth-child(3) { animation: bar 0.7s 0.24s ease-in-out infinite; }

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 8px 0 var(--soft);
  font-size: 42px;
  line-height: 1;
  display: grid;
  place-items: center;
  z-index: 3;
}

.prev { left: 14px; }
.next { right: 14px; }

.nav span {
  margin-top: -6px;
}

.nav:active {
  transform: translateY(calc(-50% + 2px));
}

.dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 8px 0;
}

.progress-wrap {
  flex: 1;
  max-width: 520px;
}

.count {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 15px;
}

.bar {
  height: 12px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 99px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.35s ease;
}

.auto {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  background: rgba(255, 255, 255, 0.55);
  padding: 8px 12px;
  border-radius: 999px;
  user-select: none;
}

.picture[hidden] {
  display: none;
}

.auto input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.picker {
  border: 0;
  border-radius: 28px;
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 18px 18px 22px;
  background: #fffaf3;
  box-shadow: var(--shadow);
}

.picker::backdrop {
  background: rgba(50, 24, 8, 0.38);
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}

.tile {
  aspect-ratio: 1;
  border: 0;
  border-radius: 18px;
  font: inherit;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  background: #ffe8c2;
  color: #3b2410;
}

.tile.is-current {
  outline: 3px solid #3b2410;
  outline-offset: 2px;
}

@media (max-width: 780px) {
  .app {
    padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px 40px 40px;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }
  .brand {
    grid-column: 1;
    grid-row: 1;
    margin-right: 0;
    min-width: 0;
    overflow: hidden;
  }
  .brand h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #picBtn { grid-column: 2; grid-row: 1; }
  #gridBtn { grid-column: 3; grid-row: 1; }
  #fullBtn { grid-column: 4; grid-row: 1; }
  .seg-filter,
  .seg-voice {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .seg-filter { grid-row: 2; }
  .seg-voice { grid-row: 3; }
  .brand p { display: none; }
  .brand h1 { font-size: 17px; }
  .logo { width: 40px; height: 40px; font-size: 18px; border-radius: 12px; }
  .seg-btn { padding: 7px 8px; font-size: 13px; }
  .icon-btn { width: 40px; height: 40px; }
  .card {
    max-height: none;
    max-width: none;
    width: 100%;
    padding: 40px 52px 14px;
  }
  .glyph { font-size: min(8rem, 38cqh, 32cqi); }
  .lower { font-size: min(3.2rem, 14cqh, 12cqi); }
  .picture { font-size: 2.6rem; }
  .word { font-size: 1.55rem; }
  .speak {
    height: 52px;
    min-width: 150px;
    font-size: 1.1rem;
    margin-top: 10px;
  }
  .nav {
    width: 46px;
    height: 46px;
    font-size: 30px;
    box-shadow: 0 5px 0 var(--soft);
  }
  .prev { left: 8px; }
  .next { right: 8px; }
  .dock { padding-top: 2px; }
  .count { font-size: 13px; margin-bottom: 4px; }
  .picker-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }
  .tile { font-size: 22px; border-radius: 14px; }
}

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

@keyframes pop {
  from { transform: scale(0.55) rotate(-8deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

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

@keyframes drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(16px, -12px); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

@keyframes pulse {
  50% { transform: scale(1.04); }
}

@keyframes bar {
  0%, 100% { height: 6px; }
  50% { height: 18px; }
}
