/* ==========================================================================
   HonniR — World Map
   โหลดเฉพาะหน้า /worldmap (ดู includes/header.php)
   ใช้ token ชุดเดียวกับ main.css : --sky --panel --ink --accent --line --radius
   ========================================================================== */

/* main.css ตั้ง img { display:block } ไว้กว้าง ๆ ซึ่งชนะ display:none ที่มากับ
   [hidden] ของเบราว์เซอร์ รูปในแผงที่ยังไม่ได้เลือกแมพจึงโผล่เป็นกล่องเปล่า */
.wm-stage [hidden] { display: none !important; }

.wm-stage {
  margin-bottom: 1.5rem;
}

.wm-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 340px);
  gap: 1rem;
  align-items: start;
}

/* --------------------------------------------------------------------------
   ผืนแผนที่
   ไอคอนวางด้วยหน่วย % ทั้งหมด ผืนจึงย่อขยายตามจอโดยไม่ต้องใช้ JS คำนวณ
   -------------------------------------------------------------------------- */

/* ไม่ตั้ง overflow:hidden ตรงนี้ ไม่งั้นไทล์แถวริมที่ถูกเลือกแล้วขยาย 1.5 เท่า
   จะโดนเฉือน — ผืนน้ำย้ายไปอยู่ใน .wm-canvas__sea ที่ตัดขอบของตัวเองแทน */
.wm-canvas {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.wm-canvas__sea {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: inherit;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.75), transparent 60%),
    linear-gradient(165deg, #dcedfa 0%, #cfe6f7 45%, #c6e0f4 100%);
}

/* ลายคลื่นจาง ๆ ใต้ผืนแผนที่ ให้ดูเป็นผืนน้ำ ไม่ใช่พื้นเรียบ ๆ */
.wm-canvas__sea::before {
  content: "";
  position: absolute;
  inset: -20%;
  background-image:
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.5) 0 2px, transparent 2px 22px);
  opacity: 0.35;
  animation: wm-drift 26s linear infinite;
  pointer-events: none;
}

@keyframes wm-drift {
  to { transform: translate3d(22px, 22px, 0); }
}

/* ---- เส้นเชื่อมแมพ ---- */

.wm-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ราง = ใต้ไทล์ (ไทล์อยู่ z-index 2) · ดาวตก = เหนือไทล์ */
.wm-links--track { z-index: 1; }
.wm-links--comet { z-index: 6; }

/* --------------------------------------------------------------------------
   เส้นเชื่อม = ดาวตกวิ่งไปตามเส้นทาง

   ทุกเส้นมี pathLength="100" จึงคิดระยะเป็นเปอร์เซ็นต์ได้เหมือนกันหมด
   หางกับหัวใช้ dasharray คาบเดียวกัน (100) ต่างกันแค่ความยาวขีด แล้วเลื่อน
   dashoffset ของหางให้ล้าหลังพอดีกับความยาวหัว ขอบหน้าของทั้งคู่จึงทับกันสนิท
   กลายเป็นหัวสว่างลากหางจาง ๆ ตามหลัง
   -------------------------------------------------------------------------- */

.wm-link__track,
.wm-link__tail,
.wm-link__head {
  fill: none;
  stroke-linecap: round;
  transition: opacity 0.3s ease, stroke 0.3s ease;
}

/* รางเส้นทาง — อยู่ใต้ไทล์ เห็นแค่ตรงร่อง บอกโครงเส้นทางแบบไม่รบกวนสายตา */
.wm-link__track {
  stroke: rgba(74, 147, 181, 0.3);
  stroke-width: 1.3;
}

/* หางดาว — ไล่จางท้ายเส้นด้วย stroke ที่บางและโปร่งกว่าหัว */
.wm-link__tail {
  stroke: rgba(150, 222, 255, 0.72);
  stroke-width: 3;
  stroke-dasharray: 22 78;
  animation: wm-comet-tail var(--wm-dur, 3s) linear infinite;
  animation-delay: var(--wm-delay, 0s);
}

/* หัวดาว — ขาวสว่างพร้อม glow ให้อ่านออกแม้วิ่งทับไทล์สีสด */
.wm-link__head {
  stroke: #ffffff;
  stroke-width: 4;
  stroke-dasharray: 5 95;
  animation: wm-comet-head var(--wm-dur, 3s) linear infinite;
  animation-delay: var(--wm-delay, 0s);
}

