:root {
  --blue-700: #1667d9;
  --blue-600: #1f7ae8;
  --blue-100: #e8f2ff;
  --red: #cf2029;
  --red-pill: #ef4238;
  --ink: #202631;
  --muted: #68707d;
  --line: #e7edf5;
  --surface: #ffffff;
  --page: #f4f7fb;
  --warning-bg: #fff7d9;
  --warning-border: #f4c542;
  --warning-text: #806600;
  --danger: #c73535;
  --shadow: 0 18px 45px rgba(34, 67, 107, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  background: linear-gradient(180deg, #eef5ff 0, var(--page) 260px);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  color: #fff;
  background: linear-gradient(135deg, #176fe3 0%, #0f83e8 60%, #249bdc 100%);
  padding: calc(24px + env(safe-area-inset-top)) 18px 34px;
}

.header-inner {
  width: min(860px, 100%);
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.86rem;
  font-weight: 700;
  opacity: 0.82;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.12;
}

.header-copy {
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.86);
}

.shell {
  width: min(860px, calc(100% - 24px));
  margin: -20px auto 48px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.tab {
  min-height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
}

.tab.is-active {
  color: #fff;
  background: var(--blue-700);
}

.panel {
  display: none;
  padding-top: 18px;
}

.panel.is-active {
  display: block;
}

.hero-card,
.calculator-card,
.result-card,
.placeholder-card {
  border: 1px solid rgba(222, 232, 245, 0.88);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 26px 22px;
  text-align: center;
}

.hero-card h2 {
  margin-bottom: 10px;
  color: var(--blue-700);
  font-size: clamp(1.75rem, 5.6vw, 2.35rem);
  line-height: 1.18;
}

.hero-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 18px 0;
  padding: 16px;
  border-left: 4px solid var(--warning-border);
  border-radius: 8px;
  color: var(--warning-text);
  background: var(--warning-bg);
}

.notice p {
  margin-bottom: 0;
}

.notice-icon {
  display: inline-grid;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  color: #6f5700;
  background: #ffd95d;
  font-weight: 900;
}

.calculator-card,
.result-card,
.placeholder-card {
  padding: 22px;
}

.form-section {
  padding: 0 0 8px;
  border-bottom: 1px solid var(--line);
}

.form-section + .form-section {
  padding-top: 18px;
}

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

.section-title h3 {
  margin-bottom: 0;
  color: var(--blue-700);
  font-size: 1.2rem;
}

.section-title span {
  color: #99a2ad;
  font-size: 0.94rem;
}

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 230px);
  gap: 14px;
  align-items: center;
  min-height: 68px;
}

.field + .field {
  border-top: 1px solid #eef2f7;
}

.field-label {
  min-width: 0;
  color: #252b35;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.5;
}

.field-label small {
  display: inline;
  margin-left: 0.35em;
  color: #8d96a3;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #dbe5f1;
  border-radius: 8px;
  color: var(--ink);
  background: #f7f9fd;
  padding: 0 14px;
  text-align: right;
  outline: none;
}

input:focus {
  border-color: var(--blue-600);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(31, 122, 232, 0.12);
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 8px;
}

.input-with-unit input {
  min-width: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 0;
}

.segmented-control label {
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px solid #cfe2ff;
  border-radius: 8px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-weight: 800;
}

.segmented-control input:checked + span {
  color: #fff;
  border-color: var(--blue-700);
  background: var(--blue-700);
}

.unit-button {
  min-height: 48px;
  border: 1px solid #cfe2ff;
  border-radius: 8px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-weight: 800;
  white-space: nowrap;
}

.unit-button::after {
  margin-left: 6px;
  content: "▼";
  font-size: 0.72rem;
}

