:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --card-2: #f0f3f4;
  --text: #14181d;
  --muted: #667080;
  --line: #e3e8ec;
  --accent: #0d9488;
  --accent-ink: #ffffff;
  --accent-soft: #d8f3ef;
  --danger: #d9262f;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 8px 24px rgba(16, 24, 32, .06);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101315;
    --card: #191d21;
    --card-2: #22272c;
    --text: #e9edf0;
    --muted: #93a0ac;
    --line: #2b3238;
    --accent: #2dd4bf;
    --accent-ink: #062421;
    --accent-soft: #10322e;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans HK",
    "PingFang HK", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card-2);
  padding: 4px;
  border-radius: 999px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .18s, color .18s;
}

.tab.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

.view { display: grid; gap: 14px; }
.view[hidden] { display: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.muted { color: var(--muted); font-size: 13px; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px;
}

/* 輸入區 */
.entry-card { display: grid; gap: 12px; }

#entry-input {
  width: 100%;
  border: 0;
  background: var(--card-2);
  border-radius: 14px;
  padding: 16px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  resize: none;
  outline: none;
  min-height: 96px;
}

#entry-input::placeholder {
  color: var(--muted);
  font-weight: 500;
  font-size: 16px;
}

#entry-input:focus { box-shadow: 0 0 0 2px var(--accent) inset; }

.entry-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 8px;
}

.mic-status {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

.primary-btn {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 17px;
  padding: 15px 20px;
  cursor: pointer;
  transition: transform .08s, filter .18s;
}

.primary-btn:active { transform: scale(.985); filter: brightness(.94); }

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .18s;
}

.ghost-btn:active { background: var(--line); }
.ghost-btn.small { font-size: 13px; padding: 7px 11px; }

.ghost-btn.is-listening {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 0%, transparent); }
}

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
}

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

.today-total {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.today-side { text-align: right; display: grid; gap: 4px; justify-items: end; }

.tip { color: var(--muted); font-size: 13px; padding: 0 4px; }

.recent-list { display: grid; gap: 8px; }
.recent-list:empty { display: none; }

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
}

.recent-item .amt { font-weight: 700; font-variant-numeric: tabular-nums; }

/* 統計 */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--card-2);
  border-radius: 999px;
  padding: 4px;
}

.seg {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background .18s, color .18s;
}

.seg.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.total-card { text-align: left; }

.big-total {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  margin: 2px 0 4px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-head h2 { font-size: 16px; font-weight: 700; }

.cat-list { display: grid; gap: 12px; }

.cat-row { display: grid; gap: 6px; }

.cat-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.cat-name { font-weight: 600; }
.cat-amount { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.cat-amount b { color: var(--text); font-size: 15px; margin-right: 6px; }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--card-2);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  min-width: 3px;
}

.empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }

.tx-list { display: grid; gap: 2px; }

.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.tx:last-child { border-bottom: 0; }

.tx-icon {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--card-2);
  font-size: 18px;
}

.tx-main { flex: 1; min-width: 0; }

.tx-note {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta { color: var(--muted); font-size: 12px; }

.tx-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  margin-left: auto;
}

.tx-del {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
}

.tx-del:active { background: var(--card-2); }

/* 彈出卡 */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 12, 16, .48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fade .18s ease-out;
}

.sheet-backdrop[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
  animation: rise .22s cubic-bezier(.2, .8, .3, 1);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}

@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 8px auto 14px;
}

.sheet h2 { font-size: 19px; font-weight: 800; margin-bottom: 14px; }

#sheet-form { display: grid; gap: 6px; }

.amount-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-2);
  border-radius: 16px;
  padding: 10px 16px;
  margin-bottom: 12px;
}

.currency { font-size: 28px; font-weight: 700; color: var(--muted); }

#f-amount {
  flex: 1;
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 36px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 0;
  min-width: 0;
  -moz-appearance: textfield;
}

#f-amount::-webkit-outer-spin-button,
#f-amount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 13px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.text-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
  margin-bottom: 12px;
}

.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 6px;
}

.sheet-actions .ghost-btn { justify-content: center; padding: 15px 10px; font-size: 16px; }
.sheet-actions .primary-btn { width: 100%; }

.danger-btn {
  margin-top: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
  font-size: 15px;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
}

.danger-btn:active { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #101315;
  color: #f2f5f7;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 999px;
  z-index: 90;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  max-width: calc(100vw - 48px);
  text-align: center;
  animation: toastIn .2s ease-out;
}

.toast[hidden] { display: none; }

@keyframes toastIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (min-width: 600px) {
  .app-main { padding-top: 24px; }
  .big-total { font-size: 46px; }
}

/* iOS/Android tap targets ≥ 44px */
.tab,
.seg,
.chip,
.primary-btn,
.ghost-btn,
.danger-btn,
.link-btn,
.tx-del {
  min-height: 44px;
  min-width: 44px;
}
.ghost-btn.small {
  min-height: 44px;
}
