:root {
  /* ページ全体と各パネルで共有する配色。 */
  --page-bg: #edf4ff;
  --panel-bg: rgba(24, 25, 22, 0.84);
  --panel-border: rgba(223, 194, 150, 0.32);
  --text: #f4eee4;
  --muted: #c8bba8;
  --selected: #4a5b38;
  --selected-stroke: #bca46f;
}

* {
  box-sizing: border-box;
}

/* ページ全体へ適用するGoogle Fontsの可変フォント設定。 */
.noto-sans-jp {
  font-family: "Noto Sans JP", sans-serif;
  font-optical-sizing: auto;
  font-weight: 400;
  font-style: normal;
}

/* 将来の個別指定で利用できるZen Kurenaidoのフォント設定。 */
.zen-kurenaido-regular {
  font-family: "Zen Kurenaido", sans-serif;
  font-weight: 400;
  font-style: normal;
}

/* 将来の個別指定で利用できるLeague Scriptのフォント設定。 */
.league-script-regular {
  font-family: "League Script", cursive;
  font-weight: 500;
  font-style: normal;
  -webkit-text-stroke: 0.35px currentColor;
  text-shadow: 0.35px 0 currentColor, -0.35px 0 currentColor;
}

/* 背景画像レイヤーを表示するため、ルート要素の背景を透明にする。 */
html {
  background: transparent;
}

/* 地図の読み込み完了までページ全体を覆うスプラッシュスクリーン。 */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #17180f;
  transition: opacity 0.4s ease;
}

/* 読み込み完了後、フェードアウトさせて操作を可能にする。 */
.splash-screen.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* title-logo.svgと同じ配色処理（黒線画をクリーム・ゴールド系へ変換）で表示。
   横長・縦長どちらのウィンドウでもはみ出さないよう、幅・高さ両方の制約で追従させる。 */
.splash-logo {
  width: min(60vw, 60vh);
  height: auto;
  filter: invert(1) sepia(8%) saturate(320%) hue-rotate(350deg) brightness(97%) contrast(96%);
  animation: splash-pulse 1.6s ease-in-out infinite;
}

@keyframes splash-pulse {
  0%, 100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

/* ページ全体の基本レイアウトと文字色。 */
body {
  margin: 0;
  font-family: "Noto Sans JP", sans-serif;
  position: relative;
  isolation: isolate;
  background: var(--page-bg);
  color: var(--text);
}

/* 背景画像を保持する専用の固定レイヤー。backdrop-filterは背後の見え方を常時再サンプリングするため、
   前景側の再描画（地図のホバーやランキング欄のスクロールなど）につられて縁がチラつくことがある。
   画像自体にfilter: blur()を直接かける方式にすると、レイヤーが静的に合成されチラつきが起きない。
   inset: -16pxはぼかし半径ぶんの余白で、viewport端にぼかされていない縁が見えるのを防ぐ。 */
body::before {
  position: fixed;
  inset: -16px;
  z-index: 0;
  content: "";
  background:
    linear-gradient(rgba(10, 12, 10, 0.18), rgba(10, 12, 10, 0.18)),
    url("../img/background.jpeg") center / cover no-repeat;
  filter: blur(8px);
}

/* ページ全体の幅と上下の余白。上部は画面上部に固定表示するモード切替バーの分を確保する。 */
.page {
  width: 100%;
  position: relative;
  z-index: 1;
  margin: 0 auto;
  padding: 70px 18px 88px;
}

/* 画面上部に固定表示するモード切替バー。 */
.mode-bar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 18px;
  background: rgba(24, 25, 22, 0.92);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
}

/* トグルスイッチ本体。inputは非表示にし、隣接するtrackで見た目を描画する。 */
.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mode-toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  transition: background-color 0.18s ease;
}

.mode-toggle-track::before {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.18s ease;
}

.mode-toggle input:checked + .mode-toggle-track {
  background: var(--selected);
}

.mode-toggle input:checked + .mode-toggle-track::before {
  transform: translateX(18px);
}

.mode-toggle input:focus-visible + .mode-toggle-track {
  outline: 2px solid #e2bd78;
  outline-offset: 2px;
}

.mode-toggle-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}

/* 画面下部に固定表示する出典・ライセンス情報。 */
.license-notice {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 8px 18px;
  background: rgba(24, 25, 22, 0.92);
  border-top: 1px solid var(--panel-border);
  color: var(--muted);
  text-align: center;
  backdrop-filter: blur(8px);
}

.license-notice small {
  font-size: 0.72rem;
  line-height: 1.5;
}

.license-notice a {
  color: #e2bd78;
}

h1 {
  margin: 0;
}

