/* =========================================
   Variables & Reset
   ========================================= */
:root {
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --primary-mid: #bfdbfe;
  --accent: #0ea5e9;
  --bg-body: #f8f9fc;
  --bg-card: #ffffff;
  --bg-card-hover: #fafbff;
  --text-main: #0f172a;
  --text-body: #334155;
  --text-sub: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-card-hover: 0 8px 24px rgba(37, 99, 235, 0.1), 0 2px 8px rgba(37, 99, 235, 0.06);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --max-width: 1200px;
  --nav-height: 60px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

a {
  text-decoration: none;
  color: inherit;
}

/* =========================================
   Layout
   ========================================= */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* =========================================
   Hero Header
   ========================================= */
.hero-header {
  padding: 52px 0 44px;
  text-align: center;
  background: var(--bg-body);
  position: relative;
}

/* Subtle decorative background */
.hero-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(37, 99, 235, 0.05) 0%, transparent 70%);
  pointer-events: none;
}

.hero-content {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.brand-logo {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 28px;
  letter-spacing: -0.03em;
  line-height: 1.2;
  transition: opacity var(--transition);
}

.brand-logo:hover {
  opacity: 0.75;
}

/* 로고 앞에 작은 뱃지 */
.brand-logo::before {
  content: '한국은행';
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--primary);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

/* Search Bar */
.search-container {
  position: relative;
}

.search-bar {
  width: 100%;
  padding: 16px 52px 16px 22px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--text-main);
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}

.search-bar::placeholder {
  color: var(--text-muted);
}

.search-bar:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08), var(--shadow-sm);
}

.search-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}

.search-btn:hover {
  background: #1d4ed8;
  transform: translateY(-50%) scale(1.05);
}

.search-btn:active {
  transform: translateY(-50%) scale(0.97);
}

/* Search hint chips */
.search-hints {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: nowrap;
  margin-top: 12px;
  width: 100%;
}

.hint-chip {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-sub);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  text-align: center;
  white-space: nowrap;
}

.hint-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* =========================================
   Sticky Index Nav
   ========================================= */
.sticky-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(248, 249, 252, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}

.index-scroll {
  display: flex;
  overflow-x: auto;
  padding: 10px 0;
  gap: 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.index-scroll::-webkit-scrollbar {
  display: none;
}

@media (min-width: 768px) {
  .index-scroll {
    justify-content: center;
  }
}

.idx-btn {
  flex-shrink: 0;
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-sub);
  font-weight: 600;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.idx-btn:hover {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-main);
}

.idx-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.idx-btn.all {
  padding: 0 14px;
}

/* =========================================
   Main Content & Grid
   ========================================= */
.main-container {
  padding: 20px 0 72px;
  min-height: 60vh;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 2px;
}

.result-count {
  color: var(--text-sub);
  font-size: 0.875rem;
  font-weight: 500;
}

.terms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
  align-items: start;
}

/* =========================================
   Term Card — Redesigned
   ========================================= */
.term-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition:
    transform var(--transition),
    box-shadow var(--transition),
    border-color var(--transition),
    background var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* Top accent line */
.term-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: background var(--transition);
  border-radius: var(--radius) var(--radius) 0 0;
}

.term-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-focus);
  background: var(--bg-card-hover);
}

.term-card:hover::before {
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
}

.term-card.expanded {
  border-color: var(--primary);
  box-shadow: var(--shadow-card-hover);
}

.term-card.expanded::before {
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
}

/* Card Layout */
.card-header {
  padding: 22px 22px 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-body {
  padding: 10px 22px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Initial Badge (top-right) */
.term-cat {
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid var(--primary-mid);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}

.term-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.35;
  padding-right: 52px; /* space for badge */
  letter-spacing: -0.01em;
}

.term-eng {
  font-size: 0.8rem;
  color: var(--text-sub);
  font-weight: 400;
  min-height: 1.2em;
  letter-spacing: 0.01em;
}

/* Divider between header and body */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 22px 0;
  opacity: 0.6;
}

.term-desc {
  font-size: 0.9rem;
  color: var(--text-body);
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Expanded */
.term-card.expanded .term-desc {
  -webkit-line-clamp: unset;
  line-clamp: unset;
}

/* =========================================
   Expand Toggle Chevron
   ========================================= */
.card-footer {
  padding: 0 22px 14px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.expand-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  transition: color var(--transition);
}

.expand-toggle svg {
  transition: transform var(--transition);
}

.term-card.expanded .expand-toggle svg {
  transform: rotate(180deg);
}

.term-card.expanded .expand-toggle {
  color: var(--primary);
}

/* =========================================
   Card Actions (Expanded)
   ========================================= */
.card-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-body);
  border: 1px solid var(--border);
  color: var(--text-sub);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.copy-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.copy-btn.copied {
  background: #10b981;
  color: white;
  border-color: #10b981;
}

