@font-face {
  font-family: 'Canda Tawa Cute';
  src: url('assets/fonts/CandaTawaCute.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Candal';
  src: url('assets/fonts/Candal.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-card: 'Canda Tawa Cute', 'Candal', -apple-system, BlinkMacSystemFont, "SF Pro Rounded", sans-serif;
  --font-heading: 'Candal', 'Canda Tawa Cute', -apple-system, BlinkMacSystemFont, "SF Pro Rounded", sans-serif;
  --font-ui: "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ink: #2b1a0e;
  --ink-soft: #64452e;
  --cream: #fffaf0;
  --cream-warm: #fff3dc;
  --parchment: #f6e7c8;
  --gold: #e5933a;
  --gold-bright: #ffd369;
  --teal-deep: #152b34;
  --teal-mid: #1f3d49;
  --shadow-soft: 0 10px 28px rgba(34, 18, 8, 0.24);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 18% 12%, #fff5cc 0%, #ffd9be 42%, #f4b7d6 100%);
  color: var(--ink);
  font-family: var(--font-ui);
  font-synthesis: none;
}

button, input {
  font-family: var(--font-ui);
  font-synthesis: none;
}

/* ================= TOP HEADER ================= */
.atlas-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.atlas-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(27, 51, 60, 0.96) 0%, rgba(21, 41, 49, 0.95) 100%);
  border-bottom: 3px solid #e7a455;
  box-shadow: 0 6px 20px rgba(17, 29, 36, 0.28);
  color: #fffaf0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 2px solid rgba(255, 224, 173, 0.45);
  background: rgba(255, 250, 240, 0.12);
  color: #fffaf0;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.16s ease, border-color 0.16s ease;
}

.nav-pill:hover {
  background: rgba(255, 232, 188, 0.24);
  border-color: #ffd369;
  transform: translateY(-1px);
}

.nav-pill.active {
  background: linear-gradient(180deg, #ffcf7d 0%, #ef9847 100%);
  color: var(--ink);
  border-color: #fff2cc;
}

.nav-pill.story-btn {
  background: linear-gradient(180deg, #ffcf7d 0%, #e78a3d 100%);
  color: var(--ink);
  border-color: #fff1cc;
}

.atlas-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.atlas-brand img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #ffd369;
  object-fit: cover;
}

.atlas-brand-title {
  font-family: var(--font-heading);
  font-size: 18px;
  letter-spacing: 0.3px;
  color: #ffe9b3;
  line-height: 1.05;
}

.atlas-brand-sub {
  font-size: 11px;
  color: #c7e1ea;
}

.search-wrap {
  position: relative;
  min-width: 220px;
  flex: 1;
  max-width: 310px;
}

.atlas-search {
  width: 100%;
  padding: 9px 32px 9px 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 217, 148, 0.55);
  background: rgba(255, 250, 240, 0.95);
  color: var(--ink);
  font-size: 13px;
  outline: none;
}

.atlas-search:focus {
  border-color: #ffd369;
  box-shadow: 0 0 0 3px rgba(255, 211, 105, 0.32);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: rgba(43, 26, 14, 0.14);
  color: var(--ink);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: none;
  align-items: center;
  justify-content: center;
}

.search-clear.visible {
  display: inline-flex;
}

.search-results-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--cream);
  border: 2px solid #df9b4d;
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(22, 14, 7, 0.35);
  max-height: 310px;
  overflow-y: auto;
  z-index: 60;
  display: none;
}

.search-results-pop.open {
  display: block;
}

.search-result-item {
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid rgba(217, 155, 67, 0.18);
  color: var(--ink);
}

.search-result-item:hover {
  background: #fff1d6;
}

.search-result-item img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1.5px solid #d99b43;
}

.search-result-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.search-result-name {
  font-weight: 700;
  font-size: 13px;
}

.search-result-region {
  font-size: 11px;
  color: var(--ink-soft);
}

/* ================= MAIN SPLIT LAYOUT ================= */
.atlas-main {
  display: grid;
  grid-template-columns: minmax(0, 1.48fr) minmax(350px, 470px);
  gap: 16px;
  padding: 16px;
  flex: 1;
  align-items: start;
}

/* ================= MAP STAGE ================= */
.map-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.map-frame-outer {
  position: relative;
  border-radius: 24px;
  padding: 9px;
  background: linear-gradient(135deg, #f9d48b 0%, #d48238 48%, #f7d083 100%);
  box-shadow: 0 16px 38px rgba(42, 22, 9, 0.28), inset 0 2px 3px rgba(255, 255, 255, 0.55);
}

.map-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 17px;
  overflow: hidden;
  background: #1c3a47;
  box-shadow: inset 0 0 0 2px rgba(43, 26, 14, 0.35);
}

