:root {
  --paper: #fffdf8;
  --surface: #ffffff;
  --soft: #f5efe3;
  --ink: #24201c;
  --muted: #7c7267;
  --line: #e9e0d2;
  --accent: #a63a2e;
  --accent-soft: #f5e5df;
  --gold: #b08a55;
  --shadow: 0 2px 18px rgba(74, 54, 38, .06);
  --nav: rgba(255, 253, 248, .94);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141210;
    --surface: #1d1a16;
    --soft: #27221d;
    --ink: #f1e9dc;
    --muted: #a99d8d;
    --line: #332c25;
    --accent: #e08375;
    --accent-soft: #35231f;
    --gold: #c9a46e;
    --shadow: 0 2px 18px rgba(0, 0, 0, .28);
    --nav: rgba(20, 18, 16, .94);
  }
}

* { box-sizing: border-box; }
html { background: var(--paper); overflow-x: hidden; }
body {
  margin: 0;
  background: var(--paper);
  overflow-x: hidden;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.45;
}
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
a { color: var(--accent); }

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}

#screen {
  padding: 10px 18px 40px;
  animation: rise .22s ease-out both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}
.topbar .grow { flex: 1; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  flex: 0 0 auto;
}
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 22px; height: 22px; display: block; }
.icon-btn.accent { color: var(--accent); }

.brand-row {
  display: flex;
  align-items: center;
  margin: 2px 0 18px;
}
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex: 0 0 auto;
  box-shadow: var(--shadow);
}
.brand-text { margin-left: 16px; }
.brand-name {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: .04em;
}
.brand-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .12em;
  margin-top: 2px;
}
.brand-spacer { flex: 1; }

.hero {
  font-size: 36px;
  line-height: 1.2;
  letter-spacing: .01em;
  font-weight: 650;
  margin: 26px 0 12px;
}
.hero-sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 22px;
}

.search-cta {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 17px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 14px;
  text-align: left;
}
.search-cta .tag {
  margin-left: auto;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 9px;
  padding: 4px 9px;
  font-size: 11px;
}
.search-cta svg { width: 21px; height: 21px; flex: 0 0 auto; color: var(--muted); }
.search-cta > span:not(.tag) {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-cta .tag { flex: 0 0 auto; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  border-radius: 18px;
  padding: 7px 14px 8px;
  font-size: 13px;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chips.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.chips.scroll::-webkit-scrollbar { display: none; }

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 0 10px;
}
.section-head h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--muted);
  margin: 0;
}
.section-head .action {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent);
  padding: 4px 0;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 17px 18px;
}
.card.soft {
  background: var(--soft);
  box-shadow: none;
}
.card + .card { margin-top: 12px; }

