/* Common styles for ema-app-basic pages */
:root {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: "Noto Sans JP", "Inter", system-ui, sans-serif;
  background: #f8f5f5;
  color: #1c0d0d;
}

/* Header / Nav: サイト用はコンパクト（スクロールで隠れる）、絵馬アプリ用をstickyで常時表示 */
/* main.css の sticky を上書き：絵馬アプリ内では main-nav はスクロールで隠す */
.app-container .main-nav {
  position: relative;
  top: auto;
  z-index: auto;
}
.main-nav {
  background: #ffffff;
  border-bottom: 1px solid #e8e8e8;
}

.nav-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nav-logo {
  font-weight: 700;
  text-decoration: none;
  color: inherit;
  font-size: 0.8rem;
}

.nav-menu {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.nav-link {
  text-decoration: none;
  color: inherit;
  font-size: 0.75rem;
}

.nav-link.active {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid #ddd;
  padding: 6px 8px;
  border-radius: 6px;
}

.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: #333;
  margin: 4px 0;
}

@media (max-width: 900px) {
  .nav-toggle {
    display: inline-block;
  }

  .nav-menu {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding-top: 8px;
  }

  .nav-menu.is-open {
    display: flex;
  }
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.ad-slot {
  text-align: center;
  max-width: 100%;
  margin: 1.5rem 0;
  padding: 0 1rem;
  box-sizing: border-box;
}

.ema-page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 8px 0 20px;
}

.ema-section {
  margin-bottom: 24px;
}

/* 絵馬ビューポート（窓枠） */
.ema-viewport {
  width: 100%;
  height: 500px;
  overflow: hidden;
  position: relative;
  background: #f8f5f5;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: 2px solid #e8e8e8;
  border-radius: 8px;
  touch-action: pinch-zoom;
  cursor: grab;
  user-select: none;
}

/* 背景画像を元のサイズで表示（枠に収めない） */
.ema-viewport.ema-bg-image {
  background-size: auto; /* 元の画像サイズを維持 */
  background-position: center center; /* 枠の中央と画像の中央を合わせる */
  background-repeat: repeat; /* タイル状に繰り返し */
}

/* 背景画像をタイル状に繰り返し表示 */
.ema-viewport.ema-bg-image {
  background-repeat: repeat;
  background-size: auto 100%; /* 高さに合わせて、幅はアスペクト比を維持 */
}

/* デフォルトパターン背景（明るいグレー） */
.ema-viewport.ema-bg-pattern {
  background: linear-gradient(135deg, #f0f0f0 0%, #e5e5e5 50%, #f0f0f0 100%);
  background-size: 200% 200%;
  animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

/* パターン背景のテクスチャ（グレー） */
.ema-viewport.ema-bg-pattern::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(180, 180, 180, 0.35) 10px,
      rgba(180, 180, 180, 0.35) 20px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 10px,
      rgba(180, 180, 180, 0.35) 10px,
      rgba(180, 180, 180, 0.35) 20px
    );
  z-index: 0;
  pointer-events: none;
}

/* 背景画像のアニメーション（タイル状に繰り返し） */
.ema-viewport.ema-bg-image {
  animation: backgroundPan 30s ease-in-out infinite;
  background-repeat: repeat;
  background-size: 330% auto; /* 初期画像サイズ（JavaScriptでズームレベルに応じて変更される） */
  background-position: center center; /* 初期位置：枠の中央と画像の中央を合わせる */
}

@keyframes backgroundPan {
  0%, 100% {
    background-position: center center; /* 初期位置に戻る */
  }
  25% {
    background-position: calc(50% + 20%) calc(50% + 10%); /* 中央からの相対移動 */
  }
  50% {
    background-position: calc(50% + 10%) calc(50% + 20%); /* 中央からの相対移動 */
  }
  75% {
    background-position: calc(50% - 10%) calc(50% + 10%); /* 中央からの相対移動 */
  }
}

/* 背景画像のオーバーレイ（画像を薄くする） */
.ema-viewport.ema-bg-image::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(248, 245, 245, 0.7); /* 背景画像を薄くするオーバーレイ */
  z-index: 0;
  pointer-events: none;
}

/* 背景画像が読み込めない場合のフォールバック */
.ema-viewport.ema-bg-image::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #f8f5f5 0%, #e8e8e8 100%);
  z-index: -1;
  opacity: 0.5;
}

.ema-viewport > * {
  position: relative;
  z-index: 1;
}

.ema-viewport:active {
  cursor: grabbing;
}

