:root {
  --sea-deep: #071b2f;
  --sea: #0e3554;
  --sea-light: #1b5980;
  --parchment: #f4e3c1;
  --parchment-dim: #e0c79c;
  --straw: #f2c14e;
  --ribbon: #c0392b;
  --ink: #2b1d0e;
  --ink-soft: #6b543a;
  --topbar-h: 60px;
  --radius: 14px;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--parchment);
  background: var(--sea-deep);
}

.hidden { display: none !important; }

/* ---------- 頂部：品牌 + 搜尋入口 ---------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: linear-gradient(180deg, rgba(7, 27, 47, .98), rgba(7, 27, 47, .9));
  border-bottom: 2px solid var(--straw);
  box-shadow: 0 2px 14px rgba(0, 0, 0, .5);
}

.jolly { display: flex; flex-shrink: 0; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }

.target-chip {
  flex: 1;
  min-width: 0;
  display: block;
  text-align: left;
  padding: 6px 12px;
  font-family: inherit;
  color: var(--parchment);
  background: rgba(244, 227, 193, .1);
  border: 1.5px solid rgba(242, 193, 78, .5);
  border-radius: 11px;
  cursor: pointer;
}
.target-chip:active { background: rgba(244, 227, 193, .2); }

.chip-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--straw);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-sub {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--parchment-dim);
  opacity: .8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-icon { flex-shrink: 0; font-size: 18px; opacity: .85; }

/* ---------- 地圖：主畫面 ---------- */

#map {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  left: 0; right: 0; bottom: 0;
  background: #cbb389;
}
.leaflet-tile-pane { filter: sepia(.62) saturate(.72) contrast(1.06) brightness(1.04); }
.leaflet-container { font-family: inherit; }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution { font-size: 9px; opacity: .7; }

.leaflet-popup-content-wrapper {
  background: var(--parchment);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.leaflet-popup-tip { background: var(--parchment); border: 2px solid var(--ink); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.5; }
.popup-name { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.popup-stock { color: var(--ribbon); font-weight: 700; }
.popup-link { display: inline-block; margin-top: 6px; color: var(--sea-light); font-weight: 700; }

.pin {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: var(--straw);
  border: 2px solid var(--ink);
  border-radius: 50% 50% 50% 6px;
  transform: rotate(-45deg);
  box-shadow: 0 2px 5px rgba(0,0,0,.45);
}
.pin span { transform: rotate(45deg); }

/* ---------- 航行進度：浮在地圖上，不佔版面 ---------- */

.voyage {
  position: fixed;
  z-index: 800;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  left: 10px; right: 10px;
  padding: 9px 12px;
  background: rgba(7, 27, 47, .93);
  border: 1.5px solid var(--straw);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
  backdrop-filter: blur(4px);
}

.voyage-row { display: flex; align-items: center; gap: 9px; }
.voyage-stats { margin-top: 7px; justify-content: space-between; font-size: 12px; }

.ship { font-size: 17px; flex-shrink: 0; }

.sea-track {
  flex: 1;
  height: 8px;
  background: var(--sea);
  border: 1.5px solid rgba(242, 193, 78, .45);
  border-radius: 20px;
  overflow: hidden;
}
.sea-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--sea-light) 0 8px, #2a79a8 8px 16px);
  transition: width .25s ease-out;
}

#voyage-area { color: var(--parchment-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.treasure-count { font-weight: 700; color: var(--straw); white-space: nowrap; }

.mini-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--parchment);
  background: transparent;
  border: 1.5px solid rgba(244, 227, 193, .45);
  border-radius: 8px;
  cursor: pointer;
}
.mini-btn:active { background: rgba(244, 227, 193, .15); }

.status {
  position: fixed;
  z-index: 800;
  left: 12px; right: 12px;
  bottom: calc(132px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 9px 13px;
  font-size: 13px;
  text-align: center;
  color: var(--ink);
  background: var(--parchment);
  border: 2px solid var(--ink);
  border-radius: 11px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
}
.status.error { background: #ffd9d0; color: #8c2318; font-weight: 700; }

/* ---------- 底部清單：可收折 ---------- */

.sheet {
  position: fixed;
  z-index: 850;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: 68dvh;
  background: var(--parchment);
  border-top: 2px solid var(--ink);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, .5);
  transition: transform .28s cubic-bezier(.32, .72, 0, 1);
}
.sheet.collapsed { transform: translateY(calc(100% - 58px - env(safe-area-inset-bottom))); }

.sheet-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px 11px;
  font-family: inherit;
  color: var(--ink);
  background: var(--parchment-dim);
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 14px 14px 0 0;
  cursor: pointer;
}

