:root {
  --bg: #0b0f14;
  --card: #141b23;
  --card2: #1c2530;
  --line: #2a3542;
  --text: #e8edf2;
  --dim: #8b98a5;
  --accent: #10b981;
  --accent-press: #0ea371;
  --danger: #f87171;
  --income: #34d399;
  --radius: 16px;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { color-scheme: dark; }

/* 禁止雙擊縮放（雙指縮放由 viewport meta 與 gesture 事件攔截處理） */
html, body { touch-action: manipulation; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 通用 ---------- */
button {
  font-family: inherit;
  font-size: 15px;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--card2);
}
button:active { transform: scale(0.98); }
.primary { background: var(--accent); color: #fff; font-weight: 600; }
.primary:active { background: var(--accent-press); }
.primary:disabled { opacity: 0.6; }
.ghost { background: none; border: 1px solid var(--line); color: var(--dim); }
.danger { background: none; color: var(--danger); }
.wide { width: 100%; }

input, select {
  font-family: inherit;
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px; /* 16px 防 iOS 聚焦自動縮放 */
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.flex { flex: 1; }
.hint { color: var(--dim); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }
.empty { color: var(--dim); text-align: center; padding: 24px 0; font-size: 14px; }

/* ---------- LINE 提示 ---------- */
#line-banner {
  background: #7c2d12;
  color: #ffedd5;
  padding: 10px 14px;
  font-size: 14px;
  text-align: center;
}
#line-banner a { color: #fdba74; }

/* ---------- 首次設定 ---------- */
#view-setup { display: grid; min-height: 100dvh; place-items: center; padding: 16px; }
.setup-card { width: 100%; max-width: 420px; text-align: center; }
.setup-card .logo { width: 72px; border-radius: 18px; }
.setup-card h1 { font-size: 22px; margin: 10px 0 22px; }
.setup-card input { width: 100%; margin: 12px 0; }
.setup-card .row input { margin: 0; }

.member-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; }
.member-list button {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 16px;
}
.member-list button.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- 主畫面 ---------- */
#view-main { max-width: 480px; margin: 0 auto; padding: 8px 16px 48px; }

header { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.app-name { font-weight: 700; font-size: 18px; }
.badge {
  background: var(--card2);
  color: var(--accent);
  font-weight: 600;
  border-radius: 999px;
  padding: 8px 16px;
}

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-top: 6px; }
.month-total { display: flex; justify-content: space-between; align-items: baseline; }
.month-total span { color: var(--dim); font-size: 14px; }
.month-total strong { font-size: 26px; font-variant-numeric: tabular-nums; }

/* ---------- 錄音按鈕 ---------- */
.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 28px 0 20px;
}
.mic {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  display: grid;
  place-items: center;
  padding: 0;
  transition: background 0.2s;
}
.mic::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  z-index: -1;
}
/* 靜音倒數圓環：--cd 0→1 順時針填滿，填滿即自動送出 */
.mic::before {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  background: conic-gradient(#fbbf24 calc(var(--cd, 0) * 360deg), rgba(255, 255, 255, 0.12) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  opacity: 0;
  pointer-events: none;
}
.mic.recording::before { opacity: 1; }
.mic.recording { background: #ef4444; }
.mic.recording::after {
  background: #ef4444;
  opacity: calc(0.35 - var(--vol, 0) * 0.15);
  transform: scale(calc(1 + var(--vol, 0) * 0.7));
  transition: transform 80ms linear;
}
.mic.processing { background: var(--card2); }
.mic .spinner { display: none; }
.mic.processing .icon-mic { display: none; }
.mic.processing .spinner {
  display: block;
  width: 36px;
  height: 36px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.mic-status { color: var(--dim); font-size: 14px; min-height: 20px; text-align: center; }

/* ---------- 文字輸入 ---------- */
.text-row { display: flex; gap: 8px; margin-bottom: 8px; }
.text-row input { flex: 1; min-width: 0; }

/* ---------- 紀錄清單 ---------- */
.date-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--dim);
  font-size: 13px;
  margin: 18px 4px 6px;
}
.date-header .date-total { font-variant-numeric: tabular-nums; }
.record {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.record:active { background: var(--card2); }
.rec-item { font-size: 16px; }
.rec-meta { color: var(--dim); font-size: 12px; margin-top: 2px; }
.rec-amount {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rec-amount.income { color: var(--income); }
#load-more { width: 100%; margin-top: 4px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: #222c37;
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-width: min(92vw, 460px);
  font-size: 14px;
  z-index: 50;
}
#toast-undo {
  color: var(--accent);
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 700;
  padding: 4px 6px;
  white-space: nowrap;
}

/* ---------- Dialog ---------- */
dialog {
  background: var(--card);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  width: min(92vw, 420px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--dim);
}
dialog input, dialog select { width: 100%; min-width: 0; max-width: 100%; }
/* iOS 的日期欄有過寬的固有寬度，會撐破對話框：拿掉原生外觀並強制縮入容器 */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
}
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