/* ズームコントローラ（ビューポート内） */
@media (max-width: 768px) {
  .ema-zoom-control { display: none !important; }
}
.ema-zoom-control {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 40;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(229, 231, 235, 1);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

/* 絵馬キャンバス（移動・ズーム可能な領域） */
/* transform-origin: 0 0 で scale を左上基準にし、pan で窓枠中央をズーム中心に合わせる */
.ema-canvas {
  width: fit-content;
  min-width: 100%;
  height: fit-content;
  min-height: 100%;
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
  z-index: 1;
}

/* 絵馬グリッド（CSS Grid 配置用） */
.ema-grid.ema-grid-horizontal {
  position: relative;
  width: fit-content;
  min-width: 100%;
  padding: 24px;
  margin: 0 auto;
}

/* 円形/スパイラル配置時のフォールバック（ema-grid が付かない場合） */
.ema-grid-horizontal:not(.ema-grid) {
  position: relative;
  width: fit-content;
  min-width: 100%;
  min-height: 100%;
  padding: 200px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .ema-viewport {
    height: 52vh;
    min-height: 340px;
  }
  
  #emaGrid {
    padding: 16px;
  }
}

.ema-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* 絵馬を書く CTA ボタン（一覧・アーカイブ・詳細で共通） */
.ema-write-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(180deg, #c53030 0%, #9b2c2c 100%);
  border: 2px solid rgba(139, 69, 19, 0.35);
  border-radius: 9999px;
  box-shadow: 0 4px 14px rgba(159, 58, 58, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.ema-write-cta:hover {
  opacity: 0.95;
  box-shadow: 0 6px 20px rgba(159, 58, 58, 0.4), inset 0 1px 0 rgba(255,255,255,0.15);
  transform: translateY(-1px);
}
.ema-write-cta:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(159, 58, 58, 0.3);
}
.ema-write-cta .material-symbols-outlined {
  font-size: 1.25rem;
}

/* アーカイブページ用のスタイル */
.ema-archive-content {
  width: 100%;
}

.ema-archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px 0;
  position: relative;
  width: 100%;
}

@media (max-width: 768px) {
  .ema-archive-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
  }
}

.ema-card-grid {
  display: grid;
  gap: 16px;
}

/* Footer (based on root index.html structure) */
.footer {
  margin-top: 48px;
  background: #ffffff;
  border-top: 1px solid #e8e8e8;
}

.footer .container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}

.footer-content {
  display: grid;
  gap: 16px;
}

.footer-title {
  font-weight: 700;
  margin: 0 0 8px;
}

.footer-description {
  margin: 0;
  color: #555;
  font-size: 0.9rem;
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}

.footer-links a {
  text-decoration: none;
  color: inherit;
  font-size: 0.9rem;
}

.footer-bottom {
  border-top: 1px solid #eee;
  margin-top: 16px;
  padding-top: 12px;
  font-size: 0.85rem;
  color: #666;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 絵馬アプリ専用ナビゲーション（常時表示・メイン） */
.ema-app-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #f8f5f5;
  border-bottom: 1px solid #e8e8e8;
  padding: 6px 12px;
}

.ema-app-nav-container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: relative;
}

.ema-app-nav-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #f20d0d;
  text-decoration: none;
}

.ema-app-nav-menu {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
}

.ema-app-nav-link {
  text-decoration: none;
  color: #5d4037;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.ema-app-nav-link:hover {
  background-color: rgba(242, 13, 13, 0.1);
}

.ema-app-nav-link.active {
  background-color: #f20d0d;
  color: #ffffff;
  font-weight: 700;
}

.ema-app-nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid #ddd;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.ema-app-nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: #333;
  margin: 4px 0;
}

/* 絵馬アプリ専用フッター */
.ema-app-footer {
  background: linear-gradient(to bottom, #faf8f5 0%, #f8f5f5 100%);
  border-top: 2px solid rgba(242, 13, 13, 0.1);
  padding: 20px 16px 16px;
  margin-top: 32px;
  position: relative;
  overflow: hidden;
}

.ema-app-footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(242, 13, 13, 0.2), transparent);
}

