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

:root {
  --bg: #09090F;
  --bg2: #0F0F1A;
  --surface: rgba(255,255,255,0.05);
  --surface2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --accent: #7C3AED;
  --accent2: #9B6DFF;
  --accent-bg: rgba(124,58,237,0.12);
  --accent-glow: rgba(124,58,237,0.25);
  --text: #EEEEF8;
  --text2: #8888A8;
  --text3: #6060A0;
  --green: #10B981;
  --red: #F87171;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* 하단 탭 메뉴용 여백: 홈 인디케이터·시스템 하단 영역만큼 메뉴바를 위로 띄운다.
     값이 0인 기기(소프트 버튼 없음·안드로이드 버튼식)는 메뉴바가 맨 아래/버튼 바로 위에 붙는다 */
  --nav-sb: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* window-controls-overlay (데스크톱 PWA 타이틀바 영역) */
  --wco-t: env(titlebar-area-height, 0px);
}

/* ── 라이트 테마 ── */
:root[data-theme="light"] {
  --bg: #F2F2FA;
  --bg2: #E8E8F5;
  --surface: rgba(0,0,0,0.05);
  --surface2: rgba(0,0,0,0.09);
  --border: rgba(0,0,0,0.07);
  --border2: rgba(0,0,0,0.14);
  --text: #16163A;
  --text2: #555580;
  --text3: #9090BB;
  --green: #059669;
  --red: #DC2626;
}

html, body { height: 100%; background: var(--bg); transition: background 0.25s; }

/* 로그인 확인 전에는 빈 목록과 Log (0/1) 이 보이지 않게 한다 */
html.is-booting #ledger-list,
html.is-booting #plan-body,
html.is-booting #ledger-summary,
html.is-booting #trip-encourage,
html.is-booting #plan-encourage { visibility: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: color 0.25s, background 0.25s;
}

/* 웹 사이즈(데스크톱): 앱 열 바깥 배경 처리 */
@media (min-width: 431px) {
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
      radial-gradient(ellipse 60% 50% at 20% 30%, rgba(124,58,237,0.07) 0%, transparent 70%),
      radial-gradient(ellipse 50% 60% at 80% 70%, rgba(99,102,241,0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
  }
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  /* fixed 자식(전체화면 패널·시트)이 뷰포트가 아닌 앱 열 기준으로 배치되도록 포함 블록 생성 */
  transform: translateZ(0);
  /* window-controls-overlay: 타이틀바가 생기면 상단 여백 확보 */
  padding-top: var(--wco-t);
}

/* 데스크톱 PWA: 앱 열에 미묘한 테두리 */
@media (min-width: 431px) {
  #app {
    box-shadow: 0 0 0 1px var(--border), 0 8px 48px rgba(0,0,0,0.4);
    border-left: 1px solid var(--border2);
    border-right: 1px solid var(--border2);
  }
}

/* 넓은 웹: 오른쪽 폰 틀, 왼쪽은 #site 마케팅. 설치본(.is-pwa)과 /app/ 에는 적용하지 않음 */
@media (min-width: 860px) {
  html:not(.is-pwa):not(.is-app) #app {
    position: fixed;
    box-sizing: border-box;
    top: 50%;
    right: 28px;
    left: auto;
    bottom: auto;
    width: 410px; /* 폰 틀 가로 (이전 390px 보다 약 5% 넓게) */
    height: min(844px, calc(100vh - 48px));
    max-width: none;
    margin: 0;
    z-index: 20;
    transform: translateY(-50%) translateZ(0);
    border: 12px solid #0b0b10;
    border-radius: 52px;
    padding-top: 36px;
    box-shadow: 0 0 0 2px #4a4a5e, 0 0 0 5px rgba(140,140,180,0.16), 0 30px 80px rgba(0,0,0,0.55);
  }
  html:not(.is-pwa):not(.is-app) #app::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 26px;
    background: #0b0b10;
    border-radius: 0 0 16px 16px;
    z-index: 1000;
    pointer-events: none;
  }
}

@media (min-width: 860px) and (display-mode: browser) {
  :root[data-theme="light"] #app {
    box-shadow: 0 0 0 2px #b8b8c8, 0 30px 80px rgba(0,0,0,0.18);
  }
}

@media (display-mode: standalone),
       (display-mode: fullscreen),
       (display-mode: minimal-ui),
       (display-mode: window-controls-overlay) {
  #site, .site-top, .site-bg { display: none !important; }
}

/* ── VIEWS ── */
.view {
  display: none;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  padding-top: var(--safe-t);
  overflow: hidden;
}
.view.active { display: flex; }

/* ── HEADER ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
  flex-shrink: 0;
}
.header-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.6px;
  background: linear-gradient(120deg, var(--text) 20%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  overflow-wrap: anywhere;
}
.header-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 3px;
  letter-spacing: 0.1px;
  overflow-wrap: anywhere;
}

/* ── ICON BUTTON ── */
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn[hidden] { display: none !important; }
.icon-btn:active { background: var(--surface2); transform: scale(0.93); }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── SCROLL AREA ── */
.scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px;
  padding-bottom: 24px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.view .scroll-area { padding-bottom: 56px; }
