:root {
  --paper: #f4f7f5;
  --paper-deep: #e9f0ed;
  --ink: #18312c;
  --muted: #64736f;
  --line: #cbd7d2;
  --accent: #d7654f;
  --accent-dark: #a64032;
  --white: #ffffff;
  --shadow: 0 20px 55px rgba(37, 73, 64, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(215,101,79,.11), transparent 28rem),
    radial-gradient(circle at 95% 18%, rgba(52,122,103,.09), transparent 32rem),
    var(--paper);
  color: var(--ink);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
}

button, input, select { font: inherit; }

.masthead {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 72px 0 42px;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 28px;
  align-items: start;
  border-bottom: 1px solid var(--ink);
}

.masthead__mark {
  width: 84px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff8ec;
  font: 700 48px/1 "Noto Serif TC", "Songti TC", serif;
  box-shadow: inset 0 0 0 7px var(--accent), inset 0 0 0 8px rgba(255,255,255,.5);
}

.eyebrow, .chart-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 12px;
  font: 700 clamp(38px, 6vw, 68px)/1.12 "Noto Serif TC", "Songti TC", serif;
  letter-spacing: .04em;
}

.lede {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
}

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.control-panel, .results, .method { padding: 46px 0; }
.control-panel, .results { border-bottom: 1px solid var(--line); }

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

.section-heading > div { display: flex; align-items: baseline; gap: 14px; }
.section-heading h2 { margin: 0; font: 700 24px/1.2 "Noto Serif TC", "Songti TC", serif; }
.section-number { color: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: .16em; }

.text-button {
  border: 0;
  border-bottom: 1px solid currentColor;
  padding: 2px 0;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
}

.date-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 24px;
  background: rgba(255,253,247,.76);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow);
}

.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 700; }
.field b, .field i { margin-left: 5px; color: var(--accent); font-size: 11px; font-style: normal; }
.field i { color: #8a867e; font-weight: 500; }

input, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 9px 11px;
  background: var(--white);
  color: var(--ink);
  outline: none;
}

input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(163,58,43,.14); }
input:disabled, select:disabled { opacity: .48; cursor: not-allowed; }

.primary-button {
  min-height: 48px;
  border: 1px solid var(--accent-dark);
  border-radius: 0;
  padding: 9px 24px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  letter-spacing: .08em;
  cursor: pointer;
  transition: background .16s ease, transform .16s ease;
}

.primary-button:hover { background: var(--accent-dark); }
.primary-button:active { transform: translateY(1px); }
.form-hint { margin: 12px 0 0; color: var(--muted); font-size: 13px; }

.result-tools { display: flex; align-items: center; gap: 18px; }
.result-date { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.view-toggle {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--ink);
  background: var(--paper-deep);
}

.view-toggle__button {
  min-width: 66px;
  border: 0;
  padding: 7px 13px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.view-toggle__button.is-active { background: var(--ink); color: var(--white); }

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  margin-bottom: 22px;
  background: var(--line);
  border: 1px solid var(--line);
}

.summary-item {
  flex: 1 1 190px;
  padding: 15px 18px;
  background: var(--paper-deep);
}
.summary-item span { display: block; color: var(--muted); font-size: 12px; }
.summary-item strong { font-size: 16px; }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.charts[hidden], #composite-chart[hidden] { display: none; }

.composite-card {
  padding: 26px;
  background: rgba(255,253,247,.88);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow);
}

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

.composite-card__header h3 { margin: 0 0 5px; font: 700 28px/1.2 "Noto Serif TC", "Songti TC", serif; }
.composite-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.composite-center { min-width: 160px; padding-left: 20px; border-left: 1px solid var(--line); text-align: right; }
.composite-center span { display: block; color: var(--muted); font-size: 11px; letter-spacing: .14em; }
.composite-center strong { font: 700 27px/1.25 "Noto Serif TC", "Songti TC", serif; letter-spacing: .06em; }

.composite-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.composite-legend span { display: inline-flex; align-items: center; gap: 7px; }
.layer-key { width: 18px; height: 3px; display: inline-block; background: var(--layer-color); }

.composite-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.composite-palace {
  position: relative;
  min-height: 178px;
  padding: 12px 14px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: rgba(255,255,255,.2);
  cursor: pointer;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}

.composite-palace--center { box-shadow: inset 0 0 0 3px var(--accent); }
.composite-palace:hover { background: rgba(163,58,43,.07); }
.composite-palace:focus-visible { outline: 3px solid rgba(163,58,43,.35); outline-offset: -3px; }
.composite-palace.is-selected { background: rgba(163,58,43,.09); box-shadow: inset 0 0 0 3px var(--accent); }
.composite-palace__direction { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .1em; }

.palace-fortune {
  position: absolute;
  z-index: 2;
  top: 9px;
  right: 9px;
  min-width: 34px;
  padding: 3px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}
