/*
 * Copyright (c) 2026 Kidsplates/UsenVideoCallApp
 * Created: 2026-05-24
 * Description: 木製おもちゃ風デザインシステムとUIスタイル
 */

@import url('https://fonts.googleapis.com/css2?family=Kosugi+Maru&family=Outfit:wght@500;700&display=swap');

:root {
  --font-family: 'Kosugi Maru', 'Outfit', sans-serif;
  
  /* カラーパレット - 木製おもちゃ風 */
  --bg-color: #f7f1e3;          /* 温かみのある背景色（白木風） */
  --board-bg: #eddcb9;        /* 木製ボードの背景色 */
  --board-border: #c8a261;    /* 木製フレームのフチ色 */
  --text-main: #5d4037;       /* ダークブラウン（文字色） */
  --text-light: #8d6e63;      /* ライトブラウン（補助テキスト） */
  --white: #ffffff;
  
  /* ボタンと要素の3Dシャドウ効果 */
  --shadow-3d: 0 8px 0 #b38f4f, 0 12px 20px rgba(0, 0, 0, 0.15);
  --shadow-btn: 0 6px 0 #d7ccc8, 0 10px 15px rgba(93, 64, 55, 0.15);
  --shadow-active: 0 2px 0 #d7ccc8, 0 4px 6px rgba(93, 64, 55, 0.1);
  --shadow-wood-inset: inset 0 4px 8px rgba(0, 0, 0, 0.15);
  
  /* トランジション */
  --transition-fast: 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --transition-normal: 0.3s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
}

/* スクロールバーのカスタマイズ */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
  background: var(--board-border);
  border-radius: 5px;
}

/* メインコンテナ */
#app-container {
  width: 100%;
  max-width: 100%;
  min-height: 95vh;
  padding: 10px 15px;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ヘッダー */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  background: var(--white);
  padding: 12px 24px;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
  border: 4px solid var(--board-bg);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.logo-icon {
  font-size: 2rem;
  animation: bounce 2s infinite ease-in-out;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.controls-header {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* 木製ボタンの基本スタイル */
.wood-btn {
  background: var(--white);
  color: var(--text-main);
  border: 4px solid var(--text-main);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-btn);
  transition: var(--transition-fast);
  transform: translateY(-4px);
  user-select: none;
}

.wood-btn:hover {
  transform: translateY(-2px);
}

.wood-btn:active {
  transform: translateY(2px);
  box-shadow: var(--shadow-active);
}

.wood-btn.small {
  padding: 6px 12px;
  font-size: 0.9rem;
  border-width: 3px;
  border-radius: 12px;
}

.wood-btn.primary {
  background: #ffb077;
  color: var(--white);
}

.wood-btn.secondary {
  background: #a8d8ea;
}

.wood-btn.accent {
  background: #ffd15c;
}

/* 画面セクション */
.screen {
  display: none;
  flex: 1;
  animation: fadeIn 0.4s ease-out;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* タイトル画面 */
#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
}

.title-card {
  background: var(--white);
  padding: 40px;
  border-radius: 32px;
  border: 8px solid var(--board-border);
  box-shadow: 0 15px 30px rgba(93, 64, 55, 0.15);
  max-width: 600px;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* 木製ボード風の背景装飾 */
.title-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(90deg, rgba(237, 220, 185, 0.05) 0px, rgba(237, 220, 185, 0.05) 20px, rgba(200, 162, 97, 0.05) 20px, rgba(200, 162, 97, 0.05) 40px);
  pointer-events: none;
}

.main-logo-image {
  max-width: 250px;
  height: auto;
  margin-bottom: 20px;
  filter: drop-shadow(0 8px 0 rgba(0,0,0,0.1));
}

.title-text-group {
  margin-bottom: 30px;
}

.title-sub {
  font-size: 1.2rem;
  letter-spacing: 2px;
  color: var(--text-light);
  margin-bottom: 5px;
  font-weight: bold;
}

.title-main {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--text-main);
  text-shadow: 2px 2px 0 var(--board-bg);
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 320px;
  margin: 0 auto;
}

.menu-list .wood-btn {
  font-size: 1.25rem;
  padding: 16px 24px;
  justify-content: center;
}

.menu-list .btn-icon {
  font-size: 1.5rem;
}

/* ゲームエリアレイアウト */
.game-layout {
  display: flex;
  gap: 24px;
  flex: 1;
  align-items: flex-start;
  width: 100%;
}

