:root {
  --primary: #7B1FA2;
  --primary-deep: #4A1259;
  --primary-soft: #F3E8FA;
  --space-deep: #120A1B;
  --space-mid: #2B1740;
  --bg: #FAF8FC;
  --surface: #FFFFFF;
  --fg: #241A2E;
  --muted: #756887;
  --border: #E9E2F1;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --shadow-1: 0 1px 2px rgba(36, 26, 46, 0.06);
  --shadow-2: 0 12px 32px rgba(36, 26, 46, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 헤더 ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 248, 252, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 13px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}

.brand-mark {
  display: block;
}

.brand h1,
.brand .brand-name {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--primary-deep);
}

.app-nav {
  display: flex;
  gap: 4px;
}

.app-nav a {
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 999px;
}

.app-nav a:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.app-nav a.active {
  color: #fff;
  background: var(--primary);
}

/* ---------- 공통 레이아웃 ---------- */

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

main.narrow {
  max-width: 940px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0 0 10px;
}

.view-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
}

.empty {
  border: 1px dashed var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.empty .button {
  margin-top: 14px;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 999px;
  padding: 9px 18px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.button:hover {
  background: var(--primary-deep);
  border-color: var(--primary-deep);
}

.button.ghost {
  background: transparent;
  color: var(--primary);
}

.button.ghost:hover {
  background: var(--primary-soft);
  color: var(--primary-deep);
}

.button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

/* ---------- 홈: 지도 ---------- */

.map-section {
  animation: rise 0.5s ease both;
}

.map-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 8px 0 18px;
}

.map-head h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 3.4vw, 32px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.22;
}

.map-head .lede {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  max-width: 620px;
}

.map-panel {
  position: relative;
  height: 540px;
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(130% 90% at 18% -10%, var(--space-mid) 0%, #1d1029 48%, var(--space-deep) 100%);
  box-shadow: var(--shadow-2), inset 0 0 120px rgba(123, 31, 162, 0.16);
}

.map-panel canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

.map-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(226, 214, 240, 0.55);
  pointer-events: none;
}

/* 범례 */

.legend {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 190px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(20, 11, 30, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(10px);
}

.legend-title {
  margin: 2px 6px 8px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(210, 196, 228, 0.75);
}

.legend-btn {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dcd2ea;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.legend-btn:hover {
  background: rgba(255, 255, 255, 0.07);
}

.legend-btn[aria-pressed="true"] {
  background: rgba(123, 31, 162, 0.42);
  color: #fff;
}

.legend-btn .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(200, 186, 220, 0.65);
}

.legend-btn:focus-visible {
  outline-color: #ce93d8;
}

/* 툴팁 */

.map-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  max-width: 230px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 9, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f2ecf8;
  pointer-events: none;
  transform: translate(-50%, -114%);
}

.map-tooltip p {
  margin: 0;
}

.tt-name {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.3;
}

.tt-brand {
  font-size: 11px;
  color: rgba(210, 198, 228, 0.75);
  margin-top: 2px;
}

.tt-family {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 7px;
}

.tt-coords {
  font-size: 10.5px;
  color: rgba(190, 176, 210, 0.65);
  margin-top: 5px;
}

/* ---------- 홈: 목록 ---------- */

.list-section {
  margin-top: 44px;
  animation: rise 0.5s ease 0.08s both;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.result-count {
  margin: 0 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}

.search-wrap {
  flex: 0 1 340px;
  min-width: 220px;
}

#search {
  width: 100%;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
}

#search::placeholder {
  color: #a99cba;
}

#search:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: transparent;
}

.axis-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 10px;
}

.axis-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.axis-pick select {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  max-width: 210px;
}

.axis-pick select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
}

.perfume-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 14px;
}

.perfume-card {
  position: relative;
}