/* ページタイトル。 */
.page-title {
  position: absolute;
  top: 5%;
  left: 15%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* SVGと同じ#map幅を基準にタイトルも拡大・縮小する。 */
  font-size: max(1rem, calc(4.25cqw + 7px));
  line-height: 1.05;
  pointer-events: none;
}

/* タイトル専用の装飾。反転した黒線を白線として背面に合成する。 */
.title-logo {
  position: absolute;
  left: 105%;
  z-index: 1;
  width: 55cqw;
  height: auto;
  object-fit: contain;
  background: transparent;
  filter: invert(1) sepia(8%) saturate(320%) hue-rotate(350deg) brightness(97%) contrast(96%);
  mix-blend-mode: screen;
  transform: translateX(-10%);
  pointer-events: none;
}

/* 地図パネルと情報パネルを横並びにするメインレイアウト。 */
.content {
  display: grid;
  grid-template-columns: minmax(320px, 6fr) minmax(280px, 4fr);
  gap: 22px;
  align-items: stretch;
}

/* 抽選モード中は動画・ランキング表示を隠し、地図パネルを全幅に拡大する。
   .contentの列数はビューポート幅を問わず上書きするため、通常時の記述より高い詳細度にしている。 */
.page.is-lottery-mode .content {
  grid-template-columns: minmax(0, 1fr);
}

.page.is-lottery-mode .info-panel {
  display: none;
}

/* 抽選モードでは地図に戻る操作自体が不要（情報パネルが表示されないため）なので隠す。 */
.page.is-lottery-mode .back-to-map-panel {
  display: none;
}

/* 地図・情報パネルに共通するカード外観。 */
.map-panel,
.info-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: 0 14px 30px rgba(110, 136, 192, 0.08);
}

/* 日本地図を表示する左側パネル。 */
.map-panel {
  position: relative;
  padding: 18px;
  height: max(460px, 52vw);
  min-height: 0;
}

/* SVG地図の表示領域。 */
#map {
  position: relative;
  container-type: inline-size;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* タイトルを保持したままSVG地図を描画する領域。 */
