:root {
  --background: #f3eeea;
  --surface: #fffdfb;
  --soft: #ebe4dd;
  --line: #ded6ce;
  --primary: #776b5d;
  --accent: #b0a695;
  --ink: #3d3731;
  --muted: #8a8076;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

html,
body {
  touch-action: manipulation;
}

#price::placeholder {
  color: #c8c4bf;
  opacity: 1;
}

button, input { font: inherit; }
button { cursor: pointer; }

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(119, 107, 93, 0.22);
  outline-offset: 2px;
}

.app {
  display: flex;
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 18px max(10px, env(safe-area-inset-bottom));
  background: var(--background);
}

.reset {
  flex: 0 0 auto;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 251, 0.78);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
}

.calculator {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

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

.heading h1 {
  margin: 0;
  font-size: clamp(25px, 7vw, 31px);
  font-weight: 760;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field label,
.rate-topline legend {
  display: block;
  margin: 0 0 6px;
  color: #5e554d;
  font-size: 11px;
  font-weight: 750;
}

.field label small {
  margin-left: 3px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
}

.input-wrap {
  display: flex;
  height: 48px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  transition: border-color 0.16s, box-shadow 0.16s;
}

.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(119, 107, 93, 0.08);
}

.input-wrap input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 5px 0 14px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.input-wrap span {
  flex: 0 0 auto;
  padding: 0 13px 0 4px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.input-wrap .prefix {
  padding: 0 1px 0 13px;
  color: var(--primary);
  font-size: 14px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 7px;
}

.keypad button {
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 251, 0.78);
  color: var(--ink);
  font-size: 14px;
  font-weight: 720;
  transition: background 0.14s, transform 0.1s;
}

.keypad button:active {
  background: var(--soft);
  transform: scale(0.97);
}

.rate-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.rate-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rate-topline legend { margin: 0; }

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border-radius: 9px;
  background: var(--soft);
}

.tabs button {
  min-width: 54px;
  padding: 5px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.tabs button.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(73, 62, 52, 0.08);
}

.rate-row,
.live-row {
  display: grid;
  min-height: 48px;
  margin-top: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.rate-row {
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 9px;
  padding-left: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.rate-row b { color: var(--accent); }

.input-wrap.compact {
  height: 46px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 12px 12px 0;
  box-shadow: none;
}

.live-row {
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 7px 8px 7px 14px;
}

.live-row[hidden],
.rate-row[hidden] { display: none; }

.live-row > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 750;
}

.live-row small {
  overflow: hidden;
  max-width: 270px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-row button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--soft);
  color: var(--primary);
  font-size: 18px;
}

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

.fee-presets,
.weight-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-top: 5px;
}

.fee-presets button,
.weight-presets button {
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 253, 251, 0.7);
  color: var(--muted);
  font-size: 8px;
  font-weight: 750;
}

.fee-presets button.active,
.weight-presets button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.result {
  padding: 17px 18px 15px;
  border-radius: 18px;
  background: var(--primary);
  color: white;
  box-shadow: 0 14px 30px rgba(82, 69, 56, 0.16);
}

.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.result-top p {
  margin: 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 10px;
  font-weight: 750;
}

.result-top span {
  color: rgba(255, 255, 255, 0.48);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.total {
  margin-top: 4px;
  font-size: clamp(38px, 12vw, 50px);
  font-weight: 760;
  letter-spacing: -0.055em;
  line-height: 1.08;
  font-variant-numeric: tabular-nums;
}

.total.confirmed { animation: confirm-total 0.28s ease; }

@keyframes confirm-total {
  50% { opacity: 0.65; transform: translateY(-2px); }
}

.breakdown {
  display: flex;
  margin-top: 11px;
  align-items: center;
  gap: 5px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 8px;
  white-space: nowrap;
}

.breakdown b {
  color: rgba(255, 255, 255, 0.88);
  font-size: 9px;
  font-weight: 750;
}

.breakdown i {
  color: rgba(255, 255, 255, 0.25);
  font-style: normal;
}

footer {
  padding-top: 7px;
  color: var(--accent);
  font-size: 8px;
  text-align: center;
}

@media (min-width: 560px) {
  body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
    background: #e9e2dc;
  }

  .app {
    min-height: min(760px, calc(100vh - 36px));
    border: 1px solid rgba(176, 166, 149, 0.38);
    border-radius: 28px;
    box-shadow: 0 24px 60px rgba(73, 61, 51, 0.11);
  }
}

@media (max-height: 680px) {
  .app { padding-top: 8px; padding-bottom: 6px; }
  .calculator { gap: 9px; }
  .heading h1 { font-size: 23px; }
  .form { gap: 8px; }
  .input-wrap { height: 43px; }
  .keypad { gap: 4px; margin-top: 5px; }
  .keypad button { height: 50px; }
  .rate-row, .live-row { min-height: 43px; }
  .input-wrap.compact { height: 41px; }
  .result { padding: 13px 16px 12px; }
  .total { font-size: 36px; }
  .breakdown { margin-top: 7px; }
  .fee-presets, .weight-presets { margin-top: 4px; }
  .fee-presets button, .weight-presets button { height: 21px; }
}
