:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-alt: #f3efe8;
  --text: #1f1c18;
  --text-muted: #4a433b;
  --border: #e5ded3;
  --accent: #9a2f05;
  --accent-btn: #9a2f05;
  --accent-soft: #fdf0ea;
  --accent-text: #8f2d06;
  --m-bg: #e7f0fd;
  --m-fg: #1d4ed8;
  --f-bg: #fce7f3;
  --f-fg: #be185d;
  --n-bg: #e6f4ea;
  --n-fg: #15803d;
  --v-bg: #fef3c7;
  --v-fg: #92400e;
  --shadow: 0 1px 3px rgba(31, 28, 24, 0.06);
  --radius: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mr: "Noto Sans Devanagari", "Kohinoor Devanagari", "Devanagari Sangam MN", "Nirmala UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface-alt: #292622;
    --text: #f3efe9;
    --text-muted: #c2bab0;
    --border: #36322d;
    --accent: #fb923c;
    --accent-btn: #c2410c;
    --accent-soft: #3a2315;
    --accent-text: #fdba74;
    --m-bg: #1e293b;
    --m-fg: #93c5fd;
    --f-bg: #3b1d2e;
    --f-fg: #f9a8d4;
    --n-bg: #163020;
    --n-fg: #86efac;
    --v-bg: #362814;
    --v-fg: #fcd34d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #151412;
  --surface: #1f1d1a;
  --surface-alt: #292622;
  --text: #f3efe9;
  --text-muted: #c2bab0;
  --border: #36322d;
  --accent: #fb923c;
  --accent-btn: #c2410c;
  --accent-soft: #3a2315;
  --accent-text: #fdba74;
  --m-bg: #1e293b;
  --m-fg: #93c5fd;
  --f-bg: #3b1d2e;
  --f-fg: #f9a8d4;
  --n-bg: #163020;
  --n-fg: #86efac;
  --v-bg: #362814;
  --v-fg: #fcd34d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mr {
  font-family: var(--font-mr);
  font-size: 1.35rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 4px 10px;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.25;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.main-nav {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 12px;
  min-height: 42px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.badge-count {
  font-size: 0.75rem;
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 1px 7px;
  border-radius: 999px;
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
  min-height: calc(100vh - 180px);
}

.loading-banner {
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.search-row {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 42px 10px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mr), var(--font-sans);
}

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

.clear-btn {
  position: absolute;
  right: 6px;
  min-width: 36px;
  min-height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  border-radius: 8px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

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

.select-ctrl {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 32px;
}

.stats-bar {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.entry-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.word-mr {
  font-family: var(--font-mr);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.word-tr {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-style: italic;
}

.save-btn {
  min-width: 38px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.save-btn.saved {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.tag {
  font-size: 0.76rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 500;
}

.tag-m { background: var(--m-bg); color: var(--m-fg); }
.tag-f { background: var(--f-bg); color: var(--f-fg); }
.tag-n { background: var(--n-bg); color: var(--n-fg); }
.tag-v { background: var(--v-bg); color: var(--v-fg); }
.tag-src-core { background: var(--accent-soft); color: var(--accent-text); }

.entry-meaning {
  margin-top: 10px;
  font-size: 1rem;
  color: var(--text);
}

.entry-meaning.masked {
  background: var(--surface-alt);
  color: transparent;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.entry-meaning.masked::after {
  content: "點擊顯示釋義";
  color: var(--text-muted);
  font-size: 0.85rem;
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.entry-en-list {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.94rem;
}

.entry-en-list li + li {
  margin-top: 4px;
}

.entry-meta {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.irreg-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.86rem;
}

.irreg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 12px;
  margin-top: 6px;
}

.load-more-wrap {
  margin-top: 16px;
  text-align: center;
}

.secondary-btn {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.danger-text {
  color: var(--accent-text);
}

.section-head h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.muted {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.mt-lg {
  margin-top: 26px;
}

.cat-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.cat-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 54px;
}

.cat-card:hover {
  border-color: var(--accent);
}

.cat-name {
  font-size: 0.92rem;
  font-weight: 600;
}

.cat-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.cat-detail-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.cat-detail-title {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.subcat-header {
  margin: 18px 0 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-text);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.verb-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.verb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.verb-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.verb-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 0.86rem;
}

.verb-dl dt {
  color: var(--text-muted);
  font-weight: 600;
}

.verb-dl dd {
  margin: 0;
  word-break: break-word;
}

.saved-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.saved-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
}

.site-footer {
  max-width: 920px;
  margin: 24px auto 0;
  padding: 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 480px) {
  .container {
    padding: 12px;
  }
  .verb-grid {
    grid-template-columns: 1fr;
  }
  .cat-grid {
    grid-template-columns: 1fr;
  }
}
