
/* ===== リセット & 基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'BIZ UDGothic', 'M PLUS Rounded 1c', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: #f0f4f8;
  color: #1e3a5f;
}

/* ===== レイアウト ===== */
.fom-app {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 1fr 280px;
  height: 100vh;
  gap: 0;
}

/* ===== ヘッダー ===== */
#fom-header {
  grid-column: 1 / -1;
  background: #1e3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
#fom-header h1 { font-size: 17px; font-weight: 700; flex: 1; }
#fom-header .fom-mode-badge {
  background: #d4af37; color: #1e3a5f; font-size: 12px;
  font-weight: 700; padding: 3px 10px; border-radius: 12px;
}

/* ===== 左パネル：設定 ===== */
#fom-setup-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(30,58,95,0.3);
  width: 320px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  z-index: 500;
}
#fom-setup-panel-overlay {
  position: fixed; inset: 0;
  background: rgba(10,20,40,0.55);
  z-index: 499;
}
#fom-setup-panel.hidden { display: none !important; }
#fom-setup-panel-overlay.hidden { display: none !important; }
#fom-settings-btn {
  position: fixed;
  top: 60px; left: 12px;
  background: #1e3a5f; color: #fff;
  border: none; border-radius: 10px;
  padding: 8px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; z-index: 100;
  box-shadow: 0 2px 8px rgba(30,58,95,0.3);
}
#fom-settings-btn:hover { background: #2a4f82; }
.fom-panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid #eef0f5;
  flex-shrink: 0;
}
.fom-panel-section h3 {
  font-size: 12px; font-weight: 700; color: #7a8fa6;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px;
}

/* モード切替 */
.fom-mode-toggle {
  display: flex; gap: 4px; margin-bottom: 6px;
}
.fom-mode-btn {
  flex: 1; padding: 7px; border: 2px solid #dde3ec; border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 600;
  color: #7a8fa6; transition: all 0.15s;
}
.fom-mode-btn.active {
  border-color: #1e3a5f; background: #1e3a5f; color: #fff;
}

/* 食品チェックリスト */
.food-icon { font-size: 20px; width: 28px; text-align: center; }
.food-label { font-size: 13px; font-weight: 600; flex: 1; }

/* アコーディオン */

/* 開始ボタン */
.fom-start-btn {
  width: 100%; padding: 10px; border: none; border-radius: 10px;
  background: #1e3a5f; color: #fff; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background 0.15s; margin-top: 4px;
}
.fom-start-btn:hover { background: #2a4f82; }
.fom-reset-btn {
  width: 100%; padding: 8px; border: 1.5px solid #dde3ec; border-radius: 10px;
  background: #fff; color: #7a8fa6; font-size: 13px; font-weight: 600;
  cursor: pointer; margin-top: 6px; transition: all 0.15s;
}
.fom-reset-btn:hover { border-color: #e74c3c; color: #e74c3c; }

/* 提出状況 */
.fom-submit-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
}
.fom-submit-cell {
  padding: 4px; text-align: center; font-size: 11px; font-weight: 700;
  border-radius: 5px; border: 1px solid #eef0f5; color: #7a8fa6; cursor: default;
}
.fom-submit-cell.submitted { background: #1e3a5f; color: #fff; border-color: #1e3a5f; }
.fom-submit-cell.current { background: #d4af37; color: #1e3a5f; border-color: #d4af37; }

/* ===== 地図エリア ===== */
#fom-map-area {
  position: relative; overflow: hidden; background: #dae8f5;
}
#fom-mapWrapper {
  width: 100%; height: 100%; position: relative; overflow: hidden; cursor: grab;
}
#fom-mapWrapper.panning { cursor: grabbing; }
#fom-mapContainer {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
}
#fom-mapSvg {
  display: block; overflow: visible;
}

.hidden { display: none !important; }