#map-svg {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* GeoloniaのSVG地図本体。 */
.geolonia-svg-map {
  position: absolute;
  inset: 0;
  width: 100%;
  max-height: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

/* 各都道府県の基本色、境界線、クリック可能状態。 */
.geolonia-svg-map .prefecture {
  fill: #e8f1fb;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 1.5;
  outline: none;
  cursor: pointer;
  transition: fill 0.18s ease, stroke 0.18s ease;
}

/* 地方ごとの都道府県カラー。 */
.geolonia-svg-map .prefecture.region-hokkaido { fill: #b9dcf5; }
.geolonia-svg-map .prefecture.region-tohoku { fill: #f3c59c; }
.geolonia-svg-map .prefecture.region-kanto { fill: #f4edb8; }
.geolonia-svg-map .prefecture.region-chubu { fill: #d9edc8; }
.geolonia-svg-map .prefecture.region-kinki { fill: #c7e7df; }
.geolonia-svg-map .prefecture.region-chugoku { fill: #c8ddf2; }
.geolonia-svg-map .prefecture.region-shikoku { fill: #d9d2f0; }
.geolonia-svg-map .prefecture.region-kyushu { fill: #ecd3e8; }

/* スプレッドシートにデータがない都道府県は、地方色のパステルと混同しないよう無彩色に近いグレーにする。 */
.geolonia-svg-map .prefecture.no-data,
.geolonia-svg-map .prefecture.no-data.is-selected {
  fill: #b8bcc2 !important;
}

/* データがない都道府県も、キーボードフォーカス時は操作対象として色を変える。 */
.geolonia-svg-map .prefecture.no-data:focus-visible {
  fill: #dfeaf8 !important;
}

/* キーボードフォーカス時の地図色。 */
.geolonia-svg-map .prefecture:focus-visible {
  fill: #dfeaf8;
}

/* マウスオーバー時の地図色。タッチ操作の端末では選択後も:hoverが残り続けてしまうため、
   実際にホバー操作ができる（マウス・トラックパッドなどの）端末でのみ適用する。 */
@media (hover: hover) and (pointer: fine) {
  .geolonia-svg-map .prefecture.no-data:hover {
    fill: #dfeaf8 !important;
  }

  .geolonia-svg-map .prefecture:hover {
    fill: #dfeaf8;
  }
}

/* 選択中の都道府県の強調表示。 */
.geolonia-svg-map .prefecture.is-selected {
  fill: var(--selected) !important;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 1.5;
}

/* 抽選アニメーション中にランダムで巡回表示する色。 */
.geolonia-svg-map .prefecture.no-data.lottery-highlight {
  fill: #f4b942 !important;
}

/* 抽選で確定した都道府県の強調表示。 */
.geolonia-svg-map .prefecture.no-data.lottery-selected {
  fill: #e2574c !important;
  stroke: #ffffff;
  stroke-width: 2.5;
}

/* SVG上に重ねる都道府県名ラベル。 */
.geolonia-svg-map .prefecture-label {
  fill: #24344d;
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 2.5px;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
}

/* 選択情報を表示する右側パネル。 */
.info-panel {
  padding: 20px 18px;
  min-width: 0;
  height: auto;
  max-height: max(460px, 52vw);
  min-height: 0;
  align-self: start;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 選択中の都道府県名。 */
.info-panel h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
}

/* 動画と詳細情報を囲む情報ボックス。 */
.selected-box {
  flex: 0 0 auto;
  background: rgba(42, 44, 40, 0.9);
  border: 1px solid rgba(223, 194, 150, 0.32);
  border-radius: 16px;
  padding: 18px 16px;
}

/* 配信動画、配信日、動画タイトルを縦に並べる領域。 */
.selected-video {
  display: none;
  margin: 0;
}

.selected-video.is-visible {
  display: block;
}

/* 動画上部の日付と下部のYouTubeタイトルリンク。 */
.video-date,
.video-title {
  margin: 0;
  color: #f4eee4;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.selected-video.is-visible {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-frame {
  overflow: hidden;
  border-radius: 10px;
  aspect-ratio: 16 / 9;
  background: rgba(42, 44, 40, 0.94);
  border: 1px solid rgba(223, 194, 150, 0.28);
  background-position: center;
  background-size: cover;
}

/* 動画タイトルからYouTubeへ遷移するリンク。 */
.video-title a {
  color: #e2bd78;
}

/* YouTube埋め込みiframe。 */
.selected-video iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

/* 動画リンクが存在しない場合のプレースホルダー。 */
.video-status {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  margin: 0;
  color: #f4eee4;
  background: rgba(42, 44, 40, 0.94);
  font-size: 1rem;
  font-weight: 700;
}

/* 商品ランキングと補足情報の表示領域。 */
.selected-details {
  flex: 1 1 auto;
  margin-top: 16px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 112, 141, 0.28) transparent;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.5;
}

/* 詳細欄のスクロールバーを細く目立たない見た目にする。 */
.selected-details::-webkit-scrollbar {
  width: 6px;
}

.selected-details::-webkit-scrollbar-track {
  background: transparent;
}

.selected-details::-webkit-scrollbar-thumb {
  background: rgba(95, 112, 141, 0.28);
  border-radius: 999px;
}

.selected-details::-webkit-scrollbar-thumb:hover {
  background: rgba(95, 112, 141, 0.42);
}

/* 横並びかつ低い画面では動画を縮小し、ランキング表示領域を確保する。 */
@media (min-width: 661px) and (max-height: 799px) {
  .selected-box {
    padding: 12px;
  }

  .info-panel h2 {
    margin-bottom: 10px;
  }

  .video-frame {
    width: min(100%, calc(22vh * 16 / 9));
    height: auto;
    aspect-ratio: 16 / 9;
    align-self: center;
  }
}

/* ランキングカテゴリごとのセクション。 */
.data-section {
  margin-top: 12px;
}

/* ランキングカテゴリ名。 */
.data-section h3 {
  margin: 0 0 5px;
  font-size: 0.82rem;
  color: #e0d4c1;
}

/* 商品カードを縦に並べるリスト。 */
.data-list {
  display: grid;
  gap: 8px;
  margin: 0;
  min-width: 0;
  padding: 0;
  list-style: none;
}

/* 番号なし補足項目を含む通常の商品カード。 */
.data-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 9px 10px;
  background: rgba(42, 44, 40, 0.9);
  border: 1px solid rgba(223, 194, 150, 0.24);
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(103, 130, 185, 0.06);
}

/* 番号エリアと商品情報エリアに分割したランキングカード。 */
.data-list li.ranked-item {
  align-items: stretch;
  background: transparent;
  gap: 0;
  overflow: hidden;
  padding: 0;
}

/* ランキング番号を表示する左側エリア。 */
.card-rank {
  flex: 0 0 2rem;
  color: #f4eee4;
  font-weight: 800;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #4a5b38;
  border-radius: 7px 0 0 7px;
}

/* 商品名とショップ情報を表示する右側エリア。 */
.card-content {
  flex: 1 1 auto;
  background: rgba(42, 44, 40, 0.9);
  min-width: 0;
  padding: 9px 10px;
  overflow-wrap: anywhere;
}

/* 商品名の下に表示するショップ情報。 */
.shop-line {
  display: block;
  margin-top: 4px;
  color: #cfc1ad;
  font-size: 0.78rem;
}

/* 商品カード内のショップリンク。 */
.data-list a {
  color: #e2bd78;
}

/* データ取得中やエラー時の状態メッセージ。 */
.data-status {
  margin: 0;
  color: var(--muted);
}

/* 地図の読み込みに失敗した場合のエラーメッセージ。 */
.error {
  margin: 0;
  padding: 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

/* 「地図に戻る」ボタンを内包する専用パネル。情報パネルとは別の部品とし、モバイル表示時のみ表示する。
   固定表示ではなく通常のフローに置き、地図・情報パネルの直後、画面最下部までスクロールした先に現れるようにする。 */
.back-to-map-panel {
  display: none;
  justify-content: center;
  margin-top: 18px;
}

.back-to-map-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.back-to-map-button:hover {
  border-color: #e2bd78;
  background: rgba(42, 44, 40, 0.94);
}

.back-to-map-button:focus-visible {
  outline: 2px solid #e2bd78;
  outline-offset: 2px;
}

.back-to-map-icon {
  width: 16px;
  height: 16px;
}

/* 抽選ボタンを内包する専用パネル。地図パネルの直後に配置し、抽選モード時のみ表示する。 */
.lottery-panel {
  display: none;
  justify-content: center;
  margin-top: 18px;
}

.page.is-lottery-mode .lottery-panel {
  display: flex;
}

.lottery-button {
  padding: 12px 40px;
  background: var(--selected);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.12s ease, opacity 0.18s ease;
}

.lottery-button:hover:not(:disabled) {
  border-color: #e2bd78;
}

.lottery-button:focus-visible {
  outline: 2px solid #e2bd78;
  outline-offset: 2px;
}

.lottery-button:active:not(:disabled) {
  transform: scale(0.97);
}

.lottery-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 縦積み時、右パネルの高さ・スクロール指定を上書きしてランキング全体を展開表示する。
   .info-panel/.selected-detailsの同名プロパティより後方に置き、カスケードで確実に上書きする。 */
@media (max-width: 660px) {
  .content {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-panel {
    height: auto !important;
    min-height: 0;
  }

  #map {
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .info-panel {
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .info-panel .selected-details {
    flex: 0 0 auto;
    overflow-y: visible;
  }

  .back-to-map-panel {
    display: flex;
  }
}

/* 横並び時、右パネルの高さ・位置指定を上書きして地図パネルと高さを揃える。
   .info-panelの同名プロパティより後方に置き、カスケードで確実に上書きする。 */
@media (min-width: 661px) {
  body {
    overflow: hidden;
  }

  .page {
    min-height: 100vh;
    height: 100vh;
    padding-bottom: 80px;
    overflow: hidden;
  }

  .content {
    /* 画面上部のモード切替バー分（約40px）を、モバイル用の基準値から追加で差し引く。 */
    height: calc(100vh - 250px);
    align-items: center;
  }

  .map-panel,
  .info-panel {
    height: max(460px, 52vw);
    max-height: none;
    min-height: 0;
  }

  .info-panel {
    align-self: center;
  }

  /* 抽選モードでは地図パネルの幅が（情報パネル分）大きく変わる一方、高さはvw基準のままだったため、
     コンテナ基準で幅が広がるタイトルロゴ（cqw単位）だけが肥大化し地図と重なっていた。
     地図パネル自体の縦横比を1:1に固定し、抽選パネル分を差し引いた表示可能領域の中で
     収まる最大サイズまで拡大したうえで、余った余白の中央に配置する。 */
  .page.is-lottery-mode .content {
    display: flex;
    justify-content: center;
    align-items: center;
    /* 通常時の予約領域（250px）に、抽選パネルの高さと余白ぶん（約70px）を追加で確保する。 */
    height: calc(100vh - 320px);
  }

  .page.is-lottery-mode .map-panel {
    width: min(100%, calc(100vh - 320px));
    height: auto;
    aspect-ratio: 1 / 1;
    max-height: none;
  }
}

/* 抽選結果を表示するモーダルウィンドウ。 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 12, 10, 0.6);
}

.modal[hidden] {
  display: none;
}

.modal-content {
  width: min(360px, 100%);
  padding: 28px 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.modal-content h2 {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--muted);
}

.lottery-result-name {
  margin: 0 0 22px;
  font-size: 1.6rem;
  font-weight: 800;
  color: #e2bd78;
}

.modal-close-button {
  padding: 8px 28px;
  background: var(--selected);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.18s ease;
}

.modal-close-button:hover,
.modal-close-button:focus-visible {
  border-color: #e2bd78;
  outline: none;
}
