.meihua-page {
    width: 100%;
    height: 100%;
    min-width: 0;
    justify-content: flex-start;
    overflow: hidden;
}

.meihua-topbar,
#page-meihua-history .history-topbar,
#page-meihua-stats .history-topbar,
#page-meihua-library .history-topbar {
    flex: 0 0 auto;
}

.meihua-workspace {
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 4px 4px 14px;
    overflow: auto;
    overscroll-behavior: contain;
}

.meihua-casting-panel,
.meihua-submit-panel,
.meihua-library-picker,
.meihua-stat-section {
    width: min(900px, 100%);
    margin: 0 auto 16px;
    padding: clamp(12px, 2vw, 20px);
    border-top: 2px solid var(--navy);
    border-bottom: 1px solid rgba(35, 47, 56, 0.45);
    background: rgba(232, 224, 203, 0.46);
}

.meihua-methods {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 12px;
}

.meihua-method {
    min-width: 0;
    min-height: 38px;
    border: 1px solid var(--navy);
    background: transparent;
    color: var(--navy);
}

.meihua-method.active {
    background: var(--red);
    color: var(--cream);
}

.meihua-method-panel {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(35, 47, 56, 0.35);
}

.meihua-method-panel[hidden] {
    display: none !important;
}

.meihua-method-panel p {
    margin: 0;
    color: #5f5d56;
    font-size: 0.82rem;
    line-height: 1.65;
}

.meihua-method-panel > .number-action {
    width: min(280px, 100%);
    justify-self: center;
}

.meihua-method-panel > label {
    color: #5f5d56;
    font-size: 0.84rem;
}

.meihua-number-entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.meihua-number-entry input {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 9px;
    border: 1px solid var(--navy);
    border-radius: 2px;
    background: var(--cream);
    color: var(--navy);
    box-sizing: border-box;
}

.meihua-input-grid,
.meihua-submit-grid,
.meihua-history-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.meihua-input-grid label,
.meihua-submit-grid label,
.meihua-history-controls label,
.user-preference-field {
    display: grid;
    min-width: 0;
    gap: 5px;
    color: #5f5d56;
    font-size: 0.84rem;
}

.meihua-input-grid select,
.meihua-submit-grid select,
.meihua-submit-grid input,
.meihua-history-controls select,
.meihua-history-controls input,
.user-preference-field select,
.meihua-library-picker select {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 9px;
    border: 1px solid var(--navy);
    background: #e8e0cb;
    color: var(--navy);
}

.meihua-figures {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(900px, 100%);
    min-width: 0;
    margin: 10px auto 18px;
    gap: clamp(10px, 3vw, 34px);
}

.meihua-figures[hidden],
.meihua-casting-panel[hidden],
.meihua-submit-panel[hidden],
.meihua-input-grid[hidden] {
    display: none !important;
}

.meihua-figure {
    display: grid;
    grid-template-rows: auto 32px minmax(112px, 1fr) 32px 5.2em;
    align-items: center;
    min-width: 0;
    padding: 10px 7px 14px;
    text-align: center;
    border-top: 5px solid var(--red);
    border-bottom: 1px solid var(--navy);
}

.meihua-figure-label {
    margin: 0 0 8px;
    color: var(--red);
    font-size: 1.15rem;
    font-weight: 700;
}

.meihua-trigram-name {
    width: 100%;
    margin: 7px 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--navy);
    font-weight: 700;
    letter-spacing: 0.1em;
    cursor: pointer;
}

.meihua-hexagram-lines {
    display: grid;
    width: min(130px, 88%);
    margin: 0 auto;
    gap: 10px;
}

.meihua-trigram-lines {
    display: grid;
    width: 100%;
    padding: 0;
    gap: 6px;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.meihua-yao {
    display: flex;
    height: 12px;
    justify-content: space-between;
    gap: 18%;
}

.meihua-yao i {
    display: block;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    height: 100%;
    background: var(--navy);
    box-shadow: none;
}

.meihua-yao.changed i {
    background: var(--red);
}

.meihua-hexagram-name {
    display: flex;
    height: 5.2em;
    width: 100%;
    min-width: 0;
    padding: 9px 3px 5px;
    align-items: flex-start;
    justify-content: center;
    line-height: 1.45;
    border: 0;
    border-top: 1px solid rgba(73, 15, 18, 0.5);
    background: transparent;
    color: var(--red);
    cursor: pointer;
    overflow-wrap: anywhere;
    overflow-y: auto;
}

.meihua-submit-panel textarea {
    width: 100%;
    min-height: 150px;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--navy);
    background: #e8e0cb;
    color: var(--navy);
}

