/* ============================================================
   サカイタイムズ RPGマップ - スタイル
   色・フォント等の"設定値"は theme.json からCSS変数として注入される
   (--pin-size, --card-bg, --card-border, --accent など)
   ============================================================ */

:root {
  --font-family: 'DotGothic16', 'Hiragino Kaku Gothic ProN', monospace;
  --card-bg: #1a1a2e;
  --card-border: #f5d76e;
  --card-border-width: 4px;
  --card-text: #ffffff;
  --accent: #f5d76e;
  --pin-size: 40px;
  --char-size: 56px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  background: #0f0f1e;
  color: #fff;
  image-rendering: pixelated;
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 8px;
}

/* ---------- ヘッダー ---------- */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
  flex-wrap: wrap;
}

#app-title {
  font-size: 1.2rem;
  margin: 0;
  color: var(--accent);
  text-shadow: 2px 2px 0 #000;
}

/* ---------- RPG風 共通パーツ ---------- */
.rpg-button {
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--card-text);
  background: var(--card-bg);
  border: 3px solid var(--card-border);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
  transition: transform 0.1s;
}
.rpg-button:hover { transform: translate(-1px, -1px); }
.rpg-button:active { transform: translate(2px, 2px); box-shadow: none; }
.rpg-button.danger { border-color: #e05a4e; }

.rpg-window {
  background: var(--card-bg);
  border: var(--card-border-width) solid var(--card-border);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.6);
}

.hidden { display: none !important; }

/* ---------- マップステージ ---------- */
#map-container { position: relative; }

#loading {
  text-align: center;
  margin: 40px auto;
  max-width: 300px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.4; } }

#map-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 4px solid var(--card-border);
  border-radius: 8px;
  background: #223;
}

#map-stage.fade-out { animation: fadeOut var(--transition-dur, 400ms) forwards; }
#map-stage.fade-in { animation: fadeIn var(--transition-dur, 400ms) forwards; }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.map-image {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- ワールドマップ:地域ホットスポット ---------- */
.region-hotspot {
  position: absolute;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: var(--font-family);
  transition: background 0.15s, box-shadow 0.15s;
}
.region-hotspot:hover,
.region-hotspot:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 16px 4px rgba(245, 215, 110, 0.5);
  outline: none;
}

.region-label {
  color: var(--region-label-color, #fff);
  font-size: clamp(0.7rem, 2vw, 1rem);
  text-shadow: 2px 2px 0 #000;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 8px;
  border-radius: 4px;
  pointer-events: none;
}

.region-count {
  color: var(--accent);
  font-size: clamp(0.6rem, 1.6vw, 0.8rem);
  text-shadow: 1px 1px 0 #000;
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* ---------- ピン ---------- */
.map-pin {
  position: absolute;
  width: var(--pin-size);
  height: var(--pin-size);
  margin-left: calc(var(--pin-size) / -2);
  margin-top: calc(var(--pin-size) * -1); /* 先端が座標に合うように */
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  transition: transform 0.15s;
  z-index: 5;
}
.map-pin img { width: 100%; height: 100%; pointer-events: none; }
.map-pin:hover { transform: scale(var(--pin-hover-scale, 1.25)); z-index: 6; }

.map-pin.idle-bounce { animation: pinBounce 1.6s ease-in-out infinite; }
@keyframes pinBounce {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -6px; }
}

.map-pin.appear-drop { animation: pinDrop var(--pin-appear-dur, 400ms) cubic-bezier(0.3, 1.4, 0.6, 1) backwards; }
@keyframes pinDrop {
  from { translate: 0 -60px; opacity: 0; }
  to { translate: 0 0; opacity: 1; }
}

.map-pin.dragging { opacity: 0.7; cursor: grabbing; animation: none !important; }

/* 編集モード中のピン */
.edit-active .map-pin { cursor: grab; animation: none; outline: 2px dashed var(--accent); outline-offset: 2px; }

/* ---------- キャラクター ---------- */
#map-character {
  position: absolute;
  width: var(--char-size);
  height: var(--char-size);
  margin-left: calc(var(--char-size) / -2);
  margin-top: calc(var(--char-size) * -1);
  pointer-events: none;
  z-index: 8;
  transition: none;
}
#map-character img { width: 100%; height: 100%; }
#map-character.flip img { transform: scaleX(-1); }

