/* ===== Base ===== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700;900&display=swap');

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  --bg: #1a0a00;
  --accent: #c8392b;
  --text: #fff8f0;
  --highlight: #f39c12;
  --panel-bg: #2a1a0a;
  --border: #4a2a1a;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  /* ビューポート丁度に固定し、ページ自体はスクロールさせない。
     スクロールは .map-container の内側だけで行う（協賛窓が画面外へ流れるのを防ぐ） */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Sticky Top ===== */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 100;
}

.sticky-top:has(.maigo-banner.active) {
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--accent), #8b1a10);
  padding: 12px 16px;
  text-align: center;
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: .05em;
  text-shadow: 0 2px 4px rgba(0,0,0,.4);
}

/* ===== Maigo Banner ===== */
.maigo-banner {
  display: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  cursor: pointer;
  animation: blink-banner 1s ease-in-out infinite;
}

.maigo-banner.active {
  display: block;
}

@media (orientation: landscape) {
  .maigo-banner {
    font-size: 0.75rem;
    padding: 4px 16px;
    white-space: nowrap;
    overflow-x: auto;
  }
}

@keyframes blink-banner {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== Search ===== */
.search-area {
  padding: 10px 12px;
}

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

.search-box input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

.search-box input:focus {
  border-color: var(--highlight);
}

.search-box button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--highlight);
  color: #1a0a00;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

/* ===== Legend Bar ===== */
.legend-bar {
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
}

.legend-bar::-webkit-scrollbar { display: none; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: #ccc;
  white-space: nowrap;
  flex-shrink: 0;
}

.legend-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-color.legend-circle {
  border-radius: 50%;
}

/* ===== Sponsor Ticker (Bronze) ===== */
.sponsor-ticker {
  overflow: hidden;
  white-space: nowrap;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 3px 0;
}

.sponsor-ticker-inner {
  display: inline-block;
  font-size: 0.65rem;
  color: #8a7a6a;
  animation: ticker linear infinite;
}

@keyframes ticker {
  0%   { transform: translateX(0); }
  100% { transform: translateX(var(--scroll-dist, -50%)); }
}

/* ===== Sponsor Line in Popup (Silver) ===== */
.sponsor-line {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: #8a7a6a;
}

/* ===== GPS Button & Marker ===== */
.gps-btn {
  cursor: pointer;
  color: #888;
  font-weight: 700;
  margin-left: auto;
}

.gps-btn.active {
  color: #4285f4;
}

.gps-pulse {
  animation: gps-pulse 2s ease-out infinite;
  transform-origin: center;
}

@keyframes gps-pulse {
  0%   { r: 5;  opacity: 0.6; }
  100% { r: 18; opacity: 0; }
}

/* ===== Map Wrapper ===== */
.map-wrapper {
  position: relative;
  flex: 1;
  /* min-height を持つと横向きなどで body からはみ出しページスクロールが復活するため 0 に */
  min-height: 0;
}

/* ===== SVG Map Container ===== */
.map-container {
  position: absolute;
  inset: 0;
  overflow: auto;
  /* マップ端まで来てもページ側へスクロールを伝播させない */
  overscroll-behavior: contain;
  /* iOS Safari は user-scalable=no を無視するため、ブラウザ自身のピンチズーム/
     ダブルタップズームをここで止める。これが発動するとビジュアルビューポートが
     変わり、position: fixed の協賛窓が画面上でずれてマップに追従して見える。
     pan-x pan-y を残すのでネイティブスクロール（パン）と map.js のピンチズームは動く。 */
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  background: #222;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.map-container::-webkit-scrollbar { display: none; }
.map-container { scrollbar-width: none; }

.map-inner {
  position: relative;
  /* sponsor-card の position: absolute の基準 */
}

.map-inner svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ===== SVG Highlight Effects ===== */
.map-container svg .highlighted {
  filter: drop-shadow(0 0 6px var(--highlight)) drop-shadow(0 0 14px var(--highlight));
  transition: filter .3s ease;
}

.map-container svg [id^="booth-"],
.map-container svg [id^="facility-"],
.map-container svg [id^="stage-"] {
  cursor: pointer;
  transition: filter .3s ease;
}

/* ===== Popup Tooltip ===== */
.map-popup {
  display: none;
  position: absolute;
  z-index: 200;
  background: var(--panel-bg);
  border: 2px solid var(--highlight);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 160px;
  max-width: 240px;
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
  pointer-events: auto;
}

.map-popup.open {
  display: block;
}

.map-popup::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--highlight);
}

.map-popup.below::after {
  bottom: auto;
  top: -6px;
  border-top: none;
  border-bottom: 6px solid var(--highlight);
}