.map-artwork {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.map-title-crest {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  background: linear-gradient(180deg, rgba(255, 249, 232, 0.94) 0%, rgba(246, 228, 192, 0.94) 100%);
  border: 2px solid #c97f34;
  border-radius: 14px;
  padding: 6px 12px;
  box-shadow: 0 5px 14px rgba(32, 16, 6, 0.28);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.map-title-crest strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--ink);
  line-height: 1.1;
}

.map-title-crest span {
  display: block;
  font-size: 10.5px;
  color: var(--ink-soft);
}

/* Clean Art Mode hides overlays */
.map-viewport.clean-mode .map-overlay-layer,
.map-viewport.clean-mode .map-title-crest {
  opacity: 0;
  pointer-events: none;
}

.map-overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  transition: opacity 0.25s ease;
}

/* ================= REGION BANNERS ON MAP ================= */
.region-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2.5px solid #fff7e2;
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255, 250, 238, 0.96) 0%, rgba(247, 231, 196, 0.96) 100%);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(24, 13, 5, 0.34), 0 0 0 2px var(--region-color, #d97724);
  transition: transform 0.16s ease, box-shadow 0.18s ease, background 0.18s ease;
  z-index: 12;
  white-space: nowrap;
}

.region-pin:hover {
  transform: translate(-50%, -56%) scale(1.06);
  z-index: 25;
}

.region-pin.active {
  background: linear-gradient(180deg, #fff5c8 0%, #ffd26e 100%);
  transform: translate(-50%, -54%) scale(1.09);
  box-shadow: 0 0 0 3px #fffaf0, 0 0 0 6px var(--region-color, #d97724), 0 10px 24px rgba(20, 10, 4, 0.45);
  z-index: 26;
}

.region-pin-ico {
  font-size: 16px;
  line-height: 1;
}

.region-pin-name {
  font-family: var(--font-heading);
  font-size: 12.5px;
  letter-spacing: 0.2px;
}

.region-pin-count {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--region-color, #d97724);
  color: #fff;
}

/* ================= MASCOT AVATAR PINS ON MAP ================= */
.mascot-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  border: 2.5px solid #fffaf0;
  background: #fffaf0;
  box-shadow: 0 5px 14px rgba(20, 11, 5, 0.4), 0 0 0 2px var(--region-color, #d97724);
  cursor: pointer;
  z-index: 10;
  transition: transform 0.16s ease, box-shadow 0.18s ease, opacity 0.2s ease;
  overflow: visible;
}

.mascot-pin img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.mascot-pin:hover {
  transform: translate(-50%, -56%) scale(1.22);
  z-index: 30;
  box-shadow: 0 8px 20px rgba(20, 11, 5, 0.5), 0 0 0 3px #ffd369;
}

.mascot-pin::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%) scale(0.92);
  background: rgba(27, 51, 60, 0.95);
  color: #fffaf0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1.5px solid #ffd369;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.mascot-pin:hover::after,
.mascot-pin.search-focus::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.mascot-pin.search-focus {
  width: 58px;
  height: 58px;
  z-index: 35;
  border: 3px solid #fff8d6;
  box-shadow: 0 0 0 4px #ff9f1c, 0 0 24px rgba(255, 200, 50, 0.95);
  animation: bouncePin 1.1s ease-in-out infinite;
}

@keyframes bouncePin {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -62%) scale(1.08); }
}

.map-viewport.hide-avatars .mascot-pin:not(.search-focus) {
  opacity: 0;
  pointer-events: none;
}

/* Mystery pin for Missing Whalermelon */
.mystery-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2px dashed #c8f3ff;
  background: rgba(15, 57, 84, 0.88);
  color: #e9faff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  z-index: 11;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(8, 30, 46, 0.48);
  animation: pulseMystery 2.4s ease-in-out infinite;
}

.mystery-pin:hover {
  background: rgba(26, 94, 134, 0.96);
  transform: translate(-50%, -54%) scale(1.06);
}

@keyframes pulseMystery {
  0%, 100% { box-shadow: 0 0 0 0 rgba(126, 224, 255, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(126, 224, 255, 0); }
}

/* ================= QUICK REGION BAR BELOW MAP ================= */
.region-quickbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(255, 250, 240, 0.86);
  border: 2px solid rgba(217, 144, 67, 0.45);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 6px 18px rgba(74, 42, 18, 0.12);
}

