:root {
  color-scheme: light dark;
  --income: #2e7d32;
  --expense: #c62828;
  --accent: #1976d2;
  --border: #d8d8d8;
  --chip-bg: #f0f0f0;
  --card-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --border: #444;
    --chip-bg: #2a2a2a;
    --card-bg: #1e1e1e;
  }
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 12px 96px;
  font-size: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 16px;
}

.topbar h1 {
  font-size: 1.4rem;
  margin: 0;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: gray;
}

.user-badge button {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--chip-bg);
  color: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

#auth-section {
  margin-top: 40px;
}

#auth-section h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  width: 100%;
  background: transparent;
  color: inherit;
}

.auth-form button[type="submit"] {
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 1.05rem;
  font-weight: bold;
  cursor: pointer;
}

.auth-error {
  color: var(--expense);
  font-size: 0.85rem;
  margin: -6px 0 0;
  min-height: 1em;
}

section {
  margin-bottom: 20px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: var(--card-bg);
}

h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

/* 지출/수입 토글 */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.type-btn {
  flex: 1;
  padding: 12px;
  font-size: 1rem;
  font-weight: bold;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.type-btn[data-type="expense"].active {
  background: var(--expense);
  color: white;
  border-color: var(--expense);
}

.type-btn[data-type="income"].active {
  background: var(--income);
  color: white;
  border-color: var(--income);
}

#transaction-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-label {
  font-size: 0.9rem;
  font-weight: bold;
  color: gray;
}

input[type="date"],
input[type="text"] {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  width: 100%;
  background: transparent;
  color: inherit;
}

#input-amount {
  font-size: 1.4rem;
  font-weight: bold;
  text-align: right;
}

/* 카테고리 칩 / 빠른 버튼 공통 */
.chip-group,
.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip-bg);
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 40px;
}

.chip.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.chip-clear {
  color: gray;
}

#submit-btn {
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 1.05rem;
  font-weight: bold;
  cursor: pointer;
  position: sticky;
  bottom: 12px;
}

/* 이번 달 요약 */
.summary-cards {
  display: flex;
  gap: 10px;
}

.card-item {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.card-item.income strong {
  color: var(--income);
}

.card-item.expense strong {
  color: var(--expense);
}

/* 지출 분석 (원형 게이지 + 앵겔지수) */
.analysis-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.gauge-block {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.donut {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
}

.donut-center {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  bottom: 18px;
  border-radius: 50%;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
}

.donut-center strong {
  font-size: 1.25rem;
}

.donut-center span {
  font-size: 0.65rem;
  color: gray;
}

.gauge-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
}

.gauge-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.legend-name {
  flex: 0 0 auto;
}

.legend-pct {
  color: gray;
  font-size: 0.8rem;
}

.engel-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.engel-block strong {
  font-size: 1.6rem;
}

.engel-desc {
  font-size: 0.8rem;
  color: gray;
}

/* 날짜별 거래 내역 */
.date-group {
  margin-bottom: 14px;
}

.date-group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.date-label {
  font-weight: bold;
}

.date-subtotal {
  color: gray;
  font-size: 0.8rem;
}

.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.tx-category {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  font-size: 0.8rem;
  white-space: nowrap;
}

.tx-memo {
  flex: 1;
  color: gray;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amount {
  flex: 0 0 auto;
  font-weight: bold;
  white-space: nowrap;
}

.tx-amount.income {
  color: var(--income);
}

.tx-amount.expense {
  color: var(--expense);
}

.delete-btn {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: gray;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
}

.empty-state {
  color: gray;
  text-align: center;
  padding: 20px 0;
  font-size: 0.9rem;
}

@media (min-width: 481px) {
  body {
    max-width: 640px;
    padding-bottom: 40px;
  }

  #submit-btn {
    position: static;
  }
}