#map-character.idle-bob { animation: charBob 1.2s steps(2) infinite; }
@keyframes charBob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -3px; }
}

#map-character.walking { animation: charWalk 0.3s steps(2) infinite; }
@keyframes charWalk {
  0%, 100% { translate: 0 0; rotate: -2deg; }
  50% { translate: 0 -4px; rotate: 2deg; }
}

/* ---------- 記事カード ---------- */
/* iframe内・スマホでも見切れないよう、overlayはスクロール可・カードは高さ制限つき */
#card-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  z-index: 100;
  padding: 12px;
  overflow-y: auto;
}

.article-card {
  width: min(360px, 94vw);
  margin: auto; /* flexの中央寄せ。カードが縦にあふれてもスクロールで全体が見える */
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: var(--card-border-width) solid var(--card-border);
  border-radius: 10px;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.7);
  color: var(--card-text);
  overflow: hidden;
  position: relative;
}
.article-card.with-frame {
  border: none;
  border-image: var(--card-frame) 24 fill / 24px stretch;
}

.article-card.open-rpg-window { animation: rpgWindowOpen var(--card-open-dur, 300ms) cubic-bezier(0.2, 1.2, 0.4, 1); }
@keyframes rpgWindowOpen {
  from { transform: scale(0.1, 0.02); opacity: 0; }
  60% { transform: scale(1.02, 0.6); opacity: 1; }
  to { transform: scale(1, 1); }
}

.article-card.spin-out {
  animation: cardSpinOut var(--card-spin-dur, 900ms) ease-in forwards;
}
@keyframes cardSpinOut {
  to {
    transform: rotateY(calc(360deg * var(--card-spin-rotations, 2))) scale(var(--card-spin-scale, 1.5));
    opacity: 0;
  }
}

.card-image {
  width: 100%;
  height: clamp(90px, 24vh, 160px); /* 低い画面では画像を縮めてボタンを優先 */
  object-fit: cover;
  display: block;
  flex-shrink: 0;
  border-bottom: 3px solid var(--card-border);
}

.card-body {
  padding: 14px 16px;
  overflow-y: auto; /* 本文が長い場合はカード内スクロール(ボタンは常に見える) */
  min-height: 0;
}

.card-category {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--card-bg);
  background: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.card-title { font-size: 1rem; margin: 0 0 8px; line-height: 1.5; }

.card-venue, .card-address {
  font-size: 0.78rem;
  margin: 2px 0;
  opacity: 0.85;
}
.card-venue::before { content: "📍 "; }

.card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap; /* 狭い画面でボタンが折り返せるように */
  flex-shrink: 0; /* カードが縮んでもボタン領域は確保 */
  padding: 10px 16px 14px;
}

.card-read-button {
  animation: readPulse 1.2s ease-in-out infinite;
}
@keyframes readPulse {
  50% { box-shadow: 3px 3px 0 rgba(0,0,0,0.6), 0 0 12px 2px rgba(245, 215, 110, 0.7); }
}

/* ---------- 編集パネル・トースト ---------- */
#edit-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 260px;
}
.edit-hint { margin: 0; font-size: 0.75rem; opacity: 0.85; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--card-bg);
  border: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.85rem;
  z-index: 200;
  animation: fadeIn 0.2s;
  max-width: 92vw;
}

/* ---------- スマホ・狭いiframe対応 ---------- */
@media (max-width: 480px) {
  #app { padding: 4px; }
  #app-title { font-size: 1rem; }
  .rpg-button { font-size: 0.8rem; padding: 6px 10px; }
  .card-title { font-size: 0.92rem; }
  #edit-panel { left: 12px; right: 12px; max-width: none; }
}

/* 高さの低いiframe(例: 横向きスマホや height:400px 埋め込み)でもボタンを死守 */
@media (max-height: 520px) {
  .card-image { height: clamp(60px, 18vh, 110px); }
  .card-body { padding: 8px 14px; }
}

/* ============================================================
   遭遇演出エンジン(encounter-engine.js)用スタイル
   タイミング・倍率などの数値は theme.json 側からインライン/CSS変数で注入
   ============================================================ */

