:root {
  --bg1: #FFF9E6;
  --bg2: #FFE5E5;
  --bg3: #E5F5FF;
  --text: #2c2c2c;
  --muted: #6b6b6b;
  --card: rgba(255, 255, 255, 0.72);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  --radius: 22px;
  --accent: #4D96FF;
  --danger: #FF6B6B;
  --ok: #6BCB77;
  --warn: #FFB830;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--text); background: #fff; }
body {
  background: linear-gradient(135deg, var(--bg1), var(--bg2), var(--bg3));
  background-attachment: fixed;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; display: block; }

#app { min-height: 100dvh; }

.page {
  min-height: 100dvh;
  padding: 16px 16px calc(24px + var(--safe-bottom));
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  min-height: 44px;
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.75);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.96); }

.home-hero {
  text-align: center;
  padding: 28px 8px 8px;
}
.home-hero .brand {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #FF6B6B, #4D96FF);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.home-hero p {
  margin: 8px 0 0;
  color: var(--muted);
}

.feature-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
  margin: 20px auto 100px;
  padding: 0 8px;
}
.feature-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: var(--radius);
  border: none;
  width: 100%;
  text-align: left;
  box-shadow: var(--shadow);
  background: var(--card);
  backdrop-filter: blur(10px);
  animation: popIn 0.55s cubic-bezier(.2,1.4,.4,1) both;
}
.feature-card:nth-child(1) { animation-delay: .05s; }
.feature-card:nth-child(2) { animation-delay: .12s; }
.feature-card:nth-child(3) { animation-delay: .19s; }
.feature-card:nth-child(4) { animation-delay: .26s; }
.feature-card:nth-child(5) { animation-delay: .33s; }
.feature-card:nth-child(6) { animation-delay: .4s; }
.feature-card:nth-child(7) { animation-delay: .47s; }
.feature-card:nth-child(8) { animation-delay: .54s; }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}
.feature-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.feature-card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.feature-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.fab-wrap {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.fab-menu {
  display: none;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.fab-menu.open { display: flex; animation: fadeIn 0.2s ease; }
.fab-action {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(255,255,255,0.92);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.fab-main {
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
  color: #fff;
  font-size: 1.8rem;
  box-shadow: 0 12px 24px rgba(255,107,107,0.35);
  transition: transform 0.25s ease;
}
.fab-main.open { transform: rotate(45deg); }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(8px);
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  text-align: center;
  padding: 12px 8px;
  border-radius: 16px;
  background: rgba(255,255,255,0.65);
}
.stat .n { font-size: 1.35rem; font-weight: 800; }
.stat .l { font-size: 0.8rem; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  background: rgba(255,255,255,0.82);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.05);
}
.list-item h3 { margin: 0 0 6px; font-size: 1rem; }
.list-item .meta { color: var(--muted); font-size: 0.82rem; }
.list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  background: #eef3ff;
  color: #2b5cff;
  font-weight: 600;
  font-size: 0.88rem;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #ffe0e0; color: #d33; }
.btn.ok { background: #e4f8e8; color: #1d8a3a; }
.btn.ghost { background: rgba(0,0,0,0.05); color: var(--text); }
.btn.block { width: 100%; padding: 12px; border-radius: 14px; }

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.form { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.9);
}
.field textarea { min-height: 120px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid rgba(0,0,0,0.1);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
}
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Calculator */
.calc-page { background: #000; color: #fff; min-height: 100dvh; }
.calc-page .topbar h1, .calc-page .icon-btn { color: #fff; }
.calc-page .icon-btn { background: #222; }
.calc-display {
  min-height: 120px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 20px;
  font-size: clamp(2rem, 10vw, 4.5rem);
  font-weight: 300;
  word-break: break-all;
  text-align: right;
}
.calc-pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
}
.calc-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  background: #333;
  color: #fff;
}
.calc-btn.fn { background: #a5a5a5; color: #000; }
.calc-btn.op { background: #ff9f0a; }
.calc-btn.zero { grid-column: span 2; border-radius: 999px; aspect-ratio: auto; }

/* Math cards */
.card-stage {
  min-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.math-card {
  width: min(86vw, 420px);
  aspect-ratio: 1;
  border-radius: 28px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: pan-y;
}
.math-card .formula { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 700; }
.math-card .expr { font-size: clamp(1.1rem, 4vw, 1.6rem); color: var(--muted); margin-top: 12px; }
.card-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
}

/* Literate — match Flutter YJCharacterCardPage */
.lit-page {
  min-height: 100dvh;
  background: #FFF9E6;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}
.lit-appbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: 56px;
}
.lit-icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.lit-title-pill {
  flex: 1;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: min(100%, 420px);
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lit-title-icon, .lit-title-tune { flex-shrink: 0; }
.lit-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 42px;
  justify-content: flex-end;
}
.lit-badge-btn {
  position: relative;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  color: var(--badge-color, #4D96FF);
  box-shadow: 0 3px 6px color-mix(in srgb, var(--badge-color, #4D96FF) 18%, transparent);
  font-size: 1.05rem;
  display: grid;
  place-items: center;
}
.lit-badge {
  position: absolute;
  right: -2px;
  top: -2px;
  background: var(--badge-color, #4D96FF);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 12px;
  padding: 1px 5px;
  line-height: 1.2;
}
.lit-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px 24px;
  overflow: auto;
}
.lit-stage {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  user-select: none;
}
.lit-viewport {
  width: 100%;
  overflow: hidden;
  touch-action: pan-y;
}
.lit-card {
  width: 100%;
  border-radius: 40px;
  border: 6px solid #fff;
  padding: 36px 28px 28px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  will-change: transform;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.32s ease;
}
.lit-card.lit-dragging {
  transition: none;
  cursor: grabbing;
}
.lit-card.lit-slide-out-left {
  transform: translate3d(-110%, 0, 0);
  opacity: 0.35;
}
.lit-card.lit-slide-out-right {
  transform: translate3d(110%, 0, 0);
  opacity: 0.35;
}
.lit-card.lit-slide-in-right,
.lit-card.lit-slide-in-left {
  opacity: 0.35;
  transition: none !important;
}
.lit-card.lit-slide-in-right { transform: translate3d(110%, 0, 0); }
.lit-card.lit-slide-in-left { transform: translate3d(-110%, 0, 0); }
.lit-card.lit-slide-in-right.lit-slide-in-active,
.lit-card.lit-slide-in-left.lit-slide-in-active {
  transform: translate3d(0, 0, 0);
  opacity: 1;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.32s ease !important;
}
.lit-char-circle {
  width: min(72vw, 260px);
  height: min(72vw, 260px);
  max-width: 280px;
  max-height: 280px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  display: grid;
  place-items: center;
}
.lit-char {
  font-size: clamp(5.5rem, 28vw, 11rem);
  font-weight: 900;
  color: #2D3436;
  line-height: 1;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.lit-pinyin {
  margin-top: 28px;
  padding: 12px 24px;
  border-radius: 30px;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  background: linear-gradient(90deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.lit-thumb-wrap {
  position: relative;
  margin-top: 24px;
  width: 100px;
  height: 100px;
  display: grid;
  place-items: center;
}
.lit-thumb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid #FFD93D;
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
}
.lit-thumb-ring.pulse {
  animation: litPulse 0.55s ease-out;
}
@keyframes litPulse {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.8); }
}
.lit-thumb {
  width: 80px;
  height: 80px;
  border: none;
  border-radius: 50%;
  font-size: 2rem;
  color: #fff;
  background: linear-gradient(135deg, #d0d0d0, #b0b0b0);
  box-shadow: 0 5px 15px rgba(120,120,120,0.35);
  transition: transform 0.2s ease, background 0.25s ease;
}
.lit-thumb.known {
  background: linear-gradient(135deg, #FFD93D, #FFB830);
  box-shadow: 0 5px 15px rgba(255, 165, 0, 0.4);
}
.lit-thumb:active { transform: scale(0.94); }
.lit-status {
  margin-top: 10px;
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: #757575;
}
.lit-status.known { color: #FF6B6B; }
.lit-bottom-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.lit-pill-btn {
  border: none;
  border-radius: 30px;
  padding: 12px 22px;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.lit-auto {
  background: linear-gradient(135deg, #9B59B6, #BB6BD9);
  box-shadow: 0 4px 12px rgba(155, 89, 182, 0.35);
}
.lit-auto.is-playing {
  background: linear-gradient(135deg, #FF6B6B, #FF9A9A);
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.35);
}
.lit-fresh {
  background: linear-gradient(135deg, #6BCB77, #4D96FF);
  box-shadow: 0 4px 12px rgba(77, 150, 255, 0.35);
}
.lit-fresh.hot {
  background: linear-gradient(135deg, #FF6B6B, #FFD93D);
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}
.lit-heart {
  width: 46px;
  height: 46px;
  border-radius: 28px;
  border: 2px solid #4D96FF;
  background: #fff;
  color: #4D96FF;
  font-size: 1.25rem;
  box-shadow: 0 3px 8px rgba(77, 150, 255, 0.25);
  display: grid;
  place-items: center;
}
.lit-heart.on {
  background: #FF6B81;
  border-color: #FF6B81;
  color: #fff;
  box-shadow: 0 3px 8px rgba(255, 107, 129, 0.3);
}
.lit-empty {
  text-align: center;
  padding: 40px 16px;
  color: #2D3436;
}
.lit-empty-ico { font-size: 4rem; margin-bottom: 12px; }
.lit-empty-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; }
.lit-empty-desc { color: #757575; font-size: 1rem; }

@media (min-width: 900px) {
  .lit-stage { width: min(100%, 480px); }
  .lit-char { font-size: 11rem; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(30,30,30,0.9);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 100;
  font-size: 0.9rem;
  max-width: 90vw;
}
.toast[hidden] { display: none; }

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.search {
  flex: 1;
  min-width: 140px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.9);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  width: min(92vw, 420px);
  background: #fff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.pin-badge {
  display: inline-block;
  font-size: 0.75rem;
  background: #fff3cd;
  color: #9a6b00;
  border-radius: 6px;
  padding: 2px 6px;
  margin-right: 6px;
}

@media (min-width: 768px) {
  .feature-list { max-width: 680px; }
}
