:root {
  --bg: #030712;
  --bg-alt: #0f1524;
  --card: rgba(16, 21, 39, 0.9);
  --card-border: rgba(255, 255, 255, 0.1);
  --accent: #7d9cff;
  --accent-strong: #f5f6ff;
  --primary: #f1c877;
  --text: #e7ecff;
  --text-muted: rgba(231, 236, 255, 0.7);
  --input-border: rgba(255, 255, 255, 0.2);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow: 0 30px 60px rgba(0, 0, 0, 0.65);
  --line-color: rgba(255, 255, 255, 0.86);
  --line-muted: rgba(255, 255, 255, 0.3);
  font-family: "Inter", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top right, rgba(125, 156, 255, 0.3), transparent 50%),
    radial-gradient(circle at 20% 30%, rgba(255, 198, 119, 0.16), transparent 45%), var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.page-shell {
  min-height: 100vh;
  padding: clamp(1.2rem, 3vw, 2rem);
  display: flex;
  flex-direction: column;
  gap: 1.8rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(15, 20, 36, 0.85);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: clamp(1.2rem, 3vw, 1.8rem);
  box-shadow: var(--shadow);
}

.brand {
  max-width: 640px;
}

.brand-eyebrow {
  letter-spacing: 0.35em;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: rgba(231, 236, 255, 0.6);
  margin: 0 0 0.3rem 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 3rem);
}

