:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --plus: #16a34a;
  --plus-hover: #15803d;
  --minus: #dc2626;
  --minus-hover: #b91c1c;
  --border: #e5e7eb;
  --positive: #16a34a;
  --negative: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --card-bg: #212327;
    --text: #f2f3f5;
    --text-muted: #9aa0a8;
    --border: #34363b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px 20px;
}

.header {
  text-align: center;
  margin-bottom: 4px;
}

.header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  cursor: pointer;
  color: var(--text-muted);
}

.balance-section {
  text-align: center;
  margin: 8px 0 24px;
}

.balance {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}

.balance.negative {
  color: var(--negative);
}

.balance.positive {
  color: var(--positive);
}

.balance-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-day {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.reset-btn {
  margin-top: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.reset-btn:hover {
  color: var(--negative);
  border-color: var(--negative);
}

.quick-adjust {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.quick-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.quick-reason-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.quick-reason-input:focus {
  outline: 2px solid var(--plus);
  outline-offset: -1px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 8px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-plus {
  background: var(--plus);
}

.btn-plus:hover {
  background: var(--plus-hover);
}

.btn-minus {
  background: var(--minus);
}

.btn-minus:hover {
  background: var(--minus-hover);
}

.btn-wide {
  padding: 12px;
}

.tasks-section {
  margin-bottom: 18px;
}

.tasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tasks-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}

.edit-toggle-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.edit-toggle-btn:hover {
  color: var(--text);
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.task-grid.editing {
  grid-template-columns: 1fr;
}

.task-edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.task-move {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  border-radius: 6px;
  width: 26px;
  height: 22px;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.icon-btn-danger {
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
  color: var(--negative);
  flex-shrink: 0;
}

.task-edit-label {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
}

.task-edit-delta {
  width: 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
  text-align: center;
}

.add-task-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.add-task-row input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
}

#newTaskLabel {
  flex: 1;
  min-width: 120px;
}

#newTaskDelta {
  width: 90px;
}

.add-task-row .btn {
  flex: 1;
  min-width: 100%;
}

.task-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 12px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
}

.task-btn span {
  font-weight: 700;
  flex-shrink: 0;
}

.task-plus {
  background: var(--plus);
}

.task-plus:hover {
  background: var(--plus-hover);
}

.task-minus {
  background: var(--minus);
}

.task-minus:hover {
  background: var(--minus-hover);
}

.history-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.history-delta {
  font-weight: 700;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.history-delta.positive {
  color: var(--positive);
}

.history-delta.negative {
  color: var(--negative);
}

.history-reason {
  flex: 1;
  color: var(--text);
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.history-delete {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.history-delete:hover {
  color: var(--negative);
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 0;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 10;
}
