:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #667085;
  --line: #e6e9f0;
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-deep: #115e59;
  --teal-soft: #e6f7f5;
  --amber: #f59e0b;
  --amber-dark: #d97706;
  --tone1: #e11d48;
  --tone2: #ea580c;
  --tone3: #b45309;
  --tone4: #16a34a;
  --tone5: #2563eb;
  --tone6: #7c3aed;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, .chip, .icon-btn {
  touch-action: manipulation;
}

.jyutping-line,
.name-big,
.breakdown,
.surname-table {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 18px calc(60px + env(safe-area-inset-bottom));
}

/* ---------- 首屏 Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--teal-deep) 0%, var(--teal-dark) 52%, var(--teal) 100%);
  color: #fff;
  text-align: center;
  padding: 54px 24px 46px;
  box-shadow: 0 18px 44px rgba(17, 94, 89, .28);
}
.hero-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, .14) 0, rgba(255, 255, 255, 0) 34%),
    radial-gradient(circle at 88% 82%, rgba(245, 158, 11, .18) 0, rgba(245, 158, 11, 0) 32%),
    radial-gradient(circle at 90% 10%, rgba(255, 255, 255, .10) 0, rgba(255, 255, 255, 0) 26%);
}
.hero-inner { position: relative; }

.hero-badge {
  display: inline-block;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
  padding: 5px 16px;
  margin-bottom: 18px;
  letter-spacing: 1px;
}
.hero h1 {
  margin: 0 0 10px;
  font-size: 44px;
  line-height: 1.32;
  letter-spacing: 1px;
  font-weight: 800;
}
.hero-sub {
  margin: 0 0 26px;
  color: rgba(255, 255, 255, .82);
  font-size: 16px;
}

.name-input-row {
  display: flex;
  gap: 10px;
  max-width: 620px;
  margin: 0 auto 16px;
}
.name-input-row input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 14px;
  padding: 15px 20px;
  font-size: 18px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  box-shadow: 0 6px 18px rgba(8, 47, 44, .22);
}
.name-input-row input:focus {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .55), 0 6px 18px rgba(8, 47, 44, .22);
}
.name-input-wrap { position: relative; flex: 1; min-width: 0; }
.name-input-wrap input { width: 100%; padding-right: 58px; }
.mic-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(107, 114, 128, .10);
  color: #6b7280;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.mic-btn svg { width: 21px; height: 21px; }
.mic-btn:hover { background: rgba(107, 114, 128, .18); }
.mic-btn:disabled { opacity: .45; cursor: not-allowed; }
.mic-btn.listening {
  color: #e11d48;
}
.mic-btn.listening svg {
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  50% { transform: scale(1.12); }
}

.voice-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 14px auto 0;
  max-width: 360px;
  color: #fff;
  background: rgba(0, 0, 0, .20);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13.5px;
  animation: rise .2s ease both;
}
.voice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f43f5e;
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink {
  50% { opacity: .35; }
}
.wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 2.5px;
  height: 15px;
}
.wave i {
  width: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .9);
  transform-origin: bottom;
  animation: wave 1s ease-in-out infinite;
}
.wave i:nth-child(1) { height: 7px; }
.wave i:nth-child(2) { height: 13px; animation-delay: .15s; }
.wave i:nth-child(3) { height: 9px; animation-delay: .3s; }
@keyframes wave {
  50% { transform: scaleY(.45); }
}
.name-input-row > button {
  border: none;
  border-radius: 14px;
  padding: 15px 26px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: var(--amber);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s;
  box-shadow: 0 6px 18px rgba(120, 53, 15, .28);
}
.name-input-row > button:hover { background: var(--amber-dark); }
.name-input-row > button:active { transform: scale(.98); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.chip {
  border: 1px solid rgba(255, 255, 255, .30);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: rgba(255, 255, 255, .24); }

.hero-lib-link { margin: 14px 0 0; }
.hero-lib-link button {
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .14);
  color: #fff;
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.hero-lib-link button:hover { background: rgba(255, 255, 255, .26); }
.hero-voice-hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .72);
}

/* ---------- 结果卡片 ---------- */
.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 28px;
  margin-top: 22px;
  box-shadow: 0 10px 30px rgba(28, 35, 51, .06);
  animation: rise .35s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.result-title h2 { margin: 0 0 2px; font-size: 20px; }
.result-title .hint { margin: 0; }
.result-title b { color: var(--teal-dark); }

.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  font-size: 13px;
  font-family: inherit;
  padding: 8px 13px;
  border-radius: 10px;
  background: #f3f5f9;
  color: #454b58;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all .15s;
}
.icon-btn:hover { border-color: var(--teal); color: var(--teal-dark); }

