:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #edf5f2;
  --text: #18211f;
  --muted: #64706d;
  --line: #d8ded8;
  --primary: #146c63;
  --primary-2: #0f514a;
  --accent: #b33b32;
  --warn: #b46a00;
  --good: #287a45;
  --shadow: 0 18px 50px rgba(24, 33, 31, 0.08);
}

body.dark {
  color-scheme: dark;
  --bg: #111716;
  --surface: #18211f;
  --surface-2: #202d2a;
  --text: #f1f4f0;
  --muted: #aab6b2;
  --line: #31403c;
  --primary: #5bc2b5;
  --primary-2: #8fded4;
  --accent: #ff8076;
  --warn: #f5b85a;
  --good: #80d29a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary);
}

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

body.dark .primary-button {
  color: #10211f;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 34px clamp(18px, 4vw, 52px) 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  margin-bottom: 0;
  letter-spacing: 0;
}

h3 {
  font-size: 19px;
  margin-bottom: 6px;
  letter-spacing: 0;
  line-height: 1.35;
}

.lead {
  margin-bottom: 0;
  color: var(--muted);
  max-width: 760px;
  line-height: 1.7;
}

.view-links {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.view-links a {
  min-width: 92px;
  padding: 9px 14px;
  text-align: center;
  font-weight: 700;
  background: var(--surface-2);
}

.view-links .primary-link {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

body.dark .view-links .primary-link {
  color: #10211f;
}

.header-actions,
.button-row,
.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-start {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 18px clamp(18px, 4vw, 52px);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.quick-start div {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.quick-start strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
}

body.dark .quick-start strong {
  color: #10211f;
}

.quick-start span {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.layout {
  display: grid;
  grid-template-columns: minmax(310px, 420px) 1fr;
  gap: 20px;
  padding: 20px clamp(18px, 4vw, 52px);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  padding: 20px;
  align-self: start;
  position: sticky;
  top: 16px;
}

.section-title,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title span,
#summary,
.subline {
  color: var(--muted);
  font-size: 14px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.checkbox-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 8px 0 16px;
}

.advanced {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.advanced summary {
  min-height: 44px;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

.advanced label {
  margin: 0 12px 14px;
}

.advanced textarea {
  background: var(--surface);
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 3px;
}

.checkbox-row label {
  margin: 0;
  display: block;
}

.results-area {
  min-width: 0;
}

.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.toolbar p {
  margin: 6px 0 0;
}

.compact button {
  min-width: 66px;
}

.notice {
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line));
  border-radius: 8px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  line-height: 1.65;
}

.culture-note {
  margin: -4px 0 16px;
  padding: 10px 12px;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.shake {
  animation: shake 0.28s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stats div {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 11px 12px;
}

.stats strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  color: var(--primary);
}

.stats span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.empty-state {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  line-height: 1.7;
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.empty-state.hidden {
  display: none;
}

.name-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 238px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.risk {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  line-height: 1;
  font-weight: 700;
  border: 1px solid var(--line);
}

.risk.low {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, var(--surface));
}

.risk.mid {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
}

.risk.high {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.meter {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--good);
}

.meter span.mid {
  background: var(--warn);
}

.meter span.high {
  background: var(--accent);
}

.reasons {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
  flex: 1;
}

.yijing-box {
  display: grid;
  gap: 5px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--line));
  border-radius: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.yijing-box strong {
  color: var(--primary);
  font-size: 14px;
}

.yijing-box span {
  display: block;
}

.card-actions {
  margin-top: auto;
}

.links-panel,
.advice,
.audit-panel,
.agreement {
  padding: 18px;
  margin-bottom: 20px;
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

a:hover {
  border-color: var(--primary);
}

.advice ul {
  margin: 14px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.audit-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.audit-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--surface-2);
  line-height: 1.55;
}

.audit-list li.ok {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 35%, var(--line));
}

.audit-list li.todo {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--line));
}

.agreement {
  margin: 0 clamp(18px, 4vw, 52px) 34px;
}

.agreement-text {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  line-height: 1.85;
  color: var(--text);
}

.signature-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 4px 0 16px;
  background: var(--surface-2);
}

.signature-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}

.signature-title h3 {
  margin-bottom: 4px;
}

