:root {
  --paper: #f3f0e8;
  --paper-deep: #e9e4d8;
  --ink: #202522;
  --muted: #747974;
  --line: rgba(32, 37, 34, 0.14);
  --jade: #46675f;
  --jade-dark: #2f4b44;
  --white: rgba(255, 255, 252, 0.66);
  --serif: "Noto Serif SC", "Songti SC", SimSun, serif;
  --sans: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 9%, rgba(87, 118, 108, 0.08), transparent 28rem),
    linear-gradient(115deg, rgba(255,255,255,.24), transparent 40%),
    var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.045'/%3E%3C/svg%3E");
}
button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 2px solid rgba(70, 103, 95, .48); outline-offset: 3px; }

#app-shell { width: min(1500px, 100%); min-height: 100vh; margin: 0 auto; padding: 0 4.2vw; position: relative; }
.site-header { height: 98px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.site-header-actions { display: flex; align-items: center; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-mark { width: 43px; height: 43px; display: grid; place-items: center; border: 1px solid var(--jade); color: var(--jade-dark); font-family: var(--serif); font-size: 21px; transform: rotate(45deg); }
.brand-mark::first-letter { transform: rotate(-45deg); }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font: 600 21px/1 var(--serif); letter-spacing: .15em; }
.brand small { color: var(--muted); font: 10px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; }

.workspace { min-height: calc(100vh - 171px); display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: clamp(48px, 7vw, 120px); }
.history-panel { padding: 48px 30px 40px 0; border-right: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
.eyebrow { margin: 0 0 10px; color: var(--jade); font-size: 10px; letter-spacing: .2em; }
.panel-heading h2 { margin: 0; font: 500 20px/1.3 var(--serif); letter-spacing: .08em; }
.icon-button, .text-button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-button { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; font: 12px var(--serif); }
.icon-button:hover { color: #8a5147; border-color: rgba(138,81,71,.45); }
.history-list { min-width: 0; list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history-item { min-width: 0; overflow: hidden; }
.history-item button { display: block; width: 100%; min-width: 0; padding: 14px 10px; overflow: hidden; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.history-item button:hover { background: rgba(255,255,255,.28); }
.history-item strong { display: block; width: 100%; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 14px/1.5 var(--serif); }
.history-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.empty-history { margin: 54px 0; color: #969992; text-align: center; font: 14px/2 var(--serif); }
.empty-history span { font: 10px var(--sans); }

.reading-space { width: min(850px, 100%); padding: clamp(64px, 9vh, 112px) 0 80px; }
.intro-section { max-width: 700px; }
.intro-section h1 { margin: 0 0 24px; font: 500 clamp(38px, 4.3vw, 64px)/1.2 var(--serif); letter-spacing: .06em; }
.intro-section h1 em { color: var(--jade); font-style: normal; }
.intro-section > p:last-child { max-width: 610px; margin: 0; color: var(--muted); font: 15px/2 var(--serif); }

.query-card { margin-top: 54px; padding: 24px 28px 18px; background: var(--white); border: 1px solid var(--line); box-shadow: 0 18px 60px rgba(36, 43, 39, .045); backdrop-filter: blur(8px); }
.query-card label { display: block; color: var(--jade-dark); font: 500 13px var(--serif); letter-spacing: .12em; }
.query-card textarea { display: block; width: 100%; min-height: 138px; margin: 14px 0; padding: 2px 0; resize: vertical; border: 0; color: var(--ink); background: transparent; font: 16px/1.9 var(--serif); }
.query-card textarea::placeholder { color: #a3a69f; }
.query-card textarea:focus { outline: 0; }
.query-actions { min-height: 48px; padding-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); }
.query-actions > span { color: var(--muted); font-size: 11px; }
.primary-button { min-width: 145px; min-height: 45px; padding: 0 18px 0 24px; display: inline-flex; align-items: center; justify-content: space-between; gap: 20px; border: 0; color: #f8f6ef; background: var(--jade-dark); cursor: pointer; transition: background .2s, transform .2s; }
.primary-button:hover { background: var(--jade); transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: .65; transform: none; }
.button-arrow { font-size: 18px; }
.primary-button.loading .button-arrow { width: 15px; height: 15px; border: 1px solid rgba(255,255,255,.35); border-top-color: white; border-radius: 50%; font-size: 0; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.conversation-section { margin-top: 38px; }
.cast-summary { padding: 22px 24px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.hexagram { display: flex; align-items: center; gap: 15px; }
.hexagram-symbol { font: 37px/1 var(--serif); color: var(--jade-dark); }
.hexagram small, .hexagram strong { display: block; }
.hexagram small { margin-bottom: 5px; color: var(--muted); font-size: 10px; letter-spacing: .12em; }
.hexagram strong { font: 500 15px var(--serif); }
.cast-arrow { color: #9b9e98; }
.cast-time { grid-column: 1 / -1; margin: -3px 0 0; text-align: center; color: var(--muted); font-size: 10px; }
.messages { display: grid; gap: 20px; padding-top: 30px; }
.message { padding: 25px 28px; border: 1px solid var(--line); background: rgba(255,255,252,.42); }
.message.user { margin-left: 12%; border-left: 2px solid #9bada6; }
.message.ai { margin-right: 4%; }
.message-label { margin: 0 0 14px; color: var(--jade); font: 10px var(--sans); letter-spacing: .16em; }
.message p { margin: 0; white-space: pre-wrap; font: 14px/1.9 var(--serif); }
.clarify-intro { margin-bottom: 18px !important; color: var(--muted); }
.question-list { margin: 0; padding: 0; list-style: none; counter-reset: questions; display: grid; gap: 9px; }
.question-list li { position: relative; padding-left: 27px; font: 14px/1.7 var(--serif); counter-increment: questions; }
.question-list li::before { content: counter(questions, cjk-ideographic) "、"; position: absolute; left: 0; color: var(--jade); }
.followup-hint { margin-top: 18px !important; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px !important; }
.reading-title { margin: 0 0 20px; font: 500 22px/1.5 var(--serif); }
.reading-grid { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.reading-block { padding: 22px 22px 22px 0; border-bottom: 1px solid var(--line); }
.reading-block:nth-child(even) { padding-left: 22px; border-left: 1px solid var(--line); }
.reading-block h3 { margin: 0 0 10px; color: var(--jade-dark); font: 500 13px var(--serif); letter-spacing: .12em; }
.reading-notice { margin-top: 17px !important; color: var(--muted); font-size: 11px !important; }
.share-actions { margin-top: 28px; padding: 24px 0; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-top: 1px solid var(--line); }
.share-actions[hidden] { display: none; }
.share-actions p { margin: 0; color: var(--muted); font: 13px var(--serif); letter-spacing: .08em; }
.share-actions > div { display: flex; gap: 10px; }
.secondary-button { min-height: 42px; padding: 0 18px; border: 1px solid var(--jade); color: var(--jade-dark); background: transparent; cursor: pointer; }
.secondary-button:hover { background: rgba(70, 103, 95, .07); }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-size: 13px; white-space: nowrap; }
.new-reading-link { display: none; }
.primary-button.compact { min-width: 0; min-height: 42px; padding: 0 18px; }
.shared-view .query-card, .shared-view .history-panel, .shared-view #history-toggle { display: none; }
.shared-view .new-reading-link { display: inline-flex; }
.shared-view .workspace { display: block; }
.shared-view .reading-space { margin: 0 auto; }

.site-footer { min-height: 73px; padding: 20px 0; display: flex; align-items: center; justify-content: space-between; gap: 30px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.site-footer span { color: var(--ink); font: 500 13px var(--serif); }
.site-footer p { margin: 0; text-align: right; }
.toast { position: fixed; right: 28px; bottom: 28px; z-index: 20; max-width: 360px; padding: 13px 18px; color: #fff; background: rgba(38, 48, 44, .94); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .22s; }
.toast.visible { opacity: 1; transform: none; }
.mobile-only { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 860px) {
  #app-shell { padding: 0 24px; }
  .site-header { height: 78px; }
  .mobile-only { display: inline-block; }
  .workspace { display: block; min-height: calc(100vh - 145px); }
  .history-panel { position: fixed; top: 0; left: 0; bottom: 0; z-index: 15; width: min(340px, 88vw); padding: 32px 24px; border: 0; background: #eeebe2; box-shadow: 12px 0 50px rgba(31,37,34,.12); transform: translateX(-105%); transition: transform .25s ease; }
  .history-panel.open { transform: none; }
  .reading-space { padding-top: 64px; margin: 0 auto; }
  .intro-section h1 { font-size: clamp(36px, 9vw, 53px); }
}

@media (max-width: 560px) {
  #app-shell { padding: 0 16px; }
  .brand-mark { width: 38px; height: 38px; }
  .reading-space { padding: 48px 0 60px; }
  .intro-section h1 { margin-bottom: 18px; }
  .intro-section > p:last-child { font-size: 14px; }
  .query-card { margin-top: 36px; padding: 20px 18px 16px; }
  .query-actions { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .cast-summary { grid-template-columns: 1fr auto 1fr; padding-inline: 12px; gap: 10px; }
  .hexagram { gap: 8px; }
  .hexagram-symbol { font-size: 30px; }
  .hexagram strong { font-size: 12px; }
  .message { padding: 22px 18px; }
  .message.user, .message.ai { margin: 0; }
  .reading-grid { grid-template-columns: 1fr; }
  .reading-block, .reading-block:nth-child(even) { padding: 18px 0; border-left: 0; }
  .share-actions { align-items: stretch; flex-direction: column; }
  .share-actions > div { display: grid; grid-template-columns: 1fr; }
  .share-actions .button-link { width: 100%; }
  .site-footer { align-items: flex-start; flex-direction: column; gap: 8px; }
  .site-footer p { text-align: left; line-height: 1.6; }
  .toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
