/* 日本周辺国パズル v1.1.0 - 共通デザインシステム準拠 */

/* ========== WPテーマ干渉リセット ========== */
.japan-nearby-puzzle-root {
  display: block;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 0;
  font-size: 0;
}
.pzl-wrap, .pzl-wrap *,
#clearOverlay, #clearOverlay * {
  box-sizing: border-box;
}
#clearOverlay, #clearOverlay * {
  line-height: normal !important;
  text-decoration: none !important;
  list-style: none !important;
  -webkit-text-fill-color: currentColor !important;
  font-family: 'Noto Sans JP', sans-serif !important;
}
#clearOverlay button {
  -webkit-appearance: none !important;
  appearance: none !important;
}

.pzl-wrap {
  --base: #FFFFFF;
  --base-light: #FAFAFA;
  --base-dark: #F0F4F8;
  --main: #1e3a5f;
  --main-light: #2d5a8f;
  --main-dark: #0f1e3a;
  --accent: #d4af37;
  --accent-light: #f4cf5f;
  --accent-dark: #b8941f;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --border: #E8E8E8;
  --shadow: 0 4px 20px rgba(30,58,95,0.1);
  --ok: #27ae60;
  --ng: #e74c3c;

  font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  line-height: 1;
  background: linear-gradient(160deg, #e8f0f8 0%, #f5f0e8 100%);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  position: relative;
  user-select: none;
}

/* ========== メインコンテンツ ========== */
.pzl-content {
  flex: 1; min-height: 0;
  display: flex; flex-direction: row;
  padding: 8px; gap: 8px; overflow: hidden;
}

/* ---- 地図パネル（カードデザイン） ---- */
.pzl-map-panel {
  /* 修正: 海の色を他の地図アプリ(japan-puzzleなど)と統一 */
  background: linear-gradient(160deg, #bfe0f0 0%, #d7ecf5 55%, #e8f4f8 100%);
  border: 2px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
  flex: 1; min-height: 0; min-width: 0;
  overflow: hidden;
  cursor: default;
  touch-action: none;
}
.pzl-map-panel::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
  border-radius: 16px 16px 0 0; z-index: 2;
}

#mapWrap { width: 100%; height: 100%; position: absolute; top: 0; left: 0; will-change: transform; }
#mapSvg { display: block; width: 100%; height: 100%; cursor: default; }

/* 背景のみ国：視認性高め */
/* 背景のみ国：視認性高め（修正: 他アプリと統一した白系の陸地色） */
.bg-only {
  fill: rgba(255,255,255,0.55); stroke: rgba(150,150,150,0.4); stroke-width: 0.4;
  vector-effect: non-scaling-stroke; pointer-events: none;
}
/* パズル対象国の背景シルエット（修正: ドロップゾーンの下敷き。クリームがかった白） */
.bg-country {
  fill: rgba(255,255,255,0.7); stroke: rgba(120,120,120,0.5); stroke-width: 0.35;
  vector-effect: non-scaling-stroke; pointer-events: none;
}
/* ドロップゾーン（修正: 未配置の陸をクリーム色に統一、海の青との対比を出す） */
.drop-zone {
  fill: rgba(244,238,222,0.92); stroke: #8a7a5c; stroke-width: 0.45;
  cursor: crosshair; transition: fill 0.15s; vector-effect: non-scaling-stroke;
}
.drop-zone.hover-active { fill: rgba(244,207,95,0.6); stroke: var(--accent); stroke-width: 0.8; }
.drop-zone.placed-ok { cursor: default; stroke: rgba(255,255,255,0.8); stroke-width: 0.8; }
.drop-zone.placed-ng { animation: ngFlash 0.45s ease; }
@keyframes ngFlash { 0%,100%{fill:rgba(244,238,222,0.92)} 50%{fill:rgba(231,76,60,0.6)} }
.map-label { pointer-events: none; }
.country-highlight {
  animation: cp 0.8s ease-in-out infinite;
  stroke: #fff !important; stroke-width: 2 !important;
  filter: drop-shadow(0 0 6px rgba(255,255,100,0.9));
}
@keyframes cp { 0%,100%{fill:rgba(255,240,80,0.85);} 50%{fill:rgba(255,200,0,0.5);} }

/* ========== 左上フロート：スコア・リセット ========== */
.pzl-float-score {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(30, 58, 95, 0.82);
  border: 1px solid rgba(212, 175, 55, 0.55);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 92px;
  z-index: 10;
}
.pzl-score-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pzl-score-lbl { color: rgba(212, 175, 55, 0.85); font-size: 10px; font-weight: 700; }
.pzl-score-val { color: #fff; font-size: 20px; font-weight: 900; line-height: 1; }
.pzl-score-timer { color: #fff; font-size: 14px; font-weight: 900; line-height: 1; }
.pzl-score-divider { width: 100%; height: 0.5px; background: rgba(212, 175, 55, 0.3); }
/* 修正: timer="off" 指定時にタイマー行を非表示 */
.pzl-wrap.timer-off .pzl-timer-row { display: none; }

.pzl-btn-reset {
  margin-top: 2px;
  background: rgba(212, 175, 55, 0.18);
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 8px;
  color: #f4cf5f;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 0;
  width: 100%;
  cursor: pointer;
  transition: background 0.15s;
}
.pzl-btn-reset:hover { background: rgba(212, 175, 55, 0.32); }
.pzl-btn-reset[data-armed="1"] {
  background: rgba(231, 76, 60, 0.35);
  border-color: var(--ng);
  color: #fff;
  animation: armedPulse 0.9s infinite;
}
@keyframes armedPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ---- パズル／テスト／国旗／領土 モード切替（右上の丸アイコンボタン） ---- */
.pzl-mode-icons {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
.pzl-mode-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--main);
  border: 2px solid var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(30,58,95,0.3);
  transition: all 0.15s;
  padding: 0;
}
.pzl-mode-icon-btn svg { width: 21px; height: 21px; display: block; }
.pzl-mode-icon-btn:hover { background: var(--main-light); transform: scale(1.06); }
.pzl-mode-icon-btn.active {
  background: var(--accent);
  border-color: #fff;
  color: var(--main-dark);
  box-shadow: 0 4px 12px rgba(212,175,55,0.5);
}

/* ========== 右下フロート：ズームボタン ========== */
.pzl-zoom-btns {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}
.pzl-zoom-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: var(--main);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(30,58,95,0.3);
  transition: all 0.15s;
  line-height: 1;
  user-select: none;
}
.pzl-zoom-btn:hover { background: var(--main-light); transform: scale(1.08); }
.pzl-zoom-btn:active { transform: scale(0.95); }
.pzl-zoom-btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.pzl-zoom-reset-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: rgba(255,255,255,0.92);
  color: var(--main);
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(30,58,95,0.15);
  transition: all 0.15s;
  user-select: none;
}
.pzl-zoom-reset-btn:hover { background: var(--base-dark); }