.meihua-history-controls {
    width: min(900px, 100%);
    padding: 12px;
    overflow: auto;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
}

.meihua-history-detail-top {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.meihua-history-detail-meta {
    margin: 0 0 9px;
    padding: 0 4px 8px;
    border-bottom: 1px solid rgba(35, 47, 56, 0.4);
    color: var(--navy);
    font-size: 0.8rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.meihua-history-item .history-item-title {
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
}

.meihua-history-figures {
    width: 100%;
    height: auto;
    min-height: 0;
    margin: 0;
    align-items: stretch;
}

.meihua-history-figures .meihua-figure {
    width: 100%;
    height: 100%;
    grid-template-rows: auto 28px minmax(86px, 1fr) 28px 5.2em;
    padding-top: 4px;
    padding-bottom: 5px;
}

.meihua-stats-results {
    width: 100%;
    min-width: 0;
    overflow: visible;
    flex: 0 0 auto;
}

#page-meihua-stats {
    overflow-x: hidden;
    overflow-y: auto;
}

.meihua-stat-section h3 {
    margin: 0 0 4px;
    color: var(--red);
}

.meihua-stat-row {
    display: grid;
    grid-template-columns: minmax(70px, 0.35fr) minmax(100px, 1fr) 42px;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    font-size: 0.82rem;
}

.meihua-stat-row i {
    height: 8px;
    background: linear-gradient(90deg, var(--red) 0 var(--bar), rgba(35,47,56,.13) var(--bar) 100%);
}

.meihua-rating-summary {
    width: min(900px, 100%);
    margin: 0 auto 10px;
    padding: 10px;
    background: var(--navy);
    color: var(--cream);
}

.meihua-library-workspace {
    width: min(900px, 100%);
    min-height: 0;
    flex: 1;
    overflow: auto;
    padding: 8px 2px 16px;
}

.meihua-library-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.meihua-library-search {
    width: 100%;
    margin: 0;
}

.meihua-library-search-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.meihua-library-search-row > label {
    color: var(--red);
    font-size: 0.8rem;
    white-space: nowrap;
}

.meihua-library-search input {
    width: 100%;
    min-height: 40px;
    padding: 0 38px 0 9px;
    border: 1px solid var(--navy);
    border-radius: 2px;
    background: var(--cream);
    color: var(--navy);
    box-sizing: border-box;
}

.meihua-library-search .history-kind-combobox-toggle {
    height: 40px;
}

#meihua-library-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.meihua-library-search-list {
    max-height: min(320px, 48dvh);
}

.meihua-library-switch button {
    min-height: 42px;
    border: 1px solid var(--navy);
    background: transparent;
    color: var(--navy);
}

.meihua-library-switch button.active {
    background: var(--red);
    color: var(--cream);
}

.meihua-library-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
    gap: 8px;
}

.meihua-library-item {
    display: grid;
    min-width: 0;
    min-height: 74px;
    padding: 10px 12px;
    gap: 5px;
    text-align: left;
    border: 1px solid var(--navy);
    border-top: 5px solid var(--red);
    background: #e8e0cb;
    color: var(--navy);
    cursor: pointer;
}

.meihua-library-item strong {
    color: var(--red);
}

.meihua-library-item span {
    color: #67665f;
    font-size: .8rem;
}

.meihua-detail-modal {
    z-index: 70;
}

.meihua-detail-track {
    position: absolute;
    left: 50%;
    top: 50%;
    display: grid;
    grid-template-columns: 330px 280px 330px;
    grid-template-rows: auto auto;
    grid-template-areas:
        "relation note ."
        "library center custom";
    align-items: start;
    gap: 46px 54px;
    transform-origin: center;
    will-change: transform;
    isolation: isolate;
}

.meihua-detail-track > article {
    position: relative;
    z-index: 2;
    box-shadow: 6px 6px 0 var(--navy);
}

.meihua-detail-library-panel { grid-area: library; }
.meihua-detail-center { grid-area: center; }
.meihua-detail-custom-panel { grid-area: custom; }
.meihua-detail-relation-panel { grid-area: relation; }
.meihua-detail-note-slot {
    grid-area: note;
    position: relative;
    z-index: 2;
    width: 400px;
    justify-self: center;
}

