:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1d1b19;
  --muted: #7a736b;
  --line: #e6e0d7;
  --key: #ffffff;
  --key-fn: #ebe5dc;
  --accent: #c8102e;
  --warn: #b45309;

  /* 세로 공간 배분: 화면이 낮으면 줄인다 */
  --gap: 10px;
  --amount-size: clamp(40px, 12vw, 54px);
  --key-h: clamp(48px, 7.6dvh, 64px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --card: #211e1b;
    --text: #f3efe9;
    --muted: #a39b91;
    --line: #34302b;
    --key: #2a2622;
    --key-fn: #3a352f;
    --accent: #ff4d5e;
    --warn: #f59e0b;
  }
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;            /* 페이지 스크롤 금지 */
  overscroll-behavior: none;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}
button { touch-action: manipulation; font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app {
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding:
    max(8px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

/* 금액 표시 */
.display { flex: none; display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.amount-line {
  font-size: var(--amount-size); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.amount-line .cur { font-size: 0.42em; color: var(--accent); margin-right: 6px; vertical-align: 0.55em; }
.amount-line[data-len="l"] { font-size: calc(var(--amount-size) * 0.82); }
.amount-line[data-len="xl"] { font-size: calc(var(--amount-size) * 0.68); }
.krw-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; align-self: stretch; }
.country-btn {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 4px 10px; font-size: 13.5px; font-weight: 600;
}
.krw {
  display: flex; align-items: center; gap: 6px; min-width: 0; border: 0; background: none; padding: 2px 0;
  font-size: clamp(17px, 5vw, 21px); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.krw #krwText { overflow: hidden; text-overflow: ellipsis; }
.krw .swap {
  flex: none; font-size: 12px; font-weight: 700; color: var(--accent);
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 2px 7px;
}

.say {
  display: flex; flex-direction: column; align-items: flex-end;
  margin-top: 2px; border: 0; background: none; padding: 2px 0; text-align: right;
}
.say-ko { font-size: clamp(14px, 4.2vw, 16px); font-weight: 600; }
.say-ko::after { content: " 🔊"; font-size: 0.85em; }
.say-native {
  font-size: 12.5px; color: var(--muted); letter-spacing: 0.05em;
  font-family: var(--native-font, inherit);
}

/* 모드 + 환율 줄 */
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mode { display: flex; background: var(--key-fn); border-radius: 10px; padding: 3px; flex: none; }
.mode button {
  border: 0; background: none; border-radius: 8px;
  padding: 6px 11px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.mode button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.talk-btn {
  flex: none; border: 0; border-radius: 10px; background: var(--key-fn);
  padding: 9px 10px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.rate {
  flex: 1; border: 0; background: none; color: var(--muted);
  padding: 2px 0; min-width: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
}
.rate-text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; min-width: 0; }
.rate-text span { font-size: 11px; white-space: nowrap; }
.rate-text b { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.gear { font-size: 15px; flex: none; }
.rate .old { color: var(--warn); font-weight: 700; }

/* 지폐/동전 카드: 남은 세로 공간을 다 쓰고, 넘치면 JS(fit)가 그림을 줄인다. 스크롤 없음. */
.pay {
  flex: 1 1 0;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pay-body {
  flex: 1 1 0; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
  padding: 10px;
  overflow: hidden;
}
.hint { text-align: center; color: var(--muted); margin: 0; font-size: 15px; line-height: 1.6; }
.hint b { color: var(--text); }
.exact { margin: 0; color: var(--muted); font-size: 14px; }

.sec { display: flex; align-items: center; gap: 8px; }
.sec-label {
  flex: none; width: 58px;
  display: flex; flex-direction: column; gap: 1px;
  font-size: 13px; font-weight: 700; color: var(--muted);
}
.sec-label small { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.sec + .sec { border-top: 1px dashed var(--line); padding-top: 10px; }
.sec-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; justify-content: center; align-items: flex-end; gap: 10px; min-width: 0; --h: 76px; }
.sec .row { justify-content: flex-start; }
.money { flex: none; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.count {
  font-size: clamp(11px, calc(var(--h) * 0.22), 14.5px); line-height: 1.25;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.count b { font-weight: 700; margin-right: 1px; }

/* 그림 칸 크기는 가로·세로 둘 다 직접 정한다. 이미지는 absolute 로 띄워서
   원본 파일 크기(지폐 320px, 동전 160px)가 칸 너비에 끼어들지 않게
   (일부 아이폰 Safari 는 그래서 지폐 한 장·동전 두 개만 보이고 나머지가 잘렸다) */
.pic { position: relative; overflow: hidden; flex: none; }
.bill .pic { height: var(--h); width: calc(var(--h) * 2.25); border-radius: 4px; box-shadow: 0 1px 3px rgb(0 0 0 / .2); }
.coin .pic { --d: max(22px, calc(var(--h) * 0.7 * var(--s))); height: var(--d); width: var(--d); border-radius: 50%; box-shadow: 0 1px 3px rgb(0 0 0 / .25); }
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.coin .pic img { transform: scale(1.05); }
.pic.fake {
  display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 800; font-size: 13px;
  text-shadow: 0 1px 2px rgb(0 0 0 / .35);
}
.coin .pic.fake { background: radial-gradient(circle at 35% 30%, #fff8 0, transparent 45%), var(--c); color: #333; text-shadow: none; }

/* 지갑 모드 하단 버튼 */
.wallet-bar {
  flex: none; display: flex; gap: 8px; padding: 0 8px 8px;
}
.wbtn {
  flex: 1; min-width: 0; height: 38px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wbtn .edit { color: var(--muted); font-weight: 500; font-size: 13px; }
.wbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.wbtn:disabled { opacity: .4; cursor: default; }

/* 키패드 */
.pad { flex: none; display: grid; grid-template-columns: repeat(12, 1fr); gap: 7px; }
.pad button {
  grid-column: span 4;
  border: 0; border-radius: 14px;
  background: var(--key);
  font-size: 25px; font-weight: 600;
  height: var(--key-h);
  box-shadow: 0 1px 0 var(--line);
}
.pad button.fn { background: var(--key-fn); font-size: 21px; }
.pad .k000 { display: none; }
/* 베트남: 맨 아랫줄 C · 0 · 000 · ⌫ */
.pad.zeros .k000 { display: block; font-size: 20px; }
.pad.zeros button:nth-last-child(-n+4) { grid-column: span 3; }
.pad button:active, .wbtn:active:not(:disabled), .step:active { transform: scale(.97); filter: brightness(.94); }

/* 알림 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: max(10px, env(safe-area-inset-top));   /* 아래쪽은 지갑 버튼(냈어요)을 가려서 위로 */
  width: max-content; max-width: calc(100vw - 28px);
  display: flex; align-items: center; gap: 12px;
  background: #1d1b19; color: #fff; border-radius: 12px; padding: 10px 14px;
  font-size: 14px; box-shadow: 0 6px 20px rgb(0 0 0 / .25); z-index: 10;
}
.toast button { border: 0; background: none; color: #ffb4bd; font-weight: 700; padding: 2px 0; white-space: nowrap; }

/* 대화상자 (내용이 길면 대화상자 안에서만 스크롤) */
dialog {
  border: 0; border-radius: 18px; padding: 16px;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2:focus { outline: none; }
dialog h2 { margin: 0 0 12px; font-size: 19px; display: flex; justify-content: space-between; align-items: baseline; }
.dlg-total { font-size: 16px; color: var(--accent); font-variant-numeric: tabular-nums; }

.wlist { display: flex; flex-direction: column; gap: 6px; }
.wrow { display: grid; grid-template-columns: 62px 1fr 44px 64px 44px; align-items: center; gap: 6px; }
.wrow .pic { justify-self: center; }
.wrow.bill .pic { height: 26px; width: 58px; border-radius: 3px; }
.wrow.coin .pic { height: 30px; width: 30px; border-radius: 50%; }
.wname { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.step {
  height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 22px; line-height: 1;
}
.wnum {
  height: 40px; width: 100%; text-align: center;
  font: inherit; font-size: 18px; font-weight: 600;   /* 16px 이상: iOS 입력 시 자동 확대 방지 */
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  -moz-appearance: textfield; -webkit-user-select: text; user-select: text;
}
.wnum::-webkit-inner-spin-button, .wnum::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-weight: 600; }
.field input {
  font: inherit; font-size: 18px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%;
  -webkit-user-select: text; user-select: text;
}
.field small, .meta { color: var(--muted); font-size: 13px; }
.meta { margin: 0 0 8px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px 8px; margin: 0 0 10px; }
legend { font-weight: 600; padding: 0 4px; }
.check { display: flex; gap: 8px; align-items: center; padding: 5px 0; }
.check input { width: 20px; height: 20px; }
.guide { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.guide summary { font-weight: 600; cursor: pointer; }
.guide ol { margin: 8px 0 0; padding-left: 20px; line-height: 1.55; }
.guide li + li { margin-top: 4px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.actions button {
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 10px; padding: 10px 14px;
}
.actions button:first-child:not(.primary) { margin-right: auto; }
.actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 회화 ---------- */

/* 전체 화면 대화상자 (목록은 이 안에서만 스크롤) */
dialog.full {
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0; border-radius: 0;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  overflow: hidden;
}
dialog.full[open] { display: flex; flex-direction: column; }
.full .close {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 8px 14px; font-size: 15px; font-weight: 600;
}
.talk-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.talk-head h2 { margin: 0; }

.tabs { display: flex; gap: 4px; background: var(--key-fn); border-radius: 12px; padding: 3px; flex: none; }
.tab {
  flex: 1 1 auto; border: 0; background: none; border-radius: 9px;
  padding: 8px 2px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.talk-list {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
.talk-list > .hint { margin-top: 40px; }

.phrase { display: flex; align-items: stretch; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; }
.phrase-main {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left;
  display: flex; flex-direction: column; gap: 2px; padding: 11px 4px 11px 14px;
}
.p-big { font-size: 17px; font-weight: 700; }
.p-native { font-size: 19px; font-family: var(--native-font, inherit); letter-spacing: .03em; }
.p-pron { font-size: 14px; color: var(--muted); }
.p-ko { font-size: 14px; color: var(--muted); }
.hear .p-ko { color: var(--text); font-weight: 600; }
.p-note { font-size: 12.5px; color: var(--accent); margin-top: 2px; }
.star {
  flex: none; width: 48px; border: 0; background: none;
  font-size: 22px; color: var(--muted);
}
.star.on { color: #e0a100; }

/* 주문 조합기 (대만 버블티, 베트남 커피) */
.builder { display: flex; flex-direction: column; gap: 12px; }
.builder-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.chip-t { font-size: 17px; font-weight: 700; font-family: var(--native-font, inherit); text-align: center; }
.chip small { font-size: 11.5px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[aria-pressed="true"] small { color: #fff; opacity: .85; }
.builder-preview {
  position: sticky; bottom: 0; background: var(--card);
  box-shadow: 0 -10px 14px var(--card);
  border: 2px dashed var(--line); border-radius: 14px; padding: 6px;
  display: flex; flex-direction: column; gap: 8px; min-height: 90px; justify-content: center;
}
.builder-preview .phrase-main { padding: 6px 8px; align-items: center; text-align: center; }
.builder-text { font-size: 26px; font-weight: 700; }
.builder-actions { display: flex; gap: 6px; }
.builder-show {
  flex: 1; height: 44px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
}
.builder-actions .star { border: 1px solid var(--line); border-radius: 12px; }

/* 크게 보여주기 */
dialog.show { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.show .close { align-self: flex-end; flex: none; }
.show-main {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 14px; cursor: pointer;
}
.show-text {
  font-weight: 800; line-height: 1.2; word-break: break-all;
  font-family: var(--native-font, inherit);
}
/* 로마자(베트남어)는 단어 중간에서 끊지 않는다 */
.show-text.latin { word-break: normal; overflow-wrap: break-word; }
.show-pron { font-size: clamp(18px, 5.5vw, 26px); font-weight: 600; }
.show-ko { font-size: clamp(15px, 4.5vw, 20px); color: var(--muted); }
.show-say {
  flex: none; height: 52px; border: 0; border-radius: 14px;
  background: var(--key-fn); font-size: 18px; font-weight: 700;
}

/* 나라 고르기 */
.country-list { display: flex; flex-direction: column; gap: 8px; }
.country {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 12px 14px; text-align: left;
}
.country .flag { font-size: 28px; }
.country b { font-size: 17px; }
.country small { color: var(--muted); }
.country[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* 여행 준비 (제휴) */
.partners { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.partners h3 { margin: 0 0 8px; font-size: 15px; }
.partner {
  display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; column-gap: 6px;
  padding: 8px 0; color: var(--text); text-decoration: none; border-top: 1px solid var(--line);
}
.partner:first-child { border-top: 0; }
.partner .p-icon { grid-row: span 2; font-size: 20px; align-self: center; }
.partner small { color: var(--muted); }
.ad-note { display: block; color: var(--muted); font-size: 11.5px; margin-top: 6px; }
.guide + .guide { margin-top: 8px; }
.credits { margin: 8px 0 0; padding-left: 18px; font-size: 12px; line-height: 1.5; color: var(--muted); word-break: break-all; }
.credits a { color: inherit; }

/* 결제 후 지갑 */
.after { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.after b { color: var(--text); }
.wbtn.icon { flex: none; width: 44px; padding: 0; font-size: 18px; }

/* 결제 기록 */
.h-sum { margin: 0 0 4px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.h-day {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin-top: 6px; padding: 6px 2px; border-bottom: 1px solid var(--line);
  font-size: 14px; position: sticky; top: 0; background: var(--card); z-index: 1;
}
.h-day span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.h-item { padding: 8px 2px; border-bottom: 1px dashed var(--line); display: flex; flex-direction: column; gap: 3px; }
.h-top { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.h-time { color: var(--muted); font-size: 13px; width: 64px; flex: none; }
.h-price { font-size: 17px; }
.h-krw { color: var(--muted); font-size: 13px; margin-left: auto; }
.h-del { border: 0; background: none; color: var(--muted); font-size: 14px; padding: 4px 6px; flex: none; }
.h-del[data-armed] { color: var(--accent); font-weight: 700; }
.h-detail { font-size: 13px; color: var(--muted); padding-left: 74px; overflow-wrap: anywhere; }
.h-actions {
  flex: none; display: flex; gap: 8px; padding: 10px 0 max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.h-actions button { flex: 1; height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 15px; font-weight: 600; }
.h-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.h-actions button:disabled { opacity: .4; }
#historyClear[data-armed] { color: var(--accent); border-color: var(--accent); }
#historyDlg .talk-list { gap: 0; padding-bottom: 8px; }

/* ---------- 낮은 화면 (아이폰 SE, 주소창 있는 Safari 등) ----------
   기본 규칙을 덮어써야 하니 파일 맨 끝에 둔다. */
@media (max-height: 680px) {
  :root { --gap: 7px; --amount-size: clamp(34px, 10.5vw, 44px); --key-h: 44px; }
  .say-native { display: none; }
}
@media (max-height: 600px) {
  :root { --gap: 6px; --amount-size: 34px; --key-h: 39px; }
  .krw { font-size: 15px; }
  .say { margin-top: 0; padding: 0; }
  .say-ko { font-size: 13.5px; }
  .mode button { padding: 4px 10px; font-size: 13px; }
  .talk-btn { padding: 6px 9px; font-size: 13px; }
  .pay-body { padding: 6px 8px; gap: 6px; }
  .sec + .sec { padding-top: 6px; }
  .sec-body { gap: 4px; }
  .wallet-bar { padding: 0 6px 6px; }
  .wbtn { height: 32px; font-size: 13px; }
  .pad { gap: 5px; }
  .pad button { font-size: 22px; border-radius: 11px; }
}