.palace-fortune--good { color: #2f7259; }
.palace-fortune--neutral { color: #766f63; }
.palace-fortune--bad { color: #a84739; }
.palace .palace-fortune { top: 8px; right: 8px; }

.layer-row {
  display: grid;
  grid-template-columns: 42px 28px 1fr auto;
  align-items: baseline;
  gap: 6px;
  min-height: 31px;
  border-top: 1px solid rgba(102, 97, 88, .2);
}

.layer-row:first-of-type { border-top: 0; }
.layer-row__name { color: var(--layer-color); font-size: 11px; font-weight: 800; }
.layer-row__number { color: var(--star-color); font: 800 23px/1.25 "Noto Serif TC", "Songti TC", serif; }
.layer-row__star { font-size: 12px; font-weight: 700; white-space: nowrap; }
.layer-row__element { color: var(--muted); font-size: 11px; }

.chart-card {
  padding: 22px;
  background: rgba(255,253,247,.84);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow);
}

.chart-card__header { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 16px; }
.chart-title { margin: 0; font: 700 25px/1.2 "Noto Serif TC", "Songti TC", serif; }
.center-badge { min-width: 76px; border-left: 1px solid var(--line); padding-left: 14px; text-align: right; }
.center-badge span { display: block; color: var(--muted); font-size: 11px; letter-spacing: .16em; }
.center-badge strong { font: 700 25px/1.2 "Noto Serif TC", "Songti TC", serif; }

.orientation { display: grid; grid-template-columns: 1fr 1fr 1fr; margin: 0 0 6px; color: var(--muted); font-size: 11px; text-align: center; letter-spacing: .12em; }
.orientation b { color: var(--accent); }
.orientation--bottom { margin: 6px 0 0; }

.palace-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.palace {
  position: relative;
  min-height: 116px;
  padding: 11px;
  display: grid;
  align-content: space-between;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  overflow: hidden;
}

.palace::after {
  content: "";
  position: absolute;
  inset: auto -22px -36px auto;
  width: 86px;
  height: 86px;
  border: 16px solid var(--star-color);
  border-radius: 50%;
  opacity: .16;
}

.palace--center { box-shadow: inset 0 0 0 3px var(--accent); }
.palace__direction { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.palace__main { display: flex; align-items: end; gap: 8px; }
.palace__number { color: var(--star-color); font: 800 38px/.9 "Noto Serif TC", "Songti TC", serif; }
.palace__meta { position: relative; z-index: 1; font-size: 12px; line-height: 1.35; }
.palace__meta b { display: block; font-size: 13px; }

.chart-note { margin: 14px 0 0; color: var(--muted); font-size: 12px; }

.palace-reading {
  margin-top: 18px;
  padding: 20px;
  background: var(--paper-deep);
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--line);
}
.palace-reading__empty { text-align: center; color: var(--muted); }
.palace-reading__empty span { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.palace-reading__empty p { margin: 8px 0 0; }
.palace-reading__header { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 15px; }
.palace-reading__header span { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.palace-reading__header h4 { margin: 4px 0 0; font: 700 25px/1.25 "Noto Serif TC", "Songti TC", serif; }
.fortune-tag { flex: 0 0 auto; padding: 6px 10px; border: 1px solid currentColor; font-size: 12px; }
.fortune-tag--good { color: #316b55; }
.fortune-tag--neutral { color: #6d665d; }
.fortune-tag--bad { color: #9a3f32; }
.reading-stars { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.reading-stars span { min-width: 130px; padding: 9px 11px; background: rgba(255,255,255,.55); border: 1px solid var(--line); }
.reading-stars b { display: block; color: var(--star-color); font: 700 16px/1.3 "Noto Serif TC", "Songti TC", serif; }
.reading-stars small { color: var(--muted); font-size: 10px; }
.relation-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 9px; }
.relation-card { padding: 12px; background: rgba(255,255,255,.62); border-left: 3px solid var(--relation-color); }
.relation-card--good { --relation-color: #557a65; }
.relation-card--neutral { --relation-color: #928775; }
.relation-card--bad { --relation-color: #a74a3b; }
.relation-card header { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px; }
.relation-card header span { color: var(--muted); font-size: 10px; }
.relation-card header b { font-size: 12px; }
.relation-card header em { grid-column: 2; grid-row: 1 / span 2; color: var(--relation-color); font-style: normal; font-size: 12px; font-weight: 800; }
.relation-card h5 { margin: 9px 0 3px; font-size: 14px; }
.relation-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.relation-card .relation-card__themes { margin-top: 5px; color: var(--ink); }
.reading-method, .single-reading { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.65; }

.method-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.method-grid > div { padding: 20px; border-right: 1px solid var(--line); }
.method-grid > div:first-child { padding-left: 0; }
.method-grid > div:last-child { border-right: 0; }
.method-grid h3 { margin-bottom: 6px; font: 700 17px/1.3 "Noto Serif TC", "Songti TC", serif; }
.method-grid p, .disclaimer { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.disclaimer { margin-top: 16px; }

footer {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 25px 0 45px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--ink);
}
footer p { margin: 0; }

/* Modern, approachable presentation layer */
.masthead { padding: 64px 0 40px; grid-template-columns: 82px 1fr; border-bottom-color: var(--line); }
.masthead__mark {
  width: 76px;
  border-radius: 24px;
  font-family: "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 40px;
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(215,101,79,.24);
}
h1 {
  font-family: "PingFang TC", "Noto Sans TC", sans-serif;
  font-weight: 800;
  font-size: clamp(36px, 5.5vw, 62px);
  letter-spacing: -.035em;
}
.section-heading h2,
.composite-card__header h3,
.palace-reading__header h4 {
  font-family: "PingFang TC", "Noto Sans TC", sans-serif;
  font-weight: 800;
  letter-spacing: -.025em;
}
.date-form,
.composite-card,
.chart-card {
  background: rgba(255,255,255,.9);
  border-color: var(--line);
  border-radius: var(--radius);
}
input, select, .primary-button { border-radius: 11px; }
.primary-button { box-shadow: 0 8px 18px rgba(215,101,79,.2); }
.view-toggle { border-color: var(--line); border-radius: 12px; }
.view-toggle__button { border-radius: 9px; }
.view-toggle__button.is-active { box-shadow: 0 4px 12px rgba(24,49,44,.18); }
.summary-strip { gap: 0; background: rgba(255,255,255,.65); border-radius: 15px; overflow: hidden; }
.summary-item { background: transparent; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.composite-grid { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.composite-palace { border-color: var(--line); }
.composite-palace--center { box-shadow: inset 0 0 0 2px var(--accent); }
.palace-reading { border: 1px solid var(--line); border-radius: 16px; }
.fortune-tag {
  padding: 8px 12px;
  border-radius: 999px;
}
.fortune-tag small,
.relation-card em small,
.relation-card h5 small {
  display: block;
  opacity: .68;
  font-size: 9px;
  font-weight: 700;
}
.fortune-tag small { display: inline; margin-left: 5px; }
.reading-stars span { background: rgba(255,255,255,.72); border-radius: 11px; }
.relation-card {
  padding: 13px;
  background: rgba(255,255,255,.76);
  border: 1px solid var(--line);
  border-top: 3px solid var(--relation-color);
  border-radius: 12px;
}
.relation-card h5 { line-height: 1.35; }
.relation-card em { line-height: 1.25; text-align: right; }

@media (max-width: 900px) {
  .date-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .primary-button { grid-column: 1 / -1; }
  .charts { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .masthead, main, footer { width: min(100% - 28px, 1180px); }
  .masthead { padding-top: 38px; grid-template-columns: 54px 1fr; gap: 15px; }
  .masthead__mark { width: 54px; font-size: 31px; box-shadow: inset 0 0 0 4px var(--accent), inset 0 0 0 5px rgba(255,255,255,.5); }
  h1 { font-size: 37px; }
  .lede { font-size: 14px; }
  .control-panel, .results, .method { padding: 34px 0; }
  .section-heading { align-items: center; }
  .section-heading--results { display: block; }
  .result-tools { margin-top: 12px; justify-content: space-between; }
  .date-form { grid-template-columns: 1fr; padding: 17px; }
  .primary-button { grid-column: auto; }
  .chart-card { padding: 15px; }
  .composite-card { padding: 14px; }
  .composite-card__header { display: block; }
  .composite-center { margin-top: 12px; padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--line); text-align: left; }
  .composite-palace { min-height: 148px; padding: 7px; }
  .palace-fortune { top: 5px; right: 5px; min-width: 27px; padding: 2px 5px; font-size: 9px; }
  .layer-row { grid-template-columns: 1fr 22px; gap: 2px 4px; padding: 3px 0; }
  .layer-row__name { grid-column: 1; }
  .layer-row__number { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-size: 20px; }
  .layer-row__star { grid-column: 1; font-size: 10px; }
  .layer-row__element { display: none; }
  .palace-reading { padding: 14px; }
  .palace-reading__header { align-items: start; }
  .palace-reading__header h4 { font-size: 21px; }
  .relation-grid { grid-template-columns: 1fr; }
  .palace { min-height: 102px; padding: 8px; }
  .palace__number { font-size: 31px; }
  .palace__meta { font-size: 10px; }
  .palace__meta b { font-size: 11px; }
  .method-grid { grid-template-columns: 1fr; }
  .method-grid > div, .method-grid > div:first-child { padding: 16px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .method-grid > div:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