.brand p {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
  max-width: 52ch;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.method-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.method-button {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.method-button span {
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  color: var(--text-muted);
}

.method-button.is-active {
  border-color: var(--accent);
  background: rgba(125, 156, 255, 0.15);
  color: var(--accent-strong);
}

.history-btn {
  border: none;
  background: linear-gradient(135deg, rgba(241, 200, 119, 0.4), rgba(125, 156, 255, 0.3));
  color: var(--text);
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.page-main {
  flex: 1;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(420px, 0.75fr);
  gap: 1.5rem;
}

.panel-column {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.method-panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: none;
  position: relative;
}

.method-panel.active {
  display: block;
}

.method-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.panel-subtitle {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.question-area label,
.method-inputs label,
.coin-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.question-area textarea {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  resize: vertical;
  font-size: 0.95rem;
}

.domain-row {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.domain-row select {
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  color: var(--text);
  padding: 0.45rem 0.8rem;
}

.helper-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.method-inputs,
.coin-grid {
  margin: 1rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
}

.input-group span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.method-inputs input,
.coin-grid input {
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.6rem 0.8rem;
  color: var(--text);
  font-size: 1rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.primary-action,
.ghost-action {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.primary-action {
  background: linear-gradient(135deg, #f1c877, #7d9cff);
  color: #0b0d16;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(27, 35, 71, 0.45);
}

.ghost-action {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.method-feedback,
.panel-note {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hex-preview {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.preview-block {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
}

.hexagram-name {
  margin: 0.5rem 0 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.hexagram-visual {
  border-radius: var(--radius-md);
  padding: 1rem 0.6rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(9, 15, 30, 0.7));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: center;
  min-height: 220px;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 6px 18px rgba(0, 0, 0, 0.45);
}

.hexagram-visual .line {
  width: 72%;
  height: 0.32rem;
  border-radius: 999px;
  background: var(--line-color);
  position: relative;
  transition: background 0.2s ease;
}

.hexagram-visual .line.yin {
  background: transparent;
}

.hexagram-visual .line.yin::before,
.hexagram-visual .line.yin::after {
  content: "";
  position: absolute;
  top: 0;
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: var(--line-color);
}

.hexagram-visual .line.yin::before {
  left: 0;
}

.hexagram-visual .line.yin::after {
  right: 0;
}

.hexagram-visual .line.moving {
  background: linear-gradient(90deg, rgba(241, 200, 119, 0.3), rgba(241, 200, 119, 0.9));
  box-shadow: 0 0 0 3px rgba(241, 200, 119, 0.45), 0 0 10px rgba(241, 200, 119, 0.3);
}

.coin-grid label,
.method-inputs label {
  font-weight: 500;
}

.library-toolbar {
  margin: 1rem 0;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.library-toolbar input {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  color: var(--text);
}

.library-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1rem;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.8rem;
  max-height: 480px;
  overflow-y: auto;
}

.library-item {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 1rem 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.library-item:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
}

.library-item.active {
  border-color: rgba(241, 200, 119, 0.7);
  background: rgba(241, 200, 119, 0.08);
}

 .library-detail-pane {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  min-height: 520px;
  padding: 1.2rem;
  background: rgba(255, 255, 255, 0.02);
  overflow-y: auto;
}

.library-detail-pane h3 {
  margin: 0;
  font-size: 1.25rem;
}

.library-detail-pane .line-entry {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.library-detail-pane .line-entry h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--primary);
}

.library-detail-pane .line-entry p {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.detail-header {
  margin-bottom: 0.8rem;
}

.detail-header h3 {
  margin: 0;
  letter-spacing: 0.2em;
}

.detail-summary {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.detail-hex-visual {
  margin: 1rem 0;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  padding: 1rem 0.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-height: 180px;
}

.detail-hex-line {
  width: 70%;
  height: 0.4rem;
  border-radius: 999px;
  border: none;
  outline: none;
  background: rgba(255, 255, 255, 0.35);
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
}

.detail-hex-line.yin {
  background: transparent;
}

.detail-hex-line.yin::before,
.detail-hex-line.yin::after {
  content: '';
  position: absolute;
  height: 100%;
  width: 40%;
  background: rgba(255, 255, 255, 0.7);
  top: 0;
}

.detail-hex-line.yin::before {
  left: 0;
}

.detail-hex-line.yin::after {
  right: 0;
}

.detail-hex-line.moving {
  background: linear-gradient(90deg, rgba(241, 200, 119, 0.4), rgba(241, 200, 119, 1));
  box-shadow: 0 0 8px rgba(241, 200, 119, 0.8);
}

.detail-body {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.detail-visual-column {
  flex: 1 1 280px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.detail-text-column {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.detail-line-preview {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  min-height: 140px;
  background: rgba(255, 255, 255, 0.02);
}

.detail-moving-explain {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.detail-moving-explain p {
  margin: 0.4rem 0;
}

.detail-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.detail-actions span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.detail-explanation {
  margin-top: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.8rem;
  line-height: 1.6;
}

.detail-line-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.detail-translation {
  font-size: 0.85rem;
  font-style: italic;
  color: rgba(244, 244, 244, 0.75);
  margin: 0;
}

.detail-explanation h4 {
  margin: 0;
  font-size: 1rem;
}

.detail-explanation p {
  margin: 0.35rem 0;
}

.detail-moving-explain {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.trigram-lines {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
}

.trigram-line {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  position: relative;
}

.trigram-line .line-display {
  width: 100%;
  height: 0.15rem;
  background: var(--line-color);
}

.trigram-line.yin .line-display {
  background: transparent;
}

.trigram-line.yin .line-display::after,
.trigram-line.yin .line-display::before {
  content: "";
  position: absolute;
  height: 2px;
  width: 40%;
  background: var(--line-color);
}

.trigram-line.moving {
  border-color: rgba(241, 200, 119, 0.8);
  box-shadow: 0 0 0 2px rgba(241, 200, 119, 0.25);
}

.trigram-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.history-panel {
  position: fixed;
  top: 2rem;
  right: 2rem;
  width: min(400px, 90vw);
  max-height: 70vh;
  background: rgba(7, 12, 22, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.35);
  display: none;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 30;
}

.history-panel header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

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

.history-tools {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.history-list {
  overflow-y: auto;
  max-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-item {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.85rem;
  line-height: 1.3;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
}

.history-item span {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.history-item:hover {
  border-color: rgba(125, 156, 255, 0.6);
  transform: translateY(-2px);
}

.history-item.active {
  border-color: rgba(241, 200, 119, 0.8);
  background: rgba(241, 200, 119, 0.08);
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.history-panel.open {
  display: flex;
}

.history-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.history-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.history-modal-content {
  background: rgba(14, 18, 28, 0.98);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(520px, 90vw);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.history-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

.history-modal-hex {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.history-modal-hex-card {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  text-align: center;
}

.history-modal-text {
  margin-top: 1rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
  background: rgba(255, 255, 255, 0.02);
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.insight-column .result-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.result-header h2 {
  margin: 0;
}

.hexagram-comparison {
  display: flex;
  gap: 1rem;
}

.hexagram-card {
  flex: 1;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.interpretation-output {
  margin-top: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 1.2rem;
  background: rgba(255, 255, 255, 0.02);
  min-height: 220px;
}

.interpretation-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.interpretation-output h4 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.interpretation-output p {
  margin: 0.2rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: pre-line;
}

.interpretation-output ul {
  margin: 0.35rem 0;
  padding-left: 1rem;
  color: var(--text-muted);
}

.placeholder {
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
}

.page-footer {
  padding-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 16, 28, 0.95);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.85rem;
  z-index: 40;
  color: var(--text);
  letter-spacing: 0.02em;
}

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

  .hexagram-comparison {
    flex-wrap: wrap;
  }

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

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

@media (max-width: 720px) {
  .method-button {
    font-size: 0.8rem;
    padding: 0.45rem 0.9rem;
  }

  .panel-column {
    gap: 0.9rem;
  }

  .history-panel {
    top: 1rem;
    right: 1rem;
    width: calc(100% - 2rem);
  }
}