.scroll-area::-webkit-scrollbar { display: none; }

/* ── BASE CARD ── */
.base-card {
  background: linear-gradient(135deg, rgba(124,58,237,0.18) 0%, rgba(99,102,241,0.08) 100%);
  border: 1px solid rgba(124,58,237,0.28);
  border-radius: 22px;
  padding: 16px 18px 18px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}
.base-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124,58,237,0.15), transparent 70%);
  pointer-events: none;
}
.base-card:active { transform: scale(0.985); }

.currency-row {
  display: flex;
  align-items: center;
  gap: 11px;
}
.flag-xl { font-size: 34px; line-height: 1; flex-shrink: 0; }
.cur-details { flex: 1; min-width: 0; }
.cur-code { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; line-height: 1.2; }
.cur-name { font-size: 12px; color: var(--text2); margin-top: 2px; }
.change-hint {
  display: flex; align-items: center; gap: 3px;
  font-size: 12px; color: var(--text3); font-weight: 500;
}

.amount-row {
  display: flex;
  align-items: baseline;
  margin-top: 14px;
  gap: 4px;
}
.cur-symbol {
  font-size: 26px;
  font-weight: 300;
  color: var(--text2);
  flex-shrink: 0;
  line-height: 1;
}
#base-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 40px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -2px;
  width: 100%;
  caret-color: var(--accent2);
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

/* ── TARGET CARDS ── */
.target-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 13px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 11px;
  animation: fadeUp 0.22s ease both;
  transition: background 0.12s;
}
.target-card:active { background: var(--surface2); }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.flag-lg { font-size: 30px; flex-shrink: 0; }
.target-info { flex: 0 1 38%; min-width: 0; }
.calc-party-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px 12px; font-size: 13px; font-weight: 700; color: var(--text2);
}
.target-code { font-size: 17px; font-weight: 800; letter-spacing: -0.3px; }
.target-name-text { font-size: 11px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.target-right { text-align: right; flex: 1 1 0; min-width: 0; }
.exchange-rate { font-size: 10px; color: var(--text3); margin-top: 3px; }

.target-amount-input {
  background: none;
  border: none;
  outline: none;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
  width: 100%;
  min-width: 0;
  font-family: inherit;
  caret-color: var(--accent2);
}
.target-amount-input::placeholder { color: var(--text3); }

.del-btn {
  width: 28px; height: 28px;
  border-radius: 9px;
  background: rgba(248,113,113,0.1);
  border: none;
  color: var(--red);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s;
}
.del-btn:active { background: rgba(248,113,113,0.22); }

/* ── ADD BUTTON ── */
.add-btn {
  width: 100%;
  padding: 15px 16px;
  border-radius: 16px;
  background: var(--accent-bg);
  border: 1.5px dashed rgba(124,58,237,0.3);
  color: var(--accent2);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  transition: all 0.15s;
  font-family: inherit;
}
.add-btn:not(:disabled):active { background: rgba(124,58,237,0.2); transform: scale(0.99); }
.add-btn:disabled { opacity: 0.38; cursor: default; }
.count-pill {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 20px;
  background: rgba(124,58,237,0.18);
  color: var(--accent2);
  font-weight: 700;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text3);
}
.empty-icon { font-size: 44px; margin-bottom: 10px; }
.empty-text { font-size: 14px; line-height: 1.6; }

/* ── RATES VIEW ── */
.search-wrapper {
  padding: 0 16px 10px;
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text);
  font-size: 15px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.search-input::placeholder { color: var(--text3); }
.search-input:focus { border-color: rgba(124,58,237,0.4); }

.rates-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px;
  padding-bottom: 20px;
  -webkit-overflow-scrolling: touch;
}
.rates-list::-webkit-scrollbar { display: none; }

.rate-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: 15px;
  margin-bottom: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  gap: 11px;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
  -webkit-user-select: none;
}
.rate-item:active { background: var(--surface2); }
.rate-item.is-base {
  background: linear-gradient(135deg, rgba(124,58,237,0.14), rgba(99,102,241,0.07));
  border-color: rgba(124,58,237,0.28);
}
.rate-item.is-target { border-color: rgba(16,185,129,0.28); }

