/* 판돈정산 — 디자인 토큰과 컴포넌트.
   값의 정본은 SPEC.md 9장과 docs/design 의 시스템 시트다. 여기에 새 색을 만들지 않는다. */

:root {
  --bg:        #12131A;   /* 밤에 게임하니까 다크 고정 */
  --surface:   #1C1E28;
  --surface-2: #262A38;
  --border:    #2A2D3A;
  --text:      #ECEDF2;
  --text-dim:  #8B8FA3;

  --win:       #3DDC84;
  --lose:      #FF6B6B;
  --even:      #8B8FA3;
  --accent:    #FFD54D;

  /* 플레이어 고정색 — 5명까지. 자리 순서대로 배정된다 (store.js PLAYER_COLORS) */
  --p1: #4DA3FF;  --p2: #FFB84D;  --p3: #B47DFF;
  --p4: #35D6C4;  --p5: #FF7EC7;

  --tap-min:   56px;
  --radius:    14px;
  --pill:      999px;

  --fd: "Hahmlet", "Nanum Myeongjo", serif;
  --fb: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic",
        "Noto Sans KR", sans-serif;
  --fn: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--fb);
  -webkit-font-smoothing: antialiased;
  /* overscroll-behavior 를 잠그지 않는다 — 주소창이 없는 홈 화면 앱에서
     "당겨서 새로고침"이 유일한 탈출구다 */
}

/*
 * 홈 화면에 추가하면 상태바(다이나믹 아일랜드 포함) 아래까지 웹뷰가 올라온다
 * — viewport-fit=cover + black-translucent 조합. 네 방향 안전영역을 전부 비켜준다.
 * 위를 빠뜨리면 첫 줄이 시계와 배터리에 그대로 가린다.
 */