.meihua-detail-library-panel,
.meihua-detail-custom-panel {
    height: min(490px, 68dvh);
}

.meihua-detail-library-panel {
    margin-top: 8px;
}

.meihua-detail-custom-panel {
    width: 315px;
    height: min(450px, 63dvh);
    margin-top: 15px;
    justify-self: center;
}

.meihua-detail-relation-panel {
    width: 266px;
    min-height: 306px;
    height: auto;
    margin-top: 12px;
    margin-left: 34px;
    justify-self: start;
    overflow: visible;
}

.meihua-detail-center {
    width: 274px;
    min-height: 420px;
    padding: 18px;
    justify-self: center;
}

.meihua-detail-symbol {
    display: flex;
    min-height: 230px;
    align-items: center;
    justify-content: center;
}

.meihua-detail-symbol-lines {
    display: grid;
    width: 210px;
    gap: 10px;
}

.meihua-detail-symbol-lines .meihua-yao {
    height: 17px;
}

.meihua-detail-meta {
    display: grid;
    gap: 6px;
    margin: 12px 0 0;
}

.meihua-detail-meta span {
    padding: 5px 8px;
    border: 1px solid rgba(35,47,56,.45);
    background: var(--cream);
    color: var(--red);
}

.meihua-detail-symbol-pager {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.meihua-detail-symbol-pager[hidden] {
    display: none !important;
}

.meihua-library-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.meihua-library-tabs button {
    min-width: 0;
    min-height: 40px;
    border: 1px solid var(--navy);
    background: transparent;
    color: var(--navy);
}

.meihua-library-tabs button.active {
    background: var(--red);
    color: var(--cream);
}

.meihua-detail-content {
    min-height: 220px;
    margin-top: 10px;
    padding: 10px 2px;
    border: 0;
    background: transparent;
    line-height: 1.75;
}

.meihua-detail-content blockquote {
    margin: 14px 0;
    padding: 10px 14px;
    border-left: 5px solid var(--red);
    color: #5f5d56;
}

.meihua-ancient-text > p:not(.muted) {
    white-space: pre-line;
}

.meihua-modern-note {
    margin-top: 8px;
    padding: 8px 10px;
    border-left: 3px solid var(--red);
    color: #5f5d56;
}

.meihua-modern-note strong {
    color: var(--red);
}

.meihua-modern-lines {
    display: grid;
    gap: 10px;
}

.meihua-modern-lines section {
    padding: 9px 10px;
    border: 1px solid rgba(31, 48, 58, 0.34);
    background: rgba(239, 230, 204, 0.24);
}

.meihua-modern-lines h4,
.meihua-modern-lines p {
    margin: 0;
}

.meihua-modern-lines h4 {
    margin-bottom: 5px;
    color: var(--navy);
}

.meihua-modern-lines .meihua-modern-note {
    margin-top: 7px;
}

.meihua-modern-source {
    margin-top: 14px;
}

.meihua-library-pager {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    text-align: center;
}

.meihua-detail-relation-panel[hidden] {
    display: none !important;
}

.meihua-detail-session-note {
    margin: 0;
}

.meihua-detail-session-note textarea {
    min-height: 110px;
}

.meihua-overall-modal {
    z-index: 72;
}

.meihua-overall-track {
    position: absolute;
    left: 50%;
    top: 50%;
    display: grid;
    grid-template-columns: 270px 70px 270px 270px 270px;
    grid-template-rows: 420px 310px 420px;
    align-items: start;
    gap: 26px 30px;
    transform-origin: center;
    will-change: transform;
    isolation: isolate;
}

.meihua-overall-track > article,
.meihua-overall-note-slot {
    position: relative;
    z-index: 2;
}

.meihua-overall-note-slot {
    grid-column: 3;
    grid-row: 1;
    width: 290px;
    justify-self: center;
    transform: translateY(-24px);
}

.meihua-overall-session-note {
    margin: 0;
}

.meihua-overall-session-note textarea {
    min-height: 245px;
    max-height: 270px;
}

.meihua-overall-elements-card {
    grid-column: 1;
    grid-row: 1;
    width: 270px;
    height: 400px;
    margin-top: 170px;
    margin-left: 85px;
    overflow: visible;
    box-shadow: 5px 5px 0 var(--navy);
}

.meihua-overall-tiyong-card {
    grid-column: 1;
    grid-row: 2;
    width: 270px;
    min-height: 430px;
    margin-top: 160px;
    margin-left: 85px;
    height: auto;
    overflow: visible;
    box-shadow: 5px 5px 0 var(--navy);
}

#meihua-overall-original-gua {
    grid-column: 3;
    grid-row: 2;
}

