:root {
  --ink: #211915;
  --muted: #75695d;
  --paper: #f6f0e5;
  --line: rgba(59, 45, 34, 0.16);
  --gold: #b78136;
  --red: #9d3e35;
  --green: #4e7661;
  --blue: #405f83;
  --shadow: 0 24px 70px rgba(43, 29, 18, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 14%, rgba(183, 129, 54, 0.16), transparent 28%),
    radial-gradient(circle at 88% 10%, rgba(64, 95, 131, 0.14), transparent 30%),
    linear-gradient(135deg, #efe4d0 0%, #f8f2e9 48%, #e8eee8 100%);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: clamp(16px, 3vw, 36px);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(290px, 380px) 1fr;
  gap: 20px;
  width: min(1240px, 100%);
  min-height: calc(100vh - clamp(32px, 6vw, 72px));
  margin: 0 auto;
}

.input-panel,
.reading-panel {
  border: 1px solid var(--line);
  background: rgba(255, 251, 244, 0.84);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  border-radius: 8px;
}

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

.seal {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid var(--red);
  color: var(--red);
  font-family: "Noto Serif TC", serif;
  font-size: 28px;
  font-weight: 900;
}

.eyebrow,
.section-heading span {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Noto Serif TC", serif;
  line-height: 1.15;
}

h1 {
  font-size: 36px;
}

h2 {
  font-size: clamp(28px, 4vw, 54px);
}

h3 {
  font-size: 22px;
}

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

label,
.field-group {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  outline: none;
}

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  line-height: 1.7;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: rgba(157, 62, 53, 0.62);
  box-shadow: 0 0 0 3px rgba(157, 62, 53, 0.12);
}

.date-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr 0.9fr;
  gap: 8px;
}

.date-grid label {
  gap: 6px;
}

.date-grid label span {
  font-size: 12px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  margin-top: 2px;
  color: var(--ink);
  cursor: pointer;
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--red);
}

.conversion-text {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.conversion-text.error {
  color: var(--red);
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
}

.segmented input:checked + span {
  border-color: var(--red);
  color: #fff;
  background: var(--red);
}

.primary-action {
  min-height: 50px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #8f332d, #bd7b3a);
  cursor: pointer;
}

.secondary-action {
  width: fit-content;
  min-height: 42px;
  border: 1px solid rgba(157, 62, 53, 0.38);
  border-radius: 6px;
  padding: 8px 16px;
  color: #fff;
  font-weight: 800;
  background: var(--red);
  cursor: pointer;
}

.secondary-action:disabled {
  cursor: wait;
  opacity: 0.68;
}

.primary-action:hover {
  filter: brightness(1.04);
}

.note {
  margin: auto 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.reading-panel {
  position: relative;
  overflow: hidden;
  min-height: 720px;
  padding: clamp(24px, 4vw, 42px);
  border-radius: 8px;
}

.sky-map {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.26;
  background-image:
    linear-gradient(rgba(33, 25, 21, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 25, 21, 0.08) 1px, transparent 1px);
  background-size: 48px 48px;
}

.sky-map span {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 24px var(--gold);
}

.sky-map span:nth-child(1) { left: 14%; top: 20%; }
.sky-map span:nth-child(2) { left: 38%; top: 11%; }
.sky-map span:nth-child(3) { left: 70%; top: 18%; }
.sky-map span:nth-child(4) { left: 82%; top: 48%; }
.sky-map span:nth-child(5) { left: 56%; top: 78%; }

.reading-header,
.result {
  position: relative;
}

.reading-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
}

.life-score {
  display: grid;
  flex: 0 0 auto;
  width: 86px;
  height: 86px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--red);
  font-family: "Noto Serif TC", serif;
  font-size: 30px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.54);
}

.empty-state {
  position: relative;
  display: grid;
  min-height: 410px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  line-height: 1.9;
}

.hidden {
  display: none;
}

.pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.pillars article,
.insight {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.pillars article {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 18px;
}

.pillars span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.pillars strong {
  font-family: "Noto Serif TC", serif;
  font-size: clamp(24px, 3vw, 36px);
}

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

.insight {
  min-height: 168px;
  padding: 20px;
}

.insight.wide {
  grid-column: 1 / -1;
}

.insight p {
  margin: 14px 0 0;
  color: #4d4239;
  line-height: 1.85;
}

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

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

.element-row span {
  font-weight: 800;
}

.bar {
  overflow: hidden;
  height: 12px;
  border-radius: 999px;
  background: rgba(33, 25, 21, 0.1);
}

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

.palace-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(168px, auto));
  gap: 10px;
  margin-top: 16px;
}

