/* ==========================================================================
   東京コーヒー豆MAP — スタイル
   ビジュアルアイデンティティ「焙煎曲線 / Roast Curve」
   ダーク単一テーマ。VISUAL-IDENTITY.md 準拠。
   ========================================================================== */

:root {
  /* ---- 配色(6色 + 派生) ---- */
  --ground:        #1D1A13; /* 地。焙煎機ドラム内部の煤色 */
  --ground-raise:  #262218; /* 面。カード・パネル背景 */
  --line:          #3C3323; /* 罫線・境界線 */
  --copper:        #A9662E; /* 中煎り豆の色。主構造色 */
  --copper-soft:   #C98A52; /* 銅のソフト版 */
  --copper-dim:    #7A4A24; /* 銅の濃色版(深煎りマーカー用) */
  --patina:        #6B8567; /* 緑青。副構造色・リンク色 */
  --patina-soft:   #8BA184;
  --parchment:     #EFE6D4; /* 紙。本文・見出しの文字色 */
  --parchment-dim: #B7AC93; /* 副次テキスト */
  --ember:         #E4713A; /* サイン色。使用箇所を厳格に制限する */
  --ember-dim:     #C2582A;

  --ground-raise-veil: rgba(38, 34, 24, 0.86); /* 浮遊トレイのフロスト背景 */

  --header-height: 60px;
  --tray-width: 400px;

  --font-heading: "Murecho", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --font-label: "Big Shoulders Stencil", "Murecho", sans-serif;
  --font-body: "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

  --motion-draw: 1.1s;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  color: var(--parchment);
  background: var(--ground);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.app-header {
  height: var(--header-height);
  flex: 0 0 auto;
  background: var(--ground-raise);
  border-bottom: 1px solid var(--line);
  color: var(--parchment);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  z-index: 1500;
  position: relative;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.logo-mark {
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
  overflow: visible;
}

.logo-mark__curve {
  fill: none;
  stroke: var(--copper-soft);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 90;
  stroke-dashoffset: 90;
  animation: draw-curve var(--motion-draw) ease-out forwards;
}

.logo-mark__spark {
  fill: var(--ember);
  opacity: 0;
  animation: spark-in 0.4s ease-out forwards;
  animation-delay: calc(var(--motion-draw) * 0.75);
}

.app-header__title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.08rem;
  margin: 0;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: var(--parchment);
}

.app-header__title-en {
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.08em;
  color: var(--copper-soft);
  margin-left: 0.3em;
}

.app-header__search {
  flex: 1 1 auto;
  max-width: 480px;
}

#search-input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--parchment);
  font-size: 0.9rem;
}

#search-input::placeholder {
  color: var(--parchment-dim);
}

#search-input:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--copper);
  color: var(--parchment);
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.sidebar-toggle:hover {
  background: var(--copper-soft);
}

.sidebar-toggle__icon {
  display: inline-block;
  transition: transform 0.2s ease;
}

/* ---------- Body layout: 全面地図 + 浮遊トレイ ---------- */

.app-body {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}

.map-wrap {
  position: absolute;
  inset: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--ground);
}

.sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: var(--tray-width);
  max-width: calc(100% - 32px);
  z-index: 1000;
  background: var(--ground-raise-veil);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar__grabber {
  display: none;
}

.sidebar__scroll {
  overflow-y: auto;
  height: 100%;
  padding: 18px;
}

/* ---------- Filter sections ---------- */

.filter-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.filter-section h2,
.list-section h2 {
  font-family: var(--font-label);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--parchment-dim);
  margin: 0 0 10px;
  font-weight: 700;
}

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

.checkbox-row--vertical {
  flex-direction: column;
  gap: 6px;
}

.checkbox-row--grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
}

.filter-subheading {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--parchment-dim);
  margin: 10px 0 4px;
}

.filter-subheading:first-of-type {
  margin-top: 2px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 4px 2px;
  color: var(--parchment);
}

.checkbox-line input {
  accent-color: var(--copper);
  width: 16px;
  height: 16px;
}

#area-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--parchment);
  font-size: 0.9rem;
}

.geo-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--copper);
  background: var(--copper);
  color: var(--parchment);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.geo-btn:hover,
.geo-btn:focus-visible {
  background: var(--ember);
  border-color: var(--ember);
}

.geo-btn:active {
  transform: translateY(1px);
}

.geo-message {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--parchment-dim);
  min-height: 1.1em;
}

.geo-message--error {
  color: #E08A6B;
}

.geo-message--ok {
  color: var(--patina-soft);
}

/* ---------- 半径フィルタ(チップ) ---------- */

.radius-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.radius-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--parchment-dim);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.radius-chip:hover {
  border-color: var(--copper-soft);
  color: var(--parchment);
}

.radius-chip.is-active {
  background: var(--copper);
  border-color: var(--copper);
  color: var(--parchment);
}

/* ---------- 豆巡りコース ---------- */

.bean-tour-actions {
  margin-top: 10px;
}

