:root {
  --ink: #202124;
  --muted: #5f6368;
  --line: #d7dce2;
  --paper: #ffffff;
  --wash: #f5f7f9;
  --accent: #006d77;
  --accent-strong: #004f57;
  --gold: #c48b13;
  --shadow: 0 18px 45px rgba(25, 35, 45, 0.1);
  --field: #ffffff;
  --soft: #fbfcfd;
}

body[data-theme="dark"] {
  --ink: #edf2f4;
  --muted: #b7c3cc;
  --line: #33424d;
  --paper: #172127;
  --wash: #0d1418;
  --accent: #3bb4bd;
  --accent-strong: #76d6dc;
  --gold: #f0b84d;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
  --field: #101a20;
  --soft: #111c22;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--wash);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 48px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  font-size: 24px;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 13px;
}

.top-nav {
  align-items: center;
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 15px;
}

.top-nav a:hover {
  color: var(--accent-strong);
}

.theme-toggle {
  position: relative;
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--line);
  padding: 0;
  color: var(--muted);
  background: var(--field);
}

.theme-toggle::before {
  content: "☾";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
}

body[data-theme="dark"] .theme-toggle::before {
  content: "☀";
  color: var(--gold);
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--soft);
}

.page-shell {
  display: grid;
  grid-template-columns: 160px minmax(0, 960px) 160px;
  gap: 24px;
  max-width: 1344px;
  margin: 0 auto;
  padding: 28px 18px 44px;
}

.content {
  min-width: 0;
}

.ad-rail {
  display: flex;
  justify-content: center;
}

.ad-slot {
  display: grid;
  width: 160px;
  height: 600px;
  place-items: center;
  color: var(--muted);
  background: var(--paper);
  border: 1px dashed #b8c1cc;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
}

ins.ad-slot {
  display: inline-block;
}

.search-panel,
.result-panel,
.quick-list,
.history-panel,
.empty-state {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 28px;
  align-items: end;
  padding: clamp(24px, 4vw, 44px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(38px, 7vw, 72px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 18px;
  font-size: 26px;
  letter-spacing: 0;
}

.lead {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 19px;
  line-height: 1.7;
}

.search-form label,
.result-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 15px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
button,
.link-button,
.primary-link,
.pager a {
  min-height: 48px;
  border-radius: 6px;
  font: inherit;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  padding: 8px 14px;
  color: var(--ink);
  background: var(--field);
  font-size: 24px;
}

button,
.primary-link,
.pager a {
  border: 0;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

button:hover,
.primary-link:hover,
.pager a:hover {
  background: var(--accent-strong);
}

.secondary,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  padding: 0 14px;
  color: var(--ink);
  background: var(--field);
}

.secondary:hover,
.link-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--soft);
}

.form-note,
.muted {
  margin: 10px 0 0;
  color: var(--muted);
}

.results-list {
  display: grid;
  gap: 22px;
  margin-top: 22px;
}

.result-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 26px;
  align-items: center;
  padding: clamp(22px, 4vw, 36px);
}

.result-main {
  display: flex;
  align-items: center;
  gap: 24px;
}

.result-char {
  display: grid;
  width: 128px;
  height: 128px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-size: 76px;
  font-family: "Noto Serif TC", "PMingLiU", serif;
  line-height: 1;
}

.result-code {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 700;
  letter-spacing: 0;
}

.result-roots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
  font-size: clamp(18px, 3vw, 26px);
  font-family: "Noto Serif TC", "PMingLiU", serif;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
}

.answer-chip {
  display: inline-grid;
  min-width: 1.42em;
  min-height: 1.42em;
  place-items: center;
  border-radius: 6px;
  padding: 0.08em 0.22em;
  color: #fff;
  line-height: 1;
}

.root-red {
  background: #e94f2d;
}

.root-blue {
  background: #2f7df6;
}

.root-green {
  background: #31ad4b;
}

.root-orange {
  background: #f2a400;
}

.root-purple {
  background: #a749f5;
}

.result-info {
  min-width: 0;
}

.root-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.diagram {
  margin: 0;
  text-align: center;
}

.diagram img {
  width: 130px;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.diagram-placeholder {
  display: grid;
  width: 130px;
  height: 130px;
  max-width: 100%;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--soft);
  font-size: 15px;
}

.diagram figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.quick-list,
.history-panel,
.empty-state {
  margin-top: 22px;
  padding: clamp(22px, 4vw, 34px);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
}

.text-button {
  min-height: auto;
  border: 0;
  padding: 6px 0;
  color: var(--muted);
  background: transparent;
}

.text-button:hover {
  color: var(--accent-strong);
  background: transparent;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.history-item {
  display: grid;
  min-height: 70px;
  justify-items: start;
  align-content: center;
  border: 1px solid var(--line);
  padding: 8px 12px;
  color: var(--ink);
  background: var(--field);
  text-align: left;
}

.history-item:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--soft);
}

.history-item span {
  font-size: 28px;
  font-family: "Noto Serif TC", "PMingLiU", serif;
  line-height: 1.1;
}

.history-item small {
  color: var(--muted);
  font-size: 13px;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 10px;
}

.char-grid a {
  display: grid;
  min-height: 78px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  transition: border-color 160ms ease, transform 160ms ease;
}

.char-grid a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.char-grid span {
  font-size: 30px;
  font-family: "Noto Serif TC", "PMingLiU", serif;
  line-height: 1;
}

.char-grid small {
  color: var(--muted);
  font-weight: 700;
}

.breadcrumb {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
}

.breadcrumb a {
  color: var(--accent-strong);
}

.pager {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.pager a,
.primary-link {
  display: inline-flex;
  align-items: center;
}

.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 18px 34px;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}

.site-footer a {
  color: var(--accent-strong);
  font-weight: 700;
}

@media (max-width: 1120px) {
  .page-shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 980px;
  }

  .ad-rail {
    display: none;
  }

}

@media (max-width: 760px) {
  .site-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .search-panel,
  .result-panel {
    grid-template-columns: 1fr;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .result-main {
    align-items: flex-start;
  }

  .result-char {
    width: 96px;
    height: 96px;
    font-size: 58px;
  }

  .diagram img {
    width: 130px;
  }

  .result-panel .diagram {
    order: -1;
  }
}

@media (max-width: 460px) {
  .page-shell {
    padding-inline: 12px;
  }

  .top-nav {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .search-panel,
  .result-panel,
  .quick-list,
  .history-panel,
  .empty-state {
    padding: 18px;
  }

  .result-main {
    gap: 14px;
  }
}
