/* ======= RESET & BASE ======= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #c85e00;
  --accent-light: #e06b00;
  --accent-bg: rgba(200, 94, 0, 0.08);
  --naver: #03c75a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 16px rgba(0,0,0,0.06);
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
}

/* LIGHT MODE */
body.light {
  --bg: #f0ede8;
  --surface: #ffffff;
  --surface-2: #f7f5f2;
  --border: rgba(0,0,0,0.08);
  --text: #1a1a1a;
  --text-secondary: #6b6b6b;
  --bar-bg: #e5e0d8;
  --nav-bg: rgba(255,255,255,0.92);
  --card-shadow: 0 2px 20px rgba(0,0,0,0.06);
  --input-bg: #fafaf8;
  --modal-bg: #ffffff;
  --overlay: rgba(0,0,0,0.45);
}

/* DARK MODE */
body.dark {
  --bg: #141414;
  --surface: #1e1e1e;
  --surface-2: #252525;
  --border: rgba(255,255,255,0.08);
  --text: #f0f0f0;
  --text-secondary: #9a9a9a;
  --bar-bg: #2e2e2e;
  --nav-bg: rgba(20,20,20,0.95);
  --card-shadow: 0 2px 20px rgba(0,0,0,0.35);
  --input-bg: #252525;
  --modal-bg: #1e1e1e;
  --overlay: rgba(0,0,0,0.7);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  line-height: 1.5;
}

/* ======= NAVBAR ======= */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 56px;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.navbar-left { display: flex; align-items: center; gap: 12px; }
.navbar-right { display: flex; align-items: center; gap: 12px; }

.brand-logo {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.3px;
  transition: opacity var(--transition);
}
.brand-logo:hover { opacity: 0.75; }

.nav-divider { color: var(--border); font-size: 18px; font-weight: 300; }

.nav-link-secondary {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.nav-link-secondary:hover { color: var(--text); background: var(--surface-2); }

.update-timer {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.update-timer:hover { color: var(--text); background: var(--surface-2); }

.theme-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.theme-btn:hover { color: var(--text); background: var(--surface); transform: rotate(20deg); }

/* ======= HERO ======= */
.hero {
  padding: 40px 28px 24px;
  max-width: 1100px;
  margin: 0 auto;
}
.hero-title {
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
  line-height: 1.25;
}
.hero-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}
.highlight { color: var(--accent); }

/* ======= MAIN LAYOUT ======= */
.main-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 28px 40px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

/* ======= CARDS ======= */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  transition: all var(--transition);
  margin-bottom: 14px;
}

/* Market Card */
.market-card { }
.card-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 4px; }
.naver-badge { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.naver-text { color: var(--naver); font-weight: 700; }
.market-rate { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; margin-bottom: 3px; }
.market-sub { font-size: 12px; color: var(--text-secondary); }

/* Amount Card */
.amount-card { }
.amount-input-wrap {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  padding: 10px 14px;
  margin-top: 8px;
  transition: border-color var(--transition);
  gap: 6px;
}
.amount-input-wrap:focus-within { border-color: var(--accent); }
.amount-input {
  flex: 1;
  font-size: 24px;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  font-family: 'Inter', sans-serif;
  min-width: 0;
}
.clear-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all var(--transition);
  display: none;
}
.clear-btn.visible { display: block; }
.clear-btn:hover { background: var(--surface-2); color: var(--text); }
.currency-symbol { font-size: 20px; color: var(--text-secondary); font-weight: 500; }

