:root {
  color-scheme: light;
  --paper: #eef4e7;
  --ink: #1f241d;
  --muted: #6f776b;
  --line: rgba(61, 78, 46, 0.14);
  --accent: #70a531;
  --accent-deep: #3f741f;
  --tag: #252723;
  --surface: rgba(255, 255, 255, 0.74);
  --shadow: 0 18px 48px rgba(37, 52, 30, 0.14);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial,
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    max(18px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 18px)
    max(18px, env(safe-area-inset-left));
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 44px;
}

.progress-copy {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button,
.text-button,
.round-button {
  min-width: 44px;
  min-height: 44px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(48, 61, 42, 0.08);
}

.icon-button {
  display: grid;
  place-items: center;
  border-radius: 999px;
}

.catalog-trigger {
  gap: 4px;
}

.catalog-trigger span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 2px 0;
  border-radius: 99px;
  background: var(--ink);
}

.text-button {
  padding: 0 15px;
  border-radius: 999px;
  color: var(--accent-deep);
  font-weight: 700;
}

.viewer {
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 74px);
  display: grid;
  place-items: stretch;
  transition: transform 180ms ease, opacity 180ms ease;
}

.word-card {
  width: min(100%, 820px);
  height: 100%;
  margin: 0 auto;
  padding: clamp(22px, 5vw, 58px) clamp(18px, 6vw, 64px) 92px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.word-card::-webkit-scrollbar,
.favorite-card::-webkit-scrollbar,
.favorite-list::-webkit-scrollbar,
.chapter-list::-webkit-scrollbar {
  display: none;
}

.chapter-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin-bottom: 26px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-deep);
  background: rgba(255, 255, 255, 0.46);
  font-size: 13px;
  font-weight: 700;
}

.word-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(44px, 11vw, 82px);
  line-height: 1.02;
  letter-spacing: 0;
  text-align: center;
  overflow-wrap: anywhere;
}

.phonetic-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0 34px;
}

.phonetic {
  margin: 0;
  color: #111;
  font-size: clamp(22px, 5.4vw, 34px);
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.speak-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  color: var(--accent-deep);
  box-shadow: 0 8px 20px rgba(48, 61, 42, 0.08);
  position: relative;
  overflow: visible;
  transition: background 140ms ease, transform 140ms ease, color 140ms ease;
}

.speak-button:active,
.speak-button.speaking {
  background: var(--accent);
  color: #fff;
  transform: scale(0.96);
}

.speak-button.speaking::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid rgba(112, 165, 49, 0.32);
  border-radius: 50%;
  animation: soundPulse 760ms ease-out infinite;
}

.speaker-icon {
  display: block;
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.speaker-wave {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.speak-button.speaking .speaker-wave {
  animation: waveBlink 520ms ease-in-out infinite;
}

.speak-button.speaking .speaker-wave-outer {
  animation-delay: 140ms;
}

.block {
  margin: 18px 0;
}

.block-label {
  display: inline-flex;
  align-items: center;
  min-width: 48px;
  min-height: 28px;
  margin-bottom: 10px;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--tag);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  font-style: italic;
}

.block-label.meaning {
  background: linear-gradient(90deg, #5e7180, #a7c2a9);
}

.block-label.example {
  background: var(--accent);
}

.block p {
  margin: 0;
  color: #242a22;
  font-size: clamp(18px, 4.6vw, 27px);
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.floating-actions {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(env(safe-area-inset-bottom) + 30px);
  z-index: 7;
}

.round-button {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 36px;
  line-height: 1;
}

.round-button.active {
  color: #fff;
  background: var(--accent);
}

.catalog-panel {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  left: max(14px, env(safe-area-inset-left));
  z-index: 10;
  width: min(410px, calc(100vw - 28px));
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 28px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 253, 246, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.catalog-head,
.favorites-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.catalog-head strong {
  font-size: 20px;
}

.close-button {
  font-size: 28px;
  box-shadow: none;
}

.chapter-list {
  display: grid;
  gap: 8px;
  max-height: calc(100dvh - 132px);
  margin-top: 14px;
  overflow-y: auto;
}

.chapter-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.chapter-item.active,
.chapter-item:active {
  background: rgba(112, 165, 49, 0.13);
}

.chapter-index {
  font-weight: 800;
}

.chapter-title {
  font-weight: 700;
}

.chapter-count {
  color: var(--muted);
  font-size: 13px;
}

.favorites-view {
  position: fixed;
  inset: 0;
  z-index: 6;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    max(16px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 20px)
    max(16px, env(safe-area-inset-left));
  background: var(--paper);
}

.favorites-head h1 {
  margin: 0;
  font-size: 22px;
}

.favorite-list {
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 76px);
  margin-top: 16px;
  overflow-y: auto;
  scroll-snap-type: y proximity;
}

.favorite-banner {
  width: 100%;
  margin: 0 0 10px;
  padding: 14px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  text-align: left;
}

.favorite-banner strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  overflow-wrap: anywhere;
}

.favorite-banner span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.favorite-card {
  max-height: calc(100dvh - 118px);
  margin-bottom: 14px;
  padding: 24px 18px 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  overflow-y: auto;
  scroll-snap-align: start;
}

.favorite-card .word-title {
  font-size: clamp(38px, 9vw, 62px);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 112px);
  z-index: 20;
  width: min(88vw, 420px);
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(31, 36, 29, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.slide-left {
  animation: slideLeft 160ms ease;
}

.slide-right {
  animation: slideRight 160ms ease;
}

@keyframes slideLeft {
  from {
    opacity: 0.15;
    transform: translateX(26px);
  }
}

@keyframes slideRight {
  from {
    opacity: 0.15;
    transform: translateX(-26px);
  }
}

@keyframes soundPulse {
  from {
    opacity: 0.9;
    transform: scale(0.88);
  }
  to {
    opacity: 0;
    transform: scale(1.28);
  }
}

@keyframes waveBlink {
  50% {
    opacity: 0.28;
  }
}

@media (min-width: 760px) {
  .topbar {
    width: min(100%, 900px);
    margin: 0 auto;
  }

  .round-button {
    width: 70px;
    height: 70px;
  }
}
