:root {
  color-scheme: light;
  --ink: #202322;
  --muted: #66706c;
  --line: #d7ddd7;
  --paper: #f6f3ed;
  --panel: #fffdf8;
  --accent: #202322;
  --accent-dark: #0f1110;
  --day-color: #b8b2a6;
  --select-bg: #f3f0e8;
  --select-line: #b8b2a6;
  --jade: #28745c;
  --gold: #c58c2b;
  --blue: #2f658c;
  --shadow: 0 20px 50px rgba(33, 33, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(32, 35, 34, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(32, 35, 34, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 430px);
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: min(1380px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

body.has-chart .app-shell {
  grid-template-columns: minmax(300px, 390px) 1fr;
  align-items: start;
  justify-content: stretch;
  min-height: auto;
}

.input-panel,
.result-panel {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.input-panel {
  align-self: start;
  padding: 24px;
}

body.has-chart .input-panel {
  position: sticky;
  top: 24px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.seal {
  display: grid;
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 30px;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

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

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

.birth-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #3d4441;
  font-size: 14px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: #202322;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.92);
}

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

.method-note {
  display: grid;
  gap: 8px;
  margin-top: 22px;
  border-left: 3px solid var(--gold);
  padding: 10px 0 10px 13px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.method-note strong {
  color: var(--ink);
}

.result-panel {
  display: none;
  min-width: 0;
  padding: 22px;
}

body.has-chart .result-panel {
  display: block;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 4px 0 18px;
}

.luck-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.basic-info-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  padding: 18px;
  background: var(--panel);
}

.pillars {
  display: grid;
  grid-template-columns: 64px repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 22px;
}

.pillar-column,
.info-block,
.luck-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.chart-labels,
.pillar-column {
  display: grid;
  grid-template-rows: 44px 38px 70px 70px minmax(112px, auto);
  min-height: 334px;
  text-align: center;
}

.chart-labels {
  align-items: stretch;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
}

.chart-labels div,
.chart-cell {
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 6px 4px;
}

.chart-labels div:last-child {
  align-items: start;
  padding-top: 12px;
}

.pillar-column.is-day {
  border-color: var(--select-line);
  background: #fffdf8;
  box-shadow: inset 0 0 0 1px rgba(184, 178, 166, 0.45);
}

.pillar-column.is-context {
  border-color: #d4cec2;
  background: var(--select-bg);
}

.row-0 {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.row-0 span {
  color: #3f4643;
}

.row-1 {
  color: #3f4643;
  font-size: 13px;
}

.chart-stem,
.chart-branch {
  display: block;
  font-size: clamp(44px, 5.8vw, 66px);
  font-weight: 760;
  line-height: 1;
}

.row-4 {
  align-content: start;
  gap: 6px;
  padding-top: 10px;
}

.hidden-stem {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  line-height: 1.1;
}

.hidden-stem b {
  font-size: 20px;
  font-style: normal;
}

.hidden-stem em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  background: #fff;
}

.insight-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 14px;
  margin-top: 14px;
}

.info-block,
.info-block {
  padding: 18px;
}

.day-master {
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.7;
}

.elements {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.element-row {
  display: grid;
  grid-template-columns: 42px 1fr 30px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #e9ece6;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.ten-gods {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.basic-info {
  display: grid;
  gap: 8px;
  color: #303633;
  font-size: 14px;
  line-height: 1.65;
}

.basic-info-row {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 10px;
  border-bottom: 1px solid rgba(215, 221, 215, 0.65);
  padding-bottom: 8px;
}

.basic-info-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.basic-info-row strong {
  color: var(--muted);
  font-weight: 600;
}

.is-hidden {
  display: none !important;
}

.luck-panel {
  margin-top: 14px;
  padding: 16px;
}

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

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

.luck-list {
  display: grid;
  grid-template-columns: repeat(10, minmax(64px, 1fr));
  gap: 6px;
}

.luck-tile,
.year-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.luck-tile {
  display: grid;
  align-content: center;
  gap: 6px;
  min-height: 126px;
  padding: 8px 4px;
}

.mini-ganzhi,
.year-ganzhi {
  display: grid;
  justify-content: center;
  gap: 7px;
  line-height: 1;
  font-size: clamp(18px, 1.6vw, 22px);
}

.mini-ganzhi span,
.year-ganzhi span {
  display: grid;
  grid-template-columns: 1em auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.mini-ganzhi b,
.year-ganzhi b {
  font-weight: 760;
  font-size: 1.5em;
}

.mini-ganzhi em,
.year-ganzhi em {
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

.mini-ganzhi em,
.year-ganzhi em {
  font-size: 1.2em;
  line-height: 1;
}

.luck-tile span,
.luck-tile small {
  color: var(--muted);
  font-size: 11px;
}

.luck-tile.is-active {
  border-color: var(--select-line);
  background: var(--select-bg);
  box-shadow: inset 0 0 0 2px rgba(184, 178, 166, 0.42);
}

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

.section-head.compact {
  margin-bottom: 10px;
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(54px, 1fr));
  gap: 6px;
}

.year-button {
  display: grid;
  align-content: center;
  gap: 6px;
  min-height: 126px;
  padding: 7px 4px;
}

.year-button span {
  color: var(--muted);
  font-size: 11px;
}

.year-button.is-active {
  border-color: var(--select-line);
  color: var(--ink);
  background: var(--select-bg);
  box-shadow: inset 0 0 0 1px rgba(184, 178, 166, 0.5);
}

.year-button.is-active span {
  color: #686259;
}

.chat-view {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.chat-panel,
.core-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
}

.core-view {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.core-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(320px, 1.25fr);
  gap: 16px;
}

.core-layout h3 {
  margin: 0 0 12px;
  color: #303633;
  font-size: 16px;
}

.core-understanding {
  min-height: 280px;
  border: 1px solid rgba(215, 221, 215, 0.75);
  border-radius: 6px;
  padding: 14px;
  color: #303633;
  background: #fff;
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.life-overview {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  background: #f8f5ed;
}

.life-overview p {
  margin: 0;
  color: #303633;
  line-height: 1.75;
}

.chat-messages {
  display: grid;
  gap: 10px;
  min-height: 0;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.message {
  display: grid;
  gap: 5px;
  max-width: 92%;
}

.message.assistant {
  max-width: 96%;
}

.message span {
  color: var(--muted);
  font-size: 12px;
}

.message p {
  margin: 0;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.65;
}

.message.assistant p {
  background: #f3f5f0;
}

.message.user {
  justify-self: end;
}

.message.user span {
  text-align: right;
}

.message.user p {
  color: #fff;
  background: var(--accent);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 8px;
  margin-top: 10px;
}

.chat-form button {
  min-height: 44px;
}

@media (max-width: 980px) {
  .app-shell,
  body.has-chart .app-shell {
    grid-template-columns: 1fr;
  }

  .input-panel,
  body.has-chart .input-panel {
    position: static;
  }

  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-actions {
    justify-content: flex-start;
  }

  .pillars {
    grid-template-columns: 56px repeat(3, minmax(0, 1fr));
  }

  .luck-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 10px 0;
  }

  .result-panel,
  .input-panel {
    padding: 14px;
  }

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

  .pillars {
    grid-template-columns: 52px repeat(2, minmax(0, 1fr));
    overflow-x: auto;
  }

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

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

  .chart-labels,
  .pillar-column {
    min-width: 104px;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .core-layout {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  .basic-info-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