.map-section {
  flex: none;
  width: 1800px;
  height: 1800px;
  min-height: 1800px;
  background: var(--board-bg);
  border: 10px solid var(--board-border);
  border-radius: 32px;
  padding: 15px;
  box-shadow: var(--shadow-wood-inset), 0 10px 25px rgba(0, 0, 0, 0.08);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-section {
  position: fixed;
  top: 120px;
  right: 40px;
  width: 400px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 15px 35px rgba(93, 64, 55, 0.25), 0 5px 15px rgba(0,0,0,0.1);
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

/* つかめるヘッダーのカーソル */
.control-section .panel-title {
  cursor: move;
  user-select: none;
}

/* 日本地図コンテナ */
.map-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 20px;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-container svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 16px rgba(93, 64, 55, 0.12));
}

/* SVG都道府県ポリゴン基本スタイル */
.prefecture {
  cursor: pointer;
  transition: filter 0.15s ease, fill 0.3s ease;
}

.prefecture polygon, .prefecture path {
  stroke: var(--text-main);
  stroke-width: 1.2px;
  stroke-linejoin: round;
  fill: var(--pref-color, #e0e0e0);
  transition: fill 0.25s ease, stroke 0.25s, stroke-width 0.25s;
}

.prefecture:hover {
  filter: brightness(1.03) drop-shadow(0 4px 8px rgba(93,64,55,0.25));
}

/* クイズ出題中の強調表示（ネオンのように強く発光） */
.prefecture.highlight {
  filter: drop-shadow(0 0 8px #ff3f34) drop-shadow(0 0 16px #ff3f34) !important;
}

.prefecture.highlight polygon, .prefecture.highlight path {
  stroke: #ffffff !important;
  stroke-width: 3px !important;
  animation: pulse-svg-color 0.8s infinite alternate ease-in-out;
}

/* パズルドラッグ間違い時の強調表示（赤く発光・点滅） */
.prefecture.highlight-error {
  filter: drop-shadow(0 0 8px #ff4757) drop-shadow(0 0 16px #ff4757) !important;
}

.prefecture.highlight-error polygon, .prefecture.highlight-error path {
  stroke: #ffffff !important;
  stroke-width: 3px !important;
  animation: pulse-svg-error 0.4s infinite alternate ease-in-out;
}

/* クイズモード中に「光っていない（未正解）」の都道府県を薄暗くしてコントラストを劇的に上げる */
.geolonia-svg-map.quiz-mode-active .prefecture:not(.highlight):not(.completed) {
  opacity: 0.4;
  filter: grayscale(0.3) brightness(0.9);
}

/* パズル未配置の半透明ガイド枠 */
.prefecture.pref-slot polygon, .prefecture.pref-slot path {
  fill: rgba(255, 255, 255, 0.25) !important;
  stroke: rgba(93, 64, 55, 0.4) !important;
  stroke-width: 1.2px !important;
  stroke-dasharray: 4, 4;
}

.prefecture.pref-slot.drag-over polygon, .prefecture.pref-slot.drag-over path {
  fill: rgba(149, 225, 211, 0.5) !important;
  stroke: var(--text-main) !important;
  stroke-dasharray: none !important;
  stroke-width: 2.2px !important;
}

/* 都道府県名テキストラベル */
.pref-label {
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 900;
  fill: var(--text-main);
  pointer-events: none;
  text-shadow: 1.5px 1.5px 0px #fff, -1.5px -1.5px 0px #fff, 1.5px -1.5px 0px #fff, -1.5px 1.5px 0px #fff, 0px 1.5px 0px #fff, 0px -1.5px 0px #fff, 1.5px 0px 0px #fff, -1.5px 0px 0px #fff;
  user-select: none;
  text-anchor: middle;
}

/* パズルピースのドラッグ要素（画面下のトレイまたはサイドバー） */
.puzzle-tray {
  background: var(--white);
  border: 4px solid var(--board-border);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.05);
}

.puzzle-piece {
  padding: 8px 14px;
  background: var(--white);
  border: 3px solid var(--text-main);
  border-radius: 12px;
  font-weight: 700;
  cursor: grab;
  user-select: none;
  box-shadow: 0 4px 0 var(--text-main);
  transition: transform 0.1s;
}

.puzzle-piece:active {
  cursor: grabbing;
}

/* 操作パネル情報カード */
.info-panel {
  background: var(--white);
  border: 6px solid var(--board-border);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 8px 20px rgba(93, 64, 55, 0.08);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.panel-title {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--board-bg);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* クイズ用UI */
.quiz-question-box {
  background: #fbf8f3;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  border: 3px solid var(--board-bg);
  text-align: center;
}

.quiz-question-box h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.quiz-hint {
  font-size: 0.9rem;
  color: var(--text-light);
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.option-btn {
  font-size: 1.1rem;
  padding: 14px;
  justify-content: center;
}

/* クイズ結果/進捗 */
.game-progress {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-weight: bold;
}

.progress-bar-container {
  height: 14px;
  background: #efebe9;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--text-main);
  margin-bottom: 20px;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: #95e1d3;
  transition: width 0.3s ease;
}

/* パズル用地方選択UI */
.region-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.region-btn {
  justify-content: center;
  font-size: 0.95rem;
}

/* 図鑑モード用UI */
.encyclopedia-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-light);
  text-align: center;
  gap: 16px;
  padding: 40px 10px;
}

.encyclopedia-placeholder .icon {
  font-size: 4rem;
  opacity: 0.5;
}

.detail-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.3s ease-out;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.detail-name-group {
  display: flex;
  flex-direction: column;
}

.detail-kana {
  font-size: 0.9rem;
  color: var(--text-light);
  font-weight: bold;
}

.detail-name {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--text-main);
}

.detail-region-badge {
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: bold;
  border: 2px solid var(--text-main);
}

.detail-row {
  background: #fbf8f3;
  border: 2px solid var(--board-bg);
  border-radius: 12px;
  padding: 12px;
}

.detail-label {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: bold;
  margin-bottom: 4px;
}

.detail-val {
  font-size: 1rem;
  font-weight: bold;
}

.detail-illustration {
  align-self: center;
  max-width: 150px;
  height: 150px;
  border-radius: 16px;
  object-fit: cover;
  border: 4px solid var(--board-border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  margin-top: 10px;
  background-color: #fff;
}

/* モーダルポップアップ (結果・設定など) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(93, 64, 55, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--white);
  border: 8px solid var(--board-border);
  border-radius: 32px;
  max-width: 500px;
  width: 100%;
  padding: 32px;
  text-align: center;
  box-shadow: 0 15px 30px rgba(0,0,0,0.25);
  animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-title {
  font-size: 1.8rem;
  font-weight: bold;
  margin-bottom: 16px;
}

.modal-body {
  margin-bottom: 24px;
}

.modal-medal {
  font-size: 4rem;
  margin: 16px 0;
  animation: bounce 1.5s infinite ease-in-out;
}

/* 設定モーダル用 */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px dashed var(--board-bg);
}

.setting-row span {
  font-weight: bold;
}

/* 切り替えスイッチ */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--board-bg);
  transition: .4s;
  border: 3px solid var(--text-main);
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: var(--text-main);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #95e1d3;
}

