/* モバイルデバッグトグル（デフォルト非表示） */
.mobile-debug-toggle {
  display: none;
}

/* モバイル用レイアウト調整（タブレット・スマホ全対応） */
@media (max-width: 768px) {
   /* スクロール可能に */
  html, body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    -ms-touch-action: manipulation;
  }
  
  body {
    font-size: 11px;
    /* モバイルコントローラーの高さ分の余白 */
    padding-bottom: 150px;
  }

  .wrap {
    padding: 6px;
    gap: 6px;
  }

  .panel {
    padding: 6px;
    margin-bottom: 8px;
    border-width: 1px;
    border-radius: 10px;
    box-shadow: none;
  }

  .section {
    padding: 5px 6px;
    gap: 3px;
    border-width: 1px;
    border-radius: 8px;
  }

  .section > strong {
    font-size: 11px;
    padding-bottom: 2px;
  }

  .rpg-stats {
    gap: 4px;
  }

  .rpg-row {
    gap: 4px;
  }

  .chip {
    padding: 4px 8px;
    border-width: 1px;
    font-size: 10px;
  }

  .status {
    padding: 4px 6px;
  }

  .project-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  /* プロジェクトボタンとToDoトリガーを縦に並べる（チップは横スクロール） */
  .projRow-wrapper {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px;
  }
  
  .projRow-wrapper .projRow {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 6px;
    align-items: center;
    padding-bottom: 2px;
  }
  
  .projRow-wrapper .projRow > * {
    flex-shrink: 0;
  }
  
  .projRow-wrapper #todoChipBtn {
    width: 100%;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 0;
    background: transparent;
    color: #fff;
    border: none;
    touch-action: manipulation;
    /* 六角形フレームは todo-badge.css で定義 */
  }
  
  /* 作業開始・集中モード・目標バーを縦に並べる（スマホ版） */
  .actions-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    margin-top: 4px;
  }
  
  .actions-row > * {
    flex-shrink: 0;
  }
  
  .actions-row-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    width: 100%;
  }
  
  .actions-row-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    width: 100%;
    flex-wrap: wrap;
  }
  
  .goal-progress-inline {
    width: 100%;
    max-width: 120px;
  }

  .subkind-inline {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 4px;
    width: 100%; /* 幅いっぱいに広げる */
  }
  
  .subkind-inline > * {
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    pointer-events: auto;
  }
  
  .subkind-inline select,
  .subkind-inline input {
    flex: 1 1 calc(50% - 2px); /* 左右に広げる: 各50% - gapの半分 */
    width: 100% !important;
    min-width: 0 !important; /* flexboxで縮小可能にする */
    box-sizing: border-box;
    padding: 3.6px 6px !important; /* 縦幅1.2倍（3px * 1.2 = 3.6px） */
    font-size: 16px !important; /* iOS Safariの自動ズームを防ぐため16px以上に設定 */
    transform: scale(0.625) !important; /* 16px * 0.625 = 10px相当の見た目 */
    transform-origin: left center !important; /* 左端を基準に縮小 */
  }

  .project-actions .subkind-inline {
    display: flex !important;
    flex-direction: row;
    flex-wrap: nowrap !important;
    gap: 8px;
    width: 100%;
  }

  .project-actions .subkind-inline select,
  .project-actions .subkind-inline input {
    flex: 1 1 calc(50% - 4px);
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
    padding: 3.6px 6px !important; /* 縦幅1.2倍（3px * 1.2 = 3.6px） */
  }

  .goal-top-left {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px;
  }
  
  .goal-top-left > * {
    flex-shrink: 0;
  }

  .goalWrap {
    margin-top: 6px !important;
  }

  .goal-top-single {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  #goalInlineStartBtn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .goal-progress-inline {
    width: 100%;
  }

  .progress-bar {
    max-width: 100%;
    min-width: 0;
  }

  .goal-top-right {
    font-size: 10px;
    width: 100%;
  }

  .goal-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .goal-progress {
    width: 100%;
  }

  .goal-remaining {
    text-align: left;
  }

  .projRow {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .projRow .chip {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: fit-content;
    text-align: center;
  }

  .middle,
  .right {
    display: block;
  }

  .middle .section.condensed,
  .pie-section,
  .log-section,
  .month-pie-section,
  .chat-section,
  .communication-section,
  .skill-tree-section {
    max-height: none;
    overflow: visible;
    display: block;
  }

  .middle .section.condensed .pieWrap,
  .middle .section.condensed .todo-list,
  .pieWrap,
  .logBox,
  .loglist {
    max-height: none;
  }
 
  /* ヘッダーを固定（モバイル専用：PC用を上書き） */
  .sessionBar {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    display: flex !important;
    flex-direction: column !important;  /* PC用のflex-wrap:nowrapを上書き */
    flex-wrap: wrap !important;
    gap: 4px !important;
    padding: 6px 8px !important;
    align-items: flex-start !important;  /* PC用のcenterを上書き */
    width: 100vw !important;  /* 画面幅いっぱいに */
    max-width: 100vw !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    left: 0 !important;
    right: 0 !important;
  }
  
  /* セッションバーの左側（タイトル、バージョン、人数）- モバイル専用 */
  .sessionBar-left {
    display: contents !important;  /* 中身を親に直接配置 */
  }
  
  /* タイトルを1行で表示 */
  .sessionBar h1 {
    font-size: 11px !important;
    line-height: 1.3 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    width: 100% !important;
    white-space: normal !important;  /* PC用のnowrapを上書き */
    overflow: visible !important;
    text-overflow: clip !important;
  }
  
  /* バージョン情報を1行で表示 */
  .sessionBar-left > span[id="versionTag"] {
    display: block !important;
    width: 100% !important;
    font-size: 9px !important;
  }
  
  /* 作業中人数を1行で表示 */
  .sessionBar-left > span:not([id="versionTag"]) {
    display: block !important;
    width: 100% !important;
    font-size: 10px !important;
  }
  
  /* セッションバーの右側（ボタン類）も親に直接配置 - モバイル専用 */
  .sessionBar-right {
    display: flex !important;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
  }
  
  .sessionBar-right > * {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: auto !important;
    padding: 4px 10px;
    font-size: 11px !important;
    margin: 0;
  }
  
  .sessionBar-right > select {
    display: inline-block !important;
    padding: 4px 8px;
  }
  
  /* #coinDisplay は削除済み */
  
  #bgmBtn, #sessionAuthBtn {
    padding: 5px 9px; /* ToDoボタンと同じサイズ: 5px 9px */
    font-size: 12px; /* ToDoボタンと同じサイズ: 12px */
  }
  
  #bgmTrackSelect {
    padding: 6px 10px; /* 小さく: 10.5px → 6px, 15px → 10px */
    font-size: 14px; /* 小さく: 21px → 14px */
    min-width: 56px; /* 小さく: 90px → 70px → 56px */
    max-width: 80px; /* 小さく: 135px → 100px → 80px */
    height: 32px; /* 小さく: 51px → 32px */
  }

  /* メインコンテンツ */
  .wrap {
    display: block;
    padding: 8px;
    gap: 0;
  }
  
  /* すべてのパネルを縦に並べる */
  .panel {
    padding: 8px;
    margin-bottom: 12px;
    width: 100%;
  }
  
  .section {
    padding: 6px 8px;
    gap: 4px;
    margin-bottom: 8px;
  }
  
  .section > strong {
    font-size: 12px;
    padding-bottom: 3px;
  }
  
  .chip {
    padding: 4px 8px;
    font-size: 10px;
  }
  
  /* ToDoのボタンは横長に統一（モバイル版） */
  #todoModal .todo-action-buttons {
    display: flex;
    gap: 6px;
    width: 100%;
  }
  
  #todoModal .todo-action-buttons button {
    flex: 1;
    padding: 8px 12px !important;
    font-size: 13px !important;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    min-height: auto;
    height: auto;
    line-height: 1.4;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  #todoModal .todo-action-buttons button span.chip-icon {
    font-size: 14px;
    flex-shrink: 0;
  }

  #todoModalScrollArea {
    margin-right: 0;
    padding-right: 4px;
    overflow-x: hidden;
  }

  #todoModal .todo-list {
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
  }
  
  #todoModal .todo-quick-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    font-size: 16px;
    margin-bottom: 8px;
  }
  
  #todoModalQuickInputList {
    margin-bottom: 8px;
  }
  
  .todo-card-header {
    margin-bottom: 12px;
  }
  
  .small {
    font-size: 10px;
  }
  
  .button, .mutebtn {
    padding: 5px 8px;
    font-size: 11px;
  }
  
  input, select, textarea {
    padding: 6px 8px;
    font-size: 16px; /* iOS Safariの自動ズームを防ぐため16px以上に設定 */
    transform: scale(0.6875); /* 16px * 0.6875 = 11px相当の見た目 */
    transform-origin: left center; /* 左端を基準に縮小 */
  }

  /* プロジェクト編集モーダル内は通常サイズで表示（縮小しない） */
  #editModal input,
  #editModal select,
  #editModal textarea {
    transform: none !important;
    font-size: 16px;
    padding: 10px 12px;
  }

  #editModal .subkind-edit-item input {
    font-size: 16px;
    padding: 12px 14px;
    min-height: 46px;
  }
  
  /* ToDo入力欄も16px以上に設定 */
  .todo-quick {
    font-size: 16px !important; /* iOS Safariの自動ズームを防ぐため16px以上に設定 */
    transform: scale(0.6875) !important; /* 16px * 0.6875 = 11px相当の見た目 */
    transform-origin: left center !important; /* 左端を基準に縮小 */
  }
  
  /* マップのサイズ */
  :root {
    --game-h: 300px;
  }
  
  #game {
    height: 300px;
    min-height: 300px;
  }

  /* ゲーム画面でのスクロール操作を許可（ボタンの無い領域はスワイプ優先） */
  /* Phaserのキャンバスにも直接設定することで、ブラウザのスワイプを優先 */
  .map-area {
    touch-action: pan-y;
  }
  
  /* Phaserキャンバスにも直接設定（ゲーム画面の空き領域でスワイプを許可） */
  #game > canvas {
    touch-action: pan-y;
  }
  
  /* 作業ボタンが展開中は、ページ全体のスクロールを無効化（JavaScriptでpreventDefault()を使用） */
  body.work-stick-expanded {
    overflow: hidden !important;
    touch-action: none !important;
  }
  
  body.work-stick-expanded html {
    overflow: hidden !important;
    touch-action: none !important;
  }
  
  body.work-stick-expanded #game > canvas {
    touch-action: none !important;
  }
  
  /* 操作要素は明示的にタッチ操作を保護 */
  /* 移動スティック: 常にタッチ操作を無効化 */
  .mobile-move-stick {
    touch-action: none !important;
  }
  
  /* 作業ボタン: 展開時は pan-x pan-y が必要（既存の設定を維持） */
  /* チャット関連: タッチ操作を無効化 */
  #worldChat,
  #worldChatToggle {
    touch-action: none !important;
  }
  
  /* マップズームコントロール: タッチ操作を無効化 */
  /* スマホ版: 全画面ボタンを🔎ボタンと同じサイズに揃える */
  .map-fullscreen-btn {
    width: 24px !important;
    height: 24px !important;
    font-size: 14px !important;
    line-height: 1;
    z-index: 1000;
    pointer-events: auto;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .map-fullscreen-close-btn {
    width: 40px !important;
    height: 40px !important;
    font-size: 18px !important;
    z-index: 10001;
    pointer-events: auto;
  }

  .map-zoom-control,
  .map-zoom-toggle-btn {
    touch-action: none !important;
  }

.map-area #game {
    height: 300px !important;
    min-height: 300px !important;
  }
  
  /* 各セクションの高さを固定 */
  .status {
    flex-wrap: wrap;
  }
  
  .mapCtrl {
    min-height: auto;
  }
  
  .chat {
    max-height: 250px;
    overflow-y: auto;
  }
  
  .pieWrap {
    min-height: auto;
  }
  
  .logBox {
    max-height: 250px;
  }
  
  .loglist {
    max-height: 180px;
    overflow: hidden;
  }
  
  /* ショートカットキーの説明を非表示 */
  .shortcut-section {
    display: none;
  }
  
  /* プロジェクト選択を横一列表示 */
  .projRow {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .projRow .chip {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: fit-content;
    text-align: center;
  }

  /* ==========================
     モバイル専用操作UI
  ========================== */
  /* モバイルデバッグトグル */
  .mobile-debug-toggle {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(calc(-50% - 140px), calc(-50% + 155px));
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    border: none;
    font-size: 20px;
    z-index: 100000;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    touch-action: manipulation;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .mobile-debug-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 2px 8px rgba(0,0,0,0.3);
  }
  
  /* 【移動ボタン】プレイヤーの移動操作用ジョイスティック。画面中央より左に50px、下に170px配置（中央位置基準）。 */
  .mobile-move-stick {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(calc(-50% - 50px), calc(-50% + 155px));
    width: 80px;
    height: 80px;
    z-index: 141;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    --stick-intensity: 0;
    --trail-x: 50%;
    --trail-y: 50%;
    --stick-angle: 0deg;
    --stick-saturation: 1;
  }

  .mobile-move-stick__pad {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    /* 時計グラデーションの計算 */
    /* --clock-progress: 0-1 (10分で1周) */
    /* --clock-cycle: 0, 1, 2, ... (周回数) */
    background:
      radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.08)),
      /* ベースグラデーション（常に表示、下層） */
      conic-gradient(
        from var(--stick-angle),
        rgba(249, 205, 83, 0.45),
        rgba(86, 194, 198, 0.38),
        rgba(249, 205, 83, 0.45)
      );
    /* 時計グラデーション用の疑似要素 */
    overflow: hidden;
    border: 2px solid rgba(15, 23, 42, 0.12);
    box-shadow:
      0 6px 12px rgba(15, 23, 42, 0.18),
      inset 0 3px 6px rgba(255, 255, 255, 0.45);
    filter: saturate(var(--stick-saturation));
    transition:
      background 200ms ease,
      filter 140ms ease,
      opacity 300ms ease;
  }

  .mobile-move-stick--active .mobile-move-stick__pad {
    background:
      radial-gradient(circle at var(--trail-x) var(--trail-y), rgba(255, 189, 26, 0.35), rgba(255, 255, 255, 0) 60%),
      /* ベースグラデーション（アクティブ時は少し濃く、下層） */
      conic-gradient(
        from var(--stick-angle),
        rgba(249, 205, 83, 0.55),
        rgba(86, 194, 198, 0.45),
        rgba(249, 205, 83, 0.55)
      );
  }
  
  .mobile-move-stick--active .mobile-move-stick__pad {
    box-shadow:
      0 8px 14px rgba(15, 23, 42, 0.25),
      inset 0 3px 6px rgba(255, 255, 255, 0.4);
    opacity: calc(0.55 + var(--stick-intensity) * 0.35);
  }
  
  .mobile-move-stick--active .mobile-move-stick__clock-overlay {
    /* アクティブ時の時計グラデーション（少し濃く） */
    opacity: 0.9;
  }

  /* 作業中/集中モード中はほぼ透明にする（移動ボタンがほぼ見えなくなる） */
  .mobile-move-stick--disabled {
    opacity: 0.1;
    pointer-events: none;
    transition: opacity 300ms ease;
  }
  
  .mobile-move-stick--disabled .mobile-move-stick__pad {
    background:
      radial-gradient(circle at 50% 50%, rgba(200, 200, 200, 0.05), rgba(150, 150, 150, 0.03)),
      /* ベースグラデーション（ほぼ透明なグレー） */
      conic-gradient(
        from 0deg,
        rgba(150, 150, 150, 0.05),
        rgba(120, 120, 120, 0.03),
        rgba(150, 150, 150, 0.05)
      );
    filter: grayscale(1) saturate(0);
  }
  
  .mobile-move-stick--disabled .mobile-move-stick__clock-overlay {
    /* 時計グラデーション（グレースケール）はJavaScriptで設定 */
    opacity: 0.1;
  }
  
  /* 終了時に復活する際の速度を早くする */
  .mobile-move-stick:not(.mobile-move-stick--disabled) {
    transition: opacity 150ms ease;
  }

  /* 時計グラデーション用の要素（実DOM要素） */
  .mobile-move-stick__clock-overlay {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    opacity: 0.8;
    pointer-events: none;
    z-index: 1;
    transition: background 200ms ease;
  }

  /* 内側のボーダー（::afterを使用） */
  .mobile-move-stick__pad::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.35);
    opacity: 0.85;
    pointer-events: none;
    z-index: 3;
  }

  .mobile-move-stick--pulse .mobile-move-stick__pad::after {
    animation: moveStickRipple 620ms ease-out forwards;
  }

  .mobile-move-stick__stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: transform 140ms ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.75);
    background:
      radial-gradient(circle at 28% 28%, rgba(255, 255, 255, 0.98), rgba(148, 163, 184, 0.4)),
      repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.2) 0 2px, transparent 2px 5px);
    box-shadow:
      0 4px 8px rgba(15, 23, 42, 0.22),
      inset 0 3px 6px rgba(255, 255, 255, 0.6);
  }

  .mobile-move-stick--active .mobile-move-stick__stick {
    transform: translate(-50%, -50%) scale(0.95);
  }

  @keyframes moveStickRipple {
    0% {
      opacity: 0.55;
      transform: scale(0.65);
    }
    80% {
      opacity: 0.2;
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
  }

  /* ==========================
    モバイル作業ボタン（6分割ホイール型）
    【作業ボタン】プロジェクト選択・作業開始用。画面中央より右に50px、下に170px配置（中央位置基準）。
  ========================== */
  .mobile-work-stick {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(calc(-50% + 50px), calc(-50% + 155px));
    width: 225px;
    height: 225px;
    z-index: 140;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    --active-sector-angle: 0deg;
    --active-sector-strength: 0;
    --drag-intensity: 0;
  }

  .mobile-work-stick__pad {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #F8FAFC;
    border: 12px solid #E2E8F0;
    box-shadow: 0 9px 18px rgba(15, 23, 42, 0.15);
    overflow: visible;
    transform-origin: center;
    transition:
      border-color 160ms ease,
      box-shadow 160ms ease,
      transform 220ms ease,
      opacity 180ms ease;
    will-change: transform, opacity;
  }

  .mobile-work-stick--active .mobile-work-stick__pad {
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
  }

  .mobile-work-stick__ribs {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    transition: opacity 180ms ease, transform 200ms ease;
  }

  .mobile-work-stick__rib {
    stroke: #94A3B8;
    stroke-width: 1.5;
    transition: stroke 140ms ease, stroke-width 140ms ease, filter 140ms ease;
  }

  .mobile-work-stick__rib.active {
    stroke: #2563EB;
    stroke-width: 2.6;
    filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.45));
  }

  .mobile-work-stick__labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    display: block;
    transition: opacity 180ms ease, transform 200ms ease;
  }

  .mobile-work-stick__label {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 39px;
    height: 39px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    color: rgba(15, 23, 42, 0.9);
    text-shadow: 0 2px 9px rgba(15, 23, 42, 0.35);
    transform: translate(-50%, -50%);
    transition: transform 140ms ease, color 140ms ease, opacity 140ms ease;
    opacity: 0.85;
  }

  .mobile-work-stick__label.active {
    color: #1d4ed8;
    transform: translate(-50%, -50%) scale(1.15);
    opacity: 1;
  }

  .mobile-work-stick__center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 63px;
    height: 63px;
    border-radius: 50%;
    background: #F8FAFC;
    border: 3px solid #E2E8F0;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 120ms ease-out, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
    z-index: 3;
    box-shadow: 0 3px 9px rgba(15, 23, 42, 0.1);
  }

  .mobile-work-stick__center.active {
    background: #3B82F6;
    border-color: #2563EB;
    box-shadow: 0 5px 18px rgba(59, 130, 246, 0.3);
  }

  .mobile-work-stick__center-label {
    font-size: 11px;
    font-weight: 600;
    color: rgba(30, 41, 59, 0.8);
    text-align: center;
    line-height: 1.2;
    transition: color 140ms ease, font-size 140ms ease;
  }

  .mobile-work-stick__center.active .mobile-work-stick__center-label {
    color: #fff;
    font-size: 12px;
  }

  .mobile-work-stick--working .mobile-work-stick__center {
    background: #ef4444;
    border-color: #b91c1c;
    box-shadow: 0 5px 18px rgba(239, 68, 68, 0.4);
  }

  .mobile-work-stick--working .mobile-work-stick__center-label {
    color: #fff;
  }

  .mobile-work-stick__pad::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    opacity: calc(var(--active-sector-strength) * 0.95);
    pointer-events: none;
    transition: opacity 140ms ease;
    background:
      radial-gradient(circle at 30% 35%, rgba(147, 197, 253, 0.75), transparent 55%),
      radial-gradient(circle at 68% 32%, rgba(167, 243, 208, 0.65), transparent 60%),
      radial-gradient(circle at 44% 68%, rgba(248, 250, 190, 0.65), transparent 58%);
    background-blend-mode: lighten;
    filter: blur(9px);
    mask: conic-gradient(
      from calc(var(--active-sector-angle) - 32deg),
      transparent 0deg,
      rgba(0, 0, 0, 0.95) 6deg,
      rgba(0, 0, 0, 0.95) 54deg,
      transparent 60deg
    );
    -webkit-mask: conic-gradient(
      from calc(var(--active-sector-angle) - 32deg),
      transparent 0deg,
      rgba(0, 0, 0, 0.95) 6deg,
      rgba(0, 0, 0, 0.95) 54deg,
      transparent 60deg
    );
  }

  .mobile-work-stick__pad::after {
    content: '';
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    opacity: calc(var(--active-sector-strength) * 0.9);
    pointer-events: none;
    transition: opacity 140ms ease;
    background: conic-gradient(
      from calc(var(--active-sector-angle) - 30deg),
      transparent 0deg,
      rgba(103, 232, 249, 0.95) 6deg,
      rgba(129, 199, 212, 0.95) 30deg,
      rgba(167, 243, 208, 0.95) 56deg,
      transparent 60deg
    );
    filter: blur(6px);
    mask: radial-gradient(circle, transparent calc(50% - 36px), #000 calc(50% - 30px), #000 100%);
    -webkit-mask: radial-gradient(circle, transparent calc(50% - 36px), #000 calc(50% - 30px), #000 100%);
  }

  .mobile-work-stick--preview .mobile-work-stick__center {
    transform: translate(-50%, -50%) scale(0.95);
  }

  .mobile-work-stick--collapsed .mobile-work-stick__pad::before,
  .mobile-work-stick--collapsed .mobile-work-stick__pad::after,
  .mobile-work-stick--collapsed .mobile-work-stick__ribs,
  .mobile-work-stick--collapsed .mobile-work-stick__labels,
  .mobile-work-stick--collapsed .mobile-work-stick__label {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .mobile-work-stick--collapsed .mobile-work-stick__pad {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    transform: none;
    pointer-events: none;
  }

  /* 展開中: プロジェクト選択のみに集中（スクロール無効化） */
  .mobile-work-stick:not(.mobile-work-stick--collapsed) {
    touch-action: none !important;
  }

  /* 展開前は外円領域で他のボタンのタップ判定を優先：container全体をpointer-events: noneに */
  .mobile-work-stick--collapsed {
    pointer-events: none;
    touch-action: pan-x pan-y;
  }

  /* ただし中央ボタンだけはタップ可能（展開用） */
  .mobile-work-stick--collapsed .mobile-work-stick__center {
    pointer-events: auto;
  }

  .mobile-work-stick--collapsed .mobile-work-stick__ribs,
  .mobile-work-stick--collapsed .mobile-work-stick__labels {
    transform: scale(0.85);
  }

  /* ==========================
    モバイル魔法ボタン（ジョイスティック型）
    【魔法ボタン】魔法陣展開用。画面中央、下に250px配置（移動・作業ボタンの下）。
    移動ボタンと同様の構造で、内円（スティック）をドラッグすると魔法陣の水晶が連動する。
  ========================== */
  .mobile-magic-button {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, calc(-50% + 235px));
    width: 60px;
    height: 60px;
    z-index: 142;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    --stick-x: 0px;
    --stick-y: 0px;
    --stick-intensity: 0;
    --stick-angle: 0deg;
  }

  .mobile-magic-button__pad {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(100, 150, 255, 0.3);
    box-shadow:
      0 6px 12px rgba(0, 0, 0, 0.4),
      inset 0 3px 6px rgba(255, 255, 255, 0.1),
      0 0 20px rgba(100, 150, 255, 0.2);
    transition:
      box-shadow 140ms ease,
      opacity 300ms ease;
    /* 宇宙の背景：星と暗い空 */
    background:
      /* 星（複数の小さな点） */
      radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.8) 0%, transparent 1%),
      radial-gradient(circle at 60% 20%, rgba(255, 255, 255, 0.6) 0%, transparent 1%),
      radial-gradient(circle at 80% 60%, rgba(255, 255, 255, 0.7) 0%, transparent 1%),
      radial-gradient(circle at 40% 80%, rgba(255, 255, 255, 0.5) 0%, transparent 1%),
      radial-gradient(circle at 15% 70%, rgba(255, 255, 255, 0.6) 0%, transparent 1%),
      radial-gradient(circle at 75% 25%, rgba(255, 255, 255, 0.5) 0%, transparent 1%),
      radial-gradient(circle at 90% 80%, rgba(255, 255, 255, 0.7) 0%, transparent 1%),
      radial-gradient(circle at 30% 50%, rgba(255, 255, 255, 0.4) 0%, transparent 1%),
      /* 宇宙のベース（暗い紫から黒へのグラデーション） */
      radial-gradient(circle at 50% 50%, 
        rgba(20, 10, 40, 0.6) 0%,
        rgba(10, 5, 25, 0.8) 50%,
        rgba(5, 2, 15, 0.95) 100%);
    position: relative;
    overflow: hidden;
  }

  /* 太陽と月を回転させるための疑似要素 */
  .mobile-magic-button__pad::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    transform-origin: center center;
    background:
      /* 月（左側） */
      radial-gradient(circle at 30% 50%, 
        rgba(220, 220, 255, 0.8) 0%,
        rgba(180, 180, 240, 0.6) 15%,
        rgba(140, 140, 200, 0.3) 30%,
        transparent 50%),
      /* 太陽（右側） */
      radial-gradient(circle at 70% 50%,
        rgba(255, 240, 150, 0.9) 0%,
        rgba(255, 200, 100, 0.7) 20%,
        rgba(255, 160, 80, 0.4) 35%,
        transparent 55%);
    animation: cosmos-rotate 20s linear infinite;
    pointer-events: none;
    z-index: 1;
  }

  @keyframes cosmos-rotate {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }


  .mobile-magic-button--active .mobile-magic-button__pad {
    /* アクティブ時も宇宙の背景を維持しつつ、少し明るく */
    box-shadow:
      0 8px 14px rgba(100, 150, 255, 0.3),
      inset 0 3px 6px rgba(255, 255, 255, 0.15),
      0 0 30px rgba(100, 150, 255, 0.3);
    opacity: calc(0.9 + var(--stick-intensity) * 0.1);
    filter: brightness(1.15);
  }

  /* 内側のボーダー */
  .mobile-magic-button__pad::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.35);
    opacity: 0.85;
    pointer-events: none;
    z-index: 3;
  }

  .mobile-magic-button__stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
    transition: transform 140ms ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(220, 230, 255, 0.85);
    background:
      radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.95) 0%, rgba(220, 225, 240, 0.9) 35%, rgba(170, 180, 210, 0.85) 65%, rgba(130, 140, 170, 0.8) 100%),
      radial-gradient(circle at 65% 70%, rgba(140, 150, 180, 0.35) 0%, transparent 35%),
      radial-gradient(circle at 30% 75%, rgba(160, 170, 190, 0.25) 0%, transparent 30%);
    box-shadow:
      0 0 14px rgba(200, 210, 255, 0.4),
      inset 0 2px 6px rgba(255, 255, 255, 0.7);
    z-index: 2;
  }

  /* 作業中は魔法ボタンを無効化（透明度90%、pointer-events: none） */
  .mobile-magic-button--work-active {
    opacity: 0.1;
    pointer-events: none;
    transition: opacity 300ms ease;
  }

  .mobile-magic-button--work-active .mobile-magic-button__pad {
    opacity: 0.1;
  }

  .mobile-magic-button--work-active .mobile-magic-button__stick {
    opacity: 0.1;
  }
  
  /* 終了時に復活する際の速度を早くする（移動ボタンと統一） */
  .mobile-magic-button:not(.mobile-magic-button--work-active) {
    transition: opacity 150ms ease;
  }
  
  .mobile-magic-button:not(.mobile-magic-button--work-active) .mobile-magic-button__pad {
    transition:
      box-shadow 140ms ease,
      opacity 150ms ease;
  }

  .mobile-magic-button--active .mobile-magic-button__stick {
    transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y))) scale(0.95);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 10px;
    padding-bottom: 160px;
  }
  
  .sessionBar {
    padding: 5px 6px;
  }
  
  .sessionBar h1 {
    font-size: 12px;
  }
  
  .sessionBar small {
    font-size: 9px;
  }
  
  .wrap {
    padding: 6px;
    gap: 6px;
  }

  .panel {
    padding: 6px;
    margin-bottom: 8px;
    border-width: 1px;
    border-radius: 10px;
    box-shadow: none;
  }

  .section {
    padding: 4px 6px;
    gap: 3px;
    margin-bottom: 6px;
    border-width: 1px;
    border-radius: 8px;
  }

  .chip {
    padding: 4px 8px;
    font-size: 10px;
  }
  
  :root {
    --game-h: 250px;
  }
  
  #game {
    height: 250px;
    min-height: 250px;
  }

  .map-area #game {
    height: 250px !important;
    min-height: 250px !important;
  }

  .goal-top-right {
    font-size: 9px;
  }
}

