:root {
  --bg: #f2eee6;
  --paper: #fffdf8;
  --ink: #1c1915;
  --muted: #756e64;
  --line: #ded6c9;
  --orange: #d95f34;
  --orange-dark: #a83e1f;
  --green: #267559;
  --gold: #c5963d;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .34;
  background-image: radial-gradient(#5b5145 0.55px, transparent 0.55px);
  background-size: 7px 7px;
}
.shell { width: calc(100% - 32px); max-width: 1080px; margin: 0 auto; padding: 56px 0 64px; position: relative; }
.hero { max-width: 760px; margin-bottom: 30px; }
.eyebrow { color: var(--orange-dark); font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.eyebrow span { display: inline-block; width: 26px; height: 2px; margin-right: 9px; vertical-align: middle; background: var(--orange); }
h1 { margin: 17px 0 18px; font-family: "Songti SC", STSong, serif; font-size: clamp(38px, 5.5vw, 64px); line-height: 1.08; letter-spacing: 0; }
h1 em { color: var(--orange); font-style: normal; }
.hero p { max-width: 620px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.8; }

.tabs { display: flex; gap: 8px; margin: 26px 0 20px; }
.tab-btn {
  padding: 10px 18px; border: 1px solid var(--line); border-radius: 99px;
  color: var(--muted); background: rgba(255,253,248,.75); cursor: pointer;
  font: inherit; font-weight: 700; font-size: 14px;
}
.tab-btn:hover { border-color: var(--orange); color: var(--orange); }
.tab-btn.is-active { color: #fff; background: var(--orange); border-color: var(--orange); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.calculator { display: grid; grid-template-columns: 1.05fr .95fr; gap: 20px; align-items: stretch; }
.card, .formula-card { border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,248,.94); box-shadow: 0 18px 50px rgba(67,48,28,.07); }
.card { padding: 26px; }
.card-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.card-heading > div { display: flex; align-items: center; gap: 12px; }
.step { color: var(--orange); font-size: 12px; font-weight: 800; letter-spacing: .08em; }
h2, h3 { margin: 0; }
h2 { font-size: 21px; }
.ghost-button, .primary-button { padding: 9px 14px; border-radius: 99px; cursor: pointer; font: inherit; font-weight: 700; font-size: 13px; }
.ghost-button { border: 1px solid var(--line); color: var(--muted); background: transparent; }
.ghost-button:hover { border-color: var(--orange); color: var(--orange); }
.primary-button { border: 1px solid var(--orange); color: #fff; background: var(--orange); }
.primary-button:hover { background: var(--orange-dark); }
.primary-button:disabled, .ghost-button:disabled { opacity: .5; cursor: not-allowed; }
.fields { display: grid; gap: 16px; }
.group-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.group-label span { font-size: 13px; font-weight: 800; }
.group-label small { color: var(--muted); font-size: 11px; }
.extra-title { margin-top: 24px; padding-top: 20px; border-top: 1px dashed var(--line); }
.triple { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.triple .input-wrap input { min-width: 0; padding: 12px; }
.triple label > span { display: block; min-height: 36px; }
.triple label i { display: block; margin-top: 3px; }
.warning { margin-top: 14px; padding: 11px 13px; border-radius: 9px; color: #806039; background: #faf0dc; font-size: 11px; line-height: 1.6; }
.warning b { color: #a44c27; }
label > span { display: flex; justify-content: space-between; margin-bottom: 8px; font-weight: 650; font-size: 14px; }
label i { color: var(--orange); font-size: 12px; font-style: normal; }
.input-wrap, .compact-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; transition: .2s; }
.input-wrap:focus-within, .compact-input:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(217,95,52,.1); }
input, select { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font: inherit; }
.input-wrap input { padding: 14px; font-size: 17px; }
.input-wrap b, .compact-input b { padding-right: 14px; color: #aaa197; font-size: 12px; white-space: nowrap; }
.target-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 22px; padding-top: 20px; border-top: 1px dashed var(--line); }
.target-row span { display: block; font-weight: 700; font-size: 14px; }
.target-row small { display: block; margin-top: 4px; color: var(--muted); }
.compact-input { width: 130px; }
.compact-input input { padding: 11px 12px; font-weight: 700; }
.submit-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 18px; align-items: end; }
.submit-row label, .rank-filters label, .modal-fields label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.submit-row select, .submit-row input, .rank-filters select, .rank-filters input, .modal-fields select, .modal-fields input {
  border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 11px 12px; font-size: 14px; color: var(--ink); font-weight: 500;
}
.inline-msg { display: block; min-height: 20px; margin-top: 8px; font-size: 12px; color: var(--green); }
.inline-msg.error { color: #b3372a; }

.result-card { color: #f9f5ed; background: #1d1915; border-color: #1d1915; }
.result-card .step { color: #ee8a62; }
.status { padding: 7px 11px; border-radius: 99px; font-size: 12px; font-weight: 800; }
.waiting { color: #bdb4aa; background: #302a25; }
.good { color: #d8f5e8; background: #256b52; }
.low { color: #ffd7c8; background: #8c3520; }
.score-block { padding: 20px 0 24px; }
.score-block > span, .score-block > small { display: block; color: #a99f94; }
.score-block strong { display: inline-block; margin: 8px 8px 5px 0; font-family: Georgia, serif; font-size: clamp(52px, 7vw, 76px); line-height: 1; font-variant-numeric: tabular-nums; }
.progress-track { height: 9px; overflow: hidden; border-radius: 99px; background: #3a332d; }
.progress-track div { width: 0; height: 100%; border-radius: inherit; background: var(--orange); transition: width .45s ease, background .2s; }
.progress-meta { display: flex; justify-content: space-between; margin-top: 10px; color: #aaa197; font-size: 12px; }
.progress-meta b { color: #fff; }
.contribution { margin-top: 30px; padding-top: 22px; border-top: 1px solid #3a332d; }
.contribution h3 { margin-bottom: 16px; font-size: 14px; }
.legend, .values { display: grid; grid-template-columns: repeat(3, 1fr); font-size: 11px; }
.legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--orange); }
.legend span:nth-child(2)::before { background: var(--gold); }
.legend span:nth-child(3)::before { background: var(--green); }
.stacked-bar { display: flex; height: 28px; overflow: hidden; margin: 10px 0; border-radius: 7px; background: #302a25; }
.stacked-bar i { width: 0; transition: width .45s ease; }
#physicalBar { background: var(--orange); } #speedBar { background: var(--gold); } #magicBar { background: var(--green); }
.values { color: #d2cbc2; font-variant-numeric: tabular-nums; }
.values span:nth-child(2) { text-align: center; }
.calculation { margin-top: 26px; padding-top: 22px; border-top: 1px solid #3a332d; }
.calculation h3 { margin-bottom: 12px; font-size: 14px; }
.calculation ol { margin: 0; padding-left: 18px; color: #c5bcb1; font-size: 12px; line-height: 1.9; }
.calculation strong { color: #fff; }

.formula-card { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 20px; padding: 28px; }
.formula-copy h2 { margin: 12px 0; font-size: 24px; }
.formula-copy p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.derivation { display: grid; gap: 10px; }
.derivation div { padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: #fbf7ef; }
.derivation b { display: block; margin-bottom: 4px; font-size: 13px; }
.derivation span { display: block; color: var(--muted); font-size: 12px; }
.derivation strong { color: var(--orange-dark); font-size: 13px; }
.full-formula { grid-column: 1 / -1; padding: 18px 20px; border-radius: 10px; color: #f6efe4; background: #241f19; }
.full-formula b { display: block; margin-bottom: 8px; color: #ee8a62; font-size: 13px; }
.full-formula code { display: block; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.8; }
.note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }

.ocr-card { max-width: 900px; }
.ocr-meta { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; font-size: 13px; color: var(--muted); }
.ocr-meta b { color: var(--ink); }
.upload-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 180px; border: 2px dashed var(--line); border-radius: 12px; background: #fbf7ef; cursor: pointer; text-align: center;
}
.upload-zone:hover, .upload-zone:focus { border-color: var(--orange); }
.upload-zone strong { font-size: 16px; }
.upload-zone small { color: var(--muted); }
.preview-wrap { margin-top: 14px; text-align: center; }
.preview-wrap canvas { max-width: 100%; max-height: 420px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.ocr-actions { display: flex; gap: 10px; margin: 16px 0; }
.ocr-raw { display: block; max-height: 220px; overflow: auto; padding: 14px; margin: 0 0 16px; border: 1px solid var(--line); border-radius: 10px; background: #fbf7ef; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.ocr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.ocr-grid fieldset { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.ocr-grid legend { padding: 0 6px; font-size: 13px; font-weight: 800; color: var(--orange-dark); }
.tmp-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tmp-fields label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); }
.tmp-fields input { border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 10px 12px; font-size: 15px; color: var(--ink); font-weight: 600; }
.corrected-card { margin-top: 18px; padding: 18px 20px; border-radius: 12px; color: #f6efe4; background: #241f19; }
.corrected-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.corrected-title span { color: #ee8a62; font-size: 13px; font-weight: 800; }
.corrected-title strong { font-size: 18px; }
.corrected-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; text-align: center; }
.corrected-values span { display: flex; flex-direction: column; gap: 6px; color: #a99f94; font-size: 12px; }
.corrected-values b { color: #fff; font-size: 24px; font-variant-numeric: tabular-nums; }
.corrected-card .note { margin-top: 12px; color: #a99f94; }
.ocr-submit { display: flex; align-items: center; gap: 12px; margin-top: 18px; }

.rank-card { max-width: 980px; }
.rank-filters { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.rank-filters label { min-width: 140px; }
.table-wrap { overflow-x: auto; }
.rank-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rank-table th, .rank-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.rank-table th { color: var(--muted); font-size: 12px; }
.rank-table th:first-child, .rank-table td:first-child, .rank-table th:nth-child(2), .rank-table td:nth-child(2) { text-align: left; }
.rank-table th:nth-child(3), .rank-table td:nth-child(3) { text-align: left; }
.rank-table tbody tr:hover { background: #fbf7ef; }
.rank-table .top { color: var(--orange-dark); font-weight: 800; }

.link-btn {
  background: none; border: none; padding: 0; margin-left: 6px;
  color: var(--orange-dark); text-decoration: underline; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 700;
}
.link-btn:hover { color: var(--orange); }
input[readonly] { background: rgba(28,25,21,.06); color: var(--muted); cursor: not-allowed; }

.modal-mask { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(28,25,21,.55); }
.modal-mask[hidden] { display: none; }
.modal { width: 100%; max-width: 560px; padding: 28px; border-radius: 14px; background: var(--paper); box-shadow: 0 24px 70px rgba(20,14,8,.35); }
.modal-head { margin-bottom: 18px; }
.modal-head h2 { margin-top: 8px; font-size: 22px; }
.rules { margin: 0 0 18px; padding-left: 20px; display: grid; gap: 10px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.rules b { color: var(--ink); }
.modal-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 820px) {
  .calculator, .formula-card, .ocr-grid { grid-template-columns: 1fr; }
  .submit-row { grid-template-columns: 1fr; }
  .corrected-values { grid-template-columns: repeat(2, 1fr); }
  .modal-fields { grid-template-columns: 1fr; }
  .shell { padding: 40px 0 48px; }
}