input:checked + .slider:before {
  transform: translateX(26px);
}

/* アニメーション */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.8) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 4px 0 rgba(93, 64, 55, 0.3); }
  100% { transform: scale(1.05); box-shadow: 0 8px 12px rgba(255, 63, 52, 0.4); }
}

@keyframes pulse-svg {
  0% { stroke-width: 1.5px; }
  100% { stroke-width: 3.5px; }
}

@keyframes pulse-svg-color {
  0% { fill: #fff200 !important; }
  100% { fill: #ff4757 !important; }
}

@keyframes pulse-svg-error {
  0% { fill: #ffffff !important; }
  100% { fill: #ff4757 !important; }
}

/* 苦手リストスタイル */
.mistake-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fbf8f3;
  border: 3px solid var(--board-bg);
  border-radius: 16px;
  padding: 12px 18px;
  transition: transform 0.15s ease;
}

.mistake-item:hover {
  transform: scale(1.015);
}

.mistake-info {
  display: flex;
  flex-direction: column;
}

.mistake-name {
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--text-main);
}

.mistake-count {
  font-size: 0.85rem;
  color: #ff4757;
  font-weight: bold;
  margin-top: 2px;
}

.mistake-actions {
  display: flex;
  gap: 8px;
}

/* レスポンシブデザイン */
@media (max-width: 900px) {
  #app-container {
    padding: 10px;
    padding-bottom: 80px; /* 全体の下部余白 */
  }
  
  .game-layout {
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding-bottom: 48vh; /* 下部パネルの高さ分だけ地図の下部に余白を空ける */
  }
  
  /* スマホでの通常時の地図サイズ：画面幅にすっぽり収める */
  .map-section {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    min-height: auto !important;
    border-width: 6px;
    border-radius: 20px;
    padding: 8px;
    overflow: hidden; /* 通常時はスクロールさせない */
  }

  /* ズームボタンが押された時の地図サイズ：拡大してドラッグスクロール可能にする */
  .map-section.zoomed {
    width: 1000px !important;
    height: 1000px !important;
    min-height: 1000px !important;
    max-width: none !important;
    aspect-ratio: auto !important;
  }

  /* SVGマップを親コンテナ（.map-section）のサイズに完全に追従させる */
  .geolonia-svg-map {
    width: 100% !important;
    height: 100% !important;
    display: block;
  }

  /* スマホ時はズーム切り替えボタンを表示する */
  #btn-zoom-toggle {
    display: flex !important;
  }
  
  /* コントロールパネルを画面下部に固定して追従させる */
  .control-section {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    top: auto !important;
    right: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 44vh !important; /* 画面下部44%に拡張 */
    max-height: 44vh !important;
    box-shadow: 0 -8px 25px rgba(93, 64, 55, 0.2) !important;
    margin-top: 0 !important;
    z-index: 90 !important;
    transform: none !important; /* ドラッグ移動のリセット */
    border-radius: 28px 28px 0 0 !important; /* 上の角だけ丸める */
    border: none !important;
    border-top: 8px solid var(--board-border) !important;
    overflow-y: auto !important;
  }
  
  .info-panel {
    border: none !important;
    border-radius: 0 !important;
    padding: 6px 12px 10px 12px !important; /* パディングを極限まで削減 */
    min-height: 100%;
  }
  
  .panel-title {
    cursor: default !important; /* スマホではドラッグ不可にする */
    margin-bottom: 4px !important;
    font-size: 0.9rem !important; /* 文字サイズ縮小 */
    padding-bottom: 4px !important;
  }

  /* クイズ・問題ボックスの縮小 */
  .quiz-question-box {
    padding: 4px 8px !important;
    margin-bottom: 4px !important;
    border-width: 2px !important;
  }
  
  .quiz-question-box h3 {
    font-size: 0.85rem !important;
    margin-bottom: 1px !important;
  }
  
  .quiz-hint {
    font-size: 0.7rem !important;
  }

  /* クイズ進捗バーの縮小 */
  .game-progress {
    margin-bottom: 2px !important;
    font-size: 0.75rem !important;
  }
  
  .progress-bar-container {
    height: 5px !important;
    margin-bottom: 4px !important;
    border-width: 1px !important;
  }

  .options-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  
  .option-btn {
    font-size: 0.8rem !important; /* ボタン内テキスト縮小 */
    padding: 6px !important;
    border-width: 2px !important;
    border-radius: 10px !important;
  }

  /* パズルピースのトレイの高さを制限 */
  .puzzle-tray {
    max-height: 90px !important; /* トレイの最大高さを削減 */
    padding: 4px !important;
    gap: 4px !important;
  }
  
  .puzzle-piece {
    padding: 4px 6px !important;
    font-size: 0.8rem !important;
    border-width: 2px !important;
    border-radius: 8px !important;
  }

  /* 図鑑のイラストとレイアウトの調整（高さを抑えてスクロール不要にする） */
  .detail-card {
    flex-direction: row !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px !important;
  }
  
  .detail-header {
    width: 100%;
    margin-bottom: 0 !important;
  }

  .detail-illustration {
    max-width: 50px !important; /* イラストの縮小 */
    height: 50px !important;
    margin-top: 0 !important;
    border-width: 2px !important;
    border-radius: 8px !important;
  }
  
  .detail-name-group {
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
  }

  .detail-name {
    font-size: 1.1rem !important; /* 県名テキスト縮小 */
  }
  
  .detail-kana {
    font-size: 0.7rem !important; /* フリガナテキスト縮小 */
  }
  
  .detail-region-badge {
    padding: 2px 6px !important;
    font-size: 0.65rem !important;
  }

  .detail-row {
    flex: 1;
    min-width: 80px;
    padding: 3px 6px !important; /* 詳細情報マージン削減 */
    border-radius: 8px !important;
  }
  
  .detail-label {
    font-size: 0.6rem !important;
    margin-bottom: 1px !important;
  }
  
  .detail-val {
    font-size: 0.75rem !important;
  }
}

/* スマホのタッチドラッグ用のスタイル */
.touch-dragging {
  opacity: 0.9 !important;
  transform: scale(1.15) !important;
  box-shadow: 0 10px 25px rgba(0,0,0,0.35) !important;
  background-color: var(--white) !important;
  color: var(--text-main) !important;
  border: 3px solid var(--text-main) !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 8px 14px !important;
  z-index: 9999 !important;
}
