:root {
  --bg: #0b1020;
  --bg-grad-1: rgba(99, 102, 241, 0.22);
  --bg-grad-2: rgba(168, 85, 247, 0.18);
  --bg-grad-3: rgba(56, 189, 248, 0.16);

  --surface: rgba(22, 28, 48, 0.72);
  --surface-2: rgba(15, 20, 38, 0.65);
  --surface-input: rgba(10, 15, 32, 0.75);

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-focus: rgba(129, 140, 248, 0.9);

  --text: #f4f6ff;
  --text-dim: #a6accc;
  --text-mute: #727899;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-soft: rgba(99, 102, 241, 0.18);

  --success: #22c55e;
  --danger: #f43f5e;
  --warning: #f59e0b;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-card: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
  --shadow-pop: 0 20px 40px -15px rgba(99, 102, 241, 0.55);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-feature-settings: "ss01", "tnum";
  background-image:
    radial-gradient(ellipse at 0% 0%, var(--bg-grad-1) 0%, transparent 45%),
    radial-gradient(ellipse at 100% 0%, var(--bg-grad-2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 110%, var(--bg-grad-3) 0%, transparent 55%);
  background-attachment: fixed;
  letter-spacing: -0.01em;
  line-height: 1.5;
}

.app-container {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + var(--safe-top)) 18px calc(32px + var(--safe-bottom));
}

/* ── Header ──────────────────────────────────────────── */
.header {
  margin-bottom: 22px;
}

.user-info {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-dim);
  margin: 4px 2px 14px;
}
.user-info #userName {
  color: var(--text);
  font-weight: 700;
}

.balance-card {
  position: relative;
  overflow: hidden;
  padding: 26px 24px 22px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(99, 102, 241, 0.95), rgba(168, 85, 247, 0.9) 55%, rgba(56, 189, 248, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-pop);
  color: #fff;
}
.balance-card::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(255,255,255,0.35), transparent 60%);
  pointer-events: none;
}
.balance-label {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
  letter-spacing: 0.02em;
}
.balance-amount {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 8px;
  font-weight: 800;
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.balance-unit {
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 0.85;
  margin-left: 2px;
}

.refresh-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background .2s ease, transform .2s ease;
}
.refresh-btn:hover { background: rgba(255, 255, 255, 0.28); }
.refresh-btn:active { transform: scale(0.96); }
.refresh-btn.is-loading svg { animation: spin .8s linear infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
  position: relative;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
  margin: 22px 0;
  backdrop-filter: blur(12px);
}
.tab-btn {
  position: relative;
  flex: 1;
  z-index: 1;
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 11px 0;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: color .25s ease;
  font-family: inherit;
}
.tab-btn.active { color: var(--text); }
.tab-indicator {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 5px;
  width: calc((100% - 10px) / 3);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.9), rgba(168, 85, 247, 0.85));
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
  transition: transform .35s cubic-bezier(.4, .0, .2, 1);
  z-index: 0;
}

/* ── Tab content ─────────────────────────────────────── */
.tab-content {
  display: none;
  animation: fadeIn .35s ease;
}
.tab-content.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Card ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(14px);
}
.card-head { margin-bottom: 16px; }
.card h3 {
  margin: 0 0 4px;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-mute);
}

/* ── Form fields ─────────────────────────────────────── */
.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 2px 8px;
}

textarea, input {
  width: 100%;
  background: var(--surface-input);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
  -webkit-appearance: none;
  appearance: none;
}
textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
input[type="number"] {
  font-weight: 700;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
textarea::placeholder, input::placeholder {
  color: var(--text-mute);
  font-weight: 400;
  opacity: 1;
}
textarea:focus, input:focus {
  border-color: var(--border-focus);
  background: rgba(10, 15, 32, 0.95);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

/* amount input with suffix */
.amount-input {
  position: relative;
}
.amount-input .suffix {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-weight: 600;
  pointer-events: none;
  font-size: 1rem;
}
.amount-input input { padding-right: 42px; }

/* quick amount chips */
.quick-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 18px;
}
.chip {
  flex: 1 0 auto;
  min-width: 70px;
  background: var(--surface-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s ease;
}
.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(99, 102, 241, 0.08);
}
.chip:active { transform: scale(0.97); }
.chip-reset { color: var(--text-mute); }

/* ── Button ──────────────────────────────────────────── */
.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  color: white;
  border: none;
  padding: 15px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 20px -8px rgba(99, 102, 241, 0.75);
  transition: transform .15s ease, box-shadow .2s ease, filter .2s ease;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: translateY(1px) scale(0.995); }
.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.3);
  transform: none;
}

/* ── History filters ─────────────────────────────────── */
.filter-group {
  margin-bottom: 14px;
}
.filter-group:last-of-type {
  margin-bottom: 18px;
}
.filter-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 2px 8px;
  letter-spacing: 0.02em;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-chip {
  background: var(--surface-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s ease;
  white-space: nowrap;
}
.filter-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.filter-chip.active {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.filter-chip:active { transform: scale(0.97); }

.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.date-range[hidden] { display: none; }
.date-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0;
  color-scheme: dark;
}
.date-sep {
  color: var(--text-mute);
  font-weight: 700;
  font-size: 0.9rem;
}
.apply-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background .2s ease, transform .15s ease;
}
.apply-btn:hover { background: var(--primary-hover); }
.apply-btn:active { transform: scale(0.97); }

.tx-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 2px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
}
#txSummary { font-weight: 500; }
#txCount {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Transaction list ────────────────────────────────── */
.tx-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tx-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 2px;
  border-bottom: 1px solid var(--border);
}
.tx-list li:last-child { border-bottom: none; }
.tx-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tx-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}
.tx-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.tx-type.charge { color: var(--success); }
.tx-type.withdraw { color: var(--danger); }
.tx-type.rate { color: #38bdf8; }
.tx-type.commission { color: var(--warning); }

.tx-date {
  font-size: 0.74rem;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
.tx-amount {
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.tx-amount.charge { color: var(--success); }
.tx-amount.withdraw { color: var(--danger); }
.tx-amount.rate { color: #38bdf8; }
.tx-amount.commission { color: var(--warning); }

.empty-msg {
  text-align: center;
  color: var(--text-mute);
  font-size: 0.9rem;
  padding: 28px 0;
  border-bottom: none !important;
  justify-content: center !important;
}

/* ── Snackbar ────────────────────────────────────────── */
#snackbar {
  visibility: hidden;
  opacity: 0;
  min-width: 240px;
  max-width: calc(100% - 32px);
  background: rgba(22, 28, 48, 0.95);
  color: #fff;
  text-align: center;
  border-radius: 12px;
  padding: 14px 18px;
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  box-shadow: 0 18px 40px -10px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(14px);
  transition: opacity .3s ease, transform .3s ease, visibility .3s;
}
#snackbar.show {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#snackbar.success { border-color: rgba(34, 197, 94, 0.5); }
#snackbar.error { border-color: rgba(244, 63, 94, 0.5); }