.daily {
  display: flex;
  align-items: center;
  gap: 8px;
}
.daily .glyph {
  width: 90px;
  flex: 0 0 90px;
  text-align: center;
  font-size: 56px;
  line-height: 1.12;
  font-weight: 500;
}
.daily .info { flex: 1; min-width: 0; }
.jp {
  color: var(--accent);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  letter-spacing: .02em;
  font-size: 13px;
}
.daily .jp { font-size: 17px; }
.gloss {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kicker {
  color: var(--gold);
  font-size: 11px;
  letter-spacing: .07em;
  margin-bottom: 10px;
}

.quote-text {
  font-size: 20px;
  line-height: 1.55;
  margin-top: 12px;
}
.quote-zh {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  margin-top: 7px;
}
.source {
  color: var(--muted);
  font-size: 10px;
  margin-top: 10px;
}

.pill {
  display: inline-block;
  background: var(--soft);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 10px;
  letter-spacing: .03em;
  white-space: nowrap;
}
.pill.red { background: var(--accent-soft); color: var(--accent); }
.pill.gold { background: var(--soft); color: var(--gold); }

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.result-row:last-child { border-bottom: 0; }
.result-main { flex: 1; min-width: 0; }
.result-title { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.result-title .hz { font-size: 23px; font-weight: 550; }
.result-title .hz.long { font-size: 19px; }
.result-title .jp { font-size: 12px; }
.result-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chevron { color: var(--line); flex: 0 0 auto; }

.empty {
  padding: 20px 18px;
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.empty strong { display: block; color: var(--ink); font-size: 16px; font-weight: 600; margin-bottom: 6px; }

.top-heading {
  display: flex;
  align-items: center;
  margin: 4px 0 5px;
}
.top-heading h1 { font-size: 30px; line-height: 1.2; margin: 0; font-weight: 650; }
.top-heading .spacer { flex: 1; }
.subtle { color: var(--muted); font-size: 13px; line-height: 1.65; }
.section-gap { height: 16px; }

/* detail */
.detail-hero { padding: 2px 4px 0; }
.detail-hz {
  font-size: 82px;
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: .02em;
}
.detail-hz.word { font-size: 46px; }
.detail-other { color: var(--muted); font-size: 12px; margin-top: 2px; }
.detail-jp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.detail-jp {
  color: var(--accent);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 20px;
  letter-spacing: .04em;
}
.tone-caption { color: var(--muted); font-size: 9px; letter-spacing: .04em; margin-top: 2px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.detail-body { margin-top: 4px; }
.detail-body h3 {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .12em;
  font-weight: 600;
  margin: 26px 0 9px;
  display: flex;
  align-items: center;
}
.detail-body h3 .edit {
  margin-left: auto;
  color: var(--accent);
  letter-spacing: 0;
  font-size: 12px;
}
.sense {
  display: flex;
  gap: 8px;
  font-size: 16px;
  line-height: 1.7;
  margin-top: 9px;
}
.sense .num { color: var(--accent); font-family: ui-monospace, monospace; font-size: 12px; padding-top: 4px; }
.example {
  background: var(--soft);
  border-radius: 18px;
  padding: 16px 17px;
}
.example .text { font-size: 19px; line-height: 1.55; }
.example .jp { margin-top: 8px; line-height: 1.55; }
.example .zh { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.55; }
.speak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 13px;
  padding: 7px 12px;
  font-size: 12px;
  background: transparent;
}
.speak svg { width: 16px; height: 16px; }
.region-card {
  background: var(--soft);
  border-radius: 18px;
  padding: 15px 16px;
}
.region-cols { display: flex; gap: 12px; }
.region-col { flex: 1; min-width: 0; }
.region-col .label { font-size: 10px; color: var(--muted); letter-spacing: .12em; }
.region-col .jp { font-size: 17px; margin-top: 4px; display: block; }
.region-col .hint { font-size: 10px; color: var(--muted); margin-top: 3px; }
.region-note { font-size: 12px; color: var(--muted); line-height: 1.65; margin-top: 11px; }
.related-row { display: flex; align-items: baseline; gap: 9px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.related-row:last-child { border-bottom: 0; }
.related-hz { font-size: 19px; min-width: 52px; }
.related-jp { font-size: 11px; color: var(--accent); }
.related-gloss { color: var(--muted); font-size: 11px; margin-left: auto; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-footer { text-align: center; color: var(--muted); font-size: 10px; margin: 28px 0 6px; }

/* differences */
.diff-card { touch-action: pan-y; }
.diff-top { display: flex; align-items: center; gap: 8px; }
.diff-top .mark { margin-left: auto; color: var(--gold); font-size: 10px; }
.diff-cols { display: flex; gap: 10px; margin-top: 14px; }
.diff-col { flex: 1; min-width: 0; }
.diff-col .label { color: var(--muted); font-size: 10px; letter-spacing: .12em; }
.diff-col .word { font-size: 21px; margin-top: 4px; word-break: break-word; }
.diff-col .jp { font-size: 11px; margin-top: 3px; }
.diff-arrow { align-self: center; color: var(--line); font-size: 18px; padding-top: 14px; }
.diff-gloss { font-size: 13px; line-height: 1.6; margin-top: 13px; }
.diff-examples { background: var(--paper); border-radius: 12px; padding: 10px 12px; margin-top: 11px; }
.diff-example { display: flex; gap: 8px; font-size: 12px; line-height: 1.55; margin: 4px 0; }
.diff-example .tag { color: var(--accent); font-weight: 600; flex: 0 0 18px; }
.diff-note { color: var(--muted); font-size: 10px; line-height: 1.55; margin-top: 10px; }
.diff-nav { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.diff-nav .page { flex: 1; text-align: center; color: var(--muted); font-size: 11px; font-family: ui-monospace, monospace; }
.swipe-hint { text-align: center; color: var(--muted); font-size: 10px; margin-top: 4px; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, .42);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
.modal[hidden] { display: none; }
.modal-panel {
  width: 100%;
  max-width: 560px;
  background: var(--paper);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .25);
}
.modal-panel h3 { margin: 0 0 10px; font-size: 18px; }
.modal-panel textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 12px;
  color: var(--ink);
  outline: none;
  font-size: 15px;
  line-height: 1.6;
}
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  border-radius: 13px;
  padding: 11px 14px;
  font-size: 14px;
  text-align: center;
  flex: 1;
  background: var(--accent);
  color: #fff;
}
.btn.ghost { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn.plain { background: var(--soft); color: var(--muted); }

/* bottom nav */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  max-width: 760px;
  margin: 0 auto;
  padding: 7px 12px calc(7px + env(safe-area-inset-bottom));
  background: var(--nav);
  border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  padding: 3px 0;
  border-radius: 14px;
}
.tab.active { color: var(--accent); }
.tab svg { width: 21px; height: 21px; }
.tab:active { background: var(--soft); }

/* search input */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0 8px 0 15px;
  min-height: 54px;
  box-shadow: var(--shadow);
}
.search-wrap svg { width: 20px; height: 20px; color: var(--muted); flex: 0 0 auto; }
.search-wrap input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 16px;
  padding: 15px 0;
}
.search-wrap input::placeholder { color: var(--muted); }
.search-wrap .clear {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.result-meta { color: var(--muted); font-size: 11px; letter-spacing: .04em; margin: 14px 0 2px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0 4px;
}
.stat {
  background: var(--surface);
  border-radius: 16px;
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat b { display: block; color: var(--accent); font-size: 16px; font-weight: 650; }
.stat span { color: var(--muted); font-size: 9px; }

.about-logo { width: 78px; height: 78px; border-radius: 20px; box-shadow: var(--shadow); }
.about-head { display: flex; align-items: center; gap: 14px; margin: 18px 0; }
.about-head h2 { font-size: 26px; margin: 0; }
.about-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.about-block { background: var(--soft); border-radius: 18px; padding: 16px; margin-top: 10px; }
.about-block h3 { margin: 0 0 6px; font-size: 13px; }
.about-block p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.about-links { font-size: 10px; color: var(--muted); line-height: 1.8; margin-top: 14px; word-break: break-all; }
.about-links a { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(98px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(36, 32, 28, .94);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 12px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
}
.loading img { width: 86px; height: 86px; border-radius: 22px; box-shadow: var(--shadow); }
.loading .name { color: var(--ink); font-size: 26px; font-weight: 650; }
.loading .sub { font-size: 11px; letter-spacing: .12em; }
.loading .bar { width: 130px; height: 2px; background: var(--line); overflow: hidden; border-radius: 2px; margin-top: 8px; }
.loading .bar i { display: block; width: 40%; height: 100%; background: var(--accent); animation: load 1.1s ease-in-out infinite; }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(330%); } }

@media (max-width: 380px) {
  #screen { padding-left: 14px; padding-right: 14px; }
  .hero { font-size: 32px; }
  .detail-hz { font-size: 72px; }
  .stat b { font-size: 14px; }
}
@media (min-width: 600px) {
  #screen { padding-left: 28px; padding-right: 28px; }
  .hero { font-size: 40px; }
}
