:root {
  --bg: #f4f7f6;
  --paper: #fffdf8;
  --panel: #ffffff;
  --ink: #142328;
  --muted: #607076;
  --line: #c8d2d2;
  --line-strong: #899a9c;
  --blue: #075a7f;
  --blue-dark: #053b55;
  --teal: #0b6b61;
  --green: #087a3e;
  --amber: #a86500;
  --red: #b4322a;
  --shadow: 0 10px 28px rgba(28, 49, 56, 0.08);
  font-family: "Arial", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(244, 247, 246, 0.92)),
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(7, 90, 127, 0.035) 32px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  color: #fff;
  background: linear-gradient(90deg, var(--blue-dark), #074f68);
  box-shadow: 0 2px 12px rgba(5, 38, 53, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 6px;
  font-size: 24px;
}

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

h1 {
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.74);
  font-size: 13px;
}

.print-button {
  min-width: 74px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 5px;
  padding: 8px 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.print-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-switch {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 5px;
  padding: 8px 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.page-switch:hover {
  background: rgba(255, 255, 255, 0.16);
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(460px, 1.08fr);
  gap: 12px;
  padding: 12px;
  min-width: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  min-width: 0;
}

.input-panel,
.result-panel,
.table-panel,
.notes-panel {
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--blue);
}

.section-title.nested {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.section-title span {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--blue);
  font-size: 14px;
  font-weight: 700;
}

.section-title h2,
.result-panel h2,
.table-panel h2,
.notes-panel h2 {
  font-size: 18px;
  line-height: 1.25;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}

.segmented label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 10px;
  background: var(--paper);
  cursor: pointer;
}

.segmented input {
  accent-color: var(--blue);
}

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

.form-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 10px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: #263b42;
  font-size: 13px;
  font-weight: 700;
}

.field small {
  color: var(--muted);
  font-weight: 400;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(7, 90, 127, 0.22);
  border-color: var(--blue);
}

.inline-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.inline-note label {
  display: flex;
  align-items: center;
  gap: 7px;
}

.result-panel {
  display: grid;
  gap: 12px;
}

.result-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 260px;
  gap: 12px;
  align-items: start;
}

.result-head p,
.table-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.calculate-row {
  display: flex;
  justify-content: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.calculate-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  width: 66.666%;
  border: 2px solid var(--blue);
  border-radius: 6px;
  padding: 5px 12px;
  color: var(--blue-dark);
  background: linear-gradient(180deg, #ffffff, #edf7f9);
  box-shadow: 0 5px 14px rgba(7, 90, 127, 0.13);
  cursor: pointer;
}

.calculate-button span {
  font-size: clamp(19px, 2.2vw, 27px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0;
}

#sourceBadge {
  display: none;
}

.calculate-button:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: linear-gradient(180deg, #ffffff, #e8f7f4);
}

.calculate-button:active {
  transform: translateY(1px);
}

.calculate-button:focus-visible {
  outline: 3px solid rgba(7, 90, 127, 0.24);
  outline-offset: 2px;
}

.diagram {
  color: #25373c;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.force-card,
.formula-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: var(--paper);
}

.force-card p,
.formula-card p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.force-card strong {
  display: block;
  margin-top: 5px;
  color: var(--green);
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.05;
  letter-spacing: 0;
}

.force-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.formula-card code {
  display: block;
  margin-top: 8px;
  overflow-x: auto;
  color: #111;
  font-family: "Menlo", "Consolas", monospace;
  font-size: 16px;
  line-height: 1.55;
  white-space: nowrap;
}

.status {
  border: 1px solid #d6c293;
  border-radius: 5px;
  padding: 10px 12px;
  color: #5c410b;
  background: #fff8e7;
  font-size: 14px;
}

.status.ok {
  border-color: #a7d2b5;
  color: #0d5933;
  background: #edf9f1;
}

.status.warn {
  border-color: #e3b0aa;
  color: var(--red);
  background: #fff1ef;
}

.process {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.process h3 {
  padding: 10px 12px;
  color: var(--blue);
  background: #eef6f8;
  font-size: 15px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px 9px;
  text-align: right;
  font-size: 13px;
  line-height: 1.35;
  vertical-align: middle;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: #1d424d;
  background: #edf5f5;
  font-weight: 700;
}

.process td:nth-child(2) {
  font-family: "Menlo", "Consolas", monospace;
  text-align: left;
}

.table-panel,
.notes-panel {
  grid-column: 1 / -1;
}

.table-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.table-head h2 {
  color: var(--blue);
}

#lookupHint {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: var(--paper);
  font-size: 12px;
  white-space: nowrap;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.table-wrap table {
  min-width: 760px;
}

.table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.active-row td,
.active-row th {
  background: #fff2c2;
}

.active-cell {
  color: #fff;
  background: var(--blue) !important;
  font-weight: 700;
}

.index-layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 12px;
}

.index-panel {
  padding: 16px;
}

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

.index-card {
  display: grid;
  gap: 8px;
  min-height: 98px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  color: var(--ink);
  background: var(--paper);
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(28, 49, 56, 0.06);
}

.index-card:hover {
  border-color: var(--blue);
  background: #f2fbfc;
}

.index-card strong {
  color: var(--blue-dark);
  font-size: 20px;
  line-height: 1.25;
}

.index-card span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.notes-panel {
  background: rgba(255, 253, 248, 0.96);
}

.notes-panel h2 {
  margin-bottom: 12px;
  color: var(--blue);
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.notes-grid article {
  border-left: 3px solid var(--teal);
  padding: 2px 10px;
}

.notes-grid h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.notes-grid p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .diagram {
    max-width: 340px;
  }

  .notes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .page-switch,
  .print-button {
    flex: 1;
    justify-content: center;
  }

  .layout {
    padding: 8px;
  }

  .segmented,
  .form-grid,
  .form-grid.compact,
  .index-grid,
  .notes-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .table-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media print {
  .topbar {
    position: static;
  }

  .print-button {
    display: none;
  }

  .layout {
    display: block;
  }

  .panel {
    margin-bottom: 10px;
    box-shadow: none;
    break-inside: avoid;
  }
}
