:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --surface: #fffbf2;
  --surface-soft: #f0eadf;
  --surface-strong: #ebe2d3;
  --ink: #211f1a;
  --muted: #6f675b;
  --faint: #918777;
  --line: #ded4c4;
  --line-strong: #c7b8a4;
  --accent: #c35f2c;
  --accent-dark: #843c1e;
  --accent-soft: rgba(195, 95, 44, 0.1);
  --accent-softer: rgba(195, 95, 44, 0.07);
  --panel: rgba(255, 251, 242, 0.88);
  --panel-soft: rgba(255, 251, 242, 0.64);
  --panel-softer: rgba(255, 251, 242, 0.44);
  --rail: rgba(240, 234, 223, 0.8);
  --band: rgba(240, 234, 223, 0.45);
  --band-soft: rgba(240, 234, 223, 0.34);
  --band-strong: rgba(240, 234, 223, 0.86);
  --page-gradient: linear-gradient(180deg, rgba(255, 251, 242, 0.72), rgba(247, 243, 234, 0.94));
  --page-glow: radial-gradient(circle at 20% 0%, rgba(195, 95, 44, 0.12), transparent 30%);
  --shadow: 0 18px 50px rgba(54, 40, 26, 0.08);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Microsoft YaHei",
    sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14110e;
  --surface: #211c17;
  --surface-soft: #1a1612;
  --surface-strong: #302820;
  --ink: #f3e8d8;
  --muted: #b9aa96;
  --faint: #8f806d;
  --line: #3c332a;
  --line-strong: #5a4b3c;
  --accent: #d17a45;
  --accent-dark: #e6a06d;
  --accent-soft: rgba(209, 122, 69, 0.16);
  --accent-softer: rgba(209, 122, 69, 0.1);
  --panel: rgba(33, 28, 23, 0.94);
  --panel-soft: rgba(43, 36, 29, 0.76);
  --panel-softer: rgba(43, 36, 29, 0.52);
  --rail: rgba(23, 19, 15, 0.88);
  --band: rgba(48, 40, 32, 0.5);
  --band-soft: rgba(48, 40, 32, 0.32);
  --band-strong: rgba(55, 46, 37, 0.9);
  --page-gradient: linear-gradient(180deg, rgba(20, 17, 14, 0.98), rgba(17, 14, 11, 0.96));
  --page-glow: radial-gradient(circle at 22% 0%, rgba(209, 122, 69, 0.13), transparent 32%);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    var(--page-gradient),
    var(--page-glow),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: var(--rail);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
  padding: 4px 6px 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--surface);
  background: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
}

:root[data-theme="dark"] .brand-mark,
:root[data-theme="dark"] .primary-button,
:root[data-theme="dark"] .new-button {
  color: #15110e;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

:root[data-theme="dark"] .primary-button:hover,
:root[data-theme="dark"] .new-button:hover {
  background: #f0b184;
}

.brand h1,
.topbar h2,
.input-header h3,
.report-header h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 23px;
  line-height: 1.1;
}

