:root {
  --bg-top: #1a2e24;
  --bg-bottom: #0f1a14;
  --surface: #f3efe6;
  --surface-soft: #e8e2d6;
  --ink: #14201a;
  --muted: #5c6b62;
  --income: #1f6b45;
  --expense: #a33b2b;
  --focus: #2f7a55;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(8, 18, 12, 0.28);
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 10% -10%, #2d4a3a 0%, transparent 55%),
    radial-gradient(90% 60% at 100% 0%, #3a5c48 0%, transparent 45%),
    linear-gradient(165deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
}

.app {
  width: min(100% - 1.5rem, 28rem);
  margin: 0 auto;
  padding: 1.25rem 0 2.5rem;
}

.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.auth-card {
  width: min(100%, 24rem);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.25rem 1.5rem;
  text-align: center;
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.auth-subtitle {
  margin: 0.5rem 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.hero {
  color: #f5f1e8;
  padding: 1.75rem 0.25rem 1.5rem;
  text-align: center;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.logout-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f1e8;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.balance {
  margin: 0.85rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 0;
  color: rgba(245, 241, 232, 0.72);
  font-size: 0.95rem;
}

.next-income-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.85rem;
  padding: 0.35rem 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  font-size: 0.88rem;
  color: #f5f1e8;
  font-weight: 500;
  letter-spacing: 0.01em;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.panel,
.history,
.debts-section,
.debt-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 1rem;
  margin-top: 1rem;
}

.debts-section {
  padding: 1rem;
  margin-top: 0;
}

.debts-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.debts-section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.debt-total {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--expense);
  white-space: nowrap;
}

.debt-item {
  padding: 1rem;
  margin-top: 0.85rem;
  background: var(--surface-soft);
  box-shadow: none;
  border: 1px solid #ddd5c6;
}

.debt-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.debt-item-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.debt-item-balance {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--expense);
  white-space: nowrap;
}

.add-debt-panel {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid #ddd5c6;
}

.add-debt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.add-debt-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 0.85rem;
  border: 1px dashed #b8b0a0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.add-debt-btn:hover {
  color: var(--ink);
  border-color: var(--focus);
  background: rgba(255, 255, 255, 0.45);
}

.ghost-btn {
  min-height: 48px;
  border: 1px solid #d2cbbd;
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ghost-btn:focus-visible,
.add-debt-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.debt-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.debt-card-head h2,
.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.section-title {
  margin-bottom: 0.85rem;
}

.debt-amount {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--expense);
  white-space: nowrap;
}

.debt-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.debt-history {
  margin-top: 1.1rem;
  padding-top: 0.85rem;
  border-top: 1px solid #ddd5c6;
}

.debt-history .history-head {
  margin-bottom: 0.35rem;
}

.debt-history-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.submit.is-repay {
  background: var(--expense);
}

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

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

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  padding: 0.3rem;
  margin-bottom: 1rem;
  background: var(--surface-soft);
  border-radius: 12px;
}

.tab {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(20, 32, 26, 0.12);
}

.tab:focus-visible,
.submit:focus-visible,
.field input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.form {
  display: grid;
  gap: 0.85rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  border: 1px solid #d2cbbd;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
}

#amount,
.amount-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.submit {
  min-height: 48px;
  margin-top: 0.25rem;
  border: 0;
  border-radius: 12px;
  background: var(--bg-top);
  color: #f5f1e8;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}

.submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

.submit.is-expense {
  background: var(--expense);
}

.error {
  margin: 0;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: #f8e4e0;
  color: var(--expense);
  font-size: 0.92rem;
}

.history {
  margin-top: 1rem;
  padding: 1.1rem 1rem 0.5rem;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.history-head h2,
.history-head .debt-history-title {
  margin: 0;
}

.history h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.clear-btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border: 1px solid #d2cbbd;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.clear-btn:hover {
  color: var(--expense);
  border-color: #e0b8b0;
  background: #f8e4e0;
}

.clear-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.clear-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

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

.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.75rem;
  padding: 0.85rem 0;
  border-top: 1px solid #ddd5c6;
}

.item-title {
  font-weight: 600;
}

.item-meta {
  grid-column: 1;
  color: var(--muted);
  font-size: 0.85rem;
}

.item-amount {
  grid-row: 1 / span 2;
  align-self: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

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

.empty {
  margin: 0;
  padding: 0.5rem 0 1.1rem;
  color: var(--muted);
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 480px) {
  .app {
    padding-top: 2rem;
  }

  .panel,
  .debts-section {
    padding: 1.25rem;
  }
}
