/* MDPop2 mobile: スマホ・タブレット向けの見た目(PC版の CSS の後に読み込む) */

html.m-mobile, html.m-mobile body {
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
html.m-mobile body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  box-sizing: border-box;
}

/* スマホ版で意味を持たないボタン(別ウィンドウ・最前面固定・Claude 連携・購入案内・保存場所を開く) */
html.m-mobile #btn-pin,
html.m-mobile #btn-ask,
html.m-mobile #btn-help,
html.m-mobile #sidebar-resizer,
html.m-mobile #comment-resizer,
html.m-mobile #cp-toolbar,
html.m-mobile #comment-panel .cc-fix,
html.m-mobile #comment-panel [data-cc-action="continue"] { display: none !important; }

/* ---------- ログイン画面・選択画面 ---------- */
#m-login, .m-picker {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 20, 20, 0.45);
  padding: 16px;
}
#m-login[hidden] { display: none; }
.m-login-card, .m-picker-card {
  width: min(420px, 100%);
  background: var(--bg, #FAFAF8);
  color: var(--text, #1f2328);
  border-radius: 12px;
  padding: 24px 20px;
  box-sizing: border-box;
}
.m-login-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.m-login-msg { margin: 0 0 18px; line-height: 1.6; }
.m-login-btn {
  width: 100%; min-height: 48px; font-size: 16px; font-weight: 600;
  border: none; border-radius: 8px; background: #1a73e8; color: #fff;
}
.m-login-btn:disabled { opacity: 0.6; }
.m-login-note { margin: 14px 0 0; font-size: 12px; color: var(--muted, #6B7280); line-height: 1.5; }
.m-fatal {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 10001;
  padding: 12px 14px; border-radius: 8px; background: #b42318; color: #fff; font-size: 14px;
}

.m-picker-card { padding: 0; display: flex; flex-direction: column; max-height: 85dvh; }
.m-picker-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border, #d0d7de); }
.m-picker-up { min-height: 40px; padding: 0 12px; flex: 0 0 auto; }
.m-picker-where { font-size: 13px; color: var(--muted, #6B7280); overflow-wrap: anywhere; }
.m-picker-list { overflow-y: auto; flex: 1 1 auto; padding: 4px 0; }
.m-picker-row {
  display: block; width: 100%; text-align: left; min-height: 46px; padding: 10px 16px;
  border: none; border-bottom: 1px solid var(--border, #eee); background: transparent;
  color: inherit; font-size: 15px; overflow-wrap: anywhere;
}
.m-picker-row.is-dir { font-weight: 600; }
.m-picker-empty { padding: 20px 16px; color: var(--muted, #6B7280); }
.m-picker-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px; border-top: 1px solid var(--border, #d0d7de); }
.m-picker-foot button { min-height: 44px; padding: 0 16px; font-size: 15px; }
.m-picker-choose { background: #1a73e8; color: #fff; border: none; border-radius: 6px; }
.m-picker-choose:disabled { opacity: 0.5; }

#m-scrim { display: none; }

/* ---------- 狭い画面(スマホ縦持ち・小さめのタブレット) ---------- */
@media (max-width: 820px) {
  html.m-mobile button, html.m-mobile select { touch-action: manipulation; }

  html.m-mobile #toolbar { padding: 6px 8px; gap: 6px; }
  html.m-mobile #toolbar .actions button { min-height: 38px; min-width: 38px; }
  html.m-mobile #btn-sidebar { min-width: 42px; min-height: 38px; font-size: 18px; }
  html.m-mobile #btn-tabbar { display: none; }
  html.m-mobile #filename { font-size: 14px; max-width: 42vw; }

  /* サイドバーは左から引き出す形にする */
  html.m-mobile #workspace { position: relative; }
  html.m-mobile #sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(86vw, 360px) !important;
    box-shadow: none;
    border-right: 1px solid var(--border);
  }
  html.m-mobile #sidebar:not(.hidden) ~ #m-scrim,
  html.m-mobile #m-scrim.on { display: block; }
  html.m-mobile body:has(#sidebar:not(.hidden)) #m-scrim {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.3);
  }
  html.m-mobile .tree { font-size: 15px; }
  html.m-mobile .tree .node, html.m-mobile .tree .row, html.m-mobile .tree li > div { min-height: 36px; }

  /* 本文は画面いっぱいに */
  html.m-mobile #viewer { padding: 16px 16px 72px; font-size: 16px; }
  html.m-mobile #viewer table { display: block; overflow-x: auto; }
  html.m-mobile #viewer pre { overflow-x: auto; }
  html.m-mobile #viewer img { max-width: 100%; height: auto; }
  html.m-mobile #editor { font-size: 16px; padding: 12px; } /* 16px 未満だと入力時に画面が拡大される */

  /* コメント欄は下から出す */
  html.m-mobile #comment-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    width: 100% !important; height: 55dvh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
  }

  html.m-mobile #breadcrumb .bc-filter { display: none; }
  html.m-mobile #statusbar { padding-bottom: calc(4px + env(safe-area-inset-bottom)); }
}

/* 指で操作する端末では、ポインタを載せたときの説明吹き出しを出さない */
@media (pointer: coarse) {
  html.m-mobile #hovertip { display: none !important; }
}

/* 選択したときに出る「コメント」ボタン */
#m-comment-fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(40px + env(safe-area-inset-bottom)); z-index: 80;
  min-height: 46px; padding: 0 20px; border: none; border-radius: 23px;
  background: #1a73e8; color: #fff; font-size: 15px; font-weight: 600;
}
#m-comment-fab[hidden] { display: none; }