#meihua-overall-mutual-gua {
    grid-column: 4;
    grid-row: 2;
}

#meihua-overall-changed-gua {
    grid-column: 5;
    grid-row: 2;
}

#meihua-overall-original {
    grid-column: 3;
    grid-row: 3;
}

#meihua-overall-mutual-upper {
    grid-column: 4;
    grid-row: 1;
}

#meihua-overall-mutual-lower {
    grid-column: 4;
    grid-row: 3;
}

#meihua-overall-changed {
    grid-column: 5;
    grid-row: 3;
}

.meihua-overall-source {
    box-sizing: border-box;
    width: 100%;
    height: 400px;
    overflow: auto;
    box-shadow: 5px 5px 0 var(--navy);
}

#meihua-overall-mutual-upper {
    height: 400px;
}

#meihua-overall-mutual-lower {
    height: 400px;
}

.meihua-overall-source > .eyebrow,
.meihua-overall-source > h3 {
    margin-top: 0;
    text-align: center;
}

.meihua-overall-source > h3 {
    min-height: 2.4em;
    color: var(--red);
    line-height: 1.25;
}

.meihua-overall-symbol {
    display: grid;
    width: 150px;
    margin: 8px auto 14px;
    gap: 6px;
}

.meihua-overall-symbol.trigram {
    width: 118px;
    gap: 5px;
}

.meihua-overall-symbol .meihua-yao {
    height: 10px;
}

.meihua-overall-symbol.trigram .meihua-yao {
    height: 9px;
}

.meihua-overall-tabs.tabs-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.meihua-overall-tabs button {
    min-height: 36px;
    padding: 4px 2px;
    font-size: .72rem;
}

.meihua-overall-content {
    min-height: 0;
    margin-top: 8px;
    padding-bottom: 0;
}

.meihua-overall-editor {
    min-height: 280px;
}

#meihua-overall-mutual-upper .meihua-overall-editor {
    min-height: 150px;
}

#meihua-overall-mutual-lower .meihua-overall-editor {
    min-height: 230px;
}

.meihua-overall-gua-card {
    display: grid;
    grid-template-rows: 26px 40px 160px 32px;
    align-items: center;
    box-sizing: border-box;
    width: 270px;
    height: 300px;
    padding: 16px;
    text-align: center;
    box-shadow: 5px 5px 0 var(--navy);
}

.meihua-overall-gua-card > .eyebrow,
.meihua-overall-gua-card > h3 {
    margin-top: 0;
}

.meihua-overall-gua-card > h3 {
    color: var(--red);
}

.meihua-overall-gua-card .meihua-overall-symbol {
    width: 170px;
    height: 150px;
    margin: 0 auto;
    align-content: center;
    gap: 10px;
}

.meihua-overall-mutual-gua {
    display: grid;
}

.meihua-overall-mutual-lines {
    position: relative;
    display: grid;
    grid-template-rows: repeat(6, 10px);
    align-content: center;
    width: 170px;
    height: 150px;
    margin: 0 auto;
    gap: 10px;
}

.meihua-overall-mutual-lines::after {
    content: "";
    position: absolute;
    left: -10px;
    right: -10px;
    top: 50%;
    height: 2px;
    background: var(--red);
    transform: translateY(-1px);
}

.meihua-overall-mutual-gua > h3 {
    margin: 0;
    color: var(--navy);
}

.meihua-overall-mutual-lines .meihua-overall-symbol {
    display: contents;
}

.meihua-overall-mutual-gua > h3:last-child {
    grid-row: 4;
}

.meihua-overall-fixed,
.meihua-overall-responses {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(122, 30, 36, .45);
}

.meihua-overall-fixed p,
.meihua-overall-responses p {
    margin: 5px 0;
    line-height: 1.55;
}

.meihua-overall-fixed strong {
    color: var(--red);
}

.meihua-overall-fixed .relation,
.meihua-overall-responses p.outgoing,
.meihua-overall-responses p.incoming {
    color: var(--navy);
}

.meihua-overall-responses p.neutral {
    color: var(--navy);
}

.meihua-overall-elements-card .meihua-five-elements {
    width: 235px;
}

.meihua-overall-elements-card .meihua-five-elements circle {
    fill: var(--cream);
    stroke: rgba(35, 47, 56, .38);
    stroke-width: 1.5;
}