.signature-title p {
  color: var(--muted);
  margin-bottom: 0;
  line-height: 1.6;
}

#signaturePad {
  display: block;
  width: 100%;
  min-height: 150px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.signature-lines {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  margin-top: 16px;
}

.signature-lines span {
  min-height: 40px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  padding-top: 10px;
}

.signature-ack {
  margin-bottom: 0;
  margin-top: 14px;
}

.mobile-action-bar {
  display: none;
}

body.force-mobile {
  background: #dfe7e3;
  padding-bottom: 88px;
}

body.force-mobile .app-header,
body.force-mobile .quick-start,
body.force-mobile .layout,
body.force-mobile .agreement {
  max-width: 430px;
  margin-left: auto;
  margin-right: auto;
}

body.force-mobile .app-header,
body.force-mobile .layout {
  display: block;
}

body.force-mobile .controls {
  position: static;
  margin-bottom: 16px;
}

body.force-mobile .quick-start,
body.force-mobile .two,
body.force-mobile .three,
body.force-mobile .stats,
body.force-mobile .link-grid,
body.force-mobile .audit-list,
body.force-mobile .signature-lines {
  grid-template-columns: 1fr;
}

body.force-mobile .header-actions {
  margin-top: 16px;
}

body.force-mobile .agreement {
  margin-bottom: 96px;
}

body.force-mobile .mobile-action-bar {
  display: grid;
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 10px;
  z-index: 20;
  width: min(410px, calc(100% - 20px));
  transform: translateX(-50%);
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

body.force-mobile .mobile-action-bar a,
body.force-mobile .mobile-action-bar button {
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  text-align: center;
}

body.force-desktop {
  min-width: 0;
}

body.force-desktop .app-header {
  display: flex;
}

body.force-desktop .quick-start {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.force-desktop .layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
}

body.force-desktop .controls {
  position: sticky;
  top: 16px;
}

body.force-desktop .two,
body.force-desktop .link-grid,
body.force-desktop .audit-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.force-desktop .three,
body.force-desktop .signature-lines {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.force-desktop .signature-lines {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.force-desktop .stats {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

body.force-desktop .toolbar {
  align-items: center;
  flex-direction: row;
}

body.force-desktop .header-actions {
  margin-top: 0;
}

body.force-desktop .mobile-action-bar {
  display: none;
}

@media (max-width: 980px) {
  body.force-desktop .layout,
  body.force-desktop .app-header {
    display: block;
  }

  body.force-desktop .controls {
    position: static;
    margin-bottom: 20px;
  }

  body.force-desktop .quick-start {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.force-desktop .header-actions {
    margin-top: 18px;
  }
}

@media (max-width: 900px) {
  .app-header,
  .layout {
    display: block;
  }

  .header-actions {
    margin-top: 18px;
  }

  .controls {
    position: static;
    margin-bottom: 20px;
  }

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

@media (max-width: 620px) {
  body {
    padding-bottom: 76px;
  }

  .two,
  .three,
  .link-grid,
  .stats,
  .audit-list,
  .signature-lines {
    grid-template-columns: 1fr;
  }

  .signature-title {
    display: block;
  }

  .signature-title button {
    margin-top: 10px;
  }

  .quick-start {
    grid-template-columns: 1fr;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .view-links a {
    flex: 1;
  }

  .app-header {
    padding-top: 24px;
  }

  .card-top {
    display: block;
  }

  .risk {
    display: inline-block;
    margin-top: 8px;
  }

  .mobile-action-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .mobile-action-bar a,
  .mobile-action-bar button {
    min-height: 44px;
    display: grid;
    place-items: center;
    padding: 0 8px;
    text-align: center;
  }
}

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

  .app-header,
  .layout,
  .quick-start,
  .mobile-action-bar,
  #printAgreement,
  #printAgreementTop {
    display: none !important;
  }

  .agreement {
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  input,
  textarea {
    border: 0;
    border-bottom: 1px solid #000;
    border-radius: 0;
    color: #000;
  }

  .signature-section {
    border: 0;
    padding: 0;
    background: #fff;
  }

  .signature-title button,
  .signature-ack {
    display: none !important;
  }

  #signaturePad {
    border: 1px solid #000;
    min-height: 120px;
  }

  .signature-lines span {
    color: #000;
    border-bottom-color: #000;
  }
}
