* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: #fafafa;
  color: #222;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ヘッダーは廃止（タブはサイドバー内に移動） */

/* タブ：サイドバー上部に表示するスタイル */
.sidebar-tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #eee;
}

.sidebar-tabs .tab {
  flex: 1;
  padding: 8px 10px;
  background: #f4f4f4;
  color: #555;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-tabs .tab:active {
  background: #e8e8e8;
}

.sidebar-tabs .tab.active {
  background: #ff8a65;
  color: #fff;
  font-weight: 600;
}

/* 候補記事タブから戻るボタン */
.back-to-spots {
  background: #fff;
  color: #ff8a65;
  border: 1px solid #ff8a65;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
}

.back-to-spots:active {
  background: #fff5f1;
}

.tab-content {
  display: none;
  flex: 1;
  min-height: 0;
}

.tab-content.active {
  display: flex;
}

#tab-spots {
  flex: 1;
}

.sidebar {
  width: 240px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  padding: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}

.search-box {
  margin-bottom: 12px;
}

.search-box input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  box-sizing: border-box;
}

.search-box input:focus {
  outline: none;
  border-color: #ff8a65;
}

.sidebar details {
  margin-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 8px;
}

.sidebar summary {
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  font-size: 14px;
  color: #333;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0 2px;
}

.filter-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
}

.filter-group input[type="checkbox"] {
  margin: 0;
}

.cat-group {
  margin: 4px 0;
}
.cat-group .cat-parent {
  font-weight: 600;
  font-size: 13px;
}
.cat-group .cat-children {
  margin: 4px 0 4px 4px;
  padding-left: 14px;
  border-left: 2px solid #f0f0f0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cat-group .cat-child {
  font-size: 12.5px;
  color: #555;
}

.result-count {
  margin: 12px 0;
  font-size: 14px;
  color: #666;
  text-align: center;
}

.result-count #count {
  font-size: 22px;
  font-weight: 700;
  color: #ff8a65;
}

.view-toggle {
  display: flex;
  gap: 2px;
  margin-top: 8px;
}

.view-btn {
  flex: 1;
  background: #f5f5f5;
  border: 1px solid #ddd;
  padding: 6px 4px;
  font-size: 12px;
  cursor: pointer;
  color: #333;
}

.view-btn.active {
  background: #ff8a65;
  color: #fff;
  border-color: #ff8a65;
}

.view-btn:first-child { border-radius: 4px 0 0 4px; }
.view-btn:last-child { border-radius: 0 4px 4px 0; }

.content {
  flex: 1;
  display: flex;
  min-width: 0;
}

#map {
  flex: 1;
  min-width: 0;
  background: #e0e0e0;
}

#list {
  width: 360px;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.content.view-map #list { display: none; }
.content.view-map #map { flex: 1; }
.content.view-list #map { display: none; }
.content.view-list #list { width: 100%; }

.spot-card {
  padding: 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.1s;
}

.spot-card:hover {
  background: #fff8f5;
}

.spot-card.highlighted {
  background: #ffe8de;
}

.spot-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin: 0 0 4px;
}

.spot-meta {
  font-size: 12px;
  color: #666;
  margin: 0 0 4px;
}

.spot-cat {
  display: inline-block;
  background: #ff8a65;
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-right: 4px;
}

.spot-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.spot-tag {
  font-size: 11px;
  background: #f0f0f0;
  color: #555;
  padding: 1px 6px;
  border-radius: 8px;
}