/* ドロップゾーン */
.fom-drop-zone {
  fill: #b8d4e8; stroke: #6fa3c7; stroke-width: 1;
  transition: fill 0.2s;
  cursor: pointer;
}
.fom-drop-zone:hover { fill: #9ec4dd; }
.fom-drop-zone.has-food { fill: #d4e8b8; stroke: #7ab87a; }
.fom-drop-zone.drag-over { fill: #ffe89e; stroke: #d4af37; stroke-width: 2; }

/* 食品アイコン（SVG上に重ねる） */
.placed-food-icon {
  font-size: 16px; cursor: pointer; pointer-events: all;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  transition: transform 0.1s;
}
.placed-food-icon:hover { transform: scale(1.2); }

/* ズームコントロール */
#fom-zoom-controls {
  position: absolute; bottom: 12px; right: 12px;
  display: flex; flex-direction: column; gap: 4px; z-index: 10;
}
.zoom-btn {
  width: 34px; height: 34px; border: none; border-radius: 8px;
  background: rgba(255,255,255,0.9); box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-size: 18px; font-weight: 700; cursor: pointer; color: #1e3a5f;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: #fff; }

/* 活動名表示 */
#fom-activity-label {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(30,58,95,0.9); color: #fff; padding: 5px 14px;
  border-radius: 20px; font-size: 13px; font-weight: 700;
  pointer-events: none; z-index: 10; white-space: nowrap;
}

/* ドラッグゴースト */
#fom-dragGhost {
  position: fixed; pointer-events: none; z-index: 9999;
  display: none; transform: translate(-50%, -50%);
  font-size: 32px;
}

/* ===== 右パネル ===== */
#fom-result-panel {
  background: #fff;
  border-left: 1px solid #dde3ec;
  overflow-y: auto;
}

/* タブ */
.fom-tab-bar {
  display: flex; border-bottom: 1px solid #eef0f5;
}
.fom-tab {
  flex: 1; padding: 10px 4px; font-size: 12px; font-weight: 700;
  text-align: center; cursor: pointer; color: #7a8fa6;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.fom-tab.active { color: #1e3a5f; border-bottom-color: #1e3a5f; }

/* 食品別集計 */
.fom-food-result-item {
  padding: 10px 14px; border-bottom: 1px solid #f0f2f7;
  display: flex; flex-direction: column; gap: 4px;
}
.fom-food-result-header {
  display: flex; align-items: center; gap: 8px;
}
.fom-food-result-icon { font-size: 20px; }
.fom-food-result-name { font-size: 14px; font-weight: 700; flex: 1; }
.fom-food-result-count {
  font-size: 13px; font-weight: 700; color: #1e3a5f;
  background: #edf2fa; padding: 2px 8px; border-radius: 10px;
}
.fom-food-result-prefs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-left: 28px;
}
.fom-pref-tag {
  font-size: 11px; padding: 2px 7px; border-radius: 8px;
  background: #f0f2f7; color: #4a5568; font-weight: 600;
}

/* 都道府県詳細 */
#fom-pref-detail {
  padding: 14px;
}
#fom-pref-detail h3 {
  font-size: 16px; font-weight: 700; margin-bottom: 10px; color: #1e3a5f;
}
.pref-food-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid #f0f2f7;
}
.pref-food-row:last-child { border-bottom: none; }
.pref-food-icon { font-size: 18px; }
.pref-food-name { font-size: 13px; flex: 1; }
.pref-food-count {
  font-size: 13px; font-weight: 700; color: #1e3a5f;
}

/* ステータスバー */
#fom-status-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(30,58,95,0.85); color: #fff; padding: 6px 12px;
  font-size: 12px; display: flex; gap: 16px; align-items: center;
  pointer-events: none;
}
.status-item { display: flex; align-items: center; gap: 5px; }
.status-badge {
  background: rgba(255,255,255,0.2); padding: 1px 7px; border-radius: 8px;
  font-weight: 700;
}

