:root {
  --color-primary: #BC4A8B;
  --color-primary-dark: #9F3870;
  --color-primary-light: #F5DCE7;
  --color-accent: #FF9F43;
  --color-bg: #FFF8FB;
  --color-surface: #FFFFFF;
  --color-text: #2A1F26;
  --color-text-sub: #7B6B73;
  --color-border: #ECDCE5;
  --color-coupon-bg: #FFF6E5;
  --color-coupon-border: #FF9F43;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 -4px 20px rgba(0,0,0,0.10);
  --radius: 12px;
  --header-h: 52px;
  --controls-h: 110px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* `display: flex` 等を持つ要素でも HTML の hidden 属性が必ず効くようにする */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ===== Header ===== */
.header {
  background: var(--color-primary);
  color: #fff;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 20;
}
.header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
}

/* ===== Controls (search + chips) ===== */
.controls {
  background: var(--color-surface);
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  z-index: 15;
}

.search {
  position: relative;
  margin-bottom: 8px;
}
.search__input {
  width: 100%;
  padding: 10px 36px 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  font-size: 14px;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search__input:focus {
  border-color: var(--color-primary);
  background: #fff;
}
.search__clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--color-text-sub);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.genre-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.genre-chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  background: #fff;
  color: var(--color-text-sub);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ===== Main: map + bottom sheet ===== */
.main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.map {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: #F0E0E8;
}

/* 現在地に戻るボタン */
.locate-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 6;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.locate-btn:active {
  transform: scale(0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.locate-btn[aria-busy="true"] {
  color: var(--color-text-sub);
}
.locate-btn svg {
  display: block;
}

/* Bottom sheet — 2 状態 (全閉/全開) */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  /* 既定は閉。ヘッダ＋ハンドルが見える程度に確保 */
  height: calc(56px + var(--safe-bottom));
  transition: height 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 5;
  padding-bottom: var(--safe-bottom);
}
.sheet.is-expanded {
  height: 100%;
}
.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #D5C0CB;
  margin: 8px auto 4px;
  cursor: grab;
  flex-shrink: 0;
}
.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 16px 8px;
  font-size: 12px;
  color: var(--color-text-sub);
  font-weight: 600;
  flex-shrink: 0;
}
.sheet__count {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet__count strong { color: var(--color-text); }
.sheet__toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: #fff;
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sheet__toggle:active {
  background: var(--color-primary-light);
}
.sheet__toggle-icon {
  display: block;
  transition: transform 0.2s;
}
.sheet.is-expanded .sheet__toggle-icon {
  transform: rotate(180deg);
}

.store-list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  flex: 1;
  /* flex item の min-height は既定で auto となり、内容より小さくならないため、
     overflow-y: auto を効かせるには 0 を明示する必要がある。 */
  min-height: 0;
}

.store-item {
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background 0.1s;
}
.store-item:active {
  background: #FBEEF4;
}
.store-item__thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #F5E5EC;
  object-fit: cover;
  flex-shrink: 0;
}
.store-item__body {
  flex: 1;
  min-width: 0;
}
.store-item__name {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 2px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.store-item__meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 2px;
}
.store-item__address {
  font-size: 12px;
  color: var(--color-text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.store-item__coupon-mark {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-coupon-bg);
  color: var(--color-accent);
  font-weight: 700;
  margin-left: 6px;
  border: 1px solid var(--color-coupon-border);
  flex-shrink: 0;
}
.store-item__distance {
  font-size: 11px;
  color: var(--color-text-sub);
  font-weight: 600;
  margin-left: auto;
  flex-shrink: 0;
}

.empty-message {
  text-align: center;
  color: var(--color-text-sub);
  padding: 20px;
  margin: 0;
  font-size: 13px;
}

/* ===== Genre badge ===== */
.genre-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--color-text-sub);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}
.modal__panel {
  position: relative;
  background: var(--color-surface);
  width: 100%;
  max-width: 560px;
  /* dvh で URL バーを除いた可視領域に収め、画面外に閉じるボタンが出るのを防ぐ */
  max-height: 92vh;
  max-height: 92dvh;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal__content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 8px;
}
.modal__footer {
  flex-shrink: 0;
  padding: 12px 20px calc(12px + var(--safe-bottom));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
@media (min-width: 768px) {
  .modal {
    align-items: center;
  }
  .modal__panel {
    border-radius: 16px;
    max-height: 88vh;
    max-height: 88dvh;
  }
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: auto;
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.modal__image-wrap {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #F5E5EC;
  overflow: hidden;
}
.modal__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.modal__image[src=""], .modal__image:not([src]) {
  display: none;
}

.modal__body {
  padding: 16px 20px 4px;
}
.modal__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.modal__title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  min-width: 0;
}
.modal__appeal {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.6;
}
.modal__address {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--color-bg);
  border-radius: 8px;
}
.modal__address p {
  margin: 0 0 4px;
  font-size: 13px;
}
.modal__sub-link {
  display: inline-block;
  color: var(--color-primary);
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
}
.modal__detail-link {
  display: block;
  text-align: center;
  margin-top: 12px;
}

.coupon {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--color-coupon-bg);
  border: 1.5px dashed var(--color-coupon-border);
  border-radius: 10px;
}
.coupon__title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.05em;
}
.coupon__text {
  margin: 0;
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.5;
  white-space: pre-wrap;
}

.cta-button {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: var(--color-primary);
  color: #fff;
  text-align: center;
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(44, 140, 108, 0.3);
  transition: background 0.15s, transform 0.1s;
}
.cta-button:active {
  background: var(--color-primary-dark);
  transform: scale(0.98);
}

/* ===== Loader ===== */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 200;
  color: var(--color-text-sub);
  font-size: 13px;
}
.loader__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  right: 8px;
  z-index: 150;
  background: #D63031;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Hide Google Maps controls overlapping bottom sheet a bit */
.gm-style-cc { display: none !important; }

/* ===== Custom map pin (OverlayView) ===== */
.store-pin {
  /* transform は draw() の translate3d で配置に使うため、
     hover/active のスケールは内側 .store-pin__circle に分離している */
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
}
.store-pin:hover,
.store-pin:active {
  z-index: 10;
}
.store-pin__circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--color-primary), 0 2px 6px rgba(0, 0, 0, 0.3);
  background: var(--color-primary);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
  will-change: transform;
}
.store-pin:hover .store-pin__circle,
.store-pin:active .store-pin__circle {
  transform: scale(1.08);
}
.store-pin__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.store-pin__label {
  margin-top: 4px;
  background: #fff;
  color: var(--color-text);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