/* ---------- 按钮体系 ---------- */
.btn-primary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 15px;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  transition: all .15s;
  touch-action: manipulation;
}
.btn-primary {
  border: none;
  background: var(--teal);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(13, 148, 136, .20);
}
.btn-primary:hover { background: var(--teal-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: #4b5563;
}
.btn-ghost:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
  background: var(--teal-soft);
}
.btn-ghost:active { transform: scale(.98); }

.save-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--teal-soft);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}
.save-picker select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.name-big {
  font-size: 46px;
  line-height: 1.8;
  text-align: center;
  margin: 10px 0 4px;
}
.name-char { display: inline-block; margin: 0 12px; }
.tone-badge {
  font-size: 14px;
  font-weight: 700;
  margin-left: 3px;
  vertical-align: super;
}

.jyutping-line {
  font-size: 17px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-radius: 12px;
  padding: 10px 16px;
  margin: 6px 0 12px;
  letter-spacing: 1px;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  user-select: all;
}

.tone-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  justify-content: center;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
}
.tone-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
}

.breakdown-wrap {
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}
.breakdown-wrap h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; }
.breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.breakdown th,
.breakdown td {
  padding: 9px 12px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.breakdown th { color: var(--muted); font-weight: 500; font-size: 13px; }
.breakdown td:first-child { font-size: 20px; font-weight: 600; }
.role-tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-dark);
}
.role-tag.given { background: #fff7ed; color: var(--amber-dark); }

/* ---------- 特色条 ---------- */
.feature-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 22px;
}
.feature {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.feature-icon { font-size: 26px; }
.feature b { font-size: 15px; }
.feature span:last-child { font-size: 12.5px; color: var(--muted); }

/* ---------- 名人专区 ---------- */
.celeb-today {
  text-align: center;
  background: var(--teal-soft);
  border: 1px dashed rgba(13, 148, 136, .35);
  border-radius: 14px;
  padding: 18px 14px;
  margin: 14px 0 16px;
}
.celeb-today-label {
  display: inline-block;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 8px;
}
.celeb-today-name { font-size: 36px; line-height: 1.7; }
.celeb-today .btn-primary { margin-top: 8px; }
.celeb-grid { justify-content: center; }

/* ---------- 双人玩法 ---------- */
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.dual-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.dual-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dual-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.dual-chips > span { font-size: 12px; color: var(--muted); }
.dual-chips .pill { padding: 4px 12px; font-size: 13px; }
.dual-inputs input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.dual-inputs input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}

/* ---------- 名字库 ---------- */
.lib-count { font-size: 14px; color: var(--muted); font-weight: 500; }
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.pill {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #4b5563;
  border-radius: 999px;
  padding: 6px 15px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.pill:hover { border-color: var(--teal); color: var(--teal-dark); }
.pill.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.lib-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.lib-item .name-char { margin: 0 6px; }
.lib-item .name-char > span { font-size: 22px; }
.lib-item .tone-badge { font-size: 11px; }
.lib-name {
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 15px;
  color: var(--teal-dark);
  cursor: pointer;
}
.lib-name:hover { text-decoration: underline; }
.lib-item select {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.lib-del {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}
.lib-del:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 26px;
  margin-top: 22px;
  box-shadow: 0 8px 24px rgba(28, 35, 51, .05);
}
.card summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 17px;
}
.more-card summary { color: var(--teal-dark); }
.more-card .more-sub { margin-top: 22px; }
.more-card[open] summary { margin-bottom: 14px; }
.section-title { margin: 0 0 8px; font-size: 21px; }
.hint { font-size: 13.5px; color: var(--muted); margin: 6px 0 0; }
.voice-tip {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.voice-tip summary {
  cursor: pointer;
  color: #4b5563;
  outline: none;
}
.voice-tip[open] summary { margin-bottom: 6px; }
.voice-tip p { margin: 4px 0; line-height: 1.5; }
.voice-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.voice-picker .pill:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.share-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--teal-soft);
  border: 1px dashed rgba(13, 148, 136, .45);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: var(--teal-dark);
}
.share-guide .icon-btn { flex: none; }
.hidden { display: none !important; }

/* ---------- 声调小课堂 ---------- */
.tone-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.tone-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  border-top-width: 3px;
}
.tone-card .t-num { font-size: 22px; font-weight: 800; }
.tone-card .t-name { font-size: 13px; color: var(--muted); }
.tone-card .t-example { font-size: 12.5px; font-family: ui-monospace, Menlo, monospace; margin-top: 4px; }