/* ========== 正解トースト ========== */
.pzl-correct-toast {
  position: absolute;
  top: 42%; left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  background: rgba(39, 174, 96, 0.92);
  color: #fff;
  font-size: clamp(15px, 3vw, 24px);
  font-weight: 900;
  padding: 9px 24px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}
.pzl-correct-toast.show { animation: toastPop 0.7s ease forwards; }
@keyframes toastPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  35%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* ========== 右パネル：ピース／国旗／テスト（カードデザイン） ========== */
.pzl-right {
  width: 200px;
  flex-shrink: 0;
  background: var(--base);
  border: 2px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pzl-right::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
  border-radius: 16px 16px 0 0; z-index: 2;
}
.pzl-right-label {
  color: var(--main); font-weight: 900; font-size: 13px;
  padding: 10px 10px 6px;
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  border-bottom: 1px solid rgba(212,175,55,0.3);
}
.pzl-right-label::before {
  content: ''; display: inline-block;
  width: 4px; height: 14px;
  background: var(--accent); border-radius: 2px;
}
.pzl-right-tray {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 8px 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  align-content: start;
}
.pzl-right-tray::-webkit-scrollbar { width: 3px; }
.pzl-right-tray::-webkit-scrollbar-track { background: var(--base-dark); border-radius: 3px; }
.pzl-right-tray::-webkit-scrollbar-thumb { background: var(--main-light); border-radius: 3px; }

