:root {
  --bg: #0c0a14;
  --bg-soft: #171125;
  --panel: rgba(17, 14, 28, 0.9);
  --panel-border: rgba(194, 161, 91, 0.42);
  --gold: #d7b56d;
  --gold-soft: #f0e0b5;
  --accent: #8d6bc1;
  --text: #f3ead6;
  --muted: #b7ab95;
  --danger: #f28b82;
  --success: #81c995;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(87, 53, 122, 0.35), transparent 34%),
    linear-gradient(180deg, #0b0911 0%, #15111f 52%, #0c0a14 100%);
  color: var(--text);
  font-family: "PingFang SC", "Noto Serif SC", "Source Han Serif SC", serif;
}

body {
  padding: 20px 14px 40px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  margin-bottom: 22px;
  padding: 28px 20px 24px;
  border: 1px solid rgba(215, 181, 109, 0.25);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(22, 16, 35, 0.92), rgba(14, 10, 23, 0.96));
  box-shadow: var(--shadow);
}

.hero-ornament {
  color: var(--gold);
  letter-spacing: 0.24em;
  margin-bottom: 14px;
  animation: fadeIn 1.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.1;
  color: var(--gold-soft);
  animation: fadeIn 1s ease-out 0.2s both;
}

.subtitle {
  margin: 10px 0 0;
  color: #c78c74;
  font-size: 1.05rem;
}

.intro {
  margin: 14px auto 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.7;
}

.first-use-tip {
  max-width: 760px;
  margin: 14px auto 0;
  color: #f0e0b5;
  line-height: 1.7;
  font-size: 0.98rem;
  font-weight: 600;
}

.disclaimer {
  max-width: 760px;
  margin: 12px auto 0;
  color: #d8bf8b;
  line-height: 1.7;
  font-size: 0.96rem;
}

/* ===== Social proof ===== */
.social-proof {
  margin: 16px auto 0;
  padding: 8px 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(215, 181, 109, 0.2);
  border-radius: 24px;
  background: rgba(215, 181, 109, 0.06);
  color: var(--gold-soft);
  font-size: 0.92rem;
  animation: fadeIn 1.4s ease-out 0.4s both;
}

.social-proof[hidden] {
  display: none !important;
}

.proof-icon {
  color: var(--gold);
  font-size: 1.1rem;
}

.social-proof strong {
  color: var(--gold);
  font-size: 1.05rem;
}

/* ===== Guide collapse ===== */
.guide-collapse {
  margin-bottom: 18px;
  border: 1px solid rgba(215, 181, 109, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.guide-toggle {
  display: block;
  padding: 14px 16px;
  cursor: pointer;
  color: var(--gold-soft);
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  user-select: none;
}

.guide-toggle::-webkit-details-marker {
  display: none;
}

.guide-body {
  padding: 0 16px 16px;
}

.guide-body ol {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  line-height: 1.75;
  font-size: 0.92rem;
}

.guide-body strong {
  color: var(--gold);
  font-weight: 700;
}

/* ===== Layout ===== */
.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(320px, 1fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 22px 18px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 18px;
  color: var(--gold-soft);
}

/* ===== Fields ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.auth-panel,
.session-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-panel[hidden],
.session-panel[hidden],
[hidden] {
  display: none !important;
}

.auth-card {
  border: 1px solid rgba(215, 181, 109, 0.12);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 18px;
  padding: 16px 14px;
}

.auth-card h2 {
  margin: 0 0 12px;
}

.access-copy {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.7;
}

.field span,
.meta-label,
.result-card h3 {
  color: var(--gold);
}

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

.tier-button {
  border-radius: 14px;
  border: 1px solid rgba(215, 181, 109, 0.18);
  background: rgba(255, 255, 255, 0.03);
  color: var(--gold-soft);
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.tier-button--active {
  border-color: rgba(215, 181, 109, 0.5);
  background: linear-gradient(135deg, rgba(189, 144, 54, 0.28), rgba(120, 74, 156, 0.25));
  color: #fff7e6;
}

.tier-hint {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.92rem;
}

textarea,
input,
select,
.submit-button,
.secondary-button {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(215, 181, 109, 0.2);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  padding: 14px 14px;
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea::placeholder {
  color: #8f8473;
}

textarea:focus,
input:focus,
select:focus {
  outline: 1px solid rgba(215, 181, 109, 0.6);
  border-color: rgba(215, 181, 109, 0.6);
  box-shadow: 0 0 0 3px rgba(215, 181, 109, 0.1);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* ===== Cards ===== */
.note-block,
.result-card,
.status-box,
.empty-state,
.error-box {
  border: 1px solid rgba(215, 181, 109, 0.12);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 18px;
  padding: 16px 14px;
}

.note-block {
  margin-bottom: 16px;
}

.note-block h3 {
  margin: 0 0 12px;
  color: var(--gold-soft);
}

.note-block ol {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.7;
}

/* ===== Buttons ===== */
.submit-button {
  cursor: pointer;
  background: linear-gradient(135deg, rgba(189, 144, 54, 0.95), rgba(120, 74, 156, 0.95));
  color: #fff7e6;
  font-weight: 700;
  transition: opacity 0.2s, transform 0.15s;
}

.submit-button:hover:not([disabled]) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.submit-button:active:not([disabled]) {
  transform: translateY(0);
}

.secondary-button {
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  color: var(--gold-soft);
  font-weight: 600;
  transition: background 0.2s;
}

.secondary-button:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.08);
}