.meihua-overall-elements-card .meihua-five-elements text {
    fill: #72716a;
}

.meihua-overall-elements-card .meihua-five-elements g.self circle {
    fill: var(--red);
    stroke: var(--red);
    stroke-width: 3;
}

.meihua-overall-elements-card .meihua-five-elements g.self text {
    fill: var(--cream);
}

.meihua-overall-elements-card .meihua-five-elements g.other circle {
    fill: var(--cream);
    stroke: var(--red);
    stroke-width: 3;
}

.meihua-overall-elements-card .meihua-five-elements g.other text {
    fill: var(--red);
}

.meihua-overall-elements-card .meihua-five-elements g.related circle {
    fill: var(--cream);
    stroke: var(--navy);
    stroke-width: 3;
}

.meihua-overall-elements-card .meihua-five-elements g.related text {
    fill: var(--navy);
}

.meihua-overall-elements-card .meihua-five-elements line.incoming,
.meihua-overall-elements-card .meihua-five-elements line.outgoing {
    stroke: var(--navy);
    stroke-width: 3.5;
}

.meihua-five-elements {
    width: min(230px, 100%);
    margin: 6px auto 0;
    padding: 8px;
    border: 1px solid rgba(35,47,56,.45);
    background: var(--cream);
    box-sizing: border-box;
}

.meihua-shao-possibilities section {
    margin-top: 10px;
    padding: 8px 10px;
    border-left: 3px solid var(--red);
    background: rgba(232, 224, 203, 0.5);
}

.meihua-shao-possibilities h4,
.meihua-shao-possibilities p {
    margin: 0;
}

.meihua-shao-possibilities section p + p {
    margin-top: 4px;
    color: var(--red);
}

.meihua-five-elements svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.meihua-five-elements line {
    stroke: rgba(35,47,56,.22);
    stroke-width: 1.5;
}

.meihua-five-elements line.controls {
    stroke-dasharray: 4 3;
}

.meihua-five-elements line.incoming {
    stroke: #234d6b;
    stroke-width: 3;
}

.meihua-five-elements line.outgoing {
    stroke: #7a1e24;
    stroke-width: 3;
}

.meihua-five-elements circle {
    fill: #e8e0cb;
    stroke: var(--navy);
}

.meihua-five-elements g.self circle {
    fill: var(--navy);
    stroke-width: 2.5;
}

.meihua-five-elements g.other circle {
    fill: var(--cream);
    stroke: var(--red);
    stroke-width: 2.5;
}

.meihua-five-elements text {
    text-anchor: middle;
    fill: var(--navy);
    font-weight: 700;
}

.meihua-five-elements g.self text {
    fill: var(--cream);
}

.meihua-five-elements-legend {
    margin: 5px 0 0;
    color: #67665f;
    font-size: .78rem;
    line-height: 1.5;
}

.meihua-five-elements-key {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    color: var(--navy);
}

.meihua-five-elements-key span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.meihua-five-elements-key i {
    display: inline-block;
    box-sizing: border-box;
    width: 15px;
    height: 15px;
    border: 2px solid var(--red);
    border-radius: 50%;
}

.meihua-five-elements-key i.ti {
    background: var(--red);
}

.meihua-five-elements-key i.yong {
    background: transparent;
}

.user-preference-section {
    margin: 20px 0;
    padding: 16px 0;
    border-top: 1px solid var(--navy);
    border-bottom: 1px solid var(--navy);
}

.user-preference-section .number-action {
    width: 100%;
    margin-top: 9px;
}

@media (max-width: 620px) {
    .meihua-input-grid,
    .meihua-submit-grid {
        grid-template-columns: 1fr;
    }

    .meihua-figures {
        gap: 5px;
    }

    .meihua-figure {
        padding-inline: 2px;
    }

    .meihua-hexagram-lines {
        width: min(94px, 92%);
        gap: 5px;
    }

    .meihua-yao {
        height: 9px;
    }

    .meihua-trigram-name,
    .meihua-hexagram-name {
        font-size: clamp(.68rem, 3vw, .86rem);
    }

    .meihua-history-controls {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .meihua-detail-track { gap: 34px; }

    .meihua-number-entry {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 260px) {
    .meihua-methods {
        grid-template-columns: 1fr;
    }

    .meihua-figures {
        grid-template-columns: 1fr;
    }

    .meihua-figure {
        width: 100%;
    }

    .meihua-history-detail-top {
        overflow: auto;
    }

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