.bean-tour-result {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--ground);
}

.bean-tour-list {
  margin: 0 0 10px;
  padding: 0 0 0 1.2em;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--parchment);
}

.bean-tour-list li {
  padding-left: 2px;
}

.bean-tour-list li::marker {
  color: var(--copper-soft);
  font-family: var(--font-mono);
}

.bean-tour-maps-link {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--patina-soft);
  text-decoration: none;
}

.bean-tour-maps-link:hover,
.bean-tour-maps-link:focus-visible {
  text-decoration: underline;
}

/* ---------- お気に入り・アクション(共有/おまかせ) ---------- */

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

.action-btn {
  flex: 1 1 0;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--copper);
  background: transparent;
  color: var(--parchment);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.action-btn:hover,
.action-btn:focus-visible {
  border-color: var(--copper-soft);
  background: color-mix(in srgb, var(--copper) 18%, transparent);
}

.action-btn:active {
  transform: translateY(1px);
}

/* ---------- お気に入りトグル(豆型) ---------- */

.fav-toggle {
  background: none;
  border: none;
  padding: 4px;
  margin: -4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
  border-radius: 6px;
}

.fav-toggle__bean {
  width: 18px;
  height: 18px;
  overflow: visible;
}

.fav-toggle__bean path:first-child {
  fill: none;
  stroke: var(--parchment-dim);
  stroke-width: 1.6;
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.fav-toggle__seam {
  stroke: var(--parchment-dim);
  transition: stroke 0.15s ease;
}

.fav-toggle:hover .fav-toggle__bean path:first-child,
.fav-toggle:hover .fav-toggle__seam {
  stroke: var(--copper-soft);
}

.fav-toggle[aria-pressed="true"] .fav-toggle__bean path:first-child {
  fill: var(--copper);
  stroke: var(--copper);
}

.fav-toggle[aria-pressed="true"] .fav-toggle__seam {
  stroke: var(--ground-raise);
}

.shop-card__header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

/* ポップアップ(背景が明るいparchment)向けの配色調整 */
.popup-content__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.popup-content .fav-toggle__bean path:first-child,
.popup-content .fav-toggle__seam {
  stroke: #8a7c5e;
}

.popup-content .fav-toggle:hover .fav-toggle__bean path:first-child,
.popup-content .fav-toggle:hover .fav-toggle__seam {
  stroke: var(--copper-dim);
}

.popup-content .fav-toggle[aria-pressed="true"] .fav-toggle__bean path:first-child {
  fill: var(--copper-dim);
  stroke: var(--copper-dim);
}

.popup-content .fav-toggle[aria-pressed="true"] .fav-toggle__seam {
  stroke: var(--parchment);
}

/* ---------- 焙煎曲線フィルタ(サイン要素) ---------- */

.roast-curve {
  position: relative;
  width: 100%;
  height: 140px;
  margin-top: 4px;
  margin-bottom: 8px;
}

.roast-curve__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.roast-curve__path {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
  stroke-linecap: round;
}

@supports selector(:has(*)) {
  .roast-curve:has(input:checked) .roast-curve__path {
    stroke: var(--copper-dim);
  }
}

.roast-curve__path {
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  animation: draw-curve calc(var(--motion-draw) * 1.3) ease-out forwards;
}

.roast-curve__crack {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 8px 1px rgba(228, 113, 58, 0.65);
  opacity: 0;
  animation: spark-in 0.5s ease-out forwards;
  animation-delay: calc(var(--motion-draw) * 1.1);
  pointer-events: none;
}

.roast-point {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  padding: 4px;
}

.roast-point input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.roast-point input:focus-visible ~ .roast-point__dot {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

.roast-point__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ground);
  border: 2px solid var(--parchment-dim);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.roast-point input:checked ~ .roast-point__dot {
  background: var(--copper);
  border-color: var(--copper-soft);
  transform: scale(1.25);
}

.roast-point__label {
  font-family: var(--font-label);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.35;
  color: var(--parchment-dim);
  white-space: nowrap;
  transition: color 0.15s ease;
  pointer-events: none;
}

.roast-point input:checked ~ .roast-point__label {
  color: var(--parchment);
}

.roast-point__en {
  display: block;
  font-size: 0.85em;
  letter-spacing: 0.12em;
  color: var(--copper-soft);
  opacity: 0.85;
}

/* 下端に近い浅煎りはラベルをドットの上に、上端に近い中煎り/深煎りは下に配置して
   トレイ内でのはみ出しを避ける */
.roast-point--light {
  flex-direction: column-reverse;
}

/* 区切り(控えめな1本の曲線) */
.section-rule {
  margin: 0 0 18px;
  height: 12px;
}

.section-rule svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.section-rule path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
}

/* ---------- Shop list ---------- */

.list-section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.list-section__header h2 {
  margin: 0;
}

.result-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--copper-soft);
  background: var(--ground);
  border: 1px solid var(--line);
  padding: 2px 10px;
  border-radius: 999px;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shop-list__empty {
  text-align: center;
  color: var(--parchment-dim);
  padding: 32px 8px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.shop-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--ground-raise);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.shop-card:hover,
