:root {
  color-scheme: light;
  --ink: #17221f;
  --muted: #62706b;
  --paper: #f4f1e9;
  --panel: #fffdf7;
  --line: #d6d0c3;
  --rail: #1f3d36;
  --rail-2: #30594f;
  --signal: #d7a62f;
  --danger: #b5412f;
  --good: #2f6f5e;
  --shadow: 0 18px 45px rgba(29, 45, 38, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(31, 61, 54, 0.07) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(180deg, #ebe4d5 0%, var(--paper) 42%, #e7eee8 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 960px);
  margin: 0 auto;
  padding: 18px 14px 34px;
}

.hero {
  min-height: 178px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 0 18px;
  border-bottom: 4px solid var(--rail);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--rail-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  max-width: 640px;
  font-size: clamp(2.05rem, 8vw, 4.4rem);
  font-weight: 950;
}

h2 {
  font-size: 1.35rem;
}

.hero-copy {
  max-width: 560px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.status-pill {
  flex: 0 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--rail);
  background: rgba(255, 253, 247, 0.76);
  color: var(--rail);
  font-size: 0.88rem;
  font-weight: 800;
}

.lookup-panel,
.results-section,
.detail-section details,
.calc-strip {
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.lookup-panel {
  margin-top: 16px;
  padding: 16px;
}

.field-group label,
.number-field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented button,
.ghost-button,
.solid-button {
  min-height: 44px;
  border: 1px solid var(--rail);
  cursor: pointer;
  font-weight: 850;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}

.segmented button {
  background: transparent;
  color: var(--rail);
}

.segmented button[aria-checked="true"],
.solid-button {
  background: var(--rail);
  color: #fffdf7;
}

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

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

.number-field input {
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  border: 2px solid var(--rail);
  background: #fff4b8;
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 900;
  text-align: center;
}

.quick-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.ghost-button {
  background: #fffdf7;
  color: var(--rail);
}

.calc-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
  overflow: hidden;
}

.calc-strip div {
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.calc-strip div:last-child {
  border-right: 0;
}

.calc-strip span {
  display: block;
  min-height: 20px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.calc-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 1.65rem;
  line-height: 1;
}

.primary-metric {
  background: var(--signal);
}

.primary-metric span,
.primary-metric strong {
  color: #221b0a;
}

.results-section {
  margin-top: 12px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.solid-button {
  min-width: 82px;
}

.warning {
  margin-top: 12px;
  padding: 12px;
  border-left: 5px solid var(--danger);
  background: #fff0e8;
  color: #6d2418;
  font-weight: 800;
}

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

.result-card {
  min-height: 124px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.result-card h3 {
  min-height: 40px;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.result-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 10px;
  color: var(--rail);
}

.result-value strong {
  font-size: 2rem;
  line-height: 1;
}

.result-value span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.result-note {
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.detail-section {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

details {
  padding: 0;
}

summary {
  min-height: 48px;
  padding: 14px 16px;
  color: var(--rail);
  cursor: pointer;
  font-weight: 900;
}

.detail-body {
  padding: 0 16px 16px;
  color: var(--muted);
  line-height: 1.65;
}

.detail-body p {
  margin: 0 0 8px;
}

.table-wrap {
  overflow-x: auto;
  padding: 0 12px 14px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 9px 10px;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  line-height: 1.45;
}

th {
  background: var(--rail);
  color: #fffdf7;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.86rem;
}

.history-item strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 5;
  transform: translate(-50%, 18px);
  opacity: 0;
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  background: var(--ink);
  color: #fffdf7;
  font-weight: 800;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 22px 10px 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
}

.site-footer div {
  position: relative;
}

.site-footer div:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -9px;
  width: 3px;
  height: 3px;
  background: var(--signal);
  transform: translateY(-50%);
}

@media (max-width: 720px) {
  .hero {
    display: block;
    min-height: 164px;
  }

  .status-pill {
    display: inline-block;
    margin-top: 14px;
  }

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

  .result-card {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    min-height: 88px;
  }

  .result-value {
    justify-content: flex-end;
    margin-top: 0;
  }

  .result-note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-inline: 10px;
  }

  .lookup-panel,
  .results-section {
    padding: 12px;
  }

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

  .quick-row,
  .calc-strip {
    grid-template-columns: 1fr;
  }

  .calc-strip div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .calc-strip div:last-child {
    border-bottom: 0;
  }

  .site-footer {
    display: grid;
    gap: 6px;
  }

  .site-footer div::after {
    display: none;
  }
}