.rate-flag { font-size: 30px; flex-shrink: 0; }
.rate-info { flex: 1; min-width: 0; }
.rate-code { font-size: 16px; font-weight: 800; letter-spacing: -0.2px; }
.rate-name { font-size: 11px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rate-right { text-align: right; flex-shrink: 0; }
.rate-value { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rate-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin-top: 4px;
}
.badge-base { background: rgba(124,58,237,0.2); color: var(--accent2); }
.badge-target { background: rgba(16,185,129,0.15); color: var(--green); }

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  height: calc(var(--nav-h) + var(--nav-sb));
  padding-bottom: var(--nav-sb);
  background: var(--bg2);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-top: 1px solid var(--border2);
  display: flex;
  z-index: 95;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
  white-space: normal;
  text-align: center;
  cursor: pointer;
  transition: color 0.2s;
  font-family: inherit;
  padding: 0 2px;
  min-width: 0;
}
.placeholder-empty {
  text-align: center;
  color: var(--text3);
  font-size: 14px;
  font-weight: 600;
  padding: 56px 20px;
}
.nav-icon-wrap {
  width: 44px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  transition: background 0.2s, transform 0.15s;
}
.nav-btn.active .nav-icon-wrap { background: var(--accent-bg); }
.nav-btn.active { color: var(--accent2); }
.nav-btn:active .nav-icon-wrap { transform: scale(0.9); }

/* ── SETTINGS SHEET ── */
.settings-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 430px;
  background: var(--bg2);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--border2);
  border-bottom: none;
  padding-bottom: calc(var(--safe-b) + 8px);
  z-index: 110;
  overflow-y: auto;
  max-height: 88vh;
  max-height: 88dvh;
  overscroll-behavior: contain;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.settings-sheet .modal-handle,
.settings-sheet .modal-header { position: sticky; top: 0; z-index: 2; background: var(--bg2); }
.settings-sheet.open { transform: translateX(-50%) translateY(0); }
.settings-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 105;
  display: none;
}
.settings-backdrop.open { display: block; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 15px; font-weight: 600; }
.settings-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }

.settings-row-lang {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.lang-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  width: 100%;
  margin-top: 6px;
}

.lang-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  background: var(--surface);
  border: 1.5px solid var(--border2);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
.lang-tab-flag { font-size: 26px; line-height: 1.1; }
.lang-tab-code {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.4px;
}
.lang-tab-name {
  font-size: 8.5px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 0 2px;
}
.lang-tab:active { transform: scale(0.93); }
.lang-tab.active {
  background: var(--accent-bg);
  border-color: var(--accent2);
}
.lang-tab.active .lang-tab-code { color: var(--accent2); }
.lang-tab.active .lang-tab-name { color: var(--accent2); opacity: 0.8; }

.theme-toggle {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
}
.theme-btn {
  padding: 7px 14px;
  border-radius: 9px;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
  display: flex; align-items: center; gap: 5px;
}
.theme-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* ── ACTION SHEET ── */
.action-backdrop {
  position: fixed; inset: 0;
  z-index: 80;
  display: none;
}
.action-backdrop.open { display: block; }

.action-sheet {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--nav-sb) + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  width: calc(100% - 32px);
  max-width: 398px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 14px;
  z-index: 90;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.action-sheet.open { transform: translateX(-50%) translateY(0); }

.action-currency-info {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.action-flag { font-size: 28px; }
.action-code { font-size: 17px; font-weight: 800; }
.action-name { font-size: 12px; color: var(--text2); margin-top: 1px; }

.action-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  transition: background 0.12s;
  font-family: inherit;
}
.action-btn:last-child { margin-bottom: 0; }
.action-btn:active { background: var(--surface2); }
.action-btn.danger { color: var(--red); border-color: rgba(248,113,113,0.15); background: rgba(248,113,113,0.05); }
.action-btn.primary { color: var(--accent2); border-color: rgba(124,58,237,0.2); background: var(--accent-bg); }

/* 설치형 앱(모바일): 화면 전체를 쓰되 하단은 기기에 맞춘다
   - 안드로이드: 소프트 버튼(뒤로·홈)이 있으면 뷰포트가 그만큼 줄어 메뉴바가 그 위에 놓이고,
     제스처 방식이라 버튼이 없으면 메뉴바가 화면 맨 아래에 붙는다 → top/bottom:0 으로 뷰포트에 그대로 맞춘다
   - iOS: 설치본에서 bottom:0 이 화면 아래까지 닿지 않는 경우가 있어 높이를 직접 지정한다 */
@media (max-width: 859px) {
  html.is-pwa #app {
    position: fixed;
    top: 0; bottom: 0; left: 0; right: 0;
    height: auto;
    width: 100%;
    margin: 0 auto;
  }
  html.is-pwa { background: var(--bg2); }
}
@supports (-webkit-touch-callout: none) {
  @media (max-width: 859px) {
    html.is-pwa { --nav-sb: calc(env(safe-area-inset-bottom, 0px) + 8px); }
    html.is-pwa #app {
      bottom: auto;
      height: 100vh;
      height: 100lvh;
    }
  }
}

/* 입력칸 포커스·키패드 때문에 #app이 위로 스크롤되면 제목이 잘리고 아래에 시트 윗부분이 드러난다 → 스크롤 자체를 막는다 */
#app { overflow: hidden; overflow: clip; }
