:root {
  --paper: #efe7d4;
  --paper-2: #e3d8bf;
  --paper-card: #fffaf0;

  --ink: #2a3554;
  --ink-2: #4d5072;
  --ink-3: #8b8aa0;

  --blue: #5a6c8d;
  --mauve: #8378a3;
  --sage: #6f8c5a;
  --butter: #c9a64a;
  --coral: #c47b5a;
  --brown: #8a6849;
  --muted: #7a7058;

  --font-display: 'Yeseva One', 'ZCOOL XiaoWei', serif;
  --font-body: 'Nunito', 'Noto Sans SC', system-ui, sans-serif;
  --font-cn: 'Noto Sans SC', 'ZCOOL XiaoWei', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
button { font: inherit; color: inherit; }

body {
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(255,250,240,.8), rgba(239,231,212,.8)),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: .38;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(0,0,0,.04) 1px, transparent 2px),
    radial-gradient(circle at 70% 55%, rgba(120,80,30,.03) 1px, transparent 2px),
    radial-gradient(circle at 40% 84%, rgba(0,0,0,.035) 1px, transparent 2px);
  background-size: 220px 220px, 180px 180px, 240px 240px;
  mix-blend-mode: multiply;
}

.site-header {
  position: relative;
  z-index: 20;
  min-height: 72px;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(42,53,84,.1);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
}

.brand-tagline {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--font-cn);
  font-size: 13px;
  font-weight: 700;
}

.sound-btn {
  width: 48px;
  height: 48px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-card);
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
}

.sound-btn:active {
  transform: translate(2px, 3px);
  box-shadow: none;
}

.app-shell {
  position: relative;
  z-index: 5;
  width: min(980px, calc(100% - 28px));
  min-height: calc(100dvh - 72px);
  margin: 0 auto;
  padding: 18px 0 20px;
  display: grid;
  grid-template-rows: minmax(190px, 31dvh) 1fr;
  gap: 16px;
}

.display-panel {
  min-height: 190px;
  display: grid;
  grid-template-columns: minmax(128px, 240px) minmax(0, 1fr);
  align-items: center;
  gap: 22px;
  padding: 22px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    radial-gradient(circle at 10% 18%, rgba(201,166,74,.2), transparent 32%),
    radial-gradient(circle at 92% 82%, rgba(111,140,90,.18), transparent 34%),
    var(--paper-card);
  box-shadow: 0 6px 0 rgba(42,53,84,.18);
}

.selected-emoji {
  height: 100%;
  min-height: 142px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255,255,255,.45);
  border: 2px solid rgba(42,53,84,.12);
  font-size: 8rem;
  line-height: 1;
}

.selected-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.selected-word {
  font-family: var(--font-cn);
  font-size: 4.6rem;
  font-weight: 900;
  line-height: 1.05;
  color: var(--ink);
}

.selected-pinyin {
  width: max-content;
  max-width: 100%;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(90,108,141,.12);
  color: var(--blue);
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

.display-panel.is-speaking .selected-emoji {
  animation: bounce .34s ease both;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-8px) scale(1.04); }
}

.keyboard-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(246,240,226,.9);
  box-shadow: 0 6px 0 rgba(42,53,84,.14);
}

.keyboard-search {
  margin: 10px 10px 6px;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1.5px solid rgba(42,53,84,.12);
  border-radius: 8px;
  background: rgba(255,255,255,.66);
  color: var(--ink-3);
}

.keyboard-search span {
  font-size: 1.35rem;
  line-height: 1;
}

.keyboard-search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-cn);
  font-size: 1rem;
  font-weight: 700;
}

.keyboard-title {
  min-height: 28px;
  padding: 0 14px 5px;
  color: var(--muted);
  font-family: var(--font-cn);
  font-size: .95rem;
  font-weight: 800;
}

.category-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(48px, 1fr);
  gap: 2px;
  padding: 7px 8px 8px;
  overflow-x: auto;
  border-top: 2px solid rgba(42,53,84,.1);
  background: rgba(42,53,84,.06);
}

.category-tab {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}

.category-tab span:first-child {
  font-size: 1.45rem;
}

.category-tab.active {
  border-color: var(--ink);
  background: var(--paper-card);
  color: var(--ink);
  box-shadow: 2px 2px 0 rgba(42,53,84,.24);
}

.emoji-grid {
  min-height: 0;
  padding: 6px 10px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  grid-auto-rows: 58px;
  gap: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.emoji-key {
  border: 1.5px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 2.15rem;
  line-height: 1;
}

.emoji-key:hover {
  background: rgba(255,255,255,.58);
}

.emoji-key:active,
.emoji-key.active {
  transform: translateY(2px);
  border-color: var(--coral);
  background: #fff6eb;
}

.emoji-key:focus-visible,
.category-tab:focus-visible,
.sound-btn:focus-visible {
  outline: 3px solid var(--butter);
  outline-offset: 3px;
}

@media (max-width: 720px) {
  .site-header {
    padding: 12px 16px;
  }

  .brand-name {
    font-size: 18px;
  }

  .brand-tagline {
    font-size: 12px;
  }

  .app-shell {
    width: min(100% - 18px, 560px);
    min-height: calc(100dvh - 66px);
    grid-template-rows: minmax(168px, 29dvh) 1fr;
    gap: 12px;
    padding-top: 12px;
  }

  .display-panel {
    min-height: 168px;
    grid-template-columns: 126px minmax(0, 1fr);
    gap: 14px;
    padding: 14px;
  }

  .selected-emoji {
    min-height: 126px;
    font-size: 5.8rem;
  }

  .selected-word {
    font-size: 3.25rem;
  }

  .selected-pinyin {
    font-size: 1rem;
  }

  .category-tab {
    min-height: 42px;
  }

  .emoji-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: 54px;
    gap: 3px;
    padding: 4px 8px 10px;
  }

  .emoji-key {
    font-size: 2rem;
  }
}

@media (max-width: 420px) {
  .brand-tagline {
    display: none;
  }

  .sound-btn {
    width: 44px;
    height: 44px;
  }

  .display-panel {
    grid-template-columns: 108px minmax(0, 1fr);
  }

  .selected-emoji {
    min-height: 108px;
    font-size: 4.8rem;
  }

  .selected-word {
    font-size: 2.65rem;
  }

  .emoji-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-rows: 52px;
  }
}