/* ---- ピース ---- */
.pzl-piece {
  display: flex; flex-direction: column; align-items: center;
  cursor: grab; transition: transform 0.18s, box-shadow 0.18s;
  flex-shrink: 0; width: 100%;
  background: var(--base-dark); border: 1.5px solid rgba(30,58,95,0.1);
  border-radius: 8px; padding: 5px 2px 4px; overflow: hidden;
}
.pzl-piece:hover:not(.dragging) { transform: translateY(-3px) scale(1.06); box-shadow: 0 6px 16px rgba(30,58,95,0.18); }
.pzl-piece.dragging { opacity: 0.28; cursor: grabbing; box-shadow: 0 10px 28px rgba(30,58,95,0.35); }
.pzl-piece svg { display: block; filter: drop-shadow(0 2px 4px rgba(30,58,95,0.22)); }
.pzl-piece-name {
  font-size: 10px; font-weight: 900; color: var(--main);
  margin-top: 3px; pointer-events: none; text-align: center; line-height: 1.4;
  white-space: normal; word-break: break-all; width: 100%; overflow: hidden;
}
.pzl-piece-name ruby { font-size: 10px; }
.pzl-piece-name rt { font-size: 6px; font-weight: 700; color: var(--main-light); letter-spacing: 0.02em; }
/* 正式名称などの補足 */
.pzl-piece-note {
  font-size: 7px; font-weight: 400; color: var(--main-light);
  white-space: normal; word-break: break-all; width: 100%;
  margin-top: 1px; line-height: 1.2; text-align: center;
}

#dragGhost { position: fixed; pointer-events: none; z-index: 9999; opacity: 0.88; display: none; }

/* ========== テストモード ========== */
.pzl-test-area { display: flex; flex-direction: column; gap: 8px; padding: 10px; flex: 1; }
.pzl-test-question {
  color: var(--main); font-weight: 900; font-size: 13px;
  display: flex; align-items: flex-start; gap: 4px; line-height: 1.3;
}
.pzl-test-question::before {
  content: ''; display: inline-block; width: 3px; height: 12px;
  background: var(--accent); border-radius: 2px; flex-shrink: 0; margin-top: 1px;
}
.pzl-test-input {
  width: 100%; border: 2px solid var(--main); border-radius: 8px; padding: 8px 10px;
  font-size: 14px; font-weight: 700; outline: none; transition: border-color 0.15s;
  font-family: 'Noto Sans JP', sans-serif; color: var(--text);
}
.pzl-test-input:focus { border-color: var(--accent); }
.pzl-test-input.correct { border-color: var(--ok); background: rgba(39,174,96,0.1); }
.pzl-test-input.wrong { border-color: var(--ng); background: rgba(231,76,60,0.1); animation: ws 0.3s ease; }
@keyframes ws { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
.pzl-test-btn {
  background: var(--main); color: #fff; border: none; border-radius: 8px;
  padding: 9px; font-size: 13px; font-weight: 900; cursor: pointer; width: 100%;
  transition: background 0.15s;
}
.pzl-test-btn:hover { background: var(--main-light); }
.pzl-test-progress { color: var(--text-light); font-size: 12px; font-weight: 700; text-align: center; }

/* ========== モーダル共通フェード ========== */
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

/* ---- クリア画面 ---- */
#clearOverlay {
  position: fixed; inset: 0;
  background: rgba(30,58,95,0.85);
  display: none; align-items: center; justify-content: center;
  z-index: 2000;
}
#clearOverlay.show { display: flex; animation: fadeIn 0.5s ease; }

