:root {
  --paper: #f7f2e8;
  --paper-2: #f3ead9;
  --panel: #fffdf8;
  --panel-soft: rgba(255, 253, 248, .78);
  --ink: #172033;
  --muted: #6b7280;
  --line: #ddd3c2;
  --accent: #1f6f5f;
  --accent-2: #315f8f;
  --warning: #9f4b31;
  --shadow: 0 12px 28px rgba(23, 32, 51, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Noto Sans SC", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--paper-2) 0%, var(--paper) 100%);
  padding: 32px clamp(16px, 4vw, 48px) 24px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 390px);
  gap: 24px;
  align-items: end;
  max-width: 1320px;
  margin: 0 auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 14px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.back-link:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 6vw, 62px);
  line-height: 1.02;
  font-weight: 600;
}

.sub {
  max-width: 800px;
  margin: 12px 0 0;
  color: var(--muted);
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.metric strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px clamp(14px, 4vw, 42px) 52px;
}

.left-panel {
  min-width: 0;
}

.right-panel {
  min-width: 0;
}

.panel-card,
.detail-card,
.root-card,
.word-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(23, 32, 51, .035);
}

.controls {
  position: sticky;
  top: 12px;
  z-index: 2;
  padding: 14px;
  margin-bottom: 12px;
}

.search-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#search-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
}

#search-input:focus {
  outline: 2px solid rgba(31, 111, 95, .18);
  border-color: var(--accent);
}

.filter-block {
  margin-top: 14px;
}

.filter-block p {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.segmented button,
.command {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.segmented button.active,
.command.primary {
  border-color: var(--ink);
  color: #fff;
  background: var(--ink);
}

.segmented button:hover,
.command:hover {
  border-color: var(--ink);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.visible-count {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.root-cards {
  display: grid;
  gap: 9px;
}

.root-card {
  position: relative;
  width: 100%;
  overflow: hidden;
  text-align: left;
  padding: 13px 14px 12px 17px;
}

.root-card:before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent-2);
}

.root-card[data-type="prefix"]:before {
  background: var(--accent);
}

.root-card[data-type="suffix"]:before {
  background: var(--warning);
}

.root-card.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(23, 32, 51, .08);
}

.root-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.root-symbol {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  line-height: 1;
  font-weight: 600;
}

.root-count {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 9px 0 7px;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fbf7ef;
  padding: 2px 8px;
  font-size: 11px;
  text-transform: uppercase;
}

.root-card p {
  margin: 0;
  color: #374151;
  font-size: 13px;
}

.empty-state {
  display: none;
  margin: 14px 0 0;
  color: var(--muted);
  text-align: center;
}

.empty-state.show {
  display: block;
}

.detail-card {
  min-height: 640px;
  padding: clamp(18px, 3vw, 28px);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-type {
  display: inline-flex;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fbf7ef;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

#detail-root {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(42px, 7vw, 76px);
  line-height: .98;
  font-weight: 600;
}

.meaning {
  margin: 10px 0 0;
  color: #2f3747;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 19px;
  font-weight: 700;
}

.explanation {
  margin: 18px 0 20px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: rgba(31, 111, 95, .06);
  padding: 13px 15px;
}

.explanation strong {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
}

.explanation p {
  margin: 0;
}

.english-meaning {
  margin-top: 8px !important;
  color: var(--muted);
  font-style: italic;
}

.word-list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.word-list-head h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
}

.word-list-head span {
  color: var(--muted);
  font-size: 13px;
}

.word-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.word-card {
  padding: 14px;
}

.word-card.match {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 95, .1);
}

.word-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 9px;
}

.word-title strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.word-title span {
  flex: none;
  color: #374151;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-weight: 700;
}

.example-en {
  margin: 0;
  color: #374151;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-style: italic;
}

.example-zh {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 28px));
  transform: translateY(14px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 920px) {
  .hero,
  .layout {
    grid-template-columns: 1fr;
  }

  .hero-metrics {
    max-width: 520px;
  }

  .controls {
    position: static;
  }

  .detail-card {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .site-header {
    padding: 26px 14px 18px;
  }

  .sub {
    font-size: 13px;
  }

  .layout {
    padding: 14px 12px 42px;
  }

  .hero-metrics,
  .word-list {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: auto;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented button,
  .command {
    width: 100%;
  }

  .toolbar,
  .detail-head,
  .word-title {
    flex-direction: column;
    align-items: stretch;
  }

  .visible-count {
    text-align: center;
  }

  .word-title span {
    flex: auto;
  }
}