.quick-region-btn {
  border: 2px solid transparent;
  background: #fff6e5;
  color: var(--ink);
  border-radius: 12px;
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.quick-region-btn:hover {
  transform: translateY(-1px);
  border-color: var(--region-color, #d97724);
}

.quick-region-btn.active {
  background: var(--region-color, #d97724);
  color: #fff;
  box-shadow: 0 4px 12px rgba(42, 22, 9, 0.2);
}

.quick-region-btn .q-count {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
}

/* ================= REGION EXPLORER PANEL ================= */
.region-panel {
  background: rgba(255, 250, 240, 0.94);
  border: 2.5px solid rgba(217, 144, 67, 0.55);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 96px);
}

.region-hero {
  padding: 16px 18px 14px;
  background: linear-gradient(135deg, var(--region-accent, #ffe3bd) 0%, #fffaf0 100%);
  border-bottom: 2px solid rgba(217, 144, 67, 0.35);
}

.region-zone-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--region-color, #d97724);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 6px;
}

.region-hero h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 23px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.region-landmark {
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
}

.region-scroll {
  padding: 14px 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lore-box {
  background: #fff5e1;
  border: 1.5px solid rgba(217, 144, 67, 0.4);
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.48;
  color: var(--ink);
}

.mystery-box {
  background: linear-gradient(135deg, #dff6ff 0%, #eefaff 100%);
  border: 2px dashed #2d8bd4;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #133b56;
}

.section-subhead {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.spotlight-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spotlight-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1.5px solid rgba(217, 144, 67, 0.35);
  border-radius: 14px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.spotlight-item:hover {
  transform: translateY(-1px);
  border-color: var(--region-color, #d97724);
}

.spotlight-item img {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--region-color, #d97724);
  flex-shrink: 0;
}

.spotlight-copy strong {
  display: block;
  font-size: 13.5px;
  color: var(--ink);
}

.spotlight-copy span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.32;
}

/* Family filter pills */
.family-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.fam-chip {
  border: 1.5px solid rgba(100, 69, 46, 0.25);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.fam-chip.active {
  background: var(--ink);
  color: #fffaf0;
  border-color: var(--ink);
}

/* Resident card grid */
.resident-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.resident-card {
  border: 2px solid rgba(217, 144, 67, 0.35);
  background: #fff;
  border-radius: 14px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.14s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.resident-card:hover {
  transform: translateY(-2px);
  border-color: var(--region-color, #d97724);
  box-shadow: 0 7px 16px rgba(64, 34, 14, 0.16);
}

.resident-card.highlighted {
  border-color: #ff9f1c;
  background: #fff7d6;
  box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.45);
}

.resident-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #f3e4c7;
}

.resident-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.resident-fam-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 250, 240, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.resident-name {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resident-stat {
  font-size: 10.5px;
  color: var(--ink-soft);
}

/* ================= MODALS ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(18, 30, 38, 0.68);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #fffbf2 0%, #f9ebd0 100%);
  border: 3px solid #d98a3b;
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 22px 54px rgba(12, 20, 26, 0.48);
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(43, 26, 14, 0.2);
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.story-title {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-size: 24px;
}

.story-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 700;
}

.story-lead {
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  border: 1.5px solid rgba(217, 144, 67, 0.4);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 14px;
}

.story-chapter {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 14px;
  padding: 11px 13px;
  margin-bottom: 10px;
  border: 1px solid rgba(217, 144, 67, 0.3);
}

.story-chapter-ico {
  font-size: 24px;
  line-height: 1;
}

.story-chapter strong {
  display: block;
  font-size: 14.5px;
  margin-bottom: 3px;
}

.story-chapter p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* Card detail modal */
.card-modal-grid {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 18px;
  align-items: start;
}

.card-modal-art {
  width: 100%;
  border-radius: 16px;
  border: 3px solid #d98a3b;
  box-shadow: 0 10px 24px rgba(42, 22, 9, 0.26);
  display: block;
}

.card-modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.badge-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f1dec0;
  color: var(--ink);
}

.card-modal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.stat-chip {
  background: #fff;
  border: 1.5px solid rgba(217, 144, 67, 0.45);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 800;
}

.time-link-btn {
  margin-top: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  border: 2px solid #6753d6;
  background: #efeaff;
  color: #36278a;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
}

.time-link-btn:hover {
  background: #e1d7ff;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 1080px) {
  .atlas-main {
    grid-template-columns: 1fr;
  }
  .region-panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .atlas-main {
    padding: 10px;
  }
  .region-pin {
    padding: 4px 8px 4px 6px;
  }
  .region-pin-name {
    font-size: 10.5px;
  }
  .mascot-pin {
    width: 32px;
    height: 32px;
  }
  .card-modal-grid {
    grid-template-columns: 1fr;
  }
  .card-modal-art {
    max-width: 210px;
    margin: 0 auto;
  }
}