/* 凡例 */
.legend-section { padding: 12px 14px; }
.legend-section h4 { font-size: 11px; font-weight: 700; color: #7a8fa6; margin-bottom: 8px; }
.fom-legend-item {
  display: flex; align-items: center; gap: 8px; padding: 4px 0;
  font-size: 12px;
}
.fom-legend-color {
  width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0;
}

/* スクリーン切替 */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; height: 100%; }

/* 児童入力パネル */
#fom-student-input {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #fff; border-radius: 16px; padding: 28px 32px;
  box-shadow: 0 8px 32px rgba(30,58,95,0.2); z-index: 100;
  display: none; flex-direction: column; align-items: center; gap: 16px;
  min-width: 280px;
}
#fom-student-input.show { display: flex; }
#fom-student-input h2 { font-size: 18px; font-weight: 700; color: #1e3a5f; }
#fom-student-input p { font-size: 14px; color: #7a8fa6; text-align: center; }
#fom-num-input {
  font-size: 32px; font-weight: 700; width: 120px; text-align: center;
  padding: 8px; border: 2px solid #dde3ec; border-radius: 12px;
  color: #1e3a5f;
}
#fom-num-input:focus { outline: none; border-color: #1e3a5f; }
#fom-join-btn {
  padding: 10px 32px; background: #1e3a5f; color: #fff; border: none;
  border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer;
}
#fom-join-btn:hover { background: #2a4f82; }

/* 食品選択パレット */
#fom-food-palette {
  display: none;
  flex-direction: column; gap: 4px;
  padding: 8px 12px;
  overflow-y: auto;
  flex: 1;
  border-top: 1px solid #dde3ec;
  margin-top: 4px;
}
#fom-food-palette.show { display: flex; }
.fom-palette-item {
  display: flex; align-items: center; gap: 10px;
  cursor: grab; padding: 7px 10px; border-radius: 8px;
  border: 1.5px solid #eef0f5; background: #fff; user-select: none;
  transition: all 0.12s;
}
.fom-palette-item:hover { border-color: #1e3a5f; background: #edf2fa; }
.fom-palette-item.dragging { opacity: 0.5; }
.fom-palette-emoji { font-size: 20px; width: 24px; text-align: center; flex-shrink: 0; }
.fom-palette-name { font-size: 13px; font-weight: 600; color: #1e3a5f; flex: 1; }

/* 提出ボタン */
#fom-submit-btn {
  position: absolute; bottom: 8px; right: 12px;
  background: #d4af37; color: #1e3a5f; border: none; border-radius: 10px;
  padding: 8px 20px; font-size: 14px; font-weight: 700; cursor: pointer;
  z-index: 11; display: none;
  box-shadow: 0 2px 8px rgba(212,175,55,0.4);
}
#fom-submit-btn.show { display: block; }
#fom-submit-btn:hover { background: #b8941f; }

/* 吹き出し */
.fom-tooltip {
  position: fixed; background: rgba(30,58,95,0.9); color: #fff;
  padding: 6px 12px; border-radius: 8px; font-size: 12px;
  pointer-events: none; z-index: 1000; display: none;
  transform: translate(-50%, -120%);
}

/* マップモード切替タブ（先生画面） */
.view-tabs {
  display: flex; padding: 8px 8px 0;
}
.view-tab {
  padding: 6px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
  color: #7a8fa6; border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0; transition: all 0.12s;
}
.view-tab.active { color: #1e3a5f; background: #edf2fa; }

/* ===== 先生設定ポップアップ ===== */
#fom-setup-overlay {
  position: fixed; inset: 0;
  background: rgba(10,20,40,0.55);
  z-index: 499;
  display: none;
}
#fom-setup-overlay.show { display: block; }

#fom-setup-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(30,58,95,0.3);
  width: 320px;
  max-height: 82vh;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  z-index: 500;
}
#fom-setup-panel.show { display: flex; }

