:root {
  color-scheme: light;
  --background: #f4f1ea;
  --paper: #fdfbf7;
  --paper-soft: #faf7f0;
  --paper-muted: #ede8dc;
  --paper-deep: #e8e3d8;
  --ink: #1f2421;
  --ink-strong: #141816;
  --ink-muted: #5e6864;
  --outline: #dcd6c8;
  --outline-soft: rgba(31, 36, 33, 0.08);
  --primary: #104640;
  --primary-hover: #1b4f48;
  --secondary: #ae3024;
  --secondary-hover: #8c170f;
  --tertiary: #8c6b2d;
  --tertiary-soft: #eae4d4;
  --shadow-soft: 0 2px 10px rgba(44, 94, 87, 0.04);
  --shadow-lift: 0 12px 32px -4px rgba(31, 36, 33, 0.07),
    0 2px 8px rgba(44, 94, 87, 0.03);
  font-family:
    "Plus Jakarta Sans", Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--background);
  background-image:
    radial-gradient(#e5dfd3 1px, transparent 1px),
    radial-gradient(#ebe6dc 1px, var(--background) 1px);
  background-position:
    0 0,
    20px 20px;
  background-size: 40px 40px;
}

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

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--outline);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-soft);
  outline: none;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease;
}

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

textarea {
  min-height: 96px;
  resize: vertical;
  padding: 12px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

input::placeholder,
textarea::placeholder {
  color: rgba(94, 104, 100, 0.72);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-style: italic;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.04),
    0 0 0 1px rgba(16, 70, 64, 0.2);
}

input[readonly] {
  color: var(--primary);
  background: var(--paper-muted);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-weight: 600;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid #e2ddd3;
  background: rgba(250, 247, 241, 0.95);
  box-shadow: 0 2px 12px rgba(44, 94, 87, 0.06);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  flex: 1 1 320px;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid #dacfb9;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(31, 36, 33, 0.08);
}

.brand-mark svg {
  display: block;
  width: 48px;
  height: 48px;
}

.brand-copy {
  min-width: 0;
}

.brand-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.brand-meta > span {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(140, 107, 45, 0.45);
}

.eyebrow {
  margin: 0;
  color: var(--tertiary);
  font-family: "Space Grotesk", ui-monospace, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.powered {
  margin: 0;
  color: var(--ink-muted);
  font-family: "Space Grotesk", ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: "Noto Serif SC", "Songti SC", serif;
  letter-spacing: 0;
}

.brand h1 {
  margin: 2px 0 0;
  color: var(--primary);
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  font-weight: 700;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.top-actions,
.button-line,
.meta-strip,
.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex: 1 1 360px;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}

.primary-button,
.secondary-button,
.icon-button,
.moving-picker button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(16, 70, 64, 0.22);
}

.primary-button::before {
  content: "▣";
  font-size: 0.92rem;
  line-height: 1;
}

.primary-button:hover {
  background: var(--primary-hover);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.moving-picker button:active {
  transform: scale(0.98);
}

.secondary-button {
  padding: 0 14px;
  color: var(--primary);
  background: var(--paper-muted);
  border-color: #d4cbba;
  font-family: "Noto Serif SC", "Songti SC", serif;
}

.secondary-button:hover,
.icon-button:hover,
.moving-picker button:hover {
  color: var(--primary);
  border-color: var(--tertiary);
  background: #ffffff;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  border-color: #d6cfbe;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1rem;
}

.status-pill,
.meta-strip span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid #d6cfbe;
  border-radius: 999px;
  color: var(--ink-muted);
  background: #e8e4da;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 999px;
  background: var(--primary);
}

.status-pill.is-error {
  color: var(--secondary);
  border-color: rgba(174, 48, 36, 0.28);
  background: rgba(174, 48, 36, 0.08);
}

.status-pill.is-error::before {
  background: var(--secondary);
}

.workspace {
  display: grid;
  grid-template-columns:
    minmax(300px, 4fr)
    minmax(470px, 5fr)
    minmax(320px, 3fr);
  align-items: start;
  gap: 22px;
  width: min(1720px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 2vw, 28px);
}