/* หัวออกตัวที่ 0 หางตามหลังอยู่ 17 หน่วย (= ยาวหาง 22 ลบยาวหัว 5)
   ขอบหน้าของหัวกับหางจึงอยู่ตำแหน่งเดียวกันตลอด กลายเป็นหัวสว่างลากหางจาง */
@keyframes wm-comet-head {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -100; }
}

@keyframes wm-comet-tail {
  from { stroke-dashoffset: 17; }
  to   { stroke-dashoffset: -83; }
}

/* เลือกแมพแล้ว : รางของแมพนั้นสว่างเป็นสีทอง ส่วนรางอื่นหรี่ลง
   ดาวตกไม่ต้องไฮไลต์ตาม เพราะหนึ่งเส้นทางพาดผ่านหลายแมพ ไฮไลต์ไปก็ชี้ไม่ตรงจุด
   แค่หรี่ทั้งชั้นลงให้เลิกแย่งสายตากับแมพที่กำลังดูอยู่ */
.wm-canvas.is-picked .wm-link__track { opacity: 0.22; }

.wm-canvas.is-picked .wm-link__track.is-lit {
  opacity: 1;
  stroke: rgba(240, 168, 136, 0.95);
  stroke-width: 2.2;
}

.wm-canvas.is-picked .wm-links--comet { opacity: 0.4; }

/* ---- ไอคอนแมพ ---- */

.wm-pin {
  position: absolute;
  z-index: 2;
  padding: 0;
  line-height: 0;
  cursor: pointer;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(58, 80, 104, 0.18);
  outline: 2px solid transparent;
  outline-offset: 1px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.18s ease,
              outline-color 0.18s ease;

  /* ไทล์ค่อย ๆ โผล่ทีละใบตอนเปิดหน้า — --wm-i คือลำดับไทล์ ตั้งค่าไว้ใน HTML
     หน่วง 6ms ต่อใบ ผืนเต็ม 104 ใบจึงใช้เวลารวมไม่ถึงครึ่งวินาที */
  animation: wm-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  animation-delay: calc(var(--wm-i, 0) * 6ms);
}

@keyframes wm-pop {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: scale(1); }
}

.wm-pin img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  image-rendering: pixelated;
}

.wm-pin__blank {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
}

/* ชื่อแมพลอยใต้ไอคอน โผล่ตอน hover เท่านั้น ไม่งั้นผืนแผนที่จะรกจนอ่านไม่ออก */
.wm-pin__name {
  position: absolute;
  top: calc(100% + 5px);
  left: 50%;
  transform: translate(-50%, -4px);
  z-index: 10;
  padding: 0.2rem 0.5rem;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  color: #fff;
  background: rgba(58, 80, 104, 0.92);
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.wm-pin:hover {
  z-index: 9;
  transform: scale(1.45);
  box-shadow: 0 8px 18px rgba(58, 80, 104, 0.38);
}

.wm-pin:hover .wm-pin__name,
.wm-pin:focus-visible .wm-pin__name {
  opacity: 1;
  transform: translate(-50%, 0) scale(0.72);  /* หักล้าง scale ของตัวแม่ */
}

.wm-pin.is-on {
  z-index: 8;
  transform: scale(1.5);
  outline-color: var(--warm);
  box-shadow: 0 8px 22px rgba(240, 168, 136, 0.65);
}

/* วงแหวนกระเพื่อมรอบไทล์ที่เลือกอยู่ ช่วยหาตำแหน่งเจอเร็วบนผืนที่ไทล์แน่น */
.wm-pin.is-on::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px solid var(--warm);
  border-radius: 6px;
  animation: wm-ping 1.6s ease-out infinite;
  pointer-events: none;
}

@keyframes wm-ping {
  0%   { opacity: 0.9; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.9); }
}

/* ไทล์ที่ถูกกรองออกตอนค้นหา — จางลงแต่ยังอยู่ที่เดิม ไม่ให้ผืนแผนที่ขยับ */
.wm-pin.is-dim {
  opacity: 0.18;
  filter: grayscale(1);
  pointer-events: none;
}

.wm-pin.is-hit {
  animation: wm-bounce 0.9s ease-in-out infinite;
}

@keyframes wm-bounce {
  0%, 100% { transform: scale(1.15); }
  50%      { transform: scale(1.35); }
}