.submit-button[disabled] {
  cursor: wait;
  opacity: 0.7;
}

.secondary-button[disabled] {
  cursor: wait;
  opacity: 0.7;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(215, 181, 109, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--gold-soft);
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.icon-button:hover:not([disabled]) {
  background: rgba(215, 181, 109, 0.12);
  border-color: rgba(215, 181, 109, 0.42);
  transform: translateY(-1px);
}

.icon-button[disabled] {
  cursor: default;
  opacity: 0.45;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button .button-feedback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

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

/* ===== Error / Status ===== */
.error-box {
  margin-bottom: 14px;
  color: var(--danger);
}

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

.status-box,
.empty-state {
  color: var(--muted);
}

/* ===== Results ===== */
.result-card + .result-card {
  margin-top: 14px;
}

.result-card--summary {
  position: relative;
  padding-top: 62px;
}

.result-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
}

.result-card h3 {
  margin-top: 0;
  margin-bottom: 10px;
}

.meta-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

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

.meta-value {
  margin-top: 6px;
  line-height: 1.6;
}

.warning-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.7;
}

/* ===== Result text typography ===== */
.result-text {
  line-height: 1.85;
  letter-spacing: 0.02em;
  color: var(--text);
}

.classical-quote {
  margin: 0;
  padding: 14px 18px;
  border-left: 3px solid var(--gold);
  background: rgba(215, 181, 109, 0.04);
  border-radius: 0 12px 12px 0;
  line-height: 1.9;
  font-size: 1.05rem;
  color: var(--gold-soft);
  font-style: italic;
}

.result-card--classical {
  border-color: rgba(215, 181, 109, 0.25);
  background: rgba(215, 181, 109, 0.03);
}

.result-card--deep {
  border-color: rgba(141, 107, 193, 0.35);
  background: rgba(141, 107, 193, 0.05);
}

.result-card--deep h3 {
  color: var(--accent);
}

.deep-upgrade-actions {
  grid-template-columns: 1fr;
}

.deep-upgrade-actions .submit-button {
  min-height: 56px;
  font-size: 1.04rem;
}

.result-card--streaming {
  border-color: rgba(215, 181, 109, 0.22);
  background: rgba(215, 181, 109, 0.05);
}

.stream-status {
  margin-bottom: 10px;
  color: var(--gold-soft);
  font-size: 0.92rem;
}

.stream-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.8;
  color: var(--text);
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 0.92rem;
}

/* ===== Hexagram visualization ===== */
.hexagram-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 18px 0;
  margin-bottom: 14px;
  position: relative;
}

.hex-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.hex-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.hex-symbol {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 100px;
}

.hex-name {
  color: var(--gold-soft);
  font-size: 0.95rem;
  margin-top: 6px;
}

.hex-arrow {
  color: var(--gold);
  font-size: 1.8rem;
  font-weight: 300;
  margin-bottom: 20px;
}

.hex-moving-badge {
  position: absolute;
  bottom: 4px;
  right: 8px;
  padding: 3px 10px;
  border-radius: 12px;
  background: rgba(215, 181, 109, 0.12);
  color: var(--gold);
  font-size: 0.82rem;
}

/* Yao lines */
.yao-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 13px;
  margin-bottom: 3px;
  position: relative;
}

.yao-bar {
  height: 5px;
  border-radius: 2px;
}

.yao-bar-solid {
  width: 52px;
  background: var(--gold-soft);
}

.yao-bar-left,
.yao-bar-right {
  width: 20px;
  background: var(--gold-soft);
}

.yao-bar-gap {
  width: 12px;
}