/* Alert Card */
.alert-card { }
.alert-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.alert-title { font-size: 14px; font-weight: 600; }
.alert-badge {
  font-size: 11px;
  background: #d4edda;
  color: #1a7f3c;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
body.dark .alert-badge { background: rgba(3,199,90,0.15); color: var(--naver); }
.alert-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.alert-threshold { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.alert-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}
.qty-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.alert-rate-input {
  flex: 1;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  outline: none;
  text-align: center;
  transition: border-color var(--transition);
}
.alert-rate-input:focus { border-color: var(--accent); }
.alert-currency { font-size: 13px; color: var(--text-secondary); }
.alert-btn {
  width: 100%;
  padding: 11px;
  border-radius: 40px;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'Inter', sans-serif;
}
.alert-btn:hover { background: var(--accent-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(200,94,0,0.3); }
.alert-btn.active { background: #2e7d32; }
.alert-btn.active:hover { background: #1b5e20; }

/* ======= RIGHT PANEL: RANKINGS ======= */
.right-panel { }
.rankings { display: flex; flex-direction: column; gap: 8px; }

.rank-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 30px 42px 1fr auto auto;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
}
.rank-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: transparent;
  transition: background var(--transition);
}
.rank-item:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.rank-item:hover::before { background: var(--accent); }
.rank-item.first { border-color: var(--accent); }
.rank-item.first::before { background: var(--accent); }

.rank-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
}
.rank-item.first .rank-num {
  background: var(--accent);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.provider-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.provider-info { min-width: 0; }
.provider-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.provider-name { font-size: 15px; font-weight: 600; color: var(--text); }
.provider-rate-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.rate-bar-wrap {
  width: 100%;
  height: 4px;
  background: var(--bar-bg);
  border-radius: 2px;
  overflow: hidden;
}
.rate-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.8s cubic-bezier(.4,0,.2,1);
  background: var(--accent);
}
.rank-item.first .rate-bar { background: var(--accent); }

.rank-rate-wrap { text-align: right; min-width: 110px; }
.rank-rate {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.rank-item.first .rank-rate { color: var(--accent); }
.rank-best-label {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}
.rank-diff {
  font-size: 12px;
  color: var(--text-secondary);
}

.rank-arrow {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

/* ======= FOOTER ======= */
.footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 28px 32px;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ======= MODAL ======= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  padding: 20px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--modal-bg);
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  transform: translateY(20px) scale(0.97);
  transition: transform var(--transition);
  border: 1px solid var(--border);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.provider-icon-lg {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.modal-chart-wrap {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 20px;
  height: 160px;
  position: relative;
}

.modal-stats { margin-bottom: 20px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
}
.stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-value { font-size: 13px; font-weight: 600; color: var(--text); }
.stat-divider { height: 1px; background: var(--border); margin: 4px 0; }
.total-row { padding: 12px 0; }
.total-value { font-size: 16px; font-weight: 700; color: var(--text); }

.modal-referral {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.referral-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
.referral-desc { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.referral-row { display: flex; gap: 8px; margin-bottom: 8px; }
.referral-input {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  outline: none;
}
.copy-btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}
.copy-btn:hover { background: var(--accent); color: white; }
.referral-note { font-size: 11px; color: var(--text-secondary); line-height: 1.5; }

.modal-close-btn {
  width: 100%;
  padding: 12px;
  border-radius: 40px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'Inter', sans-serif;
}
.modal-close-btn:hover { background: var(--surface); }

/* ======= TOAST ======= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1a1a;
  color: white;
  padding: 10px 20px;
  border-radius: 40px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s cubic-bezier(.4,0,.2,1);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
body.dark .toast { background: #f0f0f0; color: #1a1a1a; }

/* ======= RESPONSIVE ======= */
@media (max-width: 768px) {
  .main-layout { grid-template-columns: 1fr; padding: 0 16px 40px; }
  .hero { padding: 28px 16px 16px; }
  .navbar { padding: 0 16px; }
  .footer { padding: 16px; }
  .rank-item { grid-template-columns: 26px 38px 1fr auto; }
  .rank-arrow { display: none; }
}

/* ======= SCROLLBAR ======= */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ======= LOADING SPINNER ======= */
.loading-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}
.spin {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.market-loading {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ======= LIVE INDICATOR ======= */
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--naver);
  border-radius: 50%;
  margin-right: 5px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ======= ANIMATIONS ======= */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.rank-item {
  animation: fadeInUp 0.4s ease both;
}
.rank-item:nth-child(1) { animation-delay: 0.0s; }
.rank-item:nth-child(2) { animation-delay: 0.05s; }
.rank-item:nth-child(3) { animation-delay: 0.10s; }
.rank-item:nth-child(4) { animation-delay: 0.15s; }
.rank-item:nth-child(5) { animation-delay: 0.20s; }
.rank-item:nth-child(6) { animation-delay: 0.25s; }
.rank-item:nth-child(7) { animation-delay: 0.30s; }
.rank-item:nth-child(8) { animation-delay: 0.35s; }
