:root {
  --bg: #f5eddc;
  --surface: rgba(255, 250, 241, 0.78);
  --surface-strong: rgba(255, 248, 235, 0.96);
  --ink: #2f2418;
  --ink-soft: #675544;
  --line: rgba(78, 57, 31, 0.14);
  --gold: #d88f32;
  --gold-deep: #8e5222;
  --clay: #a13d2d;
  --moss: #557057;
  --shadow: 0 24px 70px rgba(85, 49, 14, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 225, 167, 0.8), transparent 35%),
    radial-gradient(circle at bottom right, rgba(171, 92, 45, 0.24), transparent 30%),
    linear-gradient(135deg, #f8f0df 0%, #f1e2c5 52%, #ebdcc6 100%);
}

button,
input {
  font: inherit;
}

.page-shell {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  padding: 32px;
}

.background-orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(10px);
  opacity: 0.45;
  pointer-events: none;
}

.orb-a {
  width: 360px;
  height: 360px;
  top: -120px;
  right: -60px;
  background: radial-gradient(circle, rgba(224, 158, 54, 0.55), transparent 70%);
  animation: floatOrb 14s ease-in-out infinite;
}

.orb-b {
  width: 320px;
  height: 320px;
  bottom: -100px;
  left: -80px;
  background: radial-gradient(circle, rgba(115, 145, 118, 0.42), transparent 68%);
  animation: floatOrb 18s ease-in-out infinite reverse;
}

.hero,
.layout {
  position: relative;
  z-index: 1;
}

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

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--clay);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "ZCOOL XiaoWei", serif;
  font-weight: 400;
}

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

.hero-copy {
  max-width: 680px;
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.8;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.95fr);
  gap: 24px;
}

.card {
  backdrop-filter: blur(22px);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
  border-radius: 28px;
  padding: 24px;
}

.panel-head,
.section-head,
.record-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.pill,
#lineProgressTag,
#finalStatus {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--ink-soft);
  font-size: 14px;
}

.ghost-button,
.primary-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.ghost-button {
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-button {
  padding: 16px 28px;
  color: #fff8f0;
  background: linear-gradient(135deg, var(--clay), var(--gold-deep));
  box-shadow: 0 14px 30px rgba(132, 63, 24, 0.26);
}

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

.primary-button:disabled {
  cursor: not-allowed;
  transform: none;
  opacity: 0.68;
  box-shadow: none;
}

.cardlike {
  margin-top: 26px;
  padding: 20px 22px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 254, 251, 0.72);
}

.rail-head {
  margin-bottom: 14px;
}

.metric-card,
.timeline-item,
.record-card,
.hex-card {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.hex-card p {
  margin: 0 0 10px;
  color: var(--ink-soft);
}

.hex-name strong {
  font-size: clamp(34px, 5vw, 56px);
  font-family: "ZCOOL XiaoWei", serif;
  font-weight: 400;
}

.heap-caption {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.stalk-rail {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 126px;
  padding: 18px 20px 22px;
  overflow: hidden;
  border-radius: 20px;
  border: 1px dashed rgba(120, 83, 40, 0.2);
  background:
    radial-gradient(circle at top, rgba(255, 244, 211, 0.75), transparent 55%),
    linear-gradient(180deg, rgba(255, 251, 243, 0.96), rgba(241, 228, 201, 0.82));
  cursor: pointer;
  touch-action: none; /* 允许移动端拖拽预演，不被浏览器滚动手势抢走 */
}

.stalk-rail.is-flash {
  animation: pulseFlash 360ms ease;
}

.rail-stalk {
  width: 10px;
  height: 76px;
  flex: 1;
  border-radius: 999px;
  background:
    linear-gradient(180deg, #7d653f 0%, #d8c49c 14%, #9b7c47 52%, #76572d 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 247, 229, 0.2),
    0 6px 14px rgba(98, 61, 18, 0.12);
  transition: transform 180ms ease, filter 180ms ease, margin 220ms ease, opacity 220ms ease;
  pointer-events: none;
}

.rail-stalk.is-left-preview {
  transform: translateX(-8px) rotate(-2deg);
}

.rail-stalk.is-right-preview {
  transform: translateX(8px) rotate(2deg);
}

.rail-stalk.is-split-edge {
  margin-right: 18px;
  filter: brightness(1.12);
}

.split-marker {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 0;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.split-marker::before {
  content: "";
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(161, 61, 45, 0.18), rgba(161, 61, 45, 0.72), rgba(161, 61, 45, 0.18));
  box-shadow: 0 0 0 1px rgba(255, 248, 238, 0.5);
}

.split-marker span {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(103, 85, 68, 0.92);
  font-size: 11px;
  white-space: nowrap;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 251, 243, 0.9);
  background: rgba(255, 251, 243, 0.9);
  padding: 2px 6px;
  border-radius: 999px;
}

.split-inputs {
  margin-top: 26px;
  padding: 20px 22px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 254, 251, 0.65);
}

.split-inputs label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--clay);
}