.grip {
  position: absolute;
  top: 6px; left: 50%;
  width: 40px; height: 4px;
  background: var(--ink-soft);
  border-radius: 3px;
  transform: translateX(-50%);
  opacity: .55;
}

.result-summary {
  flex: 1;
  text-align: left;
  padding-top: 6px;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-caret {
  padding-top: 6px;
  font-size: 11px;
  transition: transform .28s;
}
.sheet:not(.collapsed) .sheet-caret { transform: rotate(180deg); }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.store {
  padding: 10px 11px;
  background: #fffaf0;
  border: 2px solid var(--ink-soft);
  border-left: 6px solid var(--straw);
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
}
.store:active { background: var(--parchment); }
.store-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.store-name { font-weight: 700; font-size: 15px; }
.store-stock { color: var(--ribbon); font-weight: 700; white-space: nowrap; }
.store-area { margin-top: 3px; font-size: 12px; color: var(--ink-soft); letter-spacing: .06em; }
.store-addr { margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.store-hour { margin-top: 3px; font-size: 12px; color: var(--ink-soft); }
.store-nav { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--sea-light); }

.empty { padding: 26px 14px; text-align: center; color: var(--ink-soft); font-size: 14px; }

/* ---------- 搜尋彈窗 ---------- */

.dialog {
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255,255,255,.35), transparent 40%),
    var(--parchment);
  border: 2px solid var(--ink);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .6);
  overflow-y: auto;
}
.dialog::backdrop { background: rgba(4, 15, 27, .72); backdrop-filter: blur(3px); }

@media (min-width: 620px) {
  .dialog {
    margin: auto;
    border-bottom: 2px solid var(--ink);
    border-radius: 18px;
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
  padding-bottom: 8px;
  border-bottom: 2px dashed var(--ink-soft);
}
.dialog-head h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: .2em;
  font-family: Georgia, serif;
}
.dialog-head .mini-btn { color: var(--ink); border-color: var(--ink-soft); }

.search-row { display: flex; gap: 8px; }

#keyword {
  flex: 1;
  min-width: 0;
  padding: 12px 13px;
  font-size: 16px; /* iOS 聚焦時不自動放大 */
  font-family: inherit;
  color: var(--ink);
  background: #fffaf0;
  border: 2px solid var(--ink);
  border-radius: 10px;
}
#keyword::placeholder { color: #a8926f; }
#keyword:focus { outline: 3px solid var(--straw); outline-offset: 1px; }

.btn {
  padding: 12px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn-gold { background: var(--straw); }
.btn-red { background: var(--ribbon); color: #fff6e8; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 11px;
  font-size: 13px;
  font-weight: 700;
}
#county {
  flex: 1;
  padding: 9px 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: #fffaf0;
  border: 2px solid var(--ink);
  border-radius: 9px;
}

.dialog-status { margin: 11px 2px 0; font-size: 13px; min-height: 17px; color: var(--ink-soft); }
.dialog-status.error { color: #8c2318; font-weight: 700; }

.product-list { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }

.product {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px;
  background: #fffaf0;
  border: 2px solid var(--ink-soft);
  border-radius: 11px;
  cursor: pointer;
}
.product:active { background: var(--parchment); }
.product img {
  width: 54px; height: 54px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--ink-soft);
  border-radius: 7px;
  flex-shrink: 0;
}
.product-info { flex: 1; min-width: 0; }
.product-name { font-size: 14px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.product-price { margin-top: 3px; font-size: 13px; color: var(--ribbon); font-weight: 700; }

.sheet-handle { position: relative; }

/* ---------- 定位 ---------- */

.locate-btn {
  position: fixed;
  z-index: 820;
  right: 14px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  color: var(--ink);
  background: var(--straw);
  border: 2px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
  cursor: pointer;
  transition: transform .12s;
}
.locate-btn:active { transform: scale(.92); }
.locate-btn.busy { animation: locate-pulse 1s ease-in-out infinite; }
.locate-btn.on { background: var(--sea-light); color: var(--parchment); }

@keyframes locate-pulse {
  50% { opacity: .55; }
}

/* 使用者位置：海盜船 */
.ship-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
}
.ship-marker::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(242, 193, 78, .3);
  border: 2px solid var(--straw);
  animation: ship-ping 2.2s ease-out infinite;
}
.ship-marker svg {
  position: relative;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .55));
}

@keyframes ship-ping {
  0%   { transform: scale(.55); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0; }
}

.store-dist {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--sea-light);
  letter-spacing: .04em;
}