.eyebrow,
.nav-title {
  margin: 0;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.new-button,
.mode-button,
.history-item,
.ghost-button,
.primary-button,
.text-button {
  border-radius: 7px;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 120ms ease;
}

.new-button {
  width: 100%;
  height: 40px;
  margin-bottom: 18px;
  border: 1px solid var(--ink);
  color: var(--surface);
  background: var(--ink);
  font-weight: 650;
}

.mode-nav {
  display: grid;
  gap: 8px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.nav-title {
  margin: 0 6px 4px;
}

.mode-button,
.history-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
}

.mode-button {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
}

.mode-button span,
.history-item strong {
  font-size: 14px;
  font-weight: 700;
}

.mode-button small,
.history-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.mode-button:hover,
.history-item:hover {
  background: var(--panel-soft);
}

.mode-button.active {
  border-color: var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.history-section {
  min-height: 0;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.text-button {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.text-button:hover {
  color: var(--accent-dark);
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-color: var(--line);
  background: var(--panel-softer);
}

.history-item span {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 750;
}

.empty-history,
.boundary p,
.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.boundary {
  margin-top: auto;
  padding: 18px 6px 4px;
}

.boundary p:last-child {
  margin: 8px 0 0;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 18px;
  max-width: 1320px;
}

.topbar h2 {
  margin-top: 5px;
  font-size: clamp(25px, 3vw, 42px);
  line-height: 1.08;
  font-weight: 700;
}

.topbar p:last-child {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.icon-toggle {
  width: 40px;
  padding: 0;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.ghost-button {
  padding: 0 14px;
  background: var(--panel-soft);
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button {
  min-width: 112px;
  padding: 0 18px;
  border-color: var(--ink);
  color: var(--surface);
  background: var(--ink);
}

.primary-button:hover,
.new-button:hover {
  background: #39342c;
}

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

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 318px;
  align-items: start;
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto;
}

.conversation {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.input-panel,
.report-panel,
.inspector {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel,
.report-panel {
  overflow: hidden;
}

.input-header,
.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--band);
}

.input-header h3,
.report-header h3 {
  margin-top: 5px;
  font-size: 18px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 20px 0;
}

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

.is-muted {
  opacity: 0.46;
}

label {
  display: grid;
  gap: 8px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: #191511;
}

:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color: #7f715f;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 136px;
  padding: 12px;
  resize: vertical;
  line-height: 1.68;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.question-field {
  padding: 18px 20px 0;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px 20px;
}

.actions p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.result-content {
  padding: 20px;
  color: var(--ink);
  line-height: 1.82;
}

.followup-panel {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  background: var(--band-soft);
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-prompts button {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-soft);
  cursor: pointer;
}

.quick-prompts button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.followup-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  align-items: end;
}

.followup-form textarea {
  min-height: 78px;
}

.followup-question {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--band-soft);
}

.report-block + .report-block {
  margin-top: 26px;
}

.result-content h2,
.result-content h3 {
  margin: 0 0 12px;
  letter-spacing: 0;
}

.result-content h2 {
  font-size: 24px;
  line-height: 1.25;
}

.result-content h3 {
  font-size: 17px;
}

.result-content p {
  margin: 8px 0;
}

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

.result-content li {
  margin: 8px 0;
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.summary-strip span,
.tag,
.keyword-list span {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.summary-strip span {
  padding: 6px 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--band);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  min-width: 640px;
  width: 100%;
  margin: 12px 0 16px;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-size: 14px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

:root[data-theme="dark"] td {
  background: rgba(33, 28, 23, 0.42);
}

th {
  color: var(--muted);
  background: var(--band-strong);
  font-weight: 750;
}

tr:last-child td {
  border-bottom: 0;
}

.tag {
  margin: 0 6px 6px 0;
  padding: 4px 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

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

.clue-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--band-soft);
}

.clue-card span {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.clue-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

blockquote {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  border-radius: 0 7px 7px 0;
  color: var(--muted);
  background: var(--accent-softer);
}

.hexagram-card {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--band-soft);
}

.hexagram-lines {
  display: grid;
  gap: 7px;
}

.hexagram-lines span {
  position: relative;
  display: block;
  height: 8px;
  border-radius: 99px;
  background: var(--ink);
}

.hexagram-lines .yin {
  background:
    linear-gradient(90deg, var(--ink) 0 42%, transparent 42% 58%, var(--ink) 58%);
}

.hexagram-lines .moving::after {
  content: "";
  position: absolute;
  right: -13px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
}

.hexagram-title {
  font-weight: 750;
}

.refusal {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 16px;
  background: var(--accent-softer);
}

.loading-state,
.ai-warning,
.ai-source {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--band-soft);
}

.loading-state {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 16px;
}

.loading-state h2 {
  margin-bottom: 4px;
}

.loader {
  width: 24px;
  height: 24px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.ai-warning {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-color: var(--line-strong);
  background: var(--accent-softer);
}

.ai-warning p {
  margin: 6px 0 0;
  color: var(--muted);
}

.ai-source {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 12px;
}

.ai-source span {
  color: var(--accent-dark);
  font-weight: 750;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-strong);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

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

.inspector {
  position: sticky;
  top: 22px;
  display: grid;
  gap: 0;
  overflow: hidden;
  max-height: calc(100vh - 44px);
  overflow-y: auto;
}

.inspector-section {
  padding: 16px;
}

.inspector-section + .inspector-section {
  border-top: 1px solid var(--line);
}

.section-heading span {
  color: var(--muted);
  font-size: 12px;
}

.mini-chart p,
.inspector-section p {
  margin: 8px 0 0;
}

.mini-grid {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px 10px;
  margin-top: 10px;
}

.mini-grid span {
  color: var(--muted);
  font-size: 12px;
}

.mini-grid strong {
  font-size: 14px;
}

.element-bars {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.element-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 18px;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-strong);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

* {
  scrollbar-color: var(--line-strong) transparent;
}

.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.keyword-list span {
  padding: 5px 9px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

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

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

  .inspector-section + .inspector-section {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .inspector-section:nth-child(odd) {
    border-left: 0;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mode-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 12px;
  }

  .nav-title {
    flex: 0 0 100%;
  }

  .mode-button {
    min-width: 210px;
  }

  .boundary {
    margin-top: 0;
  }

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

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 16px 12px;
  }

  .topbar {
    flex-direction: column;
  }

  .toolbar,
  .ghost-button,
  .primary-button {
    width: 100%;
  }

  .toolbar {
    flex-direction: column;
  }

  .mode-nav,
  .form-grid,
  .context-grid,
  .inspector,
  .clue-grid {
    grid-template-columns: 1fr;
  }

  .mode-nav {
    display: flex;
  }

  .inspector-section + .inspector-section {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .input-header,
  .report-header,
  .actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .hexagram-card {
    grid-template-columns: 1fr;
  }

  .followup-form {
    grid-template-columns: 1fr;
  }
}
