/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;

  --color-bg: #ffffff;
  --color-text: #1a1a2e;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-surface: #f9fafb;
  --color-surface-hover: #f3f4f6;

  --color-female: #e8457a;
  --color-male: #3a7bd5;
  --color-both: #7c3aed;

  --max-width: 800px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-full: 9999px;

  --transition: 150ms ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--color-male);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1000;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-male);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-text {
  color: var(--color-muted);
  font-size: 0.9rem;
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  border-bottom: 1px solid var(--color-border);
  padding: 20px 16px 16px;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.site-title {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.site-subtitle {
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-top: 2px;
}

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
.app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
  flex: 1;
  width: 100%;
}

/* ============================================================
   SEARCH
   ============================================================ */
.search-section {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--color-bg);
  padding: 12px 0;
  border-bottom: 1px solid transparent;
}

.search-section:focus-within {
  border-bottom-color: var(--color-border);
}

.search-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 44px 12px 16px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.search-input:focus {
  border-color: var(--color-male);
  background: var(--color-bg);
}

.search-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.search-clear:hover {
  background: #d1d5db;
}

/* ============================================================
   AUTOCOMPLETE
   ============================================================ */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  list-style: none;
  z-index: 300;
  max-height: min(380px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--color-border);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.focused {
  background: var(--color-surface-hover);
}

.ac-name {
  font-weight: 500;
  flex: 1;
}

.ac-peak {
  font-size: 0.78rem;
  color: var(--color-muted);
  white-space: nowrap;
}

/* ============================================================
   GENDER BADGE
   ============================================================ */
.gender-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-F {
  background: #fce7f3;
  color: var(--color-female);
}

.badge-M {
  background: #dbeafe;
  color: var(--color-male);
}

.badge-B {
  background: #ede9fe;
  color: var(--color-both);
}

/* ============================================================
   TABS
   ============================================================ */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 12px 0 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--transition), border-color var(--transition);
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-text);
  border-bottom-color: var(--color-text);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--color-muted);
  font-size: 0.95rem;
}

/* ============================================================
   NAME HEADER
   ============================================================ */
.name-header {
  margin-bottom: 16px;
}

.name-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.name-display {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.name-stats {
  font-size: 0.84rem;
  color: var(--color-muted);
  margin-top: 6px;
}

/* ============================================================
   CHART CONTROLS
   ============================================================ */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toggle-group {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.toggle-btn {
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-muted);
  background: var(--color-bg);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.toggle-btn + .toggle-btn {
  border-left: 1px solid var(--color-border);
}

.toggle-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.toggle-btn.active {
  background: var(--color-text);
  color: var(--color-bg);
}

/* ============================================================
   CHART
   ============================================================ */
.chart-container {
  position: relative;
  height: 260px;
  margin-bottom: 24px;
}

/* ============================================================
   SIMILAR NAMES (CHIPS)
   ============================================================ */
.similar-section {
  margin-bottom: 32px;
}

.section-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin-bottom: 10px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background var(--transition), border-color var(--transition);
  cursor: pointer;
}

.chip:hover {
  background: var(--color-surface-hover);
  border-color: #d1d5db;
}

.chip.current {
  background: var(--color-surface);
  border-color: var(--color-text);
}

.chip-count {
  font-size: 0.72rem;
  color: var(--color-muted);
}

/* ============================================================
   YEAR BROWSER
   ============================================================ */
.year-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.year-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.year-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}

.year-nav-btn:hover:not(:disabled) {
  background: var(--color-surface-hover);
}

.year-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.year-display {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  min-width: 60px;
  text-align: center;
}

.year-loading {
  color: var(--color-muted);
  font-size: 0.9rem;
  padding: 24px 0;
  text-align: center;
}

.year-name-list {
  list-style: none;
  border-top: 1px solid var(--color-border);
  margin-bottom: 32px;
}

.year-name-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--color-border);
}

.year-rank {
  font-size: 0.78rem;
  color: var(--color-muted);
  font-weight: 500;
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
}

.year-name-btn {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text);
  flex-shrink: 0;
  text-align: left;
  min-width: 100px;
  padding: 0;
  transition: color var(--transition);
}

.year-name-btn:hover {
  color: var(--color-male);
}

.year-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--color-surface);
  border-radius: 3px;
  overflow: hidden;
  min-width: 40px;
}

.year-bar {
  height: 100%;
  border-radius: 3px;
  background: var(--color-border);
  transition: width 0.3s ease;
}

.year-bar.bar-F { background: var(--color-female); opacity: 0.4; }
.year-bar.bar-M { background: var(--color-male); opacity: 0.4; }

.year-count {
  font-size: 0.78rem;
  color: var(--color-muted);
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  padding: 20px 16px 28px;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.footer-byline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.footer-label {
  font-size: 0.78rem;
  color: var(--color-muted);
}

.footer-logo-link {
  display: inline-block;
  opacity: 0.85;
  transition: opacity var(--transition);
}

.footer-logo-link:hover {
  opacity: 1;
}

.footer-logo {
  height: 40px;
  width: auto;
  display: block;
}

.footer-credit {
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 768px) {
  .site-header {
    padding: 24px 24px 20px;
  }

  .app {
    padding: 0 24px;
  }

  .site-title {
    font-size: 1.6rem;
  }

  .name-display {
    font-size: 2.5rem;
  }

  .chart-container {
    height: 320px;
  }

  .search-input {
    font-size: 1.05rem;
  }
}

@media (max-width: 480px) {
  .year-name-btn {
    min-width: 80px;
    font-size: 0.88rem;
  }
}