body {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input  { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

#app { max-width: 480px; margin: 0 auto; padding: 0 0 32px; }

/* ── 공통 조각 ────────────────────────────────────────────────────── */
.bar { display: flex; align-items: baseline; justify-content: space-between; padding: 20px 20px 14px; }
.bar h1 { font-family: var(--fd); font-weight: 700; font-size: 20px; letter-spacing: .03em; margin: 0; }
.meta { font-family: var(--fn); font-size: 12px; color: var(--text-dim); letter-spacing: .02em; }
.sect { padding: 0 20px; }
.label {
  text-wrap: pretty;
  font-size: 13px; color: var(--text-dim); margin: 0 0 10px; font-weight: 500;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.hint { font-size: 12px; color: var(--text-dim); text-wrap: pretty; }
/* 라벨 줄 안의 링크. 본문 흐름을 밀지 않으면서 손가락이 닿을 만큼은 키운다 */
.linkbtn { font-size: 12px; color: var(--text-dim); text-decoration: underline;
  padding: 8px 4px; min-height: 33px; display: inline-flex; align-items: center; }
.warn p, .empty p, .sect > p { text-wrap: pretty; }
.num { font-family: var(--fn); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.win { color: var(--win); } .lose { color: var(--lose); } .even { color: var(--even); }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.divider { height: 1px; background: var(--border); margin: 22px 20px; }
.mt { margin-top: 24px; }

/* ── 잔액 카드 ────────────────────────────────────────────────────── */
.bal {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.bal.out { opacity: .45; }
/* 룰 행은 조절기가 넓을 때 다음 줄로 접힌다 — 설명이 세 줄로 눌리지 않게 */
.bal.rule { flex-wrap: wrap; row-gap: 12px; }
.bal.rule > .rule-t { flex: 1 1 58%; min-width: 0; }
.bal .tag { width: 4px; height: 30px; border-radius: 2px; flex: none; }
.av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; flex: none; }
.nm { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { font-family: var(--fn); font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.mood { font-size: 17px; }

/* ── 누르는 것 ────────────────────────────────────────────────────── */
.btn {
  width: 100%; min-height: var(--tap-min); border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: #12131A; border-color: var(--accent); letter-spacing: .28em; text-indent: .28em; }
.btn.ghost { background: transparent; }
.btn:disabled { cursor: default; }
.btn.primary:disabled { background: var(--surface); color: var(--text-dim); border-color: var(--border); }

.who {
  min-height: var(--tap-min); border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 15px; font-weight: 600; color: var(--text-dim);
}
.who[aria-pressed="true"] { color: var(--text); }

.chip {
  min-height: 44px; padding: 0 11px; border-radius: var(--pill); border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; white-space: nowrap;
  transition: transform 120ms ease, background-color 120ms ease;
}
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--text); border-color: transparent; font-weight: 600; transform: scale(1.04); }
.chip.off { opacity: .45; }
.chip:disabled { opacity: .3; cursor: default; }
.chip.dashed { border-style: dashed; }

.pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.key {
  height: 58px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center; font-family: var(--fn); font-size: 21px; font-weight: 500;
}
.key:active { background: var(--surface-2); }

.field {
  min-height: var(--tap-min); border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); display: flex; align-items: center; padding: 0 14px; gap: 10px;
}
.field input { all: unset; flex: 1; min-width: 0; font-size: 16px; }
.field input[type="number"] { text-align: right; font-family: var(--fn); font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 600; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px;
}
.seg > button {
  min-height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  gap: 6px; font-size: 15px; font-weight: 600; color: var(--text-dim);
}
.seg > button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.toggle { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-2); display: flex; align-items: center; padding: 3px; flex: none; }
.toggle > span { width: 22px; height: 22px; border-radius: 50%; background: var(--text-dim); transition: transform 140ms ease; }
.toggle[aria-pressed="true"] { background: var(--accent); }
.toggle[aria-pressed="true"] > span { background: #12131A; transform: translateX(18px); }

.stepper { display: flex; align-items: center; background: var(--surface-2); border-radius: var(--pill); overflow: hidden; flex: none; }
.stepper button { width: 38px; height: 36px; display: grid; place-items: center; font-size: 18px; color: var(--text-dim); }
.stepper .v { min-width: 38px; text-align: center; font-size: 15px; font-weight: 600; }

/* ── 영수증 — 이 앱의 시그니처 ─────────────────────────────────────── */
.rc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.rc-h { padding: 13px 16px 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tearwrap { position: relative; height: 16px; display: flex; align-items: center; }
.tearwrap::before, .tearwrap::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg); top: 1px;
}
.tearwrap::before { left: -8px; } .tearwrap::after { right: -8px; }
.tear { flex: 1; height: 1px; background: repeating-linear-gradient(90deg, var(--border) 0 5px, transparent 5px 11px); }
.rc-b { padding: 12px 16px 15px; display: flex; flex-direction: column; gap: 11px; }
.rc-l { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rc-l .nm { font-size: 14px; font-weight: 500; }
.rc-l.out { opacity: .45; }

/* ── 알림 ─────────────────────────────────────────────────────────── */
.warn {
  margin: 12px 20px 0; padding: 13px 14px; border-radius: var(--radius);
  background: rgba(255, 107, 107, .1); border: 1px solid rgba(255, 107, 107, .35);
}
.warn b { display: block; font-size: 14px; color: var(--lose); }
.warn p { margin: 6px 0 0; font-size: 12px; line-height: 1.6; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(28px + env(safe-area-inset-bottom));
  background: var(--surface-2); border-radius: var(--pill); padding: 12px 18px;
  font-size: 13px; display: flex; align-items: center; gap: 8px; z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); animation: rise 160ms ease;
  max-width: calc(100% - 40px);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.empty { text-align: center; padding: 30px 10px; }
.empty .big { font-size: 26px; }
.empty h2 { font-size: 15px; font-weight: 600; margin: 12px 0 0; }
.empty p { font-size: 13px; color: var(--text-dim); margin: 7px 0 0; line-height: 1.6; }

.foot { display: flex; justify-content: space-between; padding: 20px; }
.foot button { font-size: 14px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; min-height: 44px; }

.crown { font-size: 13px; color: var(--accent); }

/* 헤더의 더보기 — 어느 화면에서든 룰과 새로고침에 닿는 길 */
.more { width: 44px; height: 44px; margin: -10px -10px -10px 0; border-radius: var(--radius);
  display: grid; place-items: center; font-size: 19px; color: var(--text-dim); flex: none; }
.bar-r { display: flex; align-items: center; gap: 6px; }

.menu { display: flex; flex-direction: column; gap: 8px; }
.menu button {
  min-height: var(--tap-min); border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; gap: 12px; padding: 0 16px;
  font-size: 15px; font-weight: 600; text-align: left;
}
.menu button .sub { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: auto; }
.menu button.danger { color: var(--lose); }

.update {
  margin: 12px 20px 0; padding: 13px 14px; border-radius: var(--radius);
  background: rgba(255, 213, 77, .1); border: 1px solid rgba(255, 213, 77, .35);
  display: flex; align-items: center; gap: 12px;
}
.update b { font-size: 14px; color: var(--accent); }
.update button { margin-left: auto; min-height: 40px; padding: 0 14px; border-radius: var(--pill);
  background: var(--accent); color: #12131A; font-size: 13px; font-weight: 600; flex: none; }

/* 잔액 숫자 롤링 — 화면을 통째로 다시 그려도 이 노드는 살아남는다 (ui.js) */
.amt.roll { animation: roll 300ms ease; }
@keyframes roll { from { opacity: .35; transform: translateY(-4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
