:root {
    --ink: #172a23;
    --ink-soft: #24312c;
    --celadon: #e8efeb;
    --paper: #f7f9f7;
    --paper-deep: #eef3ef;
    --muted: #66736d;
    --line: #cbd7d0;
    --profit: #b64732;
    --loss: #3e6658;
    --warning: #9a742e;
    --focus: #1e6650;
    --display: STKaiti, KaiTi, serif;
    --body: "Microsoft YaHei", "PingFang SC", sans-serif;
    --data: Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { background: var(--celadon); color: var(--ink-soft); }

body {
    margin: 0;
    min-width: 320px;
    font: 15px/1.55 var(--body);
    background: var(--celadon);
}

button, input, select { font: inherit; }

button, a, select, input { -webkit-tap-highlight-color: transparent; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

.ledger-shell {
    width: min(1840px, calc(100% - 32px));
    margin: 24px auto 48px;
    background: var(--paper);
    border: 1px solid rgba(23, 42, 35, .24);
}

.ledger-masthead {
    min-height: 118px;
    padding: 24px 28px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    color: #f4f7f5;
    background: var(--ink);
    border-bottom: 4px solid var(--profit);
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.ledger-masthead .eyebrow { color: #afc2b8; }

h1, h2 { margin: 0; color: var(--ink); font-family: var(--display); font-weight: 700; }

h1 { color: inherit; font-size: clamp(32px, 4vw, 52px); line-height: 1; letter-spacing: .08em; }

h2 { font-size: clamp(22px, 2vw, 30px); }

.cutoff-block { text-align: right; }
.cutoff-block span { display: block; color: #afc2b8; font-size: 13px; letter-spacing: .08em; }
.cutoff-block strong { font: 700 22px/1.3 var(--data); }

.control-rail {
    padding: 18px 24px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 22px;
    border-bottom: 1px solid var(--line);
    background: var(--paper-deep);
}

.query-form, .update-block { display: flex; align-items: flex-end; gap: 14px; }
.query-form label > span, .period-picker legend { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.period-picker { margin: 0; padding: 0; border: 0; }

select, input[type="number"] {
    height: 40px;
    padding: 0 34px 0 11px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid #9fb1a8;
    border-radius: 3px;
}

input[type="number"] { width: 92px; padding-right: 8px; font-family: var(--data); }

.quick-periods { display: flex; height: 40px; border: 1px solid #9fb1a8; border-radius: 3px; overflow: hidden; }
.quick-periods a, .quick-periods span { min-width: 44px; padding: 9px 10px; text-align: center; text-decoration: none; border-right: 1px solid var(--line); }
.quick-periods a { color: var(--ink); background: var(--paper); }
.quick-periods a:hover, .quick-periods a[aria-current="page"] { color: #fff; background: var(--ink); }
.quick-periods > :last-child { border-right: 0; }
.period-disabled { color: #9aa59f; background: #e4e9e5; cursor: not-allowed; }

.apply-button, .update-button {
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--ink);
    border-radius: 3px;
    font-weight: 700;
    cursor: pointer;
}

.apply-button { color: var(--paper); background: var(--ink); text-decoration: none; }
.update-button { color: var(--ink); background: transparent; }
.update-button { white-space: nowrap; }
.apply-button:hover, .update-button:hover { color: #fff; background: var(--profit); border-color: var(--profit); }
.update-button:disabled { opacity: .6; cursor: wait; }

.update-block { margin-left: auto; }
.update-copy { max-width: 340px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--warning); }
.status-dot.is-ok { background: var(--loss); }

.notice { margin: 16px 24px 0; padding: 10px 12px; border-left: 3px solid var(--loss); background: #edf4f0; }
.notice-warning { border-left-color: var(--warning); background: #f5f0e4; }

.report-heading { padding: 26px 24px 15px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.report-heading > p { margin: 0; color: var(--muted); font-size: 13px; }

.table-scroll { overflow-x: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }
.summary-table { min-width: 1280px; }

th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.summary-table > thead th { position: sticky; top: 0; z-index: 2; height: 44px; color: #eaf0ed; background: var(--ink); font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.summary-row { min-height: 44px; cursor: pointer; transition: background-color 160ms ease; }
.summary-row:hover, .summary-row.is-open { background: #edf3ef; }
.summary-row:last-of-type td, .summary-row:last-of-type th { border-bottom: 0; }
.number { text-align: right; font-family: var(--data); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ratio-cell { white-space: nowrap; font-family: var(--data); }
.ratio-cell span { color: #a3afa8; }

.row-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--ink); background: transparent; border: 0; font-weight: 700; cursor: pointer; }
.toggle-mark { width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid #91a69b; border-radius: 50%; font: 15px/1 var(--data); }
.summary-row.is-open .toggle-mark { color: #fff; background: var(--ink); border-color: var(--ink); }

.is-profit { color: var(--profit); font-weight: 700; }
.is-loss { color: var(--loss); font-weight: 700; }
.is-even { color: var(--muted); }

.candidate-cell { min-width: 250px; }
.candidate-marks { display: flex; flex-wrap: wrap; gap: 4px; }
.zodiac-mark, .actual-mark {
    width: 27px;
    height: 27px;
    display: inline-grid;
    place-items: center;
    color: var(--ink);
    background: #edf2ee;
    border: 1px solid #a9bbb1;
    border-radius: 4px 4px 9px 4px;
    font-family: var(--display);
    font-weight: 700;
}
.candidate-marks.is-compact .zodiac-mark { width: 24px; height: 24px; font-size: 13px; }
.actual-mark { color: #fff; background: var(--profit); border-color: var(--profit); }
.no-candidate { color: var(--muted); font-size: 13px; white-space: nowrap; }

.js .detail-row { display: none; }
.js .detail-row.is-open { display: table-row; }
.js .detail-row summary { display: none; }
.detail-row > td { padding: 0; background: #e4ece7; border-bottom: 2px solid #8da197; }
.detail-row details > summary { padding: 12px 24px; color: var(--ink); cursor: pointer; font-weight: 700; }
.detail-wrap { padding: 18px 24px 22px 52px; }
.detail-caption { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.detail-scroll { overflow-x: auto; }
.detail-table { min-width: 920px; background: var(--paper); border: 1px solid var(--line); }
.detail-table th { color: var(--muted); background: #edf2ee; font-size: 12px; }
.detail-table td, .detail-table th { padding: 8px 10px; }
.date-cell { font-family: var(--data); white-space: nowrap; }
.result-badge {
    min-width: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: .04em;
}
.result-badge.is-hit {
    color: #07351f;
    background: #19d878;
    border-color: #06a858;
}
.result-badge.is-miss {
    color: #3a0b08;
    background: #ff5a50;
    border-color: #df332a;
}
.result-badge.is-skip {
    color: #51615a;
    background: #e0e7e3;
    border-color: #b5c1ba;
}

.ledger-notes { padding: 22px 24px 28px; }
.filter-legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 18px; }
.filter-legend p { margin: 0; color: var(--muted); font-size: 13px; }
.filter-legend b { color: var(--ink); font-size: 17px; }
.risk-note { margin: 18px 0 0; padding-top: 15px; color: #6e5829; border-top: 1px solid var(--line); font-size: 13px; }

.error-shell { width: min(680px, calc(100% - 32px)); margin: 12vh auto; padding: 32px; background: var(--paper); border-top: 5px solid var(--ink); }
.error-shell h1 { color: var(--ink); margin-bottom: 24px; }
.error-shell .apply-button { display: inline-block; margin-top: 16px; }

@media (max-width: 1100px) {
    .control-rail, .query-form { align-items: stretch; flex-wrap: wrap; }
    .update-block { width: 100%; justify-content: space-between; margin-left: 0; padding-top: 12px; border-top: 1px solid var(--line); }
    .filter-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .ledger-shell { width: 100%; margin: 0; border-left: 0; border-right: 0; }
    .ledger-masthead { min-height: 102px; padding: 20px 16px; align-items: flex-start; }
    .cutoff-block strong { font-size: 16px; }
    .control-rail, .report-heading, .ledger-notes { padding-left: 16px; padding-right: 16px; }
    .query-form { width: 100%; }
    .query-form label:first-child, .query-form label:first-child select { width: 100%; }
    .period-picker { max-width: 100%; overflow-x: auto; }
    .quick-periods a, .quick-periods span { min-width: 40px; }
    .report-heading { display: block; }
    .report-heading > p { margin-top: 8px; }
    .filter-legend { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