.yao-moving .yao-bar-solid,
.yao-moving .yao-bar-left,
.yao-moving .yao-bar-right {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(141, 107, 193, 0.5);
}

.yao-dot {
  position: absolute;
  right: -20px;
  color: var(--accent);
  font-size: 0.7rem;
}

/* ===== Deep upgrade CTA ===== */
.deep-upgrade-cta {
  border-color: rgba(141, 107, 193, 0.3);
  background: linear-gradient(135deg, rgba(22, 16, 35, 0.95), rgba(141, 107, 193, 0.08));
  text-align: center;
  padding: 22px 18px;
}

.upgrade-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.deep-upgrade-cta h3 {
  color: var(--accent);
  margin-bottom: 10px;
}

.upgrade-desc {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 12px;
}

.upgrade-desc strong {
  color: var(--gold-soft);
}

.upgrade-action {
  color: var(--gold);
  font-weight: 600;
  font-size: 1.02rem;
}

.upgrade-action strong {
  color: var(--gold-soft);
}

.catalog-list {
  display: grid;
  gap: 10px;
}

.catalog-item {
  border: 1px solid rgba(215, 181, 109, 0.12);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.catalog-item h4 {
  margin: 0 0 8px;
  color: var(--gold-soft);
}

.catalog-item p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.6;
}

.catalog-item__meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.bind-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.bind-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 10, 0.68);
  backdrop-filter: blur(6px);
}

.bind-modal__dialog {
  position: relative;
  width: min(92vw, 420px);
  margin: 8vh auto 0;
  padding: 22px 18px;
  border: 1px solid rgba(215, 181, 109, 0.24);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(24, 17, 37, 0.98), rgba(13, 10, 21, 0.98));
  box-shadow: var(--shadow);
}

.bind-modal__dialog h2 {
  margin: 0 0 10px;
  color: var(--gold-soft);
}

.bind-modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--gold-soft);
  font-size: 1.4rem;
  cursor: pointer;
}

/* ===== History ===== */
.history-card {
  margin-top: 18px;
}

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.history-card-header h3 {
  margin: 0;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-item {
  padding: 10px 0;
  border-top: 1px solid rgba(215, 181, 109, 0.12);
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.9rem;
}

.history-item:first-child {
  border-top: 0;
  padding-top: 0;
}

/* ===== CTA Footer ===== */
.cta-footer {
  margin-top: 24px;
  padding: 20px 18px;
  border: 1px solid rgba(215, 181, 109, 0.3);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(22, 16, 35, 0.95), rgba(120, 74, 156, 0.15));
  text-align: center;
  box-shadow: var(--shadow);
}

.cta-inner {
  max-width: 600px;
  margin: 0 auto;
}

.cta-text {
  margin: 0;
  color: var(--gold-soft);
  line-height: 1.8;
  font-size: 1.05rem;
}

.cta-text strong {
  color: var(--gold);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .hexagram-visual {
    gap: 16px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 14px 10px 28px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  .hero {
    padding: 22px 14px 20px;
  }

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

  .button-row {
    grid-template-columns: 1fr;
  }

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

  .cta-footer {
    border-radius: 18px;
    padding: 16px 14px;
  }

  .hexagram-visual {
    gap: 12px;
    padding: 14px 0;
  }

  .yao-bar-solid {
    width: 40px;
  }

  .yao-bar-left,
  .yao-bar-right {
    width: 16px;
  }

  .yao-bar-gap {
    width: 8px;
  }

  .hex-arrow {
    font-size: 1.4rem;
  }

  .classical-quote {
    padding: 12px 14px;
    font-size: 1rem;
  }

  .ai-chat-input-row {
    flex-direction: column;
  }

  .ai-chat-send {
    width: 100% !important;
  }
}

/* ===== AI Chat ===== */
.ai-chat-section h3 {
  color: var(--accent);
}

.ai-chat-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 14px;
  line-height: 1.6;
}

.ai-chat-messages {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  min-height: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.7;
  font-size: 0.94rem;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(189, 144, 54, 0.25), rgba(120, 74, 156, 0.2));
  border: 1px solid rgba(215, 181, 109, 0.3);
  color: var(--gold-soft);
}

.chat-assistant {
  align-self: flex-start;
  background: rgba(141, 107, 193, 0.1);
  border: 1px solid rgba(141, 107, 193, 0.2);
  color: var(--text);
}

.ai-chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-chat-input {
  flex: 1;
  resize: none;
}

.ai-chat-send {
  width: 80px;
  flex-shrink: 0;
  padding: 14px 10px;
}