.palace {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: rgba(246, 240, 229, 0.58);
}

.ziwei-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.ziwei-meta div {
  display: grid;
  gap: 4px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: rgba(246, 240, 229, 0.64);
}

.ziwei-meta span,
.star-group span,
.palace-footer span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ziwei-meta strong {
  color: var(--ink);
  font-size: 14px;
}

.palace strong,
.palace-topline strong {
  display: block;
  margin-bottom: 6px;
  color: var(--blue);
}

.palace span {
  color: #574b40;
  font-size: 13px;
  line-height: 1.55;
}

.ziwei-palace {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 168px;
  padding: 10px;
}

.soul-palace {
  border-color: rgba(157, 62, 53, 0.48);
  background: rgba(255, 246, 236, 0.9);
}

.body-palace {
  box-shadow: inset 0 0 0 2px rgba(64, 95, 131, 0.18);
}

.palace-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.palace-topline strong {
  margin: 0;
  color: var(--red);
  font-size: 18px;
}

.palace-topline span {
  color: var(--ink);
  font-family: "Noto Serif TC", serif;
  font-size: 16px;
  font-weight: 800;
}

.palace-tags,
.star-group div {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.palace-tags i,
.star-group i,
.star-group em {
  border-radius: 999px;
  padding: 2px 7px;
  color: #3e342c;
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.7);
}

.palace-tags i {
  color: #fff;
  background: var(--blue);
}

.star-group {
  display: grid;
  gap: 5px;
}

.star-group small {
  margin-left: 2px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
}

.star-group b {
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  margin-left: 3px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  background: var(--red);
}

.palace-footer {
  display: grid;
  gap: 2px;
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.ziwei-center {
  display: grid;
  grid-column: 2 / span 2;
  grid-row: 2 / span 2;
  place-items: center;
  border: 1px solid rgba(157, 62, 53, 0.32);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  background:
    linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    repeating-linear-gradient(45deg, rgba(183, 129, 54, 0.14) 0 1px, transparent 1px 12px);
}

.ziwei-center strong {
  color: var(--red);
  font-family: "Noto Serif TC", serif;
  font-size: clamp(30px, 4vw, 52px);
}

.ziwei-center span {
  color: var(--ink);
  font-weight: 800;
}

.ziwei-center small {
  color: var(--muted);
}

.ziwei-reading {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.reading-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.reading-block > p {
  margin: 14px 0 0;
  color: #4d4239;
  line-height: 1.9;
}

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

.reading-points,
.period-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

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

.focus-list article,
.reading-points article,
.period-grid article {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: rgba(246, 240, 229, 0.56);
}

.focus-list strong,
.reading-points strong,
.period-grid strong {
  display: block;
  color: var(--red);
  font-size: 15px;
}

.focus-list span,
.period-grid span {
  display: block;
  margin-top: 5px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.focus-list p,
.reading-points p,
.period-grid p {
  margin: 8px 0 0;
  color: #574b40;
  font-size: 13px;
  line-height: 1.75;
}

.annual {
  border-color: rgba(157, 62, 53, 0.28);
  background: rgba(255, 248, 238, 0.86);
}

.ai-panel {
  display: grid;
  gap: 12px;
}

.ai-answer {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  color: #4d4239;
  line-height: 1.85;
  white-space: pre-wrap;
  background: rgba(246, 240, 229, 0.58);
}

.ai-answer.error {
  color: var(--red);
  font-weight: 700;
}

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

  .reading-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .input-panel,
  .reading-panel {
    padding: 20px;
  }

  .reading-header {
    align-items: center;
  }

  .life-score {
    width: 64px;
    height: 64px;
    font-size: 23px;
  }

  .pillars,
  .insight-grid,
  .palace-grid,
  .ziwei-meta,
  .focus-list,
  .reading-points,
  .period-grid,
  .date-grid {
    grid-template-columns: 1fr;
  }

  .palace-grid {
    grid-template-rows: none;
  }

  .ziwei-palace,
  .ziwei-center {
    grid-column: auto !important;
    grid-row: auto !important;
  }
}