.fom-setup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: #1e3a5f;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}
.fom-setup-header span { color: #d4af37; font-size: 14px; font-weight: 700; }
.fom-setup-header button {
  background: none; border: none; color: #fff;
  font-size: 18px; cursor: pointer; line-height: 1;
}

/* ステッパー（人数設定） */
.fom-stepper {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.fom-step-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: #edf2fa; border: 1.5px solid #ccd3de;
  font-size: 18px; font-weight: 700; cursor: pointer; color: #1e3a5f;
  display: flex; align-items: center; justify-content: center;
}
.fom-step-btn:hover { background: #1e3a5f; color: #fff; }
.fom-stepper input[type=number] {
  width: 60px; text-align: center; font-size: 18px; font-weight: 700;
  border: 1.5px solid #ccd3de; border-radius: 8px; padding: 4px;
}

/* PIN表示 */
.fom-pin-display {
  background: #1e3a5f; border-radius: 12px;
  padding: 12px; text-align: center; margin-bottom: 12px;
}
.fom-pin-label { color: #9aaec8; font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.fom-pin-number {
  color: #d4af37; font-size: 32px; font-weight: 700;
  letter-spacing: 4px; font-family: monospace;
}

/* QRコード */
#fom-qr-container { text-align: center; margin-bottom: 10px; }
#fom-qr-container canvas, #fom-qr-container img { border-radius: 8px; }

/* 児童URL */
.fom-student-url-area { margin-top: 8px; }
.fom-student-url-area input {
  width: 100%; font-size: 11px; padding: 6px 8px;
  border: 1px solid #ccd3de; border-radius: 6px;
  color: #4a5568; background: #f7f9fc;
}
.fom-student-url-area button {
  margin-top: 6px; width: 100%; padding: 8px;
  background: #edf2fa; border: 1.5px solid #1e3a5f;
  border-radius: 8px; color: #1e3a5f; font-size: 12px;
  font-weight: 700; cursor: pointer;
}

/* 設定ボタン（右上固定） */
#fom-settings-btn {
  position: fixed; top: 14px; left: 14px;
  background: #1e3a5f; color: #fff;
  border: none; border-radius: 10px;
  padding: 8px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; z-index: 100;
  box-shadow: 0 2px 8px rgba(30,58,95,0.3);
  display: none;
}
#fom-settings-btn:hover { background: #2a4f82; }

/* 先生画面グリッド（ヘッダーなし・2列） */
.fom-host {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr;
  height: 600px;
  gap: 0;
}
#fom-map-area {
  position: relative; overflow: hidden; background: #dae8f5;
}
#fom-result-panel {
  background: #fff; border-left: 1px solid #dde3ec;
  overflow-y: auto; display: flex; flex-direction: column;
}