.spot-tag.free { background: #c8e6c9; color: #1b5e20; }
.spot-tag.rain { background: #bbdefb; color: #0d47a1; }
.spot-tag.discovered { background: #ffe0b2; color: #e65100; }
.spot-tag.approx { background: #f5f5f5; color: #888; }
.spot-tag.tetsuban { background: #ffe082; color: #c43e00; font-weight: 600; }
.spot-tag.kids { background: #fff3e0; color: #e65100; }

.spot-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.fav-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.fav-btn:hover {
  transform: scale(1.2);
}

.fav-btn.active {
  filter: drop-shadow(0 0 2px #ff5252);
}

.spot-dist {
  font-size: 11px;
  color: #ff5722;
  margin-left: 6px;
  font-weight: 600;
}

.loc-btn {
  margin-top: 6px;
  padding: 6px 10px;
  background: #ff8a65;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
}

.loc-btn:hover { background: #ff7043; }

.loc-status {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

.card-discovered {
  border-left: 3px solid #ff9800;
}

.spot-reason {
  font-size: 12px;
  color: #555;
  margin: 4px 0;
  line-height: 1.4;
  font-style: italic;
}

.popup-reason {
  font-size: 12px;
  color: #555;
  margin: 4px 0;
  font-style: italic;
}

.popup-approximate {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

.popup-source {
  font-size: 11px;
  color: #e65100;
  margin-top: 4px;
}

.spot-fee {
  font-size: 12px;
  color: #666;
  margin: 4px 0 0;
}

.spot-link {
  display: inline-block;
  font-size: 12px;
  color: #ff8a65;
  margin-top: 4px;
  text-decoration: none;
}

.spot-link:hover {
  text-decoration: underline;
}

.more-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
  padding: 10px;
  background: #ff8a65;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.more-btn:hover {
  background: #ff7043;
}

.popup-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.popup-meta {
  font-size: 12px;
  color: #666;
}

.popup-link {
  display: inline-block;
  margin-top: 6px;
  color: #ff8a65;
  font-size: 12px;
}


.hidden { display: none !important; }

/* Discover tab */
.discover-container {
  padding: 16px;
  width: 100%;
  overflow-y: auto;
}

.discover-header {
  margin-bottom: 16px;
}

.discover-hint {
  background: #fff8f5;
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
  color: #555;
  margin: 0 0 12px;
  line-height: 1.5;
}

.discover-tabs {
  display: flex;
  gap: 6px;
}

.d-tab {
  background: #f5f5f5;
  border: 1px solid #ddd;
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px;
  cursor: pointer;
}

.d-tab.active {
  background: #ff8a65;
  color: #fff;
  border-color: #ff8a65;
}

.articles-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}

.article-card {
  background: #fff;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  text-decoration: none;
  color: #333;
  display: block;
  transition: border-color 0.1s, transform 0.1s;
}

.article-card:hover {
  border-color: #ff8a65;
  transform: translateY(-1px);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.article-source {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
}

.article-source.note { background: #41c9b4; color: #fff; }
.article-source.ameblo { background: #46c700; color: #fff; }

.article-likes {
  font-size: 12px;
  color: #e91e63;
  font-weight: 600;
}

.article-user {
  font-size: 11px;
  color: #888;
}

.article-title {
  font-weight: 600;
  font-size: 14px;
  margin: 4px 0;
  line-height: 1.4;
}

.article-snippet {
  font-size: 12px;
  color: #666;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== レスポンシブ表示制御 ===== */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .mobile-only { display: block; }
  .desktop-only { display: none !important; }

  /* モバイルではサイドバー（モーダル内）のタブを表示 */

  /* タブコンテナ：縦積み・地図フルブリード */
  #tab-spots {
    flex-direction: column;
    position: relative;
  }

  /* デスクトップサイドバーをモーダル化 */
  .sidebar {
    position: fixed;
    inset: 0;
    z-index: 2000;
    width: 100%;
    max-height: 100vh;
    transform: translateY(100%);
    transition: transform 0.28s ease;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  .sidebar.modal-open {
    transform: translateY(0);
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
  }
  .sidebar-title {
    font-weight: 600;
    font-size: 16px;
  }
  .sidebar-close {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    color: #666;
    line-height: 1;
  }
  .sidebar > details,
  .sidebar > .search-box,
  .sidebar > .filter-group {
    margin-left: 16px;
    margin-right: 16px;
  }
  .sidebar-footer {
    margin-top: auto;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) 16px;
    background: #fff;
    border-top: 1px solid #eee;
    position: sticky;
    bottom: 0;
  }
  .sidebar-apply {
    width: 100%;
    padding: 14px;
    background: #ff8a65;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.28s ease;
    pointer-events: none;
  }
  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* モバイル上部ツールバー */
  .mobile-header {
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    z-index: 100;
  }
  .mobile-toolbar {
    display: flex;
    gap: 8px;
    padding: 10px 12px 6px;
  }
  .mobile-toolbar input[type="search"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 22px;
    font-size: 14px;
    background: #f7f7f7;
    -webkit-appearance: none;
  }
  .mobile-toolbar input[type="search"]:focus {
    outline: none;
    border-color: #ff8a65;
    background: #fff;
  }
  .app-version {
    align-self: center;
    flex-shrink: 0;
    font-size: 11px;
    color: #999;
    font-family: ui-monospace, monospace;
    white-space: nowrap;
    /* iOS の急な拡大・選択ループを抑止 */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    /* 起動時にフェードイン（バージョン更新が一目でわかる） */
    opacity: 0;
    animation: app-version-fade-in 0.7s ease-out 0.3s forwards;
    /* タップ時の視覚フィードバック */
    transition: color 0.25s ease, transform 0.2s ease;
  }
  .app-version:active {
    color: #ff8a65;
    transform: scale(1.15);
  }
  @keyframes app-version-fade-in {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .force-update-btn {
    align-self: center;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.6s ease, background 0.2s, color 0.2s;
  }
  .force-update-btn:active {
    background: #fff5f1;
    color: #ff8a65;
  }
  .force-update-btn.spinning {
    transform: rotate(720deg);
    color: #ff8a65;
  }
  .filter-icon-btn {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 18px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .filter-icon-btn:active {
    background: #f0f0f0;
  }
  .filter-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff5a36;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }

  /* フィルタチップ（横スクロール） */
  .filter-chips {
    display: flex;
    gap: 6px;
    padding: 6px 12px 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-chips::-webkit-scrollbar { display: none; }
  .chip {
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 16px;
    background: #fff;
    color: #555;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
  }
  .chip:active {
    background: #f0f0f0;
  }
  .chip.active {
    background: #ff8a65;
    border-color: #ff8a65;
    color: #fff;
    font-weight: 600;
  }

  /* メインコンテンツ：地図フル＋リスト非表示（ボトムシート側） */
  .content {
    flex: 1;
    flex-direction: column;
    position: relative;
    min-height: 0;
  }
  #map {
    flex: 1;
    min-height: 0;
    width: 100%;
  }
  /* 既存 #list はボトムシート内に JS で移動 */
  #list {
    width: 100%;
    border-left: none;
    border-top: none;
    max-height: none;
    flex: 1;
    overflow-y: auto;
  }

  /* ボトムシート */
  .bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    z-index: 500;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    /* iOS safe area 対応 */
    padding-bottom: env(safe-area-inset-bottom);
    /* デフォルトは collapsed（折りたたみ） */
    height: 90vh;
    transform: translateY(calc(90vh - 88px));
  }
  .bottom-sheet.half {
    transform: translateY(45vh);
  }
  .bottom-sheet.expanded {
    transform: translateY(0);
  }
  .sheet-handle {
    padding: 8px 16px 6px;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    touch-action: none;
  }
  .sheet-handle:active {
    cursor: grabbing;
  }
  .handle-bar {
    width: 36px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 0 auto 8px;
  }
  .sheet-summary {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
    font-size: 13px;
    color: #555;
  }
  .sheet-summary #sheet-count {
    font-size: 18px;
    font-weight: 700;
    color: #ff8a65;
  }
  .sheet-summary-label {
    color: #888;
  }
  .sheet-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid #f0f0f0;
  }
  .sheet-body #list {
    border: none;
    padding: 0;
  }

  /* スポット詳細ボトムシート（マーカータップで表示） */
  .spot-detail-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 20px rgba(0,0,0,0.18);
    z-index: 600;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom);
    height: 90vh;
    transform: translateY(100%);
  }
  .spot-detail-sheet.half { transform: translateY(50vh); }
  .spot-detail-sheet.expanded { transform: translateY(0); }
  .spot-detail-sheet.hidden { transform: translateY(100%); }

  /* 詳細シート表示中は一覧シートを隠す */
  .bottom-sheet.detail-open-hidden {
    visibility: hidden;
    pointer-events: none;
  }

  .spot-detail-sheet .sheet-handle {
    padding: 8px 16px 4px;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    touch-action: none;
  }
  .spot-detail-sheet .sheet-handle:active { cursor: grabbing; }
  .spot-detail-sheet .handle-bar {
    width: 36px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 0 auto;
  }
  .detail-close {
    position: absolute;
    top: 6px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0,0,0,0.06);
    color: #555;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    z-index: 1;
    line-height: 1;
  }
  .detail-close:hover { background: rgba(0,0,0,0.12); }
  .detail-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 20px 40px;
    border-top: 1px solid #f0f0f0;
  }
  .detail-photo {
    width: calc(100% + 40px);
    margin: 0 -20px 12px;
    aspect-ratio: 2 / 1;
    background: #f5f5f5;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .detail-photo.hidden { display: none; }
  .detail-photo.loading {
    background: linear-gradient(90deg, #f5f5f5 0%, #ececec 50%, #f5f5f5 100%);
    background-size: 200% 100%;
    animation: detail-photo-shimmer 1.4s infinite;
  }
  @keyframes detail-photo-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
  .detail-photo-skeleton {
    color: #999;
    font-size: 13px;
  }
  .detail-photo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  /* チェーン店用のロゴ風タイル（Street View の代替） */
  .detail-chain-tile {
    width: 33%;
    aspect-ratio: 1;
    margin: 6px 0 14px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-align: center;
    padding: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  }
  .detail-chain-tile .chain-icon {
    font-size: 36px;
    line-height: 1;
    margin-bottom: 6px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
  }
  .detail-chain-tile .chain-name {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    word-break: keep-all;
  }
  .detail-chain-tile .chain-store {
    font-size: 11px;
    font-weight: 500;
    line-height: 1.3;
    margin-top: 4px;
    opacity: 0.92;
    word-break: keep-all;
  }
  .detail-name {
    font-size: 18px;
    font-weight: 700;
    margin: 8px 0 6px;
    padding-right: 36px;
    line-height: 1.4;
  }
  .detail-meta {
    font-size: 13px;
    color: #555;
    margin: 0 0 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  .detail-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 8px 0 12px;
  }
  .detail-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid #f5f5f5;
    font-size: 14px;
    line-height: 1.5;
  }
  .detail-row:first-of-type { border-top: 1px solid #eee; }
  .detail-row-label {
    flex-shrink: 0;
    width: 64px;
    color: #888;
    font-size: 12px;
    padding-top: 2px;
  }
  .detail-row-value { flex: 1; word-break: break-word; }
  .detail-row-value a { color: #ff8a65; text-decoration: none; }
  .detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
  }
  .detail-action {
    flex: 1;
    min-width: 130px;
    padding: 12px;
    background: #ff8a65;
    color: #fff;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .detail-action.secondary {
    background: #f5f5f5;
    color: #333;
  }
}
/* ===== /Mobile ===== */

.radius-label {
  display: block;
  font-size: 13px;
  color: #555;
  margin: 6px 0 4px;
}

.radius-label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
}

/* OSM データ帰属表示（必須） */
.data-credits {
  position: fixed;
  left: 8px;
  bottom: 4px;
  z-index: 999;
  font-size: 10px;
  color: #555;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: auto;
}
.data-credits a {
  color: #555;
  text-decoration: underline;
}
@media (max-width: 768px) {
  .data-credits {
    font-size: 9px;
    bottom: 2px;
  }
}