.map-popup .close-btn {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.map-popup h2 {
  font-size: 0.9rem;
  margin-bottom: 2px;
  color: var(--highlight);
  padding-right: 18px;
}

.map-popup .detail-category {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 8px;
  background: var(--accent);
  font-size: 0.7rem;
  margin-bottom: 6px;
}

.map-popup .schedule-list {
  list-style: none;
  margin-top: 6px;
}

.map-popup .schedule-list li {
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.map-popup .schedule-list li .time {
  font-weight: 700;
  color: var(--highlight);
  margin-right: 6px;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: #8a7a6a;
}

.footer a {
  color: var(--highlight);
  text-decoration: none;
}

/* ===== Admin Page ===== */
.admin-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.admin-container h1 {
  font-size: 1.4rem;
  color: var(--highlight);
  margin-bottom: 20px;
  text-align: center;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: #ccc;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
}

.btn-primary:active {
  opacity: .8;
}

.maigo-list {
  margin-top: 24px;
}

.maigo-item {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.maigo-item.resolved {
  opacity: .5;
}

.maigo-item h3 {
  font-size: 1rem;
  color: var(--highlight);
}

.maigo-item p {
  font-size: 0.85rem;
  margin: 4px 0;
}

.btn-resolve {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: #27ae60;
  color: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
}

.btn-resolve:active {
  opacity: .8;
}

/* ===== 閉幕ページ（会期終了後の index.html） =====
   body の 100dvh 固定・overflow: hidden はマップページと共通。
   スクロールは .closed-scroll の内側だけで行うので、右下の協賛窓
   （position: fixed）がスクロールに引きずられて見えなくなることがない。 */
.closed-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
}

.closed-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* 右下の協賛窓（閉幕ページでは高さ auto。広告画像入りで最大 ~150px）に
     最後の要素が隠れないよう下に逃がす */
  padding: 0 16px 190px;
}

.closed-hero {
  text-align: center;
  padding: 34px 4px 30px;
}

.closed-lantern {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 14px;
}

.closed-hero h1 {
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1.5;
  letter-spacing: .04em;
  color: var(--highlight);
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}

.closed-lead {
  margin-top: 16px;
  font-size: 0.9rem;
  line-height: 1.9;
  color: #d8c8b8;
}

.closed-next {
  margin-top: 22px;
  display: inline-block;
  padding: 10px 26px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #8b1a10);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .06em;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}

/* ===== 閉幕ページ: 協賛一覧 ===== */
.sponsor-list-section {
  max-width: 720px;
  margin: 0 auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sponsor-list-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  color: var(--highlight);
  margin-top: 18px;
}

.sponsor-list-note {
  margin-top: 8px;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #8a7a6a;
}

/* ランクによる大小・枠色・見出しは付けない（協賛企業を序列化して見せないため）。
   カードは全社共通の体裁で、広告画像の有無だけが違う。 */
.sp-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 18px;
  /* 行内で高さを揃える。画像あり／なしが混ざっても段差にならない */
  align-items: stretch;
}

.sp-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-top: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px 10px;
  text-align: center;
  color: inherit;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.sp-card-logo {
  width: 100%;
  max-width: 200px;
  max-height: 84px;
  object-fit: contain;
  border-radius: 4px;
}

.sp-card-name {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.4;
}

.sp-card-tagline {
  font-size: 0.72rem;
  line-height: 1.5;
  color: #8a7a6a;
}

/* 画面が広いときは列を増やす */
@media (min-width: 600px) {
  .sp-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 900px) {
  .sp-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== Sponsor Floating Window（右下固定・全ランク加重ローテーション） ===== */
/* position: fixed で画面右下に貼り付ける。マップのズーム(mapInner の width 変更)や
   スクロールとは独立した固定要素になるため、倍率に関係なく常に右下に出続ける。
   祖先に transform / filter が無いので包含ブロックはビューポート。
   通常フローから外れているのでマップのレイアウトには一切影響しない。
   ランクが替わっても高さは 76px 固定 → 5秒ごとに窓が伸縮しない。
   76px = 見出し「協賛」+ 社名2行 + tagline2行 が最長データでも収まる高さ。 */
#sponsor-window {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  width: min(58vw, 224px);
  height: 76px;
  background: rgba(26,10,0,0.94);
  border: 1px solid var(--border);
  border-top: 2px solid var(--highlight);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  transition: opacity 0.4s ease;
}

/* 「協賛」ラベルを廃した分を社名に回している。
   窓が狭く「株式会社◯◯」系は1行に収まらないため2行まで折り返す（3行目以降は省略） */
.sponsor-fw-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* 「地域に受け入れられ、多くの方の主治医と…」級の長文があるため2行確保 */
.sponsor-fw-tagline {
  font-size: 11px;
  color: #8a7a6a;
  line-height: 1.25;
  margin-top: 2px;
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* 入稿画像は協賛広告そのもの（黄・黒・緑など地色を持つ）。
   下地を敷くと二重の額縁になるので、画像をそのまま出す。 */
.sponsor-fw-logo {
  max-height: 34px;
  max-width: 84%;
  object-fit: contain;
  border-radius: 3px;
}

/* --- ランク別の見せ方（枠色と社名サイズで格差をつける） --- */
#sponsor-window.rank-gold   { border-top: 2px solid #f39c12; }
#sponsor-window.rank-gold   .sponsor-fw-name { font-size: 16px; }

#sponsor-window.rank-silver { border-top: 2px solid #aab7b8; }
#sponsor-window.rank-bronze { border-top: 2px solid #b07d4f; }

/* ===== platinum 専用デザイン（金枠のカラー窓） =====
   sponsor.js が rank === 'platinum' のときだけ .platinum を付与する。
   gold 以下は上のデフォルトのまま。高さは auto なので社名・tagline の
   行数ぶん縦に伸びる（右下 bottom 基準なので上方向に伸びる）。
   ここは .rank-* より後に置くこと（同詳細度のため後勝ちで上書きしている）。 */
#sponsor-window.platinum {
  /* 「協賛」ラベルと ★PLATINUM バッジを廃した分、広告画像に幅を回す */
  width: 210px;
  height: auto;
  /* 黒地に金を差したグラデーション + 金の枠 */
  background: linear-gradient(160deg, #2e1a08 0%, #1a0a00 55%);
  border: 2px solid #b8a040;
  box-shadow: 0 0 12px rgba(184,160,64,0.6);
  padding: 6px;
}

#sponsor-window.platinum .sponsor-fw-name {
  font-size: 20px;
  font-weight: 700;
  color: #fff8f0;
  line-height: 1.15;
  /* 高さ auto なので長い社名も省略せず全文出す */
  -webkit-line-clamp: initial;
  display: block;
}

#sponsor-window.platinum .sponsor-fw-tagline {
  font-size: 13px;
  color: #b8a040;
  line-height: 1.25;
  margin-top: 2px;
  -webkit-line-clamp: initial;
  display: block;
}

