/* ================================================================
   RPG TOWN V2 — Grid Map UI + World Skin System
   /styles/rpg-town-v2.css
   ================================================================ */

/* ── ワールドスキントークン ─────────────────────────────────── */
/* ルール: UI部品のCSSに直接色を書かない。必ず var(--w-xxx) を使う */

/* === 国3「火と鉄の国」(英検3級) デフォルト === */
:root,
[data-world="fire"] {
  --w-primary:       #4ade80;
  --w-primary-glow:  rgba(74,222,128,0.3);
  --w-secondary:     #86efac;
  --w-bg-dark:       #03080a;
  --w-bg-mid:        #071410;
  --w-bg-light:      #0d1f17;
  --w-surface:       rgba(3, 10, 6, 0.88);
  --w-surface-light: rgba(6, 18, 10, 0.75);
  --w-border:        rgba(74,222,128,0.25);
  --w-text:          #ffffff;
  --w-text-muted:    rgba(180,230,190,0.6);
  --w-hud-bg:        rgba(3, 8, 5, 0.93);
  --w-hud-border:    rgba(74,222,128,0.18);
  --w-tile-border:   transparent;
  --w-tile-hover:    rgba(74,222,128,0.2);
  --w-tile-active:   rgba(74,222,128,0.3);
  --w-built-glow:    0 0 12px rgba(74,222,128,0.4);
  --w-tent-glow:     0 0 20px rgba(74,222,128,0.5);
  --w-grid-gap:      0px;
}

/* === 国2「風と保存の国」(英検4級) === */
[data-world="wind"] {
  --w-primary:       #5bbcd6;
  --w-primary-glow:  rgba(91,188,214,0.4);
  --w-secondary:     #f2d974;
  --w-bg-dark:       #0a1520;
  --w-bg-mid:        #142838;
  --w-bg-light:      #1e3a50;
  --w-surface:       rgba(10,30,50,0.85);
  --w-surface-light: rgba(15,40,65,0.7);
  --w-border:        rgba(91,188,214,0.3);
  --w-text:          #fff;
  --w-text-muted:    rgba(160,210,240,0.6);
  --w-hud-bg:        rgba(5,15,25,0.88);
  --w-hud-border:    rgba(91,188,214,0.2);
  --w-tile-border:   rgba(91,188,214,0.25);
  --w-tile-hover:    rgba(91,188,214,0.2);
  --w-tile-active:   rgba(242,217,116,0.35);
  --w-built-glow:    0 0 12px rgba(91,188,214,0.4);
  --w-tent-glow:     0 0 20px rgba(242,217,116,0.5);
}

/* === 国1「土と種の国」(英検5級) === */
[data-world="earth"] {
  --w-primary:       #6abf69;
  --w-primary-glow:  rgba(106,191,105,0.4);
  --w-secondary:     #d4a56a;
  --w-bg-dark:       #0a1408;
  --w-bg-mid:        #152810;
  --w-bg-light:      #1e3a18;
  --w-surface:       rgba(10,30,8,0.85);
  --w-surface-light: rgba(15,40,12,0.7);
  --w-border:        rgba(106,191,105,0.3);
  --w-text:          #fff;
  --w-text-muted:    rgba(160,230,160,0.6);
  --w-hud-bg:        rgba(5,15,4,0.88);
  --w-hud-border:    rgba(106,191,105,0.2);
  --w-tile-border:   rgba(106,191,105,0.25);
  --w-tile-hover:    rgba(106,191,105,0.2);
  --w-tile-active:   rgba(212,165,106,0.35);
  --w-built-glow:    0 0 12px rgba(106,191,105,0.4);
  --w-tent-glow:     0 0 20px rgba(212,165,106,0.5);
}

/* ── グリッドマップ コンテナ ───────────────────── */
.tv2-map-wrap {
  position: absolute;
  top: 56px;    /* rpg-topbarの高さ分だけ下げる */
  left: 0;
  right: 0;
  bottom: 60px; /* 下部HUD分の余白 */
  background: transparent;
  overflow: hidden;           /* パンスクロール用にクリップ */
  z-index: 5;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;         /* ブラウザスクロールを無効化しJSで制御 */
}

