* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1b1d24;
  --text-dim: #6b7080;
  --green: #1c8a4b;
  --green-bg: #e7f7ee;
  --red: #c22b2b;
  --red-bg: #fdeaea;
  --accent: #3a5bfd;
  --border: #e6e7ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --card: #1e1f27;
    --text: #f0f1f5;
    --text-dim: #9b9eac;
    --green: #3ed483;
    --green-bg: #163826;
    --red: #ff6b6b;
    --red-bg: #3a1e1e;
    --accent: #6a83ff;
    --border: #2c2e38;
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent);
  color: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 13px;
}

.install-banner.hidden { display: none; }

.install-icon { font-size: 18px; flex-shrink: 0; }

.install-text { flex: 1; line-height: 1.3; }

.install-btn {
  border: none;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.install-btn.hidden { display: none; }

.install-dismiss {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.8;
  flex-shrink: 0;
  padding: 0 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.budget-pill {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-toggle, .period-tabs {
  display: flex;
  background: var(--card);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.mode-btn, .period-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.mode-btn.active, .period-tab.active {
  background: var(--accent);
  color: #fff;
}

.period-tabs.hidden { display: none; }

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero {
  background: var(--card);
  border-radius: 20px;
  padding: 28px 20px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.hero-label {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 6px;
}

.hero-amount {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-amount.positive { color: var(--green); }
.hero-amount.negative { color: var(--red); }

.hero-sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.month-total-card {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-total-label {
  font-size: 13px;
  color: var(--text-dim);
}

.month-total-value {
  font-size: 16px;
  font-weight: 700;
}

.add-expense form {
  display: flex;
  gap: 8px;
  background: var(--card);
  padding: 10px;
  border-radius: 14px;
}

.add-expense input {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}

#expAmount { width: 90px; }
#expDesc { flex: 1; min-width: 0; }

.add-expense button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.today-list h2 {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--text-dim);
}

.expense-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expense-list li {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.expense-item-desc {
  font-size: 14px;
}

.expense-item-amount {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.delete-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
}

.empty-msg {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 12px 0;
}

.history-toggle {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.history-list.hidden, .modal.hidden { display: none; }

.history-list li {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.history-list .h-date { color: var(--text-dim); }
.history-list .h-over { color: var(--red); font-weight: 600; }
.history-list .h-under { color: var(--green); font-weight: 600; }
.history-list .h-today { border: 1px solid var(--accent); }

.who-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.who-screen.hidden { display: none; }

.who-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.who-card h2 {
  font-size: 22px;
}

.who-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

.who-card input {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
}

.who-match {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 13px;
}

.who-match.hidden { display: none; }

.who-match #whoMatchCheck {
  background: var(--green-bg);
  color: var(--green);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.who-continue {
  width: 100%;
  padding: 14px;
  font-size: 15px;
}

.who-continue:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card h3 { font-size: 16px; }

.modal-card input {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; color: var(--text-dim); }

@media (min-width: 480px) {
  .hero-amount { font-size: 52px; }
}