/* --------------------------------------------------------------------------
   แผงรายละเอียดข้างผืนแผนที่
   -------------------------------------------------------------------------- */

.wm-panel {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2rem);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.wm-panel__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(217, 236, 248, 0.9), rgba(217, 236, 248, 0.45));
}

.wm-panel__pic {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  object-fit: cover;
  image-rendering: pixelated;
  box-shadow: 0 3px 8px rgba(58, 80, 104, 0.2);
  animation: wm-fade 0.3s ease backwards;
}

.wm-panel__title { min-width: 0; }   /* กันชื่อยาวดันรูปจนล้นแผง */

.wm-panel__title b {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wm-panel__title small {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wm-panel__body {
  flex: 1;
  min-height: 220px;
  padding: 0.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.wm-panel__body > * {
  animation: wm-fade 0.28s ease;
}

@keyframes wm-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   ตารางมอนสเตอร์
   -------------------------------------------------------------------------- */

.wm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.wm-table thead th {
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: left;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.wm-table .wm-th-i { width: 46px; }
.wm-table .wm-th-a { width: 56px; text-align: right; }
.wm-table .wm-th-t { width: 82px; text-align: right; }

.wm-table tbody tr {
  transition: background 0.15s ease;
}

.wm-table tbody tr:hover {
  background: rgba(181, 223, 240, 0.28);
}

.wm-table td {
  padding: 0.28rem 0.5rem;
  border-bottom: 1px solid rgba(109, 179, 212, 0.12);
  vertical-align: middle;
}

.wm-table tbody tr:last-child td { border-bottom: 0; }

.wm-table .wm-i { width: 46px; text-align: center; }
.wm-table .wm-n { color: var(--ink); font-weight: 500; }
.wm-table .wm-a { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.wm-table .wm-t { text-align: right; font-size: 0.78rem; color: var(--ink-muted); white-space: nowrap; }

/* สไปรท์มอนแต่ละตัวขนาดไม่เท่ากัน (37x36 ถึง 54x63) ต้อง object-fit ให้อยู่กรอบเดียวกัน
   ไม่งั้นความสูงของแถวจะเต้นตามตัวที่ใหญ่ที่สุด */
.wm-mi {
  display: inline-block;
  width: 36px;
  height: 36px;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wm-table tbody tr:hover .wm-mi { transform: scale(1.35) translateY(-2px); }

.wm-mi.is-none {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 6px;
}

/* แถวบอส/มินิ ให้เด่นกว่าตัวธรรมดา */
.wm-table tr.is-boss .wm-n { color: #c9607a; font-weight: 600; }
.wm-table tr.is-mini .wm-n { color: #b2792f; font-weight: 600; }

.wm-tag {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: #fff;
  border-radius: 999px;
  vertical-align: 1px;
}

.wm-tag.is-boss {
  background: linear-gradient(180deg, #e88aa0, #d4607f);
  box-shadow: 0 0 0 0 rgba(212, 96, 127, 0.55);
  animation: wm-glow 2.2s ease-out infinite;
}

.wm-tag.is-mini {
  background: linear-gradient(180deg, #f0c07a, #d9a044);
}

@keyframes wm-glow {
  0%   { box-shadow: 0 0 0 0 rgba(212, 96, 127, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(212, 96, 127, 0); }
  100% { box-shadow: 0 0 0 0 rgba(212, 96, 127, 0); }
}

.wm-none {
  margin: 0;
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* --------------------------------------------------------------------------
   ช่องค้นหา
   -------------------------------------------------------------------------- */

.wm-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.25rem 0 0.75rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wm-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(109, 179, 212, 0.18), var(--shadow);
}

.wm-search__ico {
  display: flex;
  flex: none;
  color: var(--accent-deep);
}

.wm-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font-family: var(--font);
  font-size: 0.92rem;
  color: var(--ink);
}

.wm-search input::placeholder { color: var(--ink-muted); }

.wm-search__clear {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--ink-muted);
  background: rgba(109, 179, 212, 0.14);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.wm-search__clear:hover { background: var(--accent); color: #fff; }

.wm-empty {
  margin: 0 0 1rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--ink-muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* --------------------------------------------------------------------------
   รายการแมพ
   -------------------------------------------------------------------------- */

.wm-section { margin-bottom: 2rem; }

.wm-h {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
}

.wm-h svg { color: var(--accent-deep); flex: none; }

.wm-h span {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-muted);
}

.wm-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.6rem;
  align-items: start;
}

.wm-item {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.wm-item:hover {
  transform: translateY(-2px);
  border-color: rgba(42, 159, 216, 0.45);
}

/* แมพที่เปิดอยู่ต้องกินพื้นที่เต็มแถว ไม่งั้นตารางมอนจะถูกบีบจนอ่านไม่ออก */
.wm-item[open] {
  grid-column: 1 / -1;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 179, 212, 0.16), var(--shadow);
}

.wm-item summary {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.wm-item summary::-webkit-details-marker { display: none; }

.wm-item summary img,
.wm-item__blank {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  image-rendering: pixelated;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wm-item__blank { background: rgba(255, 255, 255, 0.55); }

.wm-item:hover summary img { transform: scale(1.12) rotate(-3deg); }

.wm-item__name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
}

.wm-item__name small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--ink-muted);
}

.wm-item__count {
  flex: none;
  min-width: 26px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  color: var(--accent-deep);
  background: rgba(181, 223, 240, 0.5);
  border-radius: 999px;
}

.wm-item__body {
  padding: 0 0.5rem 0.5rem;
  border-top: 1px solid var(--line);
  animation: wm-open 0.25s ease;
}

@keyframes wm-open {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* แมพที่ถูกกรองออกตอนค้นหา */
.wm-item.is-hidden { display: none; }

/* แมพที่ถูกกระโดดมาหาจากผืนแผนที่ — กะพริบขอบให้รู้ว่าอยู่ตรงไหน */
.wm-item.is-flash {
  animation: wm-flash 1.1s ease-out;
}

@keyframes wm-flash {
  0%   { box-shadow: 0 0 0 0 rgba(240, 168, 136, 0.85); }
  100% { box-shadow: 0 0 0 16px rgba(240, 168, 136, 0); }
}

/* ---- กลุ่มดันเจี้ยน ---- */

.wm-dun {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.wm-dun__group.is-hidden { display: none; }

.wm-dun__group h3 {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.55rem;
  padding-left: 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  border-left: 3px solid var(--accent-soft);
}

.wm-dun__group h3 span {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--ink-muted);
}

/* --------------------------------------------------------------------------
   จอแคบ
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .wm-wrap { grid-template-columns: minmax(0, 1fr); }

  .wm-panel {
    position: static;
    max-height: none;
  }

  .wm-panel__body { max-height: 60vh; }

  /* ผืนแผนที่เต็มความกว้างจอแล้วยังเล็กเกินอ่าน — ให้เลื่อนดูในแนวนอนแทน */
  .wm-canvas-scroll {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .wm-canvas-scroll .wm-canvas {
    min-width: 680px;
  }

  /* บอกให้รู้ว่าเลื่อนดูได้ ไม่งั้นบนมือถือจะนึกว่าแผนที่มีแค่ที่เห็น */
  .wm-canvas-scroll {
    position: relative;
    border-radius: var(--radius);
  }

  .wm-canvas-scroll::after {
    content: "← เลื่อนดูแผนที่ได้ →";
    position: absolute;
    right: 0.6rem;
    bottom: 0.6rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    color: #fff;
    background: rgba(58, 80, 104, 0.7);
    border-radius: 999px;
    pointer-events: none;
    animation: wm-hint 4s ease-in-out 1.5s forwards;
  }

  @keyframes wm-hint {
    0%, 60% { opacity: 1; }
    100%    { opacity: 0; }
  }

  .wm-pin__name { font-size: 0.65rem; }
}

@media (max-width: 560px) {
  .wm-list { grid-template-columns: minmax(0, 1fr); }
  .wm-table { font-size: 0.8rem; }
  .wm-table .wm-th-t, .wm-table .wm-t { display: none; }  /* เวลาเกิดสละที่ให้ชื่อก่อน */
}

/* --------------------------------------------------------------------------
   เคารพการตั้งค่าลดการเคลื่อนไหวของระบบ
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .wm-canvas::before,
  .wm-link__tail,
  .wm-link__head,
  .wm-pin,
  .wm-pin.is-on::after,
  .wm-pin.is-hit,
  .wm-tag.is-boss,
  .wm-item.is-flash,
  .wm-item__body,
  .wm-panel__body > *,
  .wm-panel__pic {
    animation: none !important;
  }
}