/* グリッド本体（12×12=960×960px）はJSのtransformで移動する */
.tv2-grid {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  gap: 0;
  padding: 0;
  background: transparent;
  image-rendering: auto;
  will-change: transform;
  transform: translate(0, 0);
}


/* ── タイル共通（80px固定） ────────────────────────────────── */
.tv2-tile {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 0;
  border: none;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
}

.tv2-tile:active {
  transform: scale(0.96);
  z-index: 3;
}

.tv2-tile:hover {
  box-shadow: inset 0 0 0 2px var(--w-primary), 0 0 8px var(--w-primary-glow);
  z-index: 2;
}

.tv2-tile.tv2-selected {
  box-shadow: inset 0 0 0 2px var(--w-secondary), 0 0 12px rgba(255,215,0,0.5);
  z-index: 2;
}

/* ── 地形タイプ別フォールバック背景色 ───────────────────── */
.tv2-tile[data-ground="scorched"] { background-color: #2a1005; }
.tv2-tile[data-ground="wasteland"]{ background-color: #4a3820; }
.tv2-tile[data-ground="grass"]    { background-color: #3a6828; }
.tv2-tile[data-ground="farm"]     { background-color: #5a4020; }

/* ── 畑タイル用フォールバック背景色 ──────────────────────── */
.tv2-tile[data-feature="farm"] { background-color: #5a4020; }

/* emoji/labelは前面 */
.tv2-tile-emoji,
.tv2-tile-label,
.tv2-lv-badge,
.tv2-farm-timer,
.tv2-sparkle { position: relative; z-index: 2; }

/* ── 建設済みグロウ ──────────────────────────────────────── */
.tv2-tile.tv2-built {
  box-shadow: var(--w-built-glow);
}

/* ── 廃墟タイル（ロック済みbuilding / deco） ────────────────── */
.tv2-tile.tv2-tile-ruin {
  opacity: 0.75;
  filter: grayscale(0.4) brightness(0.85);
  cursor: default;
}
.tv2-tile.tv2-tile-ruin:hover {
  box-shadow: inset 0 0 0 2px rgba(180,130,80,0.6);
}
.tv2-ruin-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -56%);
  font-size: 26px;
  opacity: 0.7;
  filter: grayscale(0.5) brightness(0.8);
  pointer-events: none;
  z-index: 2;
}


/* ── タイル内ラベル（タップ時のみ表示）───────────────────── */
.tv2-tile-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 3px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: var(--w-text);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.tv2-tile:hover .tv2-tile-label,
.tv2-tile:active .tv2-tile-label {
  opacity: 1;
}

.tv2-tile-emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  font-size: 28px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.7)) drop-shadow(0 1px 2px rgba(0,0,0,0.9));
  pointer-events: none;
  transition: transform 0.15s ease;
  line-height: 1;
}

.tv2-tile:hover .tv2-tile-emoji {
  transform: translate(-50%, -60%) scale(1.15);
}

.tv2-sprite {
  transition: transform 0.15s ease;
}

.tv2-tile:hover .tv2-sprite {
  transform: scale(1.04);
}

/* ── Lvバッジ ────────────────────────────────────────────── */
.tv2-lv-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  background: var(--w-primary);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 8px;
  letter-spacing: 0.03em;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* ── 農園タイマーオーバーレイ ─────────────────────────────── */
.tv2-farm-timer {
  position: absolute;
  top: auto;
  bottom: 4px;
  left: 4px;
  right: 4px;
  background: rgba(30,20,10,0.85);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  padding: 3px 2px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.4);
  text-align: center;
  pointer-events: none;
  font-family: inherit;
  backdrop-filter: blur(4px);
  -webkit-text-stroke: 0.5px rgba(0,0,0,0.8);
  box-shadow: 0 2px 4px rgba(0,0,0,0.6);
  letter-spacing: 0.05em;
}

/* ── 畑（tv2-soilはJS判定用クラスのみ / 背景はmap1.jpgのまま） */