.form-error {
  min-height: 24px;
  margin: 14px 0 10px;
  color: var(--danger);
  font-weight: 650;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.btn.primary {
  color: #fff;
  background: var(--blue-700);
}

.btn.primary:active,
.tab.is-active:active {
  background: #1059bd;
}

.btn.secondary {
  color: var(--blue-700);
  background: var(--blue-100);
}

.result-card {
  margin-top: 18px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.score-box {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.score-box strong {
  display: block;
  margin: 8px 0 6px;
  color: var(--blue-700);
  font-size: 2rem;
  line-height: 1.1;
}

.score-box p,
.formula-note p {
  margin-bottom: 0;
  color: var(--muted);
}

.formula-note {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.94rem;
}

.placeholder-panel {
  min-height: 320px;
}

.placeholder-card {
  padding: 28px 22px;
}

.placeholder-card h2 {
  margin-bottom: 10px;
  color: var(--blue-700);
}

.placeholder-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.result-screen {
  min-height: 100vh;
  background: #f0f2f5;
}

.result-appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  min-height: calc(72px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  color: #fff;
  background: #2077e5;
}

.result-appbar h1 {
  margin: 0;
  font-size: 1.48rem;
  line-height: 1;
  text-align: center;
}

.result-back-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: transparent;
  font-size: 3rem;
  font-weight: 300;
  line-height: 0.72;
}

.result-back-button:active {
  background: rgba(255, 255, 255, 0.16);
}

.result-shell {
  width: min(860px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.detail-card,
.advice-card,
.disclaimer,
.export-card {
  border: 1px solid rgba(228, 232, 239, 0.95);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(24, 44, 70, 0.06);
}

.detail-card,
.advice-card,
.export-card {
  padding: 28px 36px;
}

.detail-card + .detail-card,
.advice-card,
.export-card {
  margin-top: 24px;
}

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

.score-name {
  display: flex;
  gap: 18px;
  align-items: center;
  flex: 0 0 auto;
  min-width: 0;
}

.score-name h2,
.advice-card h2 {
  margin: 0;
  color: #2e3137;
  font-size: 1.55rem;
  white-space: nowrap;
}

.red-orb {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 2px solid #d2171f;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff5b63 0%, #d81720 50%, #b90912 100%);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.48);
}

.risk-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  max-width: 100%;
  padding: 4px 24px;
  border-radius: 999px;
  color: #fff;
  background: var(--red-pill);
  font-size: 1.05rem;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
}

.risk-pill.low {
  background: #1f9d55;
}

.risk-pill.middle {
  background: #f0a52b;
}

.big-score {
  color: var(--red);
  font-size: clamp(3.75rem, 12vw, 5.4rem);
  font-weight: 800;
  line-height: 0.98;
  overflow-wrap: anywhere;
}

.range-hint {
  margin: 12px 0 22px;
  color: #9aa0a8;
  font-size: 1.02rem;
}

.detail-section {
  padding: 24px 0;
  border-top: 1px solid #ededed;
}

.detail-section h3 {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0 0 14px;
  color: #1578f0;
  font-size: 1.12rem;
}

.section-icon {
  display: inline-block;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
}

.triangle-icon {
  position: relative;
}

.triangle-icon::before {
  position: absolute;
  top: 4px;
  left: 2px;
  width: 0;
  height: 0;
  border-left: 25px solid #a9bfd6;
  border-top: 25px solid transparent;
  content: "";
}

.triangle-icon::after {
  position: absolute;
  top: 14px;
  left: 10px;
  width: 14px;
  height: 5px;
  border-left: 5px solid #fff;
  border-bottom: 5px solid #fff;
  content: "";
}

.chart-icon {
  background:
    linear-gradient(#22a35a, #22a35a) 4px 10px / 6px 20px no-repeat,
    linear-gradient(#e5192a, #e5192a) 13px 18px / 6px 12px no-repeat,
    linear-gradient(#1667d9, #1667d9) 22px 5px / 6px 25px no-repeat,
    linear-gradient(#dae5f1, #dae5f1) 0 0 / 100% 100% no-repeat;
  border: 1px solid #edf2f8;
}

.search-icon {
  position: relative;
}

.search-icon::before {
  position: absolute;
  top: 4px;
  left: 2px;
  width: 18px;
  height: 18px;
  border: 3px solid #3c4755;
  border-radius: 50%;
  background: #fff;
  content: "";
  box-shadow: inset 0 0 0 2px #edf3fb;
}

.search-icon::after {
  position: absolute;
  top: 22px;
  left: 20px;
  width: 15px;
  height: 4px;
  border-radius: 999px;
  background: #111820;
  content: "";
  transform: rotate(45deg);
}

.clipboard-icon {
  display: inline-grid;
  place-items: center;
  font-size: 1.45rem;
  line-height: 1;
}

.clipboard-icon::before {
  content: "📋";
}

.formula-box {
  overflow-wrap: anywhere;
  padding: 16px 22px;
  border: 2px solid #cfe2ff;
  border-radius: 12px;
  color: #1376ed;
  background: #eef5ff;
  font-size: 1.22rem;
  font-weight: 650;
}

.input-summary {
  margin: 18px 0 0;
  color: #666b73;
  font-size: 1.02rem;
  line-height: 1.9;
}

.reference-table {
  width: 100%;
  overflow: hidden;
  border: 1px solid #e5e8ef;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 10px;
  color: #4e535a;
  font-size: 1.04rem;
}

.reference-table th,
.reference-table td {
  padding: 15px 22px;
  border-bottom: 1px solid #eceff3;
  text-align: left;
}

.reference-table th {
  color: #363b43;
  background: #e8f1ff;
  font-weight: 800;
}

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

.reference-table td:first-child {
  width: 38%;
  color: #282c32;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  white-space: nowrap;
}

.detail-section p,
.clinical-list,
.clinical-note,
.advice-card p,
.disclaimer p {
  color: #5f646c;
  font-size: 1.08rem;
  line-height: 1.9;
}

.clinical-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 1.05em;
}

.clinical-note {
  margin: 18px 0 0;
  color: #989da4;
  font-style: italic;
}

.collapse-detail {
  display: block;
  margin: 0 auto;
  padding: 10px 18px 0;
  border: 0;
  color: #1477ef;
  background: transparent;
  font-weight: 800;
  font-size: 1rem;
}

.advice-card h2 {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.advice-card p {
  margin-bottom: 24px;
}

.advice-card p:last-child {
  margin-bottom: 0;
}

.action-card {
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid #cfe2ff;
  border-radius: 12px;
  background: #eef5ff;
}

.action-card h3 {
  margin: 0 0 10px;
  color: #1578f0;
  font-size: 1.08rem;
}

.action-card ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.15em;
  color: #4f5966;
  font-size: 1.02rem;
  line-height: 1.75;
}

.hcc-warning {
  font-weight: 650;
}

.hcc-alert {
  margin-top: 22px;
  padding: 18px 22px 18px 24px;
  border-left: 6px solid #ef4238;
  border-radius: 12px;
  color: #5f646c;
  background: #fff7df;
}

.hcc-alert h4 {
  margin: 0 0 10px;
  color: #d51f1f;
  font-size: 1.05rem;
  line-height: 1.4;
}

.hcc-alert p {
  margin: 0;
  color: #5f646c;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.85;
}

.return-button {
  display: block;
  width: min(380px, 82%);
  min-height: 64px;
  margin: 28px auto 32px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: #1f70d7;
  font-size: 1.28rem;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(31, 112, 215, 0.18);
}

.export-card h2 {
  margin: 0 0 18px;
  color: #2e3137;
  font-size: 1.3rem;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.export-button {
  min-height: 50px;
  border: 1px solid #cfe2ff;
  border-radius: 8px;
  color: var(--blue-700);
  background: #eef5ff;
  font-weight: 800;
}

.export-button.primary-share {
  color: #fff;
  border-color: var(--blue-700);
  background: var(--blue-700);
}

.export-hint {
  margin: 14px 0 0;
  color: #7a828d;
  font-size: 0.96rem;
  line-height: 1.7;
}

.disclaimer {
  margin-bottom: 20px;
  color: #8a9098;
}

.disclaimer summary {
  min-height: 58px;
  padding: 15px 22px;
  list-style: none;
  cursor: pointer;
  font-size: 1.08rem;
  font-weight: 800;
}

.disclaimer summary::-webkit-details-marker {
  display: none;
}

.disclaimer summary::before {
  margin-right: 10px;
  content: "⚖";
}

.disclaimer summary::after {
  float: right;
  color: #babfc6;
  content: "▼";
}

.disclaimer[open] summary::after {
  content: "▲";
}

.disclaimer p {
  margin: 0;
  padding: 0 22px 20px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(720px, 100%);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.22);
}

.alert-panel {
  align-self: center;
  max-width: 420px;
  padding: 26px 22px 22px;
  text-align: center;
}

.alert-panel h2,
.unit-panel h2 {
  margin: 0 0 14px;
  color: #2e3137;
  font-size: 1.25rem;
}

.alert-panel p {
  margin: 0 0 22px;
  color: #5f646c;
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre-line;
}

.unit-panel {
  padding: 36px 48px 30px;
}

.unit-panel h2 {
  color: #8d939c;
  font-weight: 700;
  text-align: center;
}

.unit-options {
  margin: 20px 0 84px;
  border-top: 1px solid #e7e9ee;
}

.unit-option {
  display: block;
  width: 100%;
  min-height: 72px;
  border: 0;
  border-bottom: 1px solid #e7e9ee;
  color: #b7bbc2;
  background: #fff;
  font-size: 1.35rem;
}

.unit-option.is-selected {
  color: var(--blue-700);
  font-weight: 900;
  background: #f4f9ff;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-cancel,
.modal-confirm {
  min-height: 56px;
  border: 0;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 800;
}

.modal-cancel {
  color: #08b15e;
  background: #f2f2f2;
}

.modal-confirm {
  color: #fff;
  background: #10c66b;
}

@media (max-width: 520px) {
  body {
    background: linear-gradient(180deg, #eef5ff 0, var(--page) 220px);
  }

  .app-header {
    padding-left: 16px;
    padding-right: 16px;
  }

  .shell {
    width: min(100% - 20px, 860px);
    margin-bottom: 32px;
  }

  .tabs {
    gap: 6px;
    padding: 6px;
  }

  .tab {
    min-height: 46px;
    padding: 6px 8px;
    font-size: 0.88rem;
  }

  .hero-card,
  .calculator-card,
  .result-card,
  .placeholder-card {
    padding: 18px;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: stretch;
    padding: 12px 0;
  }

  .field-label {
    display: block;
  }

  input {
    min-height: 50px;
    text-align: left;
  }

  .actions,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .notice {
    padding: 14px;
  }

  .result-appbar {
    grid-template-columns: 46px 1fr 46px;
    min-height: calc(82px + env(safe-area-inset-top));
    padding-left: 10px;
    padding-right: 10px;
  }

  .result-appbar h1 {
    font-size: 1.45rem;
  }

  .result-back-button {
    width: 40px;
    height: 40px;
    font-size: 2.75rem;
  }

  .result-shell {
    width: calc(100% - 20px);
    padding-top: 12px;
  }

  .detail-card,
  .advice-card,
  .export-card {
    padding: 24px 28px;
    border-radius: 18px;
  }

  .score-heading {
    align-items: flex-start;
    margin-bottom: 26px;
  }

  .score-name {
    gap: 14px;
  }

  .score-name h2 {
    font-size: 1.34rem;
  }

  .score-name h2,
  .advice-card h2 {
    font-size: 1.42rem;
  }

  .red-orb {
    flex-basis: 38px;
    width: 38px;
    height: 38px;
  }

  .risk-pill {
    min-height: 36px;
    padding: 4px 16px;
    font-size: 1rem;
  }

  .detail-section {
    padding: 22px 0;
  }

  .formula-box {
    padding: 14px 18px;
    font-size: 1.12rem;
  }

  .reference-table {
    display: table;
    width: 100%;
    table-layout: fixed;
    font-size: 0.92rem;
  }

  .reference-table thead {
    display: table-header-group;
  }

  .reference-table tbody {
    display: table-row-group;
  }

  .reference-table tr {
    display: table-row;
  }

  .reference-table th,
  .reference-table td {
    display: table-cell;
    padding: 12px 10px;
    border-bottom: 1px solid #eceff3;
    vertical-align: top;
    text-align: left;
  }

  .reference-table td:first-child {
    width: 52%;
    font-size: 0.86rem;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .reference-table td + td {
    width: 48%;
    margin-top: 0;
    color: #5f646c;
    line-height: 1.65;
  }

  .reference-table td::before {
    display: none;
    content: none;
  }

  .reference-table th:first-child {
    width: 52%;
  }

  .detail-section p,
  .clinical-list,
  .clinical-note,
  .action-card ul,
  .advice-card p,
  .disclaimer p {
    font-size: 1.03rem;
  }

  .hcc-alert {
    padding: 16px 18px 16px 20px;
  }

  .hcc-alert h4,
  .hcc-alert p {
    font-size: 1rem;
  }

  .input-with-unit {
    grid-template-columns: 1fr;
  }

  .segmented-control {
    grid-template-columns: 1fr 1fr;
  }

  .unit-button {
    text-align: center;
  }

  .export-actions {
    grid-template-columns: 1fr;
  }

  .unit-panel {
    padding: 34px 48px 28px;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
  }
}

@media (min-width: 900px) {
  .shell {
    margin-top: -26px;
  }

  .calculator-card,
  .placeholder-card {
    padding: 28px;
  }
}

@media (max-width: 380px) {
  .detail-card,
  .advice-card,
  .export-card {
    padding: 22px 20px;
  }

  .score-heading {
    display: flex;
    gap: 10px;
  }

  .risk-pill {
    justify-self: auto;
    padding-right: 12px;
    padding-left: 12px;
    font-size: 0.93rem;
  }

  .reference-table td:first-child {
    font-size: 0.86rem;
  }
}

@media print {
  body {
    background: #fff;
  }

  body.printing #home-header,
  body.printing #home-screen,
  body.printing .result-appbar,
  body.printing .export-card,
  body.printing .return-button,
  body.printing .disclaimer,
  body.printing .collapse-detail {
    display: none !important;
  }

  body.printing #result-screen,
  body.printing .result-screen {
    display: block !important;
    background: #fff;
  }

  body.printing .result-shell {
    width: 100%;
    padding: 0;
  }

  body.printing .detail-card,
  body.printing .advice-card {
    break-inside: avoid;
    box-shadow: none;
  }
}
