:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --text: #0b0b0f;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0f;
    --card: #17171d;
    --text: #f5f5f7;
    --muted: #9ca3af;
    --border: #2a2a33;
    --primary: #3b82f6;
    --primary-text: #ffffff;
    --danger: #ef4444;
    --success: #22c55e;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.3);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#app { max-width: 640px; margin: 0 auto; padding: 16px; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px 20px;
}

.header h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.icon-btn:active { background: var(--border); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty h2 { font-weight: 600; margin: 0 0 8px; color: var(--text); }
.empty p { margin: 0; font-size: 15px; }

.counter-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: transform 0.08s;
}

.card:active { transform: scale(0.985); }

.card .name {
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .count {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  font-size: 30px;
  font-weight: 300;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  z-index: 10;
}

.fab:active { transform: scale(0.94); }

.detail-name {
  font-size: 22px;
  font-weight: 700;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: center;
  width: 100%;
  padding: 6px 0;
  letter-spacing: -0.01em;
}

.detail-name:focus { outline: none; border-bottom: 2px solid var(--primary); }

.big-number {
  text-align: center;
  font-size: 120px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
  margin: 30px 0 24px;
  line-height: 1;
  color: var(--text);
}

.plus-btn {
  width: 100%;
  height: 140px;
  border-radius: 24px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  font-size: 56px;
  font-weight: 300;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
  cursor: pointer;
  margin-bottom: 12px;
  transition: transform 0.08s;
}

.plus-btn:active { transform: scale(0.97); }

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 28px;
}

.action-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px;
}

.action-btn:active { background: var(--border); }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 20px 4px 10px;
}

.history {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.history-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.history-item:last-child { border-bottom: none; }

.history-item .delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.history-item .delta.plus { color: var(--success); }
.history-item .delta.minus { color: var(--danger); }
.history-item .delta.reset { color: var(--muted); }
.history-item .ts { color: var(--muted); font-size: 13px; }

.history-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 14px; }

.danger-btn {
  width: 100%;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 28px;
}

.danger-btn:active { background: rgba(220, 38, 38, 0.08); }

.meta {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 20px;
  padding-bottom: 40px;
}

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

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

.field-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
}

.field-help {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.action-btn.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.action-btn.primary:active { opacity: 0.85; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 15px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
}