.input-panel,
.reading-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.input-group,
.chart-panel,
.reading-card,
.skill-prompt {
  min-width: 0;
  border: 1px solid #e2ded5;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.input-group,
.chart-panel,
.reading-card,
.skill-prompt {
  padding: clamp(16px, 1.7vw, 22px);
}

.input-group {
  display: grid;
  gap: 18px;
}

.chart-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.reading-card,
.skill-prompt {
  display: grid;
  gap: 16px;
}

.reading-card {
  grid-template-rows: auto minmax(0, 1fr);
}

.section-head,
.panel-title {
  justify-content: space-between;
  flex-wrap: wrap;
  min-width: 0;
  padding-bottom: 14px;
  border-bottom: 1px solid #ece8df;
}

.section-head h2,
.panel-title h2 {
  margin: 0;
  color: var(--primary);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.section-head::before {
  content: "";
  width: 7px;
  height: 24px;
  border-radius: 999px;
  background: var(--primary);
}

.input-group:nth-of-type(2) .section-head::before {
  background: var(--tertiary);
}

.input-group:nth-of-type(3) .section-head::before {
  background: var(--secondary);
}

.section-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.section-head h2 {
  grid-column: 2;
}

.section-head .eyebrow {
  grid-column: 3;
}

.section-head.compact {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 7px;
}

label > span,
.moving-block > span {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
}

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.button-line {
  justify-content: space-between;
  flex-wrap: wrap;
}

.inline-note,
.warning-line {
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.warning-line {
  margin: -4px 0 0;
  color: var(--secondary);
  font-weight: 700;
}

.moving-block {
  display: grid;
  gap: 8px;
}

.moving-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.moving-picker button {
  color: var(--ink);
  background: var(--paper-soft);
  border-color: var(--outline);
  font-family: "Noto Serif SC", "Songti SC", serif;
}

.moving-picker button.active {
  color: #ffffff;
  background: var(--secondary);
  border-color: var(--secondary);
  box-shadow: 0 0 14px rgba(185, 56, 43, 0.28);
}

.meta-strip {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.meta-strip span:first-child {
  color: var(--secondary);
  border-color: rgba(174, 48, 36, 0.2);
  background: rgba(174, 48, 36, 0.08);
}

.meta-strip span:nth-child(2) {
  color: var(--primary);
  border-color: rgba(16, 70, 64, 0.18);
  background: rgba(16, 70, 64, 0.08);
}

.meta-strip span:nth-child(3) {
  color: var(--ink);
  background: var(--tertiary-soft);
}

#chartTitle {
  color: var(--primary);
  font-size: clamp(1.35rem, 2.1vw, 1.85rem);
}

.hexagram-stage {
  display: grid;
  grid-template-columns: minmax(280px, 8fr) minmax(160px, 4fr);
  align-items: stretch;
  gap: 20px;
}

.hexagram-visual,
.trigram-stack div {
  border: 1px solid #e8e3d8;
  border-radius: 10px;
  background: var(--paper-soft);
}

.hexagram-visual {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  min-height: 300px;
  padding: 18px;
}

.visual-line {
  display: grid;
  grid-template-columns: 40px minmax(120px, 1fr) minmax(116px, 0.52fr);
  align-items: center;
  gap: 14px;
  min-height: 32px;
  border-radius: 6px;
  transition: background 0.16s ease;
}

.visual-line:hover {
  background: rgba(44, 94, 87, 0.05);
}

.line-label {
  color: var(--ink-muted);
  font-family: "Space Grotesk", ui-monospace, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

.line-info {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.yao {
  display: grid;
  width: 100%;
  height: 8px;
  border-radius: 2px;
}

.yao.solid {
  background: var(--primary);
}

.yao.broken {
  grid-template-columns: minmax(0, 1fr) minmax(34px, 20%) minmax(0, 1fr);
}

.yao.broken i {
  display: block;
  border-radius: 2px;
  background: var(--primary);
}

.yao.broken i:first-child {
  grid-column: 1;
}

.yao.broken i:last-child {
  grid-column: 3;
}

.visual-line.is-moving {
  margin-inline: -8px;
  padding: 6px 8px;
  background: rgba(174, 48, 36, 0.06);
}

.visual-line.is-moving .line-label,
.visual-line.is-moving .line-info {
  color: var(--secondary);
}

.visual-line.is-moving .line-label::after {
  content: "○";
  margin-left: 2px;
}

.visual-line.is-moving .yao.solid,
.visual-line.is-moving .yao.broken i {
  background: var(--secondary);
}

.visual-line.is-useful {
  margin-inline: -8px;
  padding: 6px 8px;
  border: 1px solid #d6cbba;
  background: rgba(234, 228, 212, 0.58);
}

.visual-line.is-useful .line-label,
.visual-line.is-useful .line-info {
  color: var(--tertiary);
}

.visual-line.is-useful .yao.solid,
.visual-line.is-useful .yao.broken i {
  background: var(--tertiary);
}

.trigram-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trigram-stack div {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 88px;
  padding: 12px;
  text-align: center;
}

.trigram-stack div:last-child {
  border-left: 3px solid var(--primary);
  background: #fffdf8;
}

.trigram-stack span {
  color: var(--ink-muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.trigram-stack strong {
  min-width: 0;
  margin-top: 4px;
  color: var(--primary);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.45rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.trigram-stack div:nth-child(2) strong {
  color: var(--secondary);
}

.trigram-stack div:last-child strong {
  color: var(--ink);
  font-size: 0.98rem;
}

.line-table-wrap {
  overflow-x: auto;
  border: 1px solid #e4dfd4;
  border-radius: 10px;
  background: #ffffff;
}

.line-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.line-table th,
.line-table td {
  padding: 12px 11px;
  border-bottom: 1px solid #ece7dc;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.line-table th {
  color: var(--ink-muted);
  background: var(--paper-muted);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.line-table td {
  color: var(--ink);
}

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

.line-table tbody tr:hover td {
  background: #faf7f2;
}

.line-table .selected-row td {
  color: var(--tertiary);
  background: rgba(234, 228, 212, 0.45);
  font-weight: 700;
}

.line-table tr:has(td:nth-child(6):not(:empty)) td:nth-child(6) {
  color: var(--ink-muted);
}

.reading-card {
  max-height: min(760px, calc(100dvh - 148px));
}

.reading-output {
  display: grid;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.reading-block {
  padding: 14px 14px 14px 16px;
  border: 1px solid #e8e3d8;
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  background: var(--paper-soft);
}

.reading-block.tone-secondary {
  border-left-color: var(--secondary);
  background: rgba(174, 48, 36, 0.05);
}

.reading-block.tone-tertiary {
  border-left-color: var(--tertiary);
}

.reading-block h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 700;
}

.reading-block h3::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.reading-block.tone-secondary h3 {
  color: var(--secondary);
}

.reading-block.tone-tertiary h3 {
  color: var(--tertiary);
}

.reading-block ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 1rem;
}

.reading-block li {
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.skill-prompt {
  align-self: stretch;
}

#skillPrompt {
  min-height: 190px;
  max-height: 340px;
  color: var(--ink);
  background: var(--paper-soft);
  font-family: "Space Grotesk", "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
    monospace;
  font-size: 0.78rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.reading-output::-webkit-scrollbar,
#skillPrompt::-webkit-scrollbar,
.line-table-wrap::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.reading-output::-webkit-scrollbar-thumb,
#skillPrompt::-webkit-scrollbar-thumb,
.line-table-wrap::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background: #c8c2b5;
}

.reading-output::-webkit-scrollbar-track,
#skillPrompt::-webkit-scrollbar-track,
.line-table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  }

  .reading-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.62fr);
    align-items: start;
  }

  .reading-card {
    max-height: none;
  }
}

@media (max-width: 960px) {
  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .workspace,
  .reading-panel {
    grid-template-columns: 1fr;
  }

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

  .reading-output {
    overflow: visible;
  }
}

@media (max-width: 680px) {
  .topbar {
    padding-inline: 14px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    flex-basis: 46px;
    width: 46px;
    height: 46px;
  }

  .brand-mark svg {
    width: 42px;
    height: 42px;
  }

  .brand-meta {
    gap: 6px;
  }

  .powered {
    flex-basis: 100%;
  }

  .workspace {
    padding: 14px;
    gap: 16px;
  }

  .input-panel,
  .reading-panel {
    gap: 16px;
  }

  .field-grid,
  .field-grid.three {
    grid-template-columns: 1fr;
  }

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

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .visual-line {
    grid-template-columns: 32px minmax(110px, 1fr);
    gap: 10px;
  }

  .line-info {
    grid-column: 2;
    white-space: normal;
  }

  .trigram-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .top-actions {
    display: grid;
    grid-template-columns: 38px 38px minmax(0, 1fr);
  }

  .top-actions .status-pill {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .primary-button {
    padding-inline: 10px;
  }

  .primary-button::before {
    content: "";
    display: none;
  }

  .brand h1 {
    font-size: 1.45rem;
  }
}