.ema-app-footer-container {
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.ema-app-footer-content {
  margin-bottom: 16px;
}

.ema-app-footer-title {
  font-weight: 700;
  font-size: 0.875rem;
  color: #f20d0d;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  padding-bottom: 6px;
}

.ema-app-footer-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 30px;
  height: 2px;
  background: linear-gradient(to right, #f20d0d, transparent);
  border-radius: 1px;
}

.ema-app-footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ema-app-footer-links a {
  text-decoration: none;
  color: #5d4037;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(139, 69, 19, 0.1);
  position: relative;
  overflow: hidden;
  min-height: 44px;
  text-align: center;
  font-weight: 500;
}

.ema-app-footer-links a:active {
  transform: scale(0.98);
  background: rgba(242, 13, 13, 0.1);
}

.ema-app-footer-links a:hover {
  color: #f20d0d;
  background: rgba(242, 13, 13, 0.08);
  border-color: rgba(242, 13, 13, 0.25);
  box-shadow: 0 2px 6px rgba(242, 13, 13, 0.15);
}

.ema-app-footer-bottom {
  border-top: 1px solid rgba(139, 69, 19, 0.15);
  padding-top: 12px;
  margin-top: 12px;
  text-align: center;
  font-size: 0.75rem;
  color: #9c4949;
}

.ema-app-footer-bottom p {
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.3px;
}

@media (max-width: 900px) {
  .ema-app-nav-toggle {
    display: inline-block;
  }

  .ema-app-nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 8px 12px;
    border-top: 1px solid #e8e8e8;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 100;
    margin-top: 6px;
  }

  .ema-app-nav-menu.is-open {
    display: flex;
  }

  .ema-app-nav-link {
    width: 100%;
    padding: 8px 12px;
    text-align: center;
    display: block;
    box-sizing: border-box;
    font-size: 0.85rem;
  }

  .ema-app-nav-menu li {
    width: 100%;
    list-style: none;
  }

  .ema-app-nav-container {
    flex-wrap: wrap;
  }

  body.ema-menu-open .app-main {
    margin-top: 240px;
    transition: margin-top 0.3s ease;
  }

  /* フッターのレスポンシブ対応 */
  .ema-app-footer {
    padding: 16px 12px 12px;
    margin-top: 24px;
  }

  .ema-app-footer-content {
    margin-bottom: 12px;
  }

  .ema-app-footer-title {
    font-size: 0.8rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
  }

  .ema-app-footer-title::after {
    width: 25px;
    height: 1.5px;
  }

  .ema-app-footer-links {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .ema-app-footer-links a {
    font-size: 0.8rem;
    padding: 10px 6px;
    min-height: 42px;
  }

  .ema-app-footer-bottom {
    padding-top: 10px;
    margin-top: 10px;
    font-size: 0.7rem;
  }

  .app-main {
    transition: margin-top 0.3s ease;
  }

  .ema-app-footer-content {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

@media (min-width: 768px) {
  .app-main {
    padding: 32px 24px 64px;
  }
}

/* FAQアコーディオン */
.faq-icon {
  transition: transform 0.3s ease;
}

[data-faq-item].is-open .faq-icon {
  transform: rotate(180deg);
}

/* 同意画面モーダル */
.consent-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.consent-modal.is-open {
  opacity: 1;
  visibility: visible;
}

.consent-modal-content {
  background: #ffffff;
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.consent-modal.is-open .consent-modal-content {
  transform: scale(1);
}

.consent-modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #e8e8e8;
}

.consent-modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1c0d0d;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.consent-modal-title .material-symbols-outlined {
  font-size: 1.2rem;
}

.consent-modal-body {
  padding: 16px 20px;
}

.consent-modal-text {
  color: #5d4037;
  line-height: 1.6;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.consent-modal-list {
  list-style: disc;
  padding-left: 20px;
  color: #5d4037;
  line-height: 1.6;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.consent-modal-list li {
  margin-bottom: 4px;
}

.consent-modal-notice {
  margin-top: 20px;
  padding: 12px 16px;
  background: #fff9e6;
  border-left: 4px solid #ff9800;
  border-radius: 6px;
}

.consent-modal-notice-title {
  font-weight: 700;
  color: #e65100;
  margin: 0 0 8px 0;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.consent-modal-notice-title .material-symbols-outlined {
  font-size: 1.1rem;
}

.consent-modal-notice-text {
  color: #5d4037;
  line-height: 1.7;
  margin: 0;
  font-size: 0.85rem;
}
.consent-modal-text-caution {
  color: #9c4949;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}
.consent-modal-text-link {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}
.consent-modal-privacy-link {
  color: #9c4949;
  font-weight: 600;
  text-decoration: underline;
}
.consent-modal-privacy-link:hover {
  opacity: 0.85;
}

.consent-modal-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid #e8e8e8;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.consent-modal-button {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 0.9rem;
}

.consent-modal-button-primary {
  background: #f20d0d;
  color: #ffffff;
}

.consent-modal-button-primary:hover {
  background: #d10b0b;
}

.consent-modal-button-secondary {
  background: #f8f5f5;
  color: #5d4037;
}

.consent-modal-button-secondary:hover {
  background: #e8e8e8;
}

@media (max-width: 640px) {
  .consent-modal-content {
    max-width: 100%;
    max-height: 80vh;
  }
  
  .consent-modal-header {
    padding: 12px 16px 10px;
  }
  
  .consent-modal-body {
    padding: 12px 16px;
  }
  
  .consent-modal-footer {
    padding: 10px 16px 12px;
    flex-direction: column;
  }
  
  .consent-modal-title {
    font-size: 1.1rem;
  }
  
  .consent-modal-text,
  .consent-modal-list {
    font-size: 0.85rem;
  }
  
  .consent-modal-button {
    width: 100%;
    padding: 10px 16px;
  }
}

/* 同意状態ボタン：未同意時はクリックでモーダル、同意済みは無効表示 */
[data-consent-status]:disabled {
  cursor: default;
  opacity: 0.9;
}
[data-consent-status]:disabled:hover {
  text-decoration: none;
}