/* ===== 児童画面 ===== */
.fom-student {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #2a4f82 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.fom-student-card {
  background: #fff; border-radius: 20px;
  padding: 32px 24px; width: 100%; max-width: 480px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.25);
  text-align: center;
}
.fom-student-card h2 {
  font-size: 20px; font-weight: 700; color: #1e3a5f; margin-bottom: 8px;
}
.fom-student-logo { font-size: 48px; margin-bottom: 12px; }
.fom-student-sub {
  font-size: 14px; color: #6b7280; margin-bottom: 20px; line-height: 1.6;
}
.fom-pin-input {
  width: 100%; font-size: 36px; font-weight: 700; text-align: center;
  letter-spacing: 6px; border: 2.5px solid #ccd3de; border-radius: 12px;
  padding: 12px; color: #1e3a5f; margin-bottom: 16px;
  font-family: monospace;
}
.fom-pin-input:focus { border-color: #1e3a5f; outline: none; }
.fom-number-input {
  width: 100%; font-size: 40px; font-weight: 700; text-align: center;
  border: 2.5px solid #ccd3de; border-radius: 12px;
  padding: 12px; color: #1e3a5f; margin-bottom: 16px;
}
.fom-number-input:focus { border-color: #1e3a5f; outline: none; }
.fom-student-btn {
  width: 100%; padding: 14px; border-radius: 12px;
  font-size: 16px; font-weight: 700; cursor: pointer; border: none;
  margin-top: 4px;
}
.fom-btn-primary { background: #1e3a5f; color: #fff; }
.fom-btn-primary:hover { background: #2a4f82; }
.fom-btn-secondary { background: #edf2fa; color: #1e3a5f; border: 1.5px solid #1e3a5f; }
.fom-btn-submit { background: #d4af37; color: #1e3a5f; font-size: 18px; margin-top: 12px; }
.fom-btn-submit:hover { background: #b8941f; }
.fom-student-msg {
  font-size: 13px; color: #e74c3c; margin-top: 10px; min-height: 18px;
}

/* 児童地図画面 */
.fom-student-map-screen {
  max-width: 100%; padding: 12px; text-align: left;
}
.fom-student-map-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding: 8px 12px;
  background: #1e3a5f; border-radius: 10px; color: #fff;
  font-size: 14px; font-weight: 700;
}
.fom-student-hint { font-size: 12px; color: #9aaec8; font-weight: 400; }

/* 児童食品パレット（横スクロール） */
#fom-student-palette-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 10px; padding-bottom: 4px;
}
#fom-student-palette {
  display: flex; gap: 8px; padding: 4px 0;
  width: max-content;
}
.fom-student-food-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 10px; border-radius: 10px;
  border: 2.5px solid #eef0f5; background: #fff;
  cursor: pointer; min-width: 56px; flex-shrink: 0;
  transition: all 0.12s;
}
.fom-student-food-btn.selected {
  border-color: #1e3a5f; background: #edf2fa;
}
.fom-student-food-btn .emoji { font-size: 22px; }
.fom-student-food-btn .name { font-size: 10px; font-weight: 700; color: #1e3a5f; }

/* 児童用地図ラッパー */
#fom-student-map-wrap {
  width: 100%; height: 320px;
  border-radius: 12px; overflow: hidden; background: #dae8f5;
  position: relative; margin-bottom: 10px;
  touch-action: none;
}
#fom-student-mapWrapper { width: 100%; height: 100%; position: relative; overflow: hidden; }
#fom-student-mapContainer { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

/* 選択中食品インジケーター */
#fom-student-selected-food {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: #edf2fa;
  border-radius: 10px; margin-bottom: 8px;
  border: 1.5px solid #1e3a5f; font-size: 14px; font-weight: 700;
}
.fom-deselect-hint { font-size: 11px; color: #6b7280; font-weight: 400; }

/* 配置済みリスト */
#fom-student-placed-list {
  max-height: 100px; overflow-y: auto;
  margin-bottom: 8px;
}
.fom-placed-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: #f7f9fc;
  border-radius: 8px; font-size: 13px; margin-bottom: 4px;
}
.fom-placed-item button {
  background: none; border: none; color: #e74c3c; cursor: pointer;
  font-size: 16px; padding: 0 4px;
}

/* 完了画面 */
.fom-done-icon { font-size: 72px; margin-bottom: 16px; }

/* ポーリング状態インジケーター */
.fom-polling-dot {
  display: inline-block; width: 8px; height: 8px;
  background: #27ae60; border-radius: 50%;
  margin-right: 6px; animation: fom-pulse 1.5s infinite;
}
@keyframes fom-pulse {
  0%,100% { opacity: 1; } 50% { opacity: 0.3; }
}

/* 提出状況タブ */
#fom-submit-grid-wrap { padding: 12px; }
.fom-submit-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
}
.fom-submit-cell {
  aspect-ratio: 1; border-radius: 6px;
  background: #1e3a5f; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.fom-submit-cell.submitted { background: #27ae60; }
.fom-submit-cell.active { background: #d4af37; color: #1e3a5f; }
