* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #fff3b0, #ffd6e8 50%, #c9f0ff);
  min-height: 100vh; color: #3b2f63;
}
header { text-align: center; padding: 18px 12px 6px; }
header h1 { margin: 0; font-size: 2.2rem; color: #ff5e9c; text-shadow: 2px 2px 0 #fff; }
header p { margin: 4px 0 0; font-weight: bold; color: #7a5cff; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 40px; }
[hidden] { display: none !important; }

.total {
  background: #fff; border-radius: 20px; padding: 12px; text-align: center;
  font-size: 1.2rem; margin-bottom: 16px; box-shadow: 0 4px 0 #ffc94d; border: 3px solid #ffc94d;
}
.total b { color: #12b76a; font-size: 1.5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.member {
  background: #fff; border-radius: 24px; padding: 14px 8px; text-align: center; cursor: pointer;
  border: 4px solid var(--c); box-shadow: 0 6px 0 var(--c); transition: transform .1s;
}
.member:hover { transform: translateY(-4px) rotate(-1deg); }
.member:active { transform: translateY(2px); }
.member .name { font-weight: bold; margin: 8px 0 2px; font-size: 1.1rem; word-break: break-word; }
.member .money { color: #12b76a; font-weight: bold; font-size: 1.05rem; }
.empty { grid-column: 1 / -1; text-align: center; padding: 24px; font-size: 1.1rem; }

.avatar {
  width: 90px; height: 90px; border-radius: 50%; margin: 0 auto; background: var(--c, #ddd) center/cover;
  display: flex; align-items: center; justify-content: center; font-size: 2.6rem; border: 4px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.big-avatar { width: 120px; height: 120px; font-size: 3.4rem; }

button { font-family: inherit; cursor: pointer; border: none; }
.big {
  display: block; width: 100%; padding: 14px; font-size: 1.2rem; font-weight: bold; color: #fff;
  border-radius: 18px; margin-top: 12px; box-shadow: 0 5px 0 rgba(0,0,0,.2);
}
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.green { background: #22c55e; } .blue { background: #3b82f6; }
.red { background: #ef4444; margin-top: 28px; } .gray { background: #9ca3af; }
.back { background: #fff; border-radius: 14px; padding: 8px 14px; font-size: 1rem; font-weight: bold; box-shadow: 0 3px 0 #bbb; }

.profile { text-align: center; margin: 14px 0; }
.change-photo {
  display: inline-block; margin-top: 8px; background: #fff; color: #7a5cff; font-weight: bold;
  padding: 6px 14px; border-radius: 14px; cursor: pointer; box-shadow: 0 3px 0 #c4b5fd;
}
.profile h2 { margin: 10px 0 4px; font-size: 1.8rem; }
.balance {
  display: inline-block; background: #fff; border: 4px solid #22c55e; border-radius: 24px;
  padding: 8px 24px; font-size: 2rem; font-weight: bold; color: #12b76a;
}

.card { background: #fff; border-radius: 22px; padding: 16px; box-shadow: 0 5px 0 #c4b5fd; border: 3px solid #c4b5fd; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.type { padding: 12px; font-size: 1.1rem; font-weight: bold; border-radius: 14px; background: #eee; color: #777; }
.type.in.active { background: #22c55e; color: #fff; }
.type.out.active { background: #f97316; color: #fff; }
input[type=text], input[type=number] {
  width: 100%; margin-top: 10px; padding: 12px; font-size: 1.1rem; font-family: inherit;
  border: 3px solid #ddd; border-radius: 14px;
}
input:focus { outline: none; border-color: #7a5cff; }

h3 { margin: 24px 0 8px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px;
  padding: 10px 12px; margin-bottom: 8px; border-left: 8px solid var(--t);
}
.history .info { flex: 1; }
.history .note { font-weight: bold; }
.history .date { font-size: .8rem; color: #888; }
.history .amt { font-weight: bold; font-size: 1.15rem; color: var(--t); white-space: nowrap; }
.history .del { background: none; font-size: 1.1rem; opacity: .5; }
.history .del:hover { opacity: 1; }

dialog { border: 5px solid #ff5e9c; border-radius: 26px; padding: 20px; width: min(92vw, 380px); text-align: center; }
dialog::backdrop { background: rgba(60, 20, 100, .5); }
dialog h3 { margin-top: 0; }
.photo-pick { display: block; cursor: pointer; font-weight: bold; color: #7a5cff; }
.photo-pick span { display: block; margin-top: 6px; }

/* ---- Điện thoại ---- */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { padding-bottom: env(safe-area-inset-bottom); }
.big, .type, .back, .change-photo { min-height: 48px; }
@media (max-width: 520px) {
  header h1 { font-size: 1.7rem; }
  main { padding: 8px 12px 32px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .avatar { width: 76px; height: 76px; font-size: 2.2rem; }
  .big-avatar { width: 110px; height: 110px; font-size: 3.2rem; }
  .member .name { font-size: 1rem; }
  .member .money { font-size: .95rem; }
  .total { font-size: 1.05rem; }
  .balance { font-size: 1.6rem; padding: 6px 18px; }
  .profile h2 { font-size: 1.5rem; }
  .history li { flex-wrap: wrap; padding: 10px; }
  .history .amt { font-size: 1.05rem; }
  .history .del { padding: 8px; }
  dialog { padding: 16px; }
}
input[type=text], input[type=number] { font-size: 16px; } /* tránh iPhone tự phóng to khi nhập */

/* ---- Đăng nhập / đổi mật khẩu ---- */
input[type=password] {
  width: 100%; margin-top: 10px; padding: 12px; font-size: 16px; font-family: inherit;
  border: 3px solid #ddd; border-radius: 14px;
}
.err { color: #ef4444; font-weight: bold; min-height: 1.2em; margin: 8px 0 0; }
#userBar { margin-top: 8px; display: flex; gap: 8px; justify-content: center; }
#userBar[hidden] { display: none; }
#userBar button { background: #fff; border-radius: 14px; padding: 8px 12px; font-weight: bold; color: #7a5cff; box-shadow: 0 3px 0 #c4b5fd; min-height: 40px; }