.perfume-card-link {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.perfume-card-link:hover {
  transform: translateY(-2px);
  border-color: #cda9de;
  box-shadow: var(--shadow-2);
}

.card-photo {
  flex: 0 0 64px;
  width: 64px;
  height: 88px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.card-photo-empty {
  display: block;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-eyebrow {
  margin: 0 0 6px;
  padding-right: 30px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card-name {
  margin: 0 0 8px;
  padding-right: 22px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.card-family {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.card-notes {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0;
}

.tag {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-deep);
}

.fav-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #c9bbd6;
  cursor: pointer;
}

.fav-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.fav-btn svg {
  width: 17px;
  height: 17px;
}

.fav-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.fav-btn.active {
  color: var(--primary);
}

.fav-btn.active svg path {
  fill: currentColor;
}

/* ---------- 상세 ---------- */

.back-link {
  display: inline-block;
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--primary);
}

.detail-hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: start;
  animation: rise 0.5s ease both;
}

/* 병 사진이 있는 상세만 3열 — 사진 없는 향수는 기존 2열 그대로 */
.detail-hero:has(.detail-photo) {
  grid-template-columns: 200px 1.35fr 1fr;
}

.detail-photo {
  margin: 0;
}

.detail-photo img {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}

.detail-name {
  margin: 0 0 10px;
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.detail-family {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.detail-sub {
  color: #a99cba;
}

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.profile-panel {
  border-radius: 16px;
  padding: 20px 20px 10px;
  background: radial-gradient(130% 110% at 20% -10%, var(--space-mid) 0%, #1d1029 55%, var(--space-deep) 100%);
  color: #ede5f6;
  box-shadow: inset 0 0 60px rgba(123, 31, 162, 0.18);
}

.panel-title {
  margin: 0 0 16px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-family: var(--mono);
  color: rgba(214, 200, 232, 0.72);
}

.meter-row {
  display: grid;
  grid-template-columns: 52px 1fr 52px 42px;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.meter-pole {
  font-size: 11.5px;
  color: rgba(216, 204, 232, 0.85);
  text-align: right;
}

.meter-pole.pole-max {
  text-align: left;
}

.meter-track {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
}

.meter-mid {
  position: absolute;
  left: 50%;
  top: -3px;
  width: 1px;
  height: 10px;
  background: rgba(255, 255, 255, 0.22);
}

.meter-thumb {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.meter-val {
  font-size: 11px;
  color: rgba(214, 202, 230, 0.75);
  text-align: right;
}

.detail-section {
  margin-top: 38px;
}

.detail-section h3 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}

.section-sub {
  margin: -6px 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.note-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 12.5px;
  padding: 4px 12px;
  border-radius: 999px;
}

.detail-desc {
  max-width: 720px;
  font-size: 15px;
  margin: 0;
}

/* ---------- 마이페이지 ---------- */

.profile-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  animation: rise 0.5s ease both;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 120% at 25% 10%, var(--space-mid) 0%, var(--space-deep) 100%);
}

.profile-card h2 {
  margin: 0 0 2px;
  font-size: 20px;
  font-weight: 800;
}

.profile-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.stats-row {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.stat {
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  min-width: 88px;
}

.stat b {
  display: block;
  font-size: 20px;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--primary-deep);
}

.stat span {
  font-size: 11.5px;
  color: var(--muted);
}

.my-section {
  margin-top: 34px;
}

.my-section > h3 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}

.taste-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.family-bars {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.family-bars .panel-title {
  color: var(--muted);
}

.fbar {
  display: grid;
  grid-template-columns: 110px 1fr 26px;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.fbar .bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.fbar .bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
}

.fbar .fnum {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

.taste-note {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.taste-note b {
  color: var(--primary-deep);
}

.recent-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  color: inherit;
  font-size: 13.5px;
}

.recent-item a:hover {
  border-color: #cda9de;
}

.recent-item b {
  font-weight: 700;
}

.recent-brand {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.recent-family {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 푸터 ---------- */

.app-footer {
  border-top: 1px solid var(--border);
  padding: 22px 20px 30px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  background: var(--surface);
}

.app-footer p {
  margin: 2px 0;
}

#data-source {
  font-size: 11.5px;
  letter-spacing: 0.03em;
  color: #9a8fa9;
}

/* ---------- 모션/반응형 ---------- */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 860px) {
  .map-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .map-panel {
    height: 420px;
  }

  .legend {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: 12px;
    width: auto;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px;
  }

  .legend-title {
    display: none;
  }

  .legend-btn {
    flex: none;
    width: auto;
  }

  .legend-btn .count {
    margin-left: 6px;
  }

  .map-hint {
    display: none;
  }

  .detail-hero,
  .detail-hero:has(.detail-photo) {
    grid-template-columns: 1fr;
  }

  .detail-photo {
    width: 160px;
    margin: 0 auto;
  }

  .taste-grid {
    grid-template-columns: 1fr;
  }

  .profile-card {
    flex-wrap: wrap;
  }

  .stats-row {
    margin-left: 0;
    width: 100%;
  }

  .stat {
    flex: 1;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