/* ── 収穫可能キラキラ ────────────────────────────────────── */
.tv2-tile.tv2-harvestable {
  animation: tv2-harvest-pulse 1.5s ease-in-out infinite alternate;
}
@keyframes tv2-harvest-pulse {
  0%   { box-shadow: 0 0 8px rgba(255,215,0,0.3); }
  100% { box-shadow: 0 0 20px rgba(255,215,0,0.7); }
}

.tv2-sparkle {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 14px;
  animation: tv2-sparkle-spin 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes tv2-sparkle-spin {
  0%,100% { transform: scale(1) rotate(-10deg); opacity: 0.7; }
  50%     { transform: scale(1.3) rotate(10deg); opacity: 1; }
}

/* ── ロックオーバーレイ（未開拓荒地）※控えめに ──────────── */
.tv2-locked-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  pointer-events: none;
  opacity: 0.5;
}

/* ── HUD: 下部バー ───────────────────────────────────────── */
.tv2-hud-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px max(12px, env(safe-area-inset-bottom, 12px));
  background: var(--w-hud-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--w-hud-border);
  box-sizing: border-box;
}


.tv2-hp-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.tv2-hp-icon { font-size: 14px; }

.tv2-hp-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
}

.tv2-hp-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}
.tv2-hp-fill.high { background: linear-gradient(90deg, #22c55e, #16a34a); }
.tv2-hp-fill.mid  { background: linear-gradient(90deg, #eab308, #ca8a04); }
.tv2-hp-fill.low  { background: linear-gradient(90deg, #ef4444, #dc2626); }

.tv2-hp-text {
  font-size: 11px;
  font-weight: 800;
  color: var(--w-text);
  min-width: 40px;
}

.tv2-action-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--w-border);
  background: var(--w-surface-light);
  color: var(--w-text);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tv2-action-btn:active {
  transform: scale(0.95);
}

.tv2-action-btn.primary {
  background: linear-gradient(135deg, var(--w-primary), color-mix(in srgb, var(--w-primary) 70%, black));
  border-color: var(--w-primary);
  box-shadow: 0 2px 8px var(--w-primary-glow);
}

/* ── ベースキャンプメニュー（テントタップ時） ─────────────── */
.tv2-camp-menu {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--w-hud-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--w-border);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom, 20px));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
}

.tv2-camp-menu.tv2-open {
  transform: translateY(0);
}

.tv2-camp-menu-handle {
  width: 40px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.tv2-camp-menu-title {
  font-family: 'Exo 2', sans-serif;
  font-size: 16px;
  font-weight: 900;
  color: var(--w-secondary);
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.05em;
}

.tv2-camp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tv2-camp-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: 12px;
  border: 1px solid var(--w-border);
  background: var(--w-surface);
  color: var(--w-text);
  cursor: pointer;
  transition: all 0.15s;
}

.tv2-camp-btn:active {
  transform: scale(0.95);
  background: var(--w-tile-active);
}

.tv2-camp-btn-emoji {
  font-size: 24px;
}

.tv2-camp-btn-label {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

/* ── キャンプメニュー背景マスク ───────────────────────────── */
.tv2-camp-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.tv2-camp-backdrop.tv2-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── メッセージトースト ──────────────────────────────────── */
.tv2-toast {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  z-index: 200;
  opacity: 0;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14px;
  font-weight: 900;
  color: var(--w-text);
  background: var(--w-hud-bg);
  border: 1px solid var(--w-border);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 10px 24px;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.25s, transform 0.25s;
}

.tv2-toast.tv2-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  animation: tv2-toast-fade 1.8s ease forwards;
}

@keyframes tv2-toast-fade {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-4px); }
}

/* ── レスポンシブ ────────────────────────────────────────── */
@media (max-width: 400px) {
  .tv2-tile {
    width: 60px;
    height: 60px;
  }
  .tv2-tile-label { font-size: 8px; }
  .tv2-tile-emoji { font-size: 20px; }
  .tv2-camp-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .tv2-camp-btn { padding: 10px 6px; }
  .tv2-camp-btn-emoji { font-size: 20px; }
}
