:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-soft: #f8faf7;
  --ink: #17211c;
  --muted: #5f6b64;
  --line: #dfe5df;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e6f4f1;
  --accent: #b45309;
  --accent-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 18px;
  --shadow: 0 18px 45px rgba(23, 33, 28, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei",
    system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.wrap {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(244, 246, 242, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(223, 229, 223, 0.8);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 18px;
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.28);
}

.header-nav {
  display: flex;
  gap: 8px;
}

.hero {
  padding-block: 54px 26px;
}

.eyebrow {
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.hero h1 {
  margin-top: 10px;
  font-size: clamp(30px, 4.6vw, 52px);
  line-height: 1.18;
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.hero-copy {
  max-width: 720px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 17px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.8fr);
  gap: 24px;
  align-items: start;
  padding-bottom: 64px;
}

.layout > * {
  min-width: 0;
}

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

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

.form-section:last-of-type {
  border-bottom: none;
}

.form-section h2 {
  margin-bottom: 16px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

details.advanced {
  padding: 0;
}

details.advanced > summary {
  padding: 18px 24px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

details.advanced > summary::after {
  content: "+";
  color: var(--brand);
  font-size: 20px;
  font-weight: 600;
}

details.advanced[open] > summary::after {
  content: "−";
}

details.advanced > .grid,
details.advanced > .hint,
details.advanced > .checkbox-field {
  margin: 0 24px 18px;
}

details.advanced > .checkbox-field {
  display: flex;
}

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

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

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.label-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #33443c;
  font-size: 14px;
  font-weight: 700;
}

.field input[type="number"],
.field input[type="date"],
.field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input[type="number"]:focus,
.field input[type="date"]:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.input-unit {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-unit:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.input-unit input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 4px 0 12px;
  border: none;
  outline: none;
  background: transparent;
}

.input-unit > span {
  padding: 0 12px 0 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  color: #33443c;
  font-size: 14px;
  line-height: 1.45;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
  flex: 0 0 auto;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.hint.full {
  grid-column: 1 / -1;
}

.hint strong {
  color: var(--brand-dark);
}

.rate-fields {
  margin-top: 16px;
}

.info {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid #b9c7c0;
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.info:hover,
.info:focus-visible {
  border-color: var(--brand);
  color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.form-actions {
  display: flex;
  gap: 10px;
  padding: 22px 24px 26px;
  background: var(--surface-soft);
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 10px;
  font-weight: 700;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}

.primary-button {
  flex: 1;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.primary-button:active,
.ghost-button:active {
  transform: translateY(1px);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover {
  border-color: #b9c7c0;
  background: #fbfdfb;
}

.results {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.result-hero {
  padding: 26px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #0f766e, #134e4a);
  color: #fff;
  box-shadow: 0 20px 40px rgba(15, 118, 110, 0.22);
}

.result-hero .eyebrow {
  color: #b7e4dc;
}

.result-hero .big {
  margin-top: 6px;
  font-size: clamp(34px, 5vw, 46px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.result-hero .sub {
  margin-top: 8px;
  color: #d1fae5;
  font-size: 14px;
}

.result-hero .sub.small {
  margin-top: 5px;
  color: #a7f3d0;
  font-size: 13px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.result-grid.small {
  padding: 12px;
}

.result-cell {
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--surface-soft);
}

.result-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.result-cell strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.result-grid.small .result-cell strong {
  font-size: 15px;
}

.warnings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warning {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.warning.info {
  background: var(--brand-soft);
  color: #115e59;
}

.warning.warn {
  background: var(--accent-soft);
  color: #92400e;
}

.warning.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.result-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
}

.result-section h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 9px 8px;
  border-bottom: 1px solid #edf1ed;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .muted {
  color: var(--muted);
}

.data-table tr.total-row td {
  font-weight: 800;
  border-top: 2px solid var(--line);
}

.table-scroll {
  max-height: 360px;
  max-width: 100%;
  overflow: auto;
  border: 1px solid #edf1ed;
  border-radius: 10px;
}

.table-scroll thead {
  position: sticky;
  top: 0;
  background: #fbfdfb;
  z-index: 1;
}

.link-button {
  margin-top: 10px;
  padding: 0;
  border: none;
  background: none;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chart {
  min-height: 180px;
}

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

.disclaimer {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.site-footer {
  padding-block: 24px 40px;
  color: var(--muted);
  font-size: 12px;
}

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 1000;
  width: min(340px, calc(100vw - 24px));
  padding: 16px 40px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(23, 33, 28, 0.18);
}

.tooltip-term {
  font-weight: 800;
  font-size: 14px;
}

.tooltip-short {
  margin-top: 6px;
  font-size: 14px;
}

.tooltip-example,
.tooltip-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tooltip-note {
  color: var(--accent);
}

.tooltip-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

/* Glossary dialog */
.glossary-dialog {
  width: min(920px, calc(100% - 32px));
  max-height: min(82vh, 900px);
  padding: 0;
  border: none;
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(23, 33, 28, 0.3);
}

.glossary-dialog::backdrop {
  background: rgba(23, 33, 28, 0.45);
  backdrop-filter: blur(3px);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.dialog-header h2 {
  font-size: 18px;
}

.glossary-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 22px 26px;
  overflow: auto;
  max-height: calc(82vh - 70px);
}

.glossary-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.glossary-item h3 {
  font-size: 14px;
}

.glossary-item p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.glossary-item .example {
  color: #33443c;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .results {
    position: static;
  }
}

@media (max-width: 640px) {
  .wrap {
    width: calc(100% - 24px);
  }

  .hero {
    padding-block: 36px 18px;
  }

  .grid.two,
  .result-grid,
  .result-grid.small,
  .glossary-content {
    grid-template-columns: 1fr;
  }

  .form-section {
    padding: 20px 16px 22px;
  }

  details.advanced > summary {
    padding: 16px;
  }

  details.advanced > .grid,
  details.advanced > .hint,
  details.advanced > .checkbox-field {
    margin-inline: 16px;
  }

  .form-actions {
    padding: 18px 16px 20px;
  }

  .result-hero {
    padding: 22px;
  }

  .result-section {
    padding: 14px;
  }

  .tooltip {
    left: 12px;
    right: 12px;
    bottom: 12px;
    top: auto !important;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
  }
}