/* 演出中: オーバーレイを透過してマップを見せ、カードは一時退場 */
#card-overlay.encounter-mode {
  background: transparent;
  pointer-events: none;
}
#card-overlay.encounter-mode .article-card { visibility: hidden; }

/* 市民キャラ */
.citizen-sprite {
  position: absolute;
  transform: translate(-50%, -100%); /* 足元中央が座標点 */
  pointer-events: none;
  z-index: 7;
  transition-property: left, top;
  transition-timing-function: linear;
}
.citizen-sprite img { width: 100%; height: 100%; image-rendering: pixelated; }
.citizen-sprite.flip img { transform: scaleX(-1); }

.citizen-sprite.citizen-pop { animation: citizenPop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1) backwards; }
@keyframes citizenPop {
  from { scale: 0; opacity: 0; }
  to { scale: 1; opacity: 1; }
}

.citizen-sprite.hop { animation: citizenHop 0.24s ease-in-out; }
@keyframes citizenHop {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -7px; }
}

.citizen-sprite.citizen-out { animation: citizenOut 0.3s ease-in forwards; }
@keyframes citizenOut {
  to { scale: 0; opacity: 0; }
}

/* 全画面エフェクトレイヤー(暗転・点滅) */
.encounter-fx-layer {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
  opacity: 0;
}

/* スパークル(出現エフェクト) */
.fx-sparkle {
  position: absolute;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -130%);
  pointer-events: none;
  z-index: 9;
  animation: sparklePop 0.6s ease-out forwards;
}
@keyframes sparklePop {
  0% { scale: 0; opacity: 1; rotate: 0deg; }
  60% { scale: 1.2; opacity: 1; }
  100% { scale: 0.4; opacity: 0; rotate: 90deg; }
}

/* 「〜があらわれた!」バナー */
.rpg-banner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 160;
  min-width: min(480px, 88vw);
  max-width: 92vw;
  text-align: center;
  background: var(--card-bg);
  border: 4px solid var(--card-border);
  border-radius: 10px;
  padding: 18px 24px;
  box-shadow: 0 0 0 3px #000, 6px 6px 0 rgba(0, 0, 0, 0.7);
  animation: bannerIn 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes bannerIn {
  from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.rpg-banner.rpg-banner-out { animation: bannerOut 0.2s ease-in forwards; }
@keyframes bannerOut {
  to { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
}

.rpg-banner-catch {
  margin: 0 0 8px;
  font-size: clamp(0.85rem, 3vw, 1.05rem);
  color: var(--card-text);
  animation: catchBlink 0.8s steps(2) infinite;
}
@keyframes catchBlink { 50% { opacity: 0.55; } }

.rpg-banner-title {
  margin: 0;
  font-size: clamp(1.1rem, 4.5vw, 1.7rem);
  line-height: 1.4;
  color: var(--accent);
  text-shadow: 2px 2px 0 #000;
}

/* カード入場エフェクト(cardEntrance ステップ) */
.article-card.enc-card-spin { animation: encCardSpin var(--enc-card-dur, 700ms) cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes encCardSpin {
  from { transform: rotateY(calc(360deg * var(--enc-card-rot, 1))) scale(0.2); opacity: 0; }
  to { transform: rotateY(0) scale(1); opacity: 1; }
}

.article-card.enc-card-zoom { animation: encCardZoom var(--enc-card-dur, 600ms) cubic-bezier(0.2, 1.3, 0.4, 1); }
@keyframes encCardZoom {
  from { transform: scale(0.1); opacity: 0; }
  70% { transform: scale(var(--enc-card-scale, 1.06)); opacity: 1; }
  to { transform: scale(1); }
}

.article-card.enc-card-shake { animation: encCardShake var(--enc-card-dur, 700ms) ease-out; }
@keyframes encCardShake {
  0% { transform: scale(0.4); opacity: 0; }
  30% { transform: scale(1) translateX(0); opacity: 1; }
  40% { transform: translateX(-8px) rotate(-2deg); }
  55% { transform: translateX(7px) rotate(2deg); }
  70% { transform: translateX(-5px) rotate(-1deg); }
  85% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.article-card.enc-card-rise { animation: encCardRise var(--enc-card-dur, 700ms) cubic-bezier(0.2, 1, 0.4, 1); }
@keyframes encCardRise {
  from { transform: translateY(60vh) scale(0.85); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