/* =========================================
   Related Terms
   ========================================= */
.related-area {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.related-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 8px;
}

.related-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.related-term-link {
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--primary-light);
  border: 1px solid var(--primary-mid);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-block;
  -webkit-tap-highlight-color: transparent;
}

.related-term-link:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* =========================================
   Highlight
   ========================================= */
.highlight {
  background: rgba(250, 204, 21, 0.35);
  color: #92400e;
  font-weight: 600;
  border-radius: 2px;
  padding: 0 1px;
}

/* =========================================
   Animations
   ========================================= */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeUp 0.3s ease both;
}

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

/* =========================================
   No Results / Loader / Sentinel
   ========================================= */
.no-results {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-sub);
}

.no-results p {
  font-size: 1rem;
  margin-bottom: 8px;
}

.scroll-sentinel {
  height: 20px;
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.loader {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.hidden {
  display: none !important;
}

/* =========================================
   Footer
   ========================================= */
.footer {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-sub);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  background-color: var(--bg-body);
}

.footer-desc {
  margin-bottom: 16px;
  line-height: 1.7;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.footer-link {
  color: var(--primary);
  font-weight: 500;
  transition: opacity var(--transition);
}

.footer-link:hover {
  opacity: 0.7;
  text-decoration: underline;
}

.divider {
  color: var(--border);
}

/* =========================================
   Mobile — Back-to-top FAB
   ========================================= */
.fab-top {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--text-main);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.2);
  cursor: pointer;
  opacity: 0;
  transform: translateY(16px) scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 200;
  border: none;
}

.fab-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* =========================================
   Responsive — Mobile
   ========================================= */
@media (max-width: 640px) {
  .search-hints {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .hint-chip {
    font-size: 0.75rem;
    padding: 8px 10px;
    white-space: normal;
    word-break: keep-all;
    line-height: 1.4;
  }

  .hero-header {
    padding: 36px 0 32px;
  }

  .brand-logo {
    font-size: 1.4rem;
    margin-bottom: 20px;
  }

  .search-bar {
    padding: 14px 50px 14px 18px;
    font-size: 0.95rem;
    border-radius: 14px; /* slightly less round on mobile */
  }

  .search-btn {
    right: 8px;
    width: 34px;
    height: 34px;
  }

  .search-hints {
    margin-top: 10px;
  }

  .terms-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Tighter card padding on mobile */
  .card-header {
    padding: 18px 18px 0;
  }

  .card-body {
    padding: 10px 18px 16px;
  }

  .card-divider {
    margin: 10px 18px 0;
  }

  .card-footer {
    padding: 0 18px 12px;
  }

  .term-cat {
    top: 14px;
    right: 14px;
  }

  .idx-btn {
    min-width: 34px;
    height: 32px;
    font-size: 0.82rem;
  }

  .toolbar {
    margin-bottom: 12px;
  }

  .footer {
    padding: 36px 20px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 14px;
  }
}

/* =========================================
   Tablet
   ========================================= */
@media (min-width: 641px) and (max-width: 1023px) {
  .terms-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =========================================
   Welcome Modal (첫 방문 머리말)
   ========================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.visible {
  opacity: 1;
}

.modal-overlay.hiding {
  opacity: 0;
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.2);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  scrollbar-width: none;
}

.modal-box::-webkit-scrollbar { display: none; }

.modal-overlay.visible .modal-box {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 32px 32px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.modal-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-body);
  border: 1px solid var(--border);
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 2px;
}

.modal-close:hover {
  background: var(--text-main);
  color: white;
  border-color: var(--text-main);
}

.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 32px 0;
}

.modal-body {
  padding: 20px 32px 28px;
  font-size: 0.92rem;
  color: var(--text-body);
  line-height: 1.85;
}

.modal-body p + p {
  margin-top: 14px;
}

.modal-footer {
  padding: 0 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-sub);
  cursor: pointer;
  user-select: none;
}

.modal-check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.modal-btn-close {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition);
  white-space: nowrap;
}

.modal-btn-close:hover {
  background: #1d4ed8;
}

/* Mobile modal */
@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 82vh;
    transform: translateY(100%);
  }

  .modal-overlay.visible .modal-box {
    transform: translateY(0);
  }

  .modal-header {
    padding: 24px 24px 0;
  }

  .modal-body {
    padding: 16px 24px 20px;
    font-size: 0.88rem;
  }

  .modal-divider {
    margin: 16px 24px 0;
  }

  .modal-footer {
    padding: 0 24px 32px;
  }
}
