:root {
  --ink: #1c2428;
  --ink-muted: #5c6770;
  --paper-0: #cfd5d8;
  --paper-1: #d9dee1;
  --surface: rgba(232, 236, 238, 0.72);
  --surface-strong: rgba(236, 239, 241, 0.88);
  --accent: #2f6f68;
  --accent-hover: #255952;
  --accent-soft: rgba(47, 111, 104, 0.16);
  --accent-glow: rgba(47, 111, 104, 0.28);
  --warn: #b7791f;
  --danger: #c45c4a;
  --danger-soft: rgba(196, 92, 74, 0.12);
  --line: rgba(28, 36, 40, 0.14);
  --focus: #2f6f68;
  --radius: 10px;
  --font-display: "Noto Serif TC", "Source Han Serif TC", serif;
  --font-body: "Noto Sans TC", "Source Han Sans TC", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  background: var(--paper-0);
  -webkit-font-smoothing: antialiased;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(980px 520px at 50% -8%, rgba(47, 111, 104, 0.11), transparent 52%),
    linear-gradient(168deg, #c5ccd1 0%, #d2d8dc 44%, #c9d0d4 100%);
  z-index: 0;
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cpath d='M0 40H80M40 0V80' stroke='%231c2428' stroke-opacity='0.045' stroke-width='1'/%3E%3C/svg%3E");
  pointer-events: none;
}

.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    calc(1.15rem + var(--safe-t))
    calc(1rem + var(--safe-r))
    calc(0.55rem + var(--safe-b))
    calc(1rem + var(--safe-l));
  max-width: 32rem;
  margin: 0 auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding-top: 0.55rem;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  text-align: center;
}
.brand-logo {
  display: block;
  width: clamp(4.25rem, 16vw, 5.5rem);
  height: clamp(4.25rem, 16vw, 5.5rem);
  object-fit: cover;
  object-position: center;
  border: 0;
  outline: none;
  box-shadow: none;
  background: transparent;
  border-radius: 22%;
  overflow: hidden;
  -webkit-clip-path: inset(0 round 22%);
  clip-path: inset(0 round 22%);
  animation: logoFloat 4.2s ease-in-out infinite;
}
.brand-caption {
  margin: 0;
  max-width: 18rem;
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 3.2vw, 1.05rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1.35;
}

.stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  padding: 0.35rem 0 0.5rem;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  animation: fadeIn 0.28s ease both;
}
.screen.active { display: flex; }

.eyebrow {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.lead {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 3.6vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.label {
  display: block;
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.field {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.amount-wrap {
  text-align: center;
  padding: 0.25rem 0 0.1rem;
}
.amount-prefix {
  display: block;
  color: var(--ink-muted);
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}
.amount-input {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.15rem 0.35rem 0.35rem;
  box-shadow: inset 0 -2px 0 var(--accent-glow);
  transform-origin: center;
  animation: amountPulse 2.4s ease-in-out infinite;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.amount-input:hover {
  background: var(--accent-soft);
  box-shadow:
    inset 0 -2px 0 var(--accent),
    0 0 0 3px var(--accent-soft);
}
.amount-input:focus {
  cursor: text;
  transform: scale(1.03);
  background: var(--accent-soft);
  box-shadow:
    inset 0 -3px 0 var(--accent),
    0 0 0 3px var(--accent-glow);
  animation: none;
}
.amount-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}
.amount-hint.edit-tip {
  color: var(--accent);
  font-weight: 500;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}
.segmented button {
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.segmented button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn {
  min-height: 2.85rem;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--surface); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { filter: brightness(0.95); }
.btn.block { width: 100%; }
.btn.is-loading {
  position: relative;
  opacity: 0.92;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-left: 0.45rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -0.1rem;
  animation: spin 0.7s linear infinite;
}

.trust {
  margin: 0;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.choice-grid .btn {
  min-height: 4.5rem;
  font-size: 1rem;
}

.stack { display: flex; flex-direction: column; gap: 0.65rem; }
.row { display: flex; gap: 0.55rem; align-items: center; }
.row .btn { flex: 1; }

.turnstile-slot {
  min-height: 65px;
  display: flex;
  justify-content: center;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: min(42dvh, 18rem);
  overflow: auto;
  padding-right: 0.15rem;
}
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}
.item-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
}
.item-meta {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.78rem;
}
.item-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  align-self: center;
}
.item-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--ink-muted);
}
.pager button {
  min-height: 2.4rem;
  min-width: 2.4rem;
}

.status {
  min-height: 1.4rem;
  font-size: 0.82rem;
  color: var(--ink-muted);
  text-align: center;
}
.status.is-error { color: var(--danger); }
.status.is-ok { color: var(--accent); }

.success-mark {
  width: 3rem;
  height: 3rem;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid var(--accent);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 1.4rem;
  animation: popIn 0.32s ease both;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(28, 36, 40, 0.38);
  padding: 1rem;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(100%, 22rem);
  padding: 1.15rem 1.1rem 1rem;
  border-radius: 12px;
  background: #e8ecee;
  border: 1px solid var(--line);
}
.modal-card h2 {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.modal-card p {
  margin: 0 0 1rem;
  color: var(--ink-muted);
  font-size: 0.92rem;
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.82); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes amountPulse {
  0%, 100% {
    box-shadow: inset 0 -2px 0 var(--accent-glow);
  }
  50% {
    box-shadow:
      inset 0 -2px 0 var(--accent),
      0 0 0 3px var(--accent-soft);
  }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 400px) {
  .choice-grid { grid-template-columns: 1fr; }
  .segmented {
    grid-template-columns: repeat(3, 1fr);
  }
  .segmented button {
    font-size: 0.72rem;
    min-height: 2.55rem;
    padding: 0.35rem 0.2rem;
  }
  .amount-input { font-size: 2.2rem; }
}

@media (max-height: 560px) {
  .shell { padding-top: calc(0.65rem + var(--safe-t)); }
  .top { padding-top: 0.28rem; }
  .brand-logo {
    width: clamp(3.2rem, 12vw, 4rem);
    height: clamp(3.2rem, 12vw, 4rem);
  }
  .brand-caption { font-size: 0.9rem; }
  .brand { gap: 0.28rem; }
  .stage { justify-content: flex-start; padding-top: 0.15rem; }
  .lead { font-size: 1.15rem; }
  .amount-input { font-size: 2.1rem; }
  .choice-grid .btn { min-height: 3.4rem; }
  .list { max-height: 28dvh; }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .success-mark,
  .amount-input,
  .brand-logo,
  .btn,
  .btn.is-loading::after,
  .segmented button,
  .field {
    animation: none !important;
    transition: none !important;
  }
  .amount-input:focus { transform: none; }
  .btn.is-loading::after { display: none; }
}