.manual-tip {
  min-height: 52px;
  display: flex;
  align-items: center;
  color: var(--ink-soft);
  line-height: 1.7;
}

.workbench-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.calc-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  padding: 18px;
}

.metric-card span,
.timeline-topline,
.record-line,
.record-value {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: 32px;
  font-family: "ZCOOL XiaoWei", serif;
  font-weight: 400;
}

.timeline-wrap,
.line-records {
  margin-top: 24px;
}

.timeline,
.line-records {
  display: grid;
  gap: 14px;
}
.timeline {
  margin-top: 26px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  padding: 16px;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
}

.timeline-item.is-visible,
.record-card.is-visible {
  animation: riseIn 380ms ease forwards;
}

.timeline-index {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(216, 143, 50, 0.18), rgba(161, 61, 45, 0.18));
  font-family: "ZCOOL XiaoWei", serif;
  font-size: 20px;
}

.timeline-detail {
  margin-top: 8px;
  line-height: 1.7;
  color: var(--ink);
}

.hexagram-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}

.hex-card {
  padding: 18px;
}

.hex-name {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.hex-name span {
  font-size: 26px;
  color: var(--clay);
  min-width: 52px;
}

#primarySymbol,
#changedSymbol {
  display: none;
}

.hex-lines {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.hex-line {
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateX(-10px);
}

.hex-line.is-visible {
  animation: lineSlide 300ms ease forwards;
}

.hex-line-drawing {
  /* 让卦线绘制区域随容器收缩，避免窄屏/中屏两列时溢出或留白 */
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 290px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-bar {
  flex: 1 1 0;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6a5440, #2f2418);
}

.line-bar.broken {
  flex: 1 1 0;
}

.line-gap {
  width: 22px;
  height: 12px;
  flex: 0 0 22px;
}

.line-marker {
  min-width: 64px;
  text-align: left;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.record-card {
  padding: 16px;
  opacity: 0;
  transform: translateY(10px);
}

.record-head {
  margin-bottom: 12px;
}

.record-head strong {
  font-size: 28px;
  font-family: "ZCOOL XiaoWei", serif;
  font-weight: 400;
}

.record-changes {
  display: grid;
  gap: 8px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.result-panel {
  display: flex;
  flex-direction: column;
}

.is-pulse {
  animation: pulseFlash 420ms ease;
}

@keyframes floatOrb {
  0%, 100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(20px, 24px, 0) scale(1.08);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulseFlash {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(216, 143, 50, 0);
  }
  50% {
    transform: scale(1.04);
    box-shadow: 0 0 0 10px rgba(216, 143, 50, 0.16);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(216, 143, 50, 0);
  }
}

@keyframes riseIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes lineSlide {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

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

@media (max-width: 760px) {
  .page-shell {
    padding: 18px;
  }

  .layout {
    /* 窄屏强制单列，避免 grid 在某些内容宽度下产生溢出 */
    grid-template-columns: 1fr;
  }

  /* grid 子项默认 min-width:auto 可能导致不收缩、从而溢出 */
  .layout > * {
    min-width: 0;
  }

  .hero,
  .panel-head,
  .section-head,
  .hexagram-summary {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero,
  .panel-head,
  .section-head {
    justify-content: stretch;
  }

  .pill-group {
    justify-content: flex-start;
  }

  .workbench-controls {
    display: grid;
  }

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

  .hex-line-drawing {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .control-panel,
  .result-panel {
    width: 100%;
    min-width: 0;
  }

  .stalk-rail {
    width: 100%;
  }

  /* 避免窄屏出现横向滚动 */
  body {
    overflow-x: hidden;
  }

  /* 缩小卦线侧标的最小宽度，提升窄屏可用空间 */
  .line-marker {
    min-width: 56px;
  }
}

@media (max-width: 480px) {
  .page-shell {
    padding: 12px;
  }

  .layout {
    gap: 16px;
  }

  .card {
    padding: 16px;
    border-radius: 22px;
  }

  .cardlike {
    margin-top: 18px;
    padding: 16px;
  }

  .hero {
    gap: 14px;
    margin-bottom: 18px;
  }

  .hero-copy {
    font-size: 14px;
  }

  .stalk-rail {
    min-height: 110px;
    padding: 14px 14px 16px;
  }

  .split-inputs {
    margin-top: 18px;
    padding: 14px;
  }

  .calc-grid {
    gap: 10px;
  }

  .metric-card {
    padding: 14px;
  }

  .metric-card strong {
    font-size: 26px;
  }

  .timeline-item {
    grid-template-columns: 52px 1fr;
    padding: 12px;
  }

  .timeline-index {
    width: 40px;
    height: 40px;
  }

  .hex-name span {
    font-size: 22px;
  }

  .line-marker {
    min-width: 44px;
    font-size: 11px;
  }

  .line-gap {
    width: 16px;
    flex: 0 0 16px;
  }
}