.shop-card:focus-visible {
  border-color: var(--copper-soft);
  box-shadow: var(--shadow-sm);
}

.shop-card.is-active {
  border-color: var(--copper);
  background: color-mix(in srgb, var(--copper) 14%, var(--ground-raise));
  box-shadow: var(--shadow-sm);
}

.shop-card__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.shop-card__name {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--parchment);
}

.shop-card__distance {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: var(--copper-soft);
  font-weight: 500;
  white-space: nowrap;
  flex: 0 0 auto;
}

.shop-card__area {
  font-size: 0.78rem;
  color: var(--parchment-dim);
  margin-top: 2px;
}

.shop-card__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0;
}

.roast-badge {
  display: inline-block;
  font-family: var(--font-label);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--ground);
  border: 1px solid transparent;
}

.roast-badge--light { background: var(--patina-soft); }
.roast-badge--medium { background: var(--copper-soft); }
.roast-badge--dark { background: var(--copper-dim); color: var(--parchment); }

.feature-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ground);
  color: var(--parchment-dim);
  border: 1px solid var(--line);
}

.shop-card__desc {
  font-size: 0.82rem;
  color: var(--parchment);
  margin: 4px 0;
  line-height: 1.5;
}

.shop-card__address {
  font-size: 0.75rem;
  color: var(--parchment-dim);
}

/* ---------- Leaflet marker (divIcon) ---------- */

.bean-marker {
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--parchment);
  box-shadow: var(--shadow-sm);
}

.bean-marker__glyph {
  transform: rotate(45deg);
  font-size: 13px;
  line-height: 1;
}

/* マーカー色: light=patina系, medium=copper系, dark=copper-dim相当 */
.bean-marker--light { background: var(--patina); }
.bean-marker--medium { background: var(--copper); }
.bean-marker--dark { background: var(--copper-dim); }

.bean-marker--user {
  background: var(--patina);
  border-radius: 50%;
  transform: none;
  width: 20px;
  height: 20px;
}

.bean-marker--user .bean-marker__glyph {
  transform: none;
  font-size: 11px;
}

.bean-marker.is-pulsing {
  animation: marker-pulse 0.6s ease-out 1;
}

/* ---------- クラスタアイコン(leaflet.markercluster カスタム) ---------- */

.cluster-marker {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--copper);
  border: 2px solid var(--parchment);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cluster-marker__count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--parchment);
  line-height: 1;
}

/* ---------- 豆巡りコース: 順番ラベル・ルート線 ---------- */

.route-label {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ground-raise);
  border: 2px solid var(--copper);
  color: var(--parchment);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

/* ---------- Leaflet popup content ---------- */

.popup-content {
  font-family: var(--font-body);
  min-width: 220px;
  max-width: 260px;
}

.popup-content h3 {
  font-family: var(--font-heading);
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--ground);
}

.popup-content .popup-area {
  font-size: 0.78rem;
  color: #5c5344;
  margin-bottom: 6px;
}

.popup-content .popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.popup-content .popup-desc {
  font-size: 0.83rem;
  margin: 6px 0;
  line-height: 1.5;
  color: #2c2618;
}

.popup-content .popup-address {
  font-size: 0.78rem;
  color: #5c5344;
  margin-bottom: 8px;
}

.popup-content .popup-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.popup-content .popup-links a {
  font-size: 0.78rem;
  color: var(--copper-dim);
  font-weight: 700;
  text-decoration: none;
}

.popup-content .popup-links a:hover {
  text-decoration: underline;
}

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  background: var(--parchment);
}

.leaflet-popup-tip {
  background: var(--parchment);
}

/* ---------- モーション ---------- */

@keyframes draw-curve {
  to { stroke-dashoffset: 0; }
}

@keyframes spark-in {
  to { opacity: 1; }
}

@keyframes marker-pulse {
  0% { transform: rotate(-45deg) scale(1); }
  40% { transform: rotate(-45deg) scale(1.35); }
  100% { transform: rotate(-45deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .logo-mark__curve,
  .roast-curve__path {
    animation: none;
    stroke-dashoffset: 0;
  }
  .logo-mark__spark,
  .roast-curve__crack {
    animation: none;
    opacity: 1;
  }
  .bean-marker.is-pulsing {
    animation: none;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .checkbox-row--grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    row-gap: 8px;
  }

  .app-header__title {
    font-size: 0.95rem;
  }

  .app-header__search {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }

  .sidebar-toggle {
    display: flex;
    order: 2;
  }

  .map-wrap {
    width: 100%;
  }

  .sidebar {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 85vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar__grabber {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    margin: 10px auto 0;
    flex: 0 0 auto;
  }

  .sidebar.is-open {
    transform: translateY(0);
  }

  .sidebar:not(.is-open) {
    pointer-events: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .sidebar {
      transition: none;
    }
  }
}