/* platinum は広告画像が主役。窓の内寸いっぱいに出す。 */
#sponsor-window.platinum .sponsor-fw-logo {
  width: 100%;
  max-width: 100%;
  /* 横長の広告は幅いっぱい、正方形に近い霧島(279x277)だけ高さで頭打ちにする */
  max-height: 150px;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  margin: 0;
}

/* 横向きは画面が低いので窓を少し小さく */
@media (orientation: landscape) and (max-height: 480px) {
  #sponsor-window {
    width: min(34vw, 190px);
    height: 66px;
    bottom: 8px;
  }
  .sponsor-fw-name { font-size: 12px; }

  /* platinum は横向きでも金枠のまま、サイズだけ詰める */
  #sponsor-window.platinum { width: 190px; height: auto; padding: 5px; }
  #sponsor-window.platinum .sponsor-fw-logo { max-height: 110px; }
  #sponsor-window.platinum .sponsor-fw-name    { font-size: 16px; }
  #sponsor-window.platinum .sponsor-fw-tagline { font-size: 11px; }
}

/* ===== 閉幕ページの協賛窓: ランクで見た目を変えない =====
   会期中は platinum だけ金枠＋大きめだったが、閉幕ページでは序列を見せないので
   全社を同じ枠・同じサイズで出す（高さ auto なので広告画像も社名も収まる）。
   .rank-* / .platinum より詳細度が高く、かつファイル末尾なので確実に後勝ちする。
   マップページ（index-map.html）は body に .closed-page が無いので従来のまま。 */
.closed-page #sponsor-window,
.closed-page #sponsor-window.platinum {
  width: min(58vw, 210px);
  height: auto;
  background: rgba(26,10,0,0.94);
  border: 1px solid var(--border);
  border-top: 2px solid var(--highlight);
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
  padding: 6px;
}

.closed-page #sponsor-window .sponsor-fw-name,
.closed-page #sponsor-window.platinum .sponsor-fw-name {
  font-size: 15px;
  color: var(--text);
  -webkit-line-clamp: initial;
  display: block;
}

.closed-page #sponsor-window .sponsor-fw-tagline,
.closed-page #sponsor-window.platinum .sponsor-fw-tagline {
  font-size: 11px;
  color: #8a7a6a;
  -webkit-line-clamp: initial;
  display: block;
}

.closed-page #sponsor-window .sponsor-fw-logo,
.closed-page #sponsor-window.platinum .sponsor-fw-logo {
  width: 100%;
  max-width: 100%;
  max-height: 120px;
  height: auto;
}

@media (orientation: landscape) and (max-height: 480px) {
  .closed-page #sponsor-window,
  .closed-page #sponsor-window.platinum {
    width: 190px;
    padding: 5px;
  }
  .closed-page #sponsor-window .sponsor-fw-logo,
  .closed-page #sponsor-window.platinum .sponsor-fw-logo { max-height: 90px; }
}
