:root {
  --bg: #f6f7f3;
  --paper: #ffffff;
  --ink: #20231f;
  --muted: #687066;
  --line: #dce1d5;
  --green: #24705d;
  --green-dark: #174e42;
  --gold: #b9852e;
  --red: #b84a3a;
  --blue: #2f6f9f;
  --shadow: 0 18px 50px rgba(34, 39, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(36, 112, 93, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(36, 112, 93, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: calc(100% - 32px);
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.seal {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 2px solid var(--red);
  color: var(--red);
  background: rgba(255, 255, 255, 0.74);
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 46px;
  font-weight: 700;
}

.tool-panel,
.results-section,
.favorites-section {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head p,
.section-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.section-head.compact {
  align-items: center;
  margin-bottom: 14px;
}

.input-block {
  padding-bottom: 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.name-row {
  display: grid;
  grid-template-columns: 140px minmax(160px, 1fr) minmax(160px, 1fr);
  gap: 14px;
  align-items: end;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(108px, 0.9fr) minmax(108px, 0.9fr) minmax(118px, 0.9fr) minmax(90px, 0.7fr) minmax(170px, 1.45fr) minmax(112px, 0.9fr);
  gap: 12px;
  align-items: end;
}

.name-row > *,
.control-row > *,
.content-grid > *,
.board-controls > * {
  min-width: 0;
}

.fixed-surname,
.char-field,
.stroke-field,
.gender-field,
.position-field {
  display: grid;
  gap: 7px;
}

.fixed-surname span,
.char-field span,
.stroke-field span,
.gender-field span,
.position-field span,
.board-controls span {
  color: var(--muted);
  font-size: 13px;
}

.fixed-surname strong,
.char-field input,
.stroke-field select,
.gender-field select,
.position-field select,
.board-controls select,
.tag-input {
  width: 100%;
  height: 48px;
  border: 1px solid #cbd3c7;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.fixed-surname strong {
  display: grid;
  place-items: center;
  font-size: 26px;
}

.char-field input {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  outline: none;
}

.char-field input:focus,
.stroke-field select:focus,
.gender-field select:focus,
.position-field select:focus,
.board-controls select:focus,
.tag-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(36, 112, 93, 0.14);
}

.stroke-field select,
.gender-field select,
.position-field select,
.board-controls select {
  padding: 0 12px;
}

.primary-button,
.shuffle-button,
.secondary-button,
.favorite-button,
.small-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button {
  height: 48px;
  background: var(--green);
  color: white;
}

.shuffle-button {
  height: 48px;
  border: 1px solid rgba(36, 112, 93, 0.35);
  background: #eef5f0;
  color: var(--green-dark);
}

.primary-button:hover {
  background: var(--green-dark);
}

.shuffle-button:hover {
  background: #dfece4;
}

.primary-button:disabled,
.shuffle-button:disabled {
  cursor: wait;
  background: #8aa99d;
  color: white;
}

.secondary-button,
.small-button {
  border: 1px solid var(--line);
  background: #f7f8f5;
  color: var(--ink);
}

.element-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.element-chip {
  min-width: 58px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfa;
  color: var(--ink);
}

.element-chip.active {
  border-color: var(--green);
  background: rgba(36, 112, 93, 0.12);
  color: var(--green-dark);
  font-weight: 700;
}

.element-chip.metal.active {
  border-color: #967135;
  background: rgba(185, 133, 46, 0.14);
}

.element-chip.wood.active {
  border-color: #24705d;
}

.element-chip.water.active {
  border-color: #2f6f9f;
  background: rgba(47, 111, 159, 0.14);
}

.element-chip.fire.active {
  border-color: #b84a3a;
  background: rgba(184, 74, 58, 0.14);
}

.element-chip.earth.active {
  border-color: #7a6847;
  background: rgba(122, 104, 71, 0.14);
}

.radical-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.results-section,
.favorites-section {
  padding: 18px;
}

.result-grid,
.favorites-list {
  display: grid;
  gap: 12px;
}

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

.empty-state {
  padding: 28px 18px;
  border: 1px dashed #c6cec2;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.name-card,
.favorite-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
}

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

.name-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.name-title strong {
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 34px;
  line-height: 1.1;
}

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

.total-score {
  display: grid;
  place-items: center;
  min-width: 58px;
  height: 58px;
  border: 2px solid rgba(36, 112, 93, 0.24);
  border-radius: 50%;
  color: var(--green-dark);
  font-size: 20px;
  font-weight: 800;
}

.badges,
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.badge,
.tag,
.tag-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  line-height: 1.4;
}

.badge {
  border: 1px solid rgba(36, 112, 93, 0.2);
  background: rgba(36, 112, 93, 0.08);
  color: var(--green-dark);
}

.tag,
.tag-toggle {
  border: 1px solid #d5dccf;
  background: #f7f8f5;
  color: #394137;
}

.tag-toggle.active {
  border-color: var(--green);
  background: rgba(36, 112, 93, 0.12);
  color: var(--green-dark);
  font-weight: 700;
}

.tag button {
  margin-left: 6px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
  cursor: pointer;
}

.meaning,
.source,
.warning {
  color: #384036;
  font-size: 14px;
  line-height: 1.65;
}

.source {
  margin-top: 8px;
  color: var(--muted);
}

.warning {
  margin-top: 8px;
  color: #8a4b1f;
}

.scores {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.score-row {
  display: grid;
  grid-template-columns: 48px minmax(80px, 1fr) 36px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.score-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe2;
}

.score-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.favorite-button {
  width: 100%;
  margin-top: 14px;
  background: #232820;
  color: #fff;
}

.favorite-button.saved {
  background: #dfe6da;
  color: var(--green-dark);
}

.board-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.board-controls label {
  display: grid;
  gap: 6px;
}

.favorite-card.selected {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.favorite-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.favorite-actions select {
  height: 38px;
  border: 1px solid #cbd3c7;
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

.compare-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.tag-tools {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

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

.tag-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tag-input {
  height: 38px;
  padding: 0 10px;
}

.compare-panel {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.compare-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.compare-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: #fff;
}

.compare-table th,
.compare-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.5;
}

.compare-table tr:last-child th,
.compare-table tr:last-child td {
  border-bottom: 0;
}

.compare-table th {
  width: 96px;
  color: var(--muted);
  background: #f7f8f5;
}

@media (max-width: 1080px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

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

  .name-row {
    grid-template-columns: minmax(70px, 0.75fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 9px;
    align-items: end;
  }

  .control-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }

  .fixed-surname,
  .char-field,
  .stroke-field,
  .gender-field,
  .position-field {
    gap: 5px;
  }

  .fixed-surname strong,
  .char-field input,
  .stroke-field select,
  .gender-field select,
  .position-field select {
    height: 44px;
  }

  .fixed-surname strong,
  .char-field input {
    font-size: 24px;
  }

  .primary-button {
    grid-column: 1 / span 2;
  }

  .shuffle-button {
    grid-column: 3;
  }

  .primary-button,
  .shuffle-button {
    height: 44px;
    padding: 0 10px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100% - 20px);
    max-width: 720px;
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-end;
  }

  .seal {
    width: 64px;
    height: 64px;
    font-size: 36px;
  }

  .tool-panel,
  .results-section,
  .favorites-section {
    padding: 14px;
  }

  .panel-head,
  .section-head {
    display: grid;
  }

  .name-row {
    grid-template-columns: minmax(70px, 0.75fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 9px;
    align-items: end;
  }

  .control-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }

  .fixed-surname,
  .char-field,
  .stroke-field,
  .gender-field,
  .position-field {
    gap: 5px;
  }

  .fixed-surname strong,
  .char-field input,
  .stroke-field select,
  .gender-field select,
  .position-field select {
    height: 44px;
  }

  .fixed-surname strong,
  .char-field input {
    font-size: 24px;
  }

  .primary-button {
    grid-column: 1 / span 2;
  }

  .shuffle-button {
    grid-column: 3;
  }

  .primary-button,
  .shuffle-button {
    height: 44px;
    padding: 0 10px;
  }

  .board-controls,
  .favorite-actions,
  .tag-entry {
    grid-template-columns: 1fr;
  }
}
