/* ===============================
   Stylish Controls for Toyama Bear Map
   Last updated: 2025-11-15 (JST)
   =============================== */

/* --- Base layout --- */
html, body {
  height: 100%;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Noto Sans JP, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

#map {
  position: absolute;
  inset: 0;
}

/* --- Popup & Lightbox --- */
.thumb-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.thumb-box img {
  max-width: 200px;
  height: auto;
  display: block;
  border-radius: 6px;
}
.thumb-title {
  font-weight: 700;
  font-size: 14px;
}
.thumb-actions {
  display: flex;
  gap: 8px;
}
.btn {
  appearance: none;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}
.btn:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

#lightbox {
  position: fixed;
  inset: 0;
  display: none;
}
#lightbox[aria-hidden="false"] {
  display: block;
}
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
}
.lightbox-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #111;
  color: #fff;
  border-radius: 14px;
  width: min(960px, 92vw);
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.lightbox-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}
.lightbox-close {
  background: transparent;
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  line-height: 44px;
  text-align: center;
  border-radius: 8px;
}
.lightbox-close:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
.lightbox-body {
  padding: 12px 16px 18px;
}
.lightbox-img-wrap {
  display: flex;
  justify-content: center;
}
.lightbox-img {
  max-width: 100%;
  max-height: 68vh;
  height: auto;
  border-radius: 10px;
  display: block;
}
.lightbox-caption {
  margin: 12px auto 0;
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.95;
}

@media (max-width: 480px) {
  .thumb-box img {
    max-width: 160px;
  }
  .lightbox-panel {
    width: 94vw;
  }
  .lightbox-caption {
    font-size: 13px;
  }
}

/* ===============================
   FILTER PANEL (top-left)
   =============================== */
.control {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  background: rgba(255,255,255,.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 16px;
  padding: 8px 10px;
  box-shadow: 0 12px 30px rgba(15,23,42,.12);
  display: grid;
  grid-auto-flow: row;
  gap: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  width: 240px;
}
.control .row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 8px;
  align-items: center;
}
.control label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #0f172a;
  display: grid;
  gap: 4px;
}

/* Selects */
.control select {
  appearance: none;
  padding: 8px 32px 8px 12px;
  font-size: 13px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background:
    linear-gradient(180deg, #ffffff, #f8fafc) padding-box,
    linear-gradient(180deg, rgba(255,255,255,.9), rgba(15,23,42,.06)) border-box;
  color: #0f172a;
  font-weight: 500;
  outline: none;
  box-shadow:
    0 1px 2px rgba(16,24,40,.08),
    inset 0 1px 0 rgba(255,255,255,.6);
  transition: box-shadow .2s ease, border-color .2s ease, background .25s ease;
  position: relative;
  background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5' stroke='%23566' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px 16px;
}
.control select:hover {
  box-shadow: 0 8px 22px rgba(2,6,23,.10);
  background: linear-gradient(180deg, #ffffff, #f1f5f9);
}
.control select:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

/* Buttons */
.control button {
  appearance: none;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 9999px;
  border: 1px solid #cbd5e1;
  background: linear-gradient(180deg, #ffffff, #f6f8fb);
  color: #0f172a;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow:
    0 1px 2px rgba(16, 24, 40, .08),
    inset 0 1px 0 rgba(255, 255, 255, .65);
  transition: transform .06s ease, box-shadow .2s ease, background .25s ease, border-color .25s ease, filter .2s ease;
}
.control button:hover {
  background: #f1f5f9;
  box-shadow: 0 10px 24px rgba(2, 6, 23, .10);
}
.control button:active {
  transform: translateY(1px);
}
.control button:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}
.control button:disabled {
  opacity: .55;
  cursor: default;
}

/* Primary (Apply) */
#apply {
  border-color: #1e3a8a;
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow:
    0 6px 16px rgba(37,99,235,.35),
    inset 0 1px 0 rgba(255,255,255,.35);
}
#apply:hover {
  filter: brightness(1.06);
}
#apply:active {
  transform: translateY(1px);
}

/* Secondary (Reset) */
#reset {
  background: transparent;
  color: #334155;
  border-color: #cbd5e1;
}
#reset:hover {
  background: #f8fafc;
}

/* --- Mapbox default control polish --- */
.mapboxgl-ctrl-top-right .mapboxgl-ctrl {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(15,23,42,.12);
}
.mapboxgl-ctrl button {
  border-radius: 0;
}

/* --- Zoom slider (right bottom) --- */
#zoomSlider {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  background: rgba(255,255,255,.75);
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: 0 6px 14px rgba(0,0,0,.08);
  backdrop-filter: blur(6px);
}
#zoomRange {
  width: 160px;
}
/* ==== スマホ折りたたみコントロール ==== */

/* トグルボタン（PCでは非表示） */
.control-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 9999px;
  border: 1px solid #cbd5e1;
  background: rgba(255,255,255,.9);
  box-shadow: 0 4px 10px rgba(15,23,42,.15);
  cursor: pointer;
  display: none; /* デフォルトはPCでは非表示 */
}
.control-toggle:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

/* ===== スマホ（縦画面〜タブレット） ===== */
@media (max-width: 768px) {

  .control-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 4;
  }

  .control {
    display: none;
    position: fixed;
    top: auto !important;       /* ★ 上側は無効にする */
    bottom: 12px !important;    /* ★ 画面下に固定する */
    left: 50%;
    transform: translateX(-50%);
    width: 40vw;
    padding: 6px 8px;
    gap: 6px;
    font-size: 12px;
    background: rgba(255,255,255,0.95);
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(15,23,42,.15);
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 3;
  }

  .control.is-open {
    display: grid;
  }

  .control button,
  .control input,
  .control select {
    width: 100%;
    font-size: 12px;
    padding: 6px 8px;
    margin-bottom: 4px;
  }
}

@media (max-width: 480px) {
  .control {
    width: 65vw;
    top: auto !important;
    bottom: 10px !important;
  }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .control button,
  .control select {
    transition: none;
  }
}

/* ==== 操作パネル クローズボタン ==== */
/* デフォルト（PC含む）は非表示 */
.control-close {
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 20px;
  color: #0f172a;
  cursor: pointer;
  padding: 4px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: none;   /* ← !important を外す */
}
.control-close:hover {
  background: rgba(0,0,0,0.08);
}
.control-close:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* 一定幅以下（スマホ幅）では表示させる */
@media (max-width: 768px) {
  .control-close {
    display: block;      /* ← 幅が狭いときは必ず表示 */
    font-size: 18px;
    width: 26px;
    height: 26px;
    top: 4px;
    right: 6px;
  }
}
