:root {
  --bg: #f6f5f2;
  --card: #fff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e2dd;
  --accent: #c0392b;
  --accent-soft: #fbe9e7;
  --chip: #efede8;
  --tabbar-h: 58px;
  --hanzi-font: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.hanzi { font-family: var(--hanzi-font); }

/* Tabs: bottom bar on phones, inline in the header on wider screens. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; font-family: var(--hanzi-font); }

.tabs { display: flex; }

.tab {
  flex: 1;
  text-align: center;
  padding: 10px 18px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.tab.active { color: var(--accent); }

@media (max-width: 719px) {
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    border-top: 1px solid var(--line);
  }
  .tab { display: flex; align-items: center; justify-content: center; }
  .view { padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
}

@media (min-width: 720px) {
  .tab { border-bottom: 2px solid transparent; }
  .tab.active { border-bottom-color: var(--accent); }
}

.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

/* Search and filters */
.search {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
}

.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chip .count { opacity: 0.7; margin-left: 4px; }

.summary { color: var(--muted); font-size: 14px; margin: 4px 2px 8px; }

/* Result list */
.list { list-style: none; margin: 0; padding: 0; }

.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
}

.row:active { background: var(--accent-soft); }

.row-head { min-width: 0; flex: 0 1 auto; }

.row-hanzi { font-size: 24px; line-height: 1.2; word-break: break-all; }

.row-pinyin { color: var(--muted); font-size: 14px; }

.row-body { min-width: 0; flex: 1 1 50%; text-align: right; }

.row-translation { overflow-wrap: anywhere; }

.labels { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; margin-top: 4px; }

.label {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  white-space: nowrap;
  text-decoration: none;
}

.label.hsk { background: var(--accent-soft); color: var(--accent); }

.more {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  overflow-wrap: anywhere;
}

/* Term card */
.back {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  padding: 6px 0;
  cursor: pointer;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 16px;
  margin-top: 8px;
}

.card-hanzi { font-size: 48px; line-height: 1.15; word-break: break-all; }

.card-pinyin { font-size: 20px; color: var(--muted); margin-top: 4px; }

.card .labels { justify-content: flex-start; margin-top: 12px; }

.card .label { font-size: 13px; padding: 3px 10px; }

.meanings { margin: 16px 0 0; padding-left: 22px; font-size: 18px; }

.meanings li { margin-bottom: 4px; }

.section { margin-top: 24px; }

.section h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 8px; }

.phrase { padding: 10px 0; border-top: 1px solid var(--line); }

.phrase-hanzi { font-size: 20px; }

.phrase-pinyin { color: var(--muted); font-size: 14px; }

.phrase-ru { margin-top: 2px; }

/* HSK tab */
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 12px; }

.level {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 8px 4px;
  text-align: center;
  color: inherit;
  text-decoration: none;
}

.level.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.level-name { font-weight: 600; }

.level-count { font-size: 13px; opacity: 0.75; }

h1.page-title { font-size: 20px; margin: 4px 2px 12px; }