.pzl-clear-box {
  background: #ffffff !important; border: none !important;
  border-radius: 28px !important;
  padding: clamp(28px, 4vw, 40px) clamp(24px, 5vw, 44px) clamp(24px, 4vw, 32px) !important;
  text-align: center !important; box-shadow: 0 24px 64px rgba(30,58,95,0.35) !important;
  max-width: 90vw; width: 380px !important;
  position: relative !important;
  overflow: visible !important;
}
.pzl-clear-confetti { position: relative !important; height: 36px !important; margin: 0 0 4px !important; padding: 0 !important; }
.pzl-confetti-dot {
  position: absolute !important; width: 8px; height: 8px; border-radius: 50% !important;
  top: 50%; left: 50%; opacity: 0;
  animation: confettiFly 0.7s ease-out forwards; animation-delay: 0.15s;
  margin: 0 !important; padding: 0 !important;
}
.pzl-confetti-dot-1 { background: #e74c3c !important; --tx: -46px; --ty: -18px; }
.pzl-confetti-dot-2 { background: #2980b9 !important; --tx: 44px; --ty: -20px; }
.pzl-confetti-dot-3 { background: #27ae60 !important; --tx: -34px; --ty: 14px; }
.pzl-confetti-dot-4 { background: #d4af37 !important; --tx: 36px; --ty: 16px; }
.pzl-confetti-dot-5 { background: #9b59b6 !important; --tx: -14px; --ty: -28px; }
.pzl-confetti-dot-6 { background: #e67e22 !important; --tx: 16px; --ty: -30px; }
@keyframes confettiFly {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1); opacity: 0; }
}
.pzl-clear-title {
  display: block !important;
  font-size: clamp(30px, 5vw, 42px) !important; font-weight: 900 !important;
  color: var(--main-dark) !important; letter-spacing: 0.02em;
  margin: 0 !important; padding: 0 !important;
}
.pzl-clear-subtitle {
  display: block !important;
  font-size: clamp(13px, 2vw, 15px) !important; font-weight: 700 !important;
  color: var(--text-light) !important;
  margin: 4px 0 0 !important; padding: 0 !important;
}
.pzl-clear-divider { display: flex !important; justify-content: center !important; gap: 5px !important; margin: 14px 0 18px !important; padding: 0 !important; }
.pzl-clear-divider span { width: 4px; height: 4px; border-radius: 50% !important; background: var(--accent-light) !important; margin: 0 !important; padding: 0 !important; }
.pzl-clear-stat {
  display: flex !important; align-items: center !important; gap: 10px !important;
  background: var(--base-dark) !important; border-radius: 14px !important;
  padding: 12px 16px !important; margin: 0 0 10px !important; text-align: left !important;
}
.pzl-clear-stat-label { display: inline-block !important; font-size: 13px !important; font-weight: 700 !important; color: var(--text) !important; flex: 1; margin: 0 !important; }
.pzl-clear-stat-value { display: inline-block !important; font-size: 19px !important; font-weight: 900 !important; margin: 0 !important; }
.pzl-clear-stat-miss .pzl-clear-stat-value { color: #2980b9 !important; }
.pzl-clear-stat-time .pzl-clear-stat-value { color: #1e8449 !important; }

#clearOverlay .pzl-btn-again {
  border: none !important; border-radius: 14px !important;
  padding: 13px 32px !important; font-size: 17px !important; font-weight: 900 !important;
  cursor: pointer; margin: 10px 0 0 !important; width: 100% !important;
  transition: all 0.2s;
  display: flex !important; align-items: center !important; justify-content: center !important; gap: 8px;
  opacity: 1 !important;
  background: linear-gradient(135deg, var(--main-light), var(--main)) !important;
  background-color: #1e3a5f !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  box-shadow: 0 4px 16px rgba(30,58,95,0.3) !important;
}
#clearOverlay .pzl-btn-again:hover { transform: translateY(-3px); }

/* ==========================================
   タブレット（900px 以下）：右パネルを狭く
========================================== */
@media (max-width: 900px) {
  .pzl-content { padding: 6px; gap: 6px; }
  .pzl-right { width: 168px; }
  .pzl-right-tray { grid-template-columns: 1fr; }
  .pzl-float-score { min-width: 80px; padding: 6px 8px; }
  .pzl-score-val { font-size: 16px; }
  .pzl-score-timer { font-size: 12px; }
  .pzl-mode-icon-btn { width: 40px; height: 40px; }
  .pzl-mode-icon-btn svg { width: 19px; height: 19px; }
  .pzl-zoom-btn { width: 40px; height: 40px; font-size: 18px; }
  .pzl-zoom-reset-btn { width: 40px; height: 40px; font-size: 9px; }
}

/* ==========================================
   スマホ（600px 以下）：右パネルを下に回す
========================================== */
@media (max-width: 600px) {
  .pzl-content { flex-direction: column; }
  .pzl-right { width: 100%; max-height: 34vh; }
  .pzl-right-tray { grid-template-columns: repeat(3, 1fr); }
}
