/* 색: 라이트 기본, 다크는 data-mode=dark 또는 시스템 설정 */
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #111;
  --muted: #6b6b76;
  --line: #e4e4ea;
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, 0.12);
  --plus: #12a150;
  --minus: #e5484d;
  --together: #f59e0b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #0b0b0d; --card: #17171b; --text: #f2f2f5; --muted: #9a9aa6; --line: #2a2a31;
    --plus: #3dd68c; --minus: #ff6369; color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: #0b0b0d; --card: #17171b; --text: #f2f2f5; --muted: #9a9aa6; --line: #2a2a31;
  --plus: #3dd68c; --minus: #ff6369; color-scheme: dark;
}
:root[data-accent="purple"] { --accent: #7c5cff; --accent-soft: rgba(124, 92, 255, 0.14); }
:root[data-accent="blue"] { --accent: #3b82f6; --accent-soft: rgba(59, 130, 246, 0.14); }
:root[data-accent="green"] { --accent: #16a34a; --accent-soft: rgba(22, 163, 74, 0.14); }
:root[data-accent="orange"] { --accent: #f97316; --accent-soft: rgba(249, 115, 22, 0.14); }
:root[data-accent="pink"] { --accent: #ec4899; --accent-soft: rgba(236, 72, 153, 0.14); }
:root[data-accent="red"] { --accent: #ef4444; --accent-soft: rgba(239, 68, 68, 0.14); }

* { box-sizing: border-box; }
/* hidden 속성이 display 지정(#login의 grid 등)에 덮이지 않게 */
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
.screen { max-width: 480px; margin: 0 auto; padding: 20px 16px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.label { font-size: 0.9rem; color: var(--muted); margin-bottom: 8px; }
.error { color: var(--minus); font-size: 0.9rem; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 12px 18px; font-size: 1rem; cursor: pointer; font-family: inherit; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--minus); border-color: var(--minus); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn.wide { width: 100%; margin-top: 8px; }
.icon-btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; width: 36px; height: 34px; font-size: 1rem; cursor: pointer; position: relative; }
.icon-btn .badge-dot { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--minus); }

/* 로그인 */
#login { min-height: 100vh; display: grid; place-items: center; }
.login-card { text-align: center; width: 100%; }
.logo { font-size: 2.6rem; }
h1 { margin: 6px 0; letter-spacing: -0.02em; }
.dots { display: flex; gap: 12px; justify-content: center; margin: 22px 0 10px; min-height: 16px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.keypad button { font-size: 1.5rem; padding: 16px 0; border-radius: 16px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; font-family: inherit; }
.keypad button:active { background: var(--line); }
.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* 메인 */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.top-btns { display: flex; gap: 6px; align-items: center; }
.hello { font-size: 1.05rem; }
.balance-card { text-align: center; }
.balance { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 6px; font-variant-numeric: tabular-nums; }
.balance.neg { color: var(--minus); }
.interest { margin-top: 10px; display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.88rem; font-weight: 600; }
.big-clock { font-size: 3rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; margin: 6px 0; }
#active-card { text-align: center; border-color: var(--accent); }
#active-card.together { border-color: var(--together); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 9px; font-size: 1rem; cursor: pointer; font-family: inherit; }
.tab.active { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.tab small { font-weight: 400; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chips button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-family: inherit; }
.chips button.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.hms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hms label { display: flex; align-items: center; gap: 6px; }
.hms input { width: 100%; min-width: 0; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 1.1rem; text-align: center; }
.hms span { color: var(--muted); white-space: nowrap; }

/* 누나 타임 */
.sister-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.sister-btns .btn { display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; }
.sister-btns small { font-weight: 400; font-size: 0.78rem; color: var(--muted); }

/* 통계 막대 */
.chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 140px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar .stack { width: 70%; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 3px 3px; overflow: hidden; background: var(--bg); min-height: 4px; }
.bar .used { background: var(--accent); }
.bar .tog { background: var(--together); }
.bar .v { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }
.bar .d { font-size: 0.8rem; color: var(--muted); }
.bar.today .d { color: var(--accent); font-weight: 800; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; text-align: center; }
.stat-row div { background: var(--bg); border-radius: 12px; padding: 10px 4px; }
.stat-row b { display: block; font-size: 1rem; }
.stat-row span { font-size: 0.75rem; color: var(--muted); }
.legend { display: flex; gap: 12px; justify-content: center; margin-top: 8px; font-size: 0.75rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* 기록 */
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 0.93rem; }
.ledger li:first-child { border-top: 0; }
.ledger .when { color: var(--muted); font-size: 0.8rem; }
.ledger .amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger .plus { color: var(--plus); }
.ledger .minus { color: var(--minus); }
.ledger .zero { color: var(--together); }
.ledger .empty { color: var(--muted); justify-content: center; }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { background: var(--card); border-radius: 20px; padding: 22px; width: 100%; max-width: 400px; max-height: 90vh; overflow: auto; }
.modal-card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.modal-card .keypad button { padding: 12px 0; font-size: 1.3rem; }
.modal-foot { display: flex; gap: 8px; margin-top: 16px; }
.modal-foot .btn { flex: 1; }
.choice-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.choice-row button { padding: 14px 0; font-size: 1.1rem; font-weight: 700; }
.choice-row button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* 테마 */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; margin: 8px 0 16px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; cursor: pointer; font-family: inherit; font-size: 0.95rem; }
.seg button.on { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.swatches button { width: 40px; height: 40px; padding: 0; border-radius: 50%; border: 3px solid transparent; cursor: pointer; flex: none; }
.swatches button.on { border-color: var(--text); }

/* 성적표 */
.report-head { text-align: center; }
.report-title { font-size: 2.4rem; }
.report-title + div { font-size: 1.2rem; font-weight: 800; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.report-grid div { background: var(--bg); border-radius: 12px; padding: 12px; }
.report-grid b { display: block; font-size: 1.1rem; }
.report-grid span { font-size: 0.78rem; color: var(--muted); }
.report-lines { font-size: 0.92rem; line-height: 1.7; }
.report-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