/* ---------- 姓氏表 ---------- */
.surname-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}
.surname-table th,
.surname-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.surname-table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.hear-btn {
  border: 1px solid var(--line);
  background: var(--teal-soft);
  color: var(--teal-dark);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .15s;
}
.hear-btn:hover { border-color: var(--teal); }
.hear-btn:active { transform: scale(.95); }

@media (max-width: 640px) {
  .hear-btn { padding: 6px 12px; font-size: 14px; }
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 18px;
  max-width: 520px;
  width: 100%;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body img {
  width: 100%;
  border-radius: 12px;
  display: block;
}
.modal-save-hint {
  text-align: center;
  margin-top: 10px;
  color: var(--amber-dark);
}
.modal-foot { margin-top: 14px; text-align: center; }
.modal-foot .btn-primary { padding: 12px 34px; font-size: 16px; }

/* ---------- 其他 ---------- */
footer { color: var(--muted); font-size: 12.5px; margin-top: 26px; text-align: center; }
footer p { margin: 4px 0; }
footer a { color: var(--teal-dark); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: #232a38;
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
  z-index: 200;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 移动端适配 ---------- */
@media (max-width: 768px) {
  .hero { border-radius: 20px; }
  .result-head { flex-direction: column; }
  .feature-strip { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .page {
    padding: 10px 12px calc(40px + env(safe-area-inset-bottom));
  }
  .hero {
    padding: 36px 16px 32px;
    border-radius: 18px;
  }
  .hero h1 { font-size: 30px; }
  .hero-sub { font-size: 14.5px; margin-bottom: 20px; }
  .hero-badge { font-size: 12px; }

  .name-input-row {
    flex-direction: column;
    gap: 10px;
  }
  .name-input-row input {
    padding: 14px 58px 14px 16px;
    font-size: 16px; /* >=16px 防止 iOS 聚焦自动缩放 */
    border-radius: 12px;
  }
  .name-input-row > button {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    min-height: 48px;
  }
  .chip { padding: 7px 15px; font-size: 13.5px; }

  .result-card { padding: 18px 14px; }
  .result-title h2 { font-size: 18px; }

  .tools {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
  }
  .tools .icon-btn {
    padding: 12px 10px;
    font-size: 13.5px;
    min-height: 44px;
  }

  .name-big { font-size: 34px; }
  .name-char { margin: 0 8px; }
  .tone-badge { font-size: 12px; }

  .jyutping-line {
    font-size: 14.5px;
    padding: 9px 10px;
  }

  .breakdown { font-size: 14px; }
  .breakdown th,
  .breakdown td { padding: 8px 6px; }
  .breakdown .role-tag { padding: 2px 8px; font-size: 11.5px; }

  .feature-strip { grid-template-columns: 1fr; }
  .dual-inputs { grid-template-columns: 1fr; }
  .celeb-today-name { font-size: 30px; }
  .actions { flex-direction: column; }
  .actions .btn-primary,
  .actions .btn-ghost { width: 100%; }
  .card { padding: 18px 14px; }
  .tone-grid { grid-template-columns: repeat(3, 1fr); }

  .surname-table { font-size: 13px; }
  .surname-table th,
  .surname-table td { padding: 7px 6px; }

  .modal { padding: 12px; }
  .modal-box {
    max-height: 92vh;
    overflow-y: auto;
    padding: 16px;
  }
  footer { font-size: 11.5px; }
}

/* 小屏手机（iPhone SE / 老安卓等） */
@media (max-width: 380px) {
  .page { padding-left: 10px; padding-right: 10px; }
  .hero {
    padding: 28px 12px 26px;
    border-radius: 16px;
  }
  .hero h1 { font-size: 24px; }
  .hero-sub { font-size: 13.5px; }
  .hero-badge { font-size: 11px; padding: 4px 12px; }

  .name-big { font-size: 27px; }
  .name-char { margin: 0 5px; }
  .tone-badge { font-size: 11px; }
  .jyutping-line { font-size: 13.5px; }

  .tone-grid { grid-template-columns: repeat(2, 1fr); }
  .breakdown td:first-child { font-size: 17px; }
}

/* 横屏且高度较小的手机：压缩首屏 */
@media (max-height: 480px) and (orientation: landscape) {
  .hero { padding: 24px 16px 20px; }
  .hero h1 { font-size: 24px; }
  .hero-sub { margin-bottom: 14px; }
  .name-input-row { flex-direction: row; max-width: 560px; }
  .name-input-row > button { width: auto; }
}
