:root {
  color-scheme: light;
  --ink: #1c1a16;
  --muted: #676158;
  --line: #d7d0c4;
  --panel: rgba(255, 252, 246, 0.9);
  --paper: #f7f0e3;
  --accent: #9f3e2f;
  --accent-dark: #742b22;
  --jade: #2e6f60;
  --gold: #c79035;
  --shadow: 0 24px 70px rgba(77, 54, 33, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(159, 62, 47, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(46, 111, 96, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 18% 16%, rgba(199, 144, 53, 0.18), transparent 28%),
    linear-gradient(135deg, #fbf7ef 0%, #eee5d6 48%, #f5efe6 100%);
  background-size:
    42px 42px,
    42px 42px,
    auto,
    auto;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 44px 0;
}

.page-footer {
  padding: 28px 0 44px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.sponsor {
  position: fixed;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  color: #544a38;
  font-size: 1.25rem;
  font-weight: 800;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.18em;
  cursor: default;
  outline: none;
}

.sponsor-text {
  display: block;
  padding: 22px 14px;
  border: 1px solid rgba(199, 144, 53, 0.45);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
  cursor: pointer;
}

.sponsor:hover .sponsor-text,
.sponsor:focus-within .sponsor-text {
  color: var(--accent);
  border-color: rgba(159, 62, 47, 0.55);
  background: #fffdf8;
}

.sponsor-popup {
  position: absolute;
  right: calc(100% + 16px);
  top: 50%;
  transform: translateY(-50%);
  display: none;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(112, 93, 72, 0.2);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 21;
}

.sponsor:hover .sponsor-popup,
.sponsor:focus-within .sponsor-popup,
.sponsor.is-open .sponsor-popup {
  display: grid;
}

.sponsor-popup img {
  width: 11vw;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 4px;
}

@media (max-width: 1280px) {
  .sponsor {
    position: relative;
    transform: none;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    letter-spacing: 0;
    margin: 0 auto 20px;
    width: fit-content;
  }

  .sponsor-text {
    padding: 14px 24px;
  }

  .sponsor-popup {
    right: 50%;
    top: auto;
    bottom: calc(100% + 12px);
    transform: translateX(50%);
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .sponsor-popup {
    grid-template-columns: 1fr;
  }

  .sponsor-popup img {
    width: min(240px, 72vw);
  }
}

.workspace {
  width: 100%;
}

.intro {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 780px;
  font-size: clamp(2.35rem, 7vw, 5.8rem);
  line-height: 0.96;
  letter-spacing: 0;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-weight: 800;
}

.lead {
  max-width: 520px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(420px, 1.14fr);
  gap: 20px;
  align-items: stretch;
}

.panel {
  border: 1px solid rgba(112, 93, 72, 0.2);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.form-panel {
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.guidance {
  padding: 14px 16px;
  border-left: 4px solid var(--jade);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  background: rgba(46, 111, 96, 0.1);
  font-weight: 800;
  line-height: 1.65;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.66);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.field input:focus {
  border-color: rgba(159, 62, 47, 0.72);
  background: #fffdf8;
  box-shadow: 0 0 0 4px rgba(159, 62, 47, 0.12);
}

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

.error-message {
  min-height: 22px;
  color: var(--accent-dark);
  font-size: 0.92rem;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary-button,
.ghost-button {
  min-height: 50px;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
  font-weight: 800;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.primary-button {
  color: #fffaf0;
  background: var(--accent);
  box-shadow: 0 14px 30px rgba(159, 62, 47, 0.24);
}

.primary-button:disabled {
  background: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
}

.primary-button.full-width {
  width: 100%;
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.ghost-button:active {
  transform: translateY(0);
}

.ghost-button {
  color: var(--accent-dark);
  background: rgba(159, 62, 47, 0.08);
  border: 1px solid rgba(159, 62, 47, 0.18);
}

.result-panel {
  min-height: 504px;
  padding: 28px;
  display: grid;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-items: center;
  gap: 18px;
  color: var(--muted);
  text-align: center;
}

.compass-mark {
  position: relative;
  width: min(320px, 76vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(112, 93, 72, 0.22);
  background:
    conic-gradient(from 22.5deg, rgba(159, 62, 47, 0.12), rgba(46, 111, 96, 0.1), rgba(199, 144, 53, 0.16), rgba(159, 62, 47, 0.12)),
    rgba(255, 253, 247, 0.72);
}

.compass-mark::before,
.compass-mark::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  border: 1px solid rgba(112, 93, 72, 0.16);
}

.compass-mark::after {
  inset: 40%;
  background: linear-gradient(135deg, var(--accent) 0 50%, var(--ink) 50% 100%);
}

.compass-mark span {
  position: absolute;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 252, 246, 0.82);
  color: var(--ink);
  font-size: 1.42rem;
  box-shadow: 0 10px 28px rgba(77, 54, 33, 0.11);
}

.compass-mark span:nth-child(1) {
  top: 6%;
  left: calc(50% - 22px);
}

.compass-mark span:nth-child(2) {
  top: 17%;
  right: 17%;
}

.compass-mark span:nth-child(3) {
  top: calc(50% - 22px);
  right: 6%;
}

.compass-mark span:nth-child(4) {
  right: 17%;
  bottom: 17%;
}

.compass-mark span:nth-child(5) {
  bottom: 6%;
  left: calc(50% - 22px);
}

.compass-mark span:nth-child(6) {
  left: 17%;
  bottom: 17%;
}

.compass-mark span:nth-child(7) {
  top: calc(50% - 22px);
  left: 6%;
}

.compass-mark span:nth-child(8) {
  top: 17%;
  left: 17%;
}

.result-content {
  display: grid;
  gap: 24px;
}

.is-hidden {
  display: none;
}

.result-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.result-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.result-head h2 {
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  max-width: 148px;
  border-radius: 999px;
  padding: 8px 12px;
  color: #fffaf0;
  background: var(--jade);
  font-size: 0.92rem;
  font-weight: 800;
  text-align: center;
}

.hexagram-stage {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 22px;
  border: 1px solid rgba(112, 93, 72, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(28, 26, 22, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(28, 26, 22, 0.04) 1px, transparent 1px),
    rgba(255, 253, 247, 0.62);
  background-size: 24px 24px;
}

.hexagram-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.hexagram {
  width: min(180px, 100%);
  display: grid;
  gap: 9px;
}

.line {
  width: 100%;
  height: 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.line span {
  border-radius: 999px;
  background: var(--ink);
}

.line.yin {
  grid-template-columns: 1fr 1fr;
}

.line.is-moving span {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(159, 62, 47, 0.13);
}

.symbol {
  color: var(--muted);
  font-size: 1.24rem;
  font-family: "Songti SC", "STSong", serif;
}

.change-arrow {
  color: var(--gold);
  font-size: 2.2rem;
  font-weight: 900;
}

.reading-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.reading-grid div {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px;
  border: 1px solid rgba(112, 93, 72, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.64);
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
}

.note {
  min-height: 52px;
  padding: 16px;
  border-left: 4px solid var(--gold);
  color: var(--muted);
  background: rgba(199, 144, 53, 0.11);
  border-radius: 0 8px 8px 0;
  line-height: 1.65;
}

.note:empty {
  display: none;
}

.ai-section {
  display: grid;
  gap: 16px;
}

.ai-button {
  width: 100%;
}

.ai-button.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.ai-button.is-loading::after {
  content: "";
  position: absolute;
  top: calc(50% - 10px);
  left: calc(50% - 10px);
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 250, 240, 0.3);
  border-top-color: #fffaf0;
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}

@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}

.ai-result {
  padding: 22px;
  border: 1px solid rgba(112, 93, 72, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.72);
  line-height: 1.85;
}

.ai-result h1,
.ai-result h2,
.ai-result h3,
.ai-result h4,
.ai-result h5,
.ai-result h6 {
  margin: 24px 0 12px;
  color: var(--accent-dark);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-weight: 800;
}

.ai-result h1:first-child,
.ai-result h2:first-child,
.ai-result h3:first-child,
.ai-result h4:first-child,
.ai-result h5:first-child,
.ai-result h6:first-child {
  margin-top: 0;
}

.ai-result h3 {
  font-size: 1.15rem;
}

.ai-result h4 {
  font-size: 1.05rem;
}

.ai-result p {
  margin: 0 0 14px;
}

.ai-result p:last-child {
  margin-bottom: 0;
}

.ai-result ul,
.ai-result ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.ai-result li {
  margin-bottom: 6px;
}

.ai-result li:last-child {
  margin-bottom: 0;
}

.ai-result strong {
  color: var(--accent-dark);
  font-weight: 800;
}

.ai-result blockquote {
  margin: 0 0 14px;
  padding: 12px 16px;
  border-left: 4px solid var(--gold);
  border-radius: 0 8px 8px 0;
  background: rgba(199, 144, 53, 0.11);
  color: var(--muted);
}

.ai-result blockquote p:last-child {
  margin-bottom: 0;
}

.ai-result code {
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(28, 26, 22, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.ai-error {
  min-height: 22px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.92rem;
  font-weight: 700;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100% - 22px, 720px);
    align-items: start;
    padding: 24px 0;
  }

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

  .result-panel {
    min-height: 460px;
  }

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

@media (max-width: 560px) {
  .number-grid,
  .actions,
  .hexagram-stage,
  .reading-grid {
    grid-template-columns: 1fr;
  }

  .form-panel,
  .result-panel {
    padding: 18px;
  }

  .change-arrow {
    transform: rotate(90deg);
    justify-self: center;
  }

  .result-head {
    display: grid;
  }

  .result-head h2 {
    line-height: 1.08;
  }

  .badge {
    max-width: none;
    justify-self: start;
  }
}
