:root {
  --bg: #f7f4ef;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #6d655c;
  --line: #ded7cf;
  --brand: #0f766e;
  --brand-strong: #0b4f4a;
  --accent: #c7522a;
  --soft: #eef7f4;
  --shadow: 0 18px 50px rgba(42, 35, 28, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(199, 82, 42, 0.08), transparent 42%),
    var(--bg);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.calculator-panel,
.side-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(222, 215, 207, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.calculator-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  padding: 24px;
}

.app-header,
.side-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.1;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 15px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--brand-strong);
  background: var(--soft);
  font-size: 13px;
  font-weight: 700;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

.control {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.control > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.stepper,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stepper {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 44px;
  align-items: stretch;
  width: min(100%, 280px);
  overflow: hidden;
}

.stepper button {
  border: 0;
  color: #fff;
  background: var(--brand);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}

.stepper button:active {
  background: var(--brand-strong);
}

.stepper input {
  min-width: 0;
  width: 100%;
  border: 0;
  padding: 0 10px;
  text-align: right;
  font-weight: 800;
  color: var(--ink);
  background: transparent;
}

.unit {
  align-self: center;
  padding-right: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

select {
  max-width: 280px;
  padding: 0 14px;
  color: var(--ink);
  font-weight: 800;
}

.select-control {
  justify-content: start;
}

.select-control select {
  width: min(100%, 280px);
}

.self-managed-control.is-hidden {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 14px;
  align-content: start;
}

.result-card {
  display: grid;
  gap: 8px;
  min-height: 156px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-card.primary {
  color: #fff;
  border-color: var(--brand-strong);
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}

.result-label,
.result-note {
  font-size: 14px;
  font-weight: 700;
}

.result-label {
  color: var(--muted);
}

.result-card.primary .result-label,
.result-card.primary .result-note {
  color: rgba(255, 255, 255, 0.82);
}

.result-card strong {
  align-self: center;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

.result-note {
  align-self: end;
  color: var(--muted);
}

.side-panel {
  display: grid;
  gap: 18px;
  align-content: start;
  max-height: calc(100vh - 36px);
  padding: 20px;
  overflow: auto;
}

.side-header {
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.sidebar-section {
  display: grid;
  gap: 10px;
}

.metric-list {
  display: grid;
  gap: 8px;
}

.metric {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid rgba(222, 215, 207, 0.78);
}

.metric-name {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-code {
  display: block;
  margin-top: 3px;
  color: #8a8178;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.metric-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.compact .metric {
  padding: 8px 0;
}

.invalid {
  color: var(--accent);
}

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

  .side-panel {
    max-height: none;
  }
}

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

  .calculator-panel,
  .side-panel {
    padding: 16px;
  }

  .app-header,
  .side-header {
    display: grid;
  }

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

  .select-control select {
    width: 100%;
    max-width: none;
  }

  .stepper {
    width: 100%;
  }

  .result-card {
    min-height: 132px;
  }
}
