/* believe-pwa.css (2026-11-07): スマホ・タブレットとホーム画面のアプリ（PWA）向けの層。
   believe.css（外観）の後に読む。指で押す・キーボード・切り欠き・横向き・ホーム画面から開いたとき・
   オフラインと追加の案内をここにまとめる。PC の見た目は変えない。確認は docs/reports/_ui_pwa/audit.py
   （78 画面 × スマホ・タブレットの 9 サイズ）。 */

/* ---- タッチ端末の基本 ----------------------------------------------------
   回転しても文字が勝手に大きくならない。ダブルタップの拡大待ちをなくす。引っ張ったときに見える
   ページの外も背景色に。ホバーの色は believe.css・hub.css で (hover: hover) の端末だけにしたので、
   指で押したときは押している間だけ色を返す（押した後に色が残らない）。 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}
:is(a, button, input, select, textarea, label, summary) {
  touch-action: manipulation;
}
@media (hover: none) {
  body {
    -webkit-tap-highlight-color: transparent;
  }
  :is(a.hub-exam-card, a.hub-mode, button.hub-mode, a.hub-row-card, a.hub-scard, button.hub-scard):active,
  .hub-choice:active {
    border-color: var(--hub-blue);
    background: var(--bl-pale);
  }
  .hub-btn--primary:active {
    background: var(--bl-blue-dark);
  }
  :is(.hub-btn--outline, .hub-btn--soft, .hub-btn--ghost, a.hub-chip, label.hub-chip, .hub-linkish):active {
    background: var(--bl-pale);
  }
  :is(.app-tabs a, .hub-topnav a, .hub-topbar__links a, .hub-exam-switch__menu a):active {
    background: var(--bl-pale);
    color: var(--hub-blue);
  }
}

/* ---- 入力欄 ------------------------------------------------------------
   iPhone は 16px 未満の欄を押すと画面を拡大する。.hub-field の中の欄は 0.9rem（14.4px）を
   受け継いでいた（検索・模試の開始・問題エディタなど 9 画面）。タッチ端末だけ 16px 以上に。 */
@media (pointer: coarse) {
  .app-main :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]), select, textarea) {
    font-size: max(16px, 1em);
  }
}

/* ---- キーボードが出ているとき ---------------------------------------------
   下のタブと「N問で始める」帯はキーボードの上に浮いて、打っている欄の近くを隠すことがある。
   字を打っている間だけ隠す（問題画面の解答帯は hub.css が同じように流れに戻す）。 */
@media (hover: none) and (pointer: coarse) {
  body:has(:is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="range"]), textarea):focus) :is(.app-tabs, .hub-sticky-bar) {
    display: none;
  }
}

/* ---- 横に流れる表・メニュー ------------------------------------------------
   中で横に動かした勢いが、ページの「戻る」操作や画面全体のスクロールに移らないように。 */
:is(.hub-table-wrap, .table-responsive, .exam-table-scroll, .hub-exam-switch__menu) {
  overscroll-behavior-x: contain;
}

/* ---- 押しやすさ（2026-11-07） ------------------------------------------
   指で押す部品は 44px 以上（docs/reports/_ui_pwa/audit.py で 320〜1180 を測った）。
   見た目の大きさは変えず、高さと押せる範囲だけを広げる。 */
:is(a, label, button).hub-chip,
.hub-exam-switch summary,
.hub-home-switch,
.hub-linkish {
  min-height: 44px;
}
:is(a, label, button).hub-chip {
  min-width: 44px;
  justify-content: center;
}
.hub-linkish {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}
.hub-mock-nav button {
  width: 44px;
  height: 44px;
}
/* 段落や表の中で 1 つだけ置いたリンクと .hub-tap-link（テンプレートで付ける）。文中のリンクはそのまま。 */
.hub-sub-links a,
.hub-guide-list a,
.hub-tap-link,
:is(.hub-empty p, .hub-lead, .hub-foot, p.small, .app-main td) > a:only-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}
.app-main details > summary {
  min-height: 44px;
  padding-block: 0.6rem;
}
.app-main select {
  min-height: 44px;
}
.hub-check input[type="checkbox"],
.form-check .form-check-input {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  padding-left: 0;
}
.form-check .form-check-input {
  float: none;
  margin: 0;
}
/* Django の form.as_p のチェック欄（取込のアップロードなど）：行全体を押せるように。 */
.app-main form > p:has(> input[type="checkbox"]) > label {
  display: flex;
  align-items: center;
  min-height: 44px;
}
.form-check .form-check-label {
  display: inline-block;  /* 中のリンク（利用規約）は文中のまま */
  padding-block: 0.65rem;
}

/* ---- 一覧の行（2026-11-07、390 の目視で見つけた崩れ） ---------------------
   ・行の右のボタン（模試一覧の「見る」など）が縮んで「見／る」と縦に割れていた。
   ・1問ずつ練習のボタンの「304問から」が 1 字ずつ折れ、紺の上で灰色だった。
   ・出題が多い分野の行は、左の文が inline の flex:1（幅 0 から）でボタンに押されて細くなっていた。 */
:is(.hub-session-row, .hub-list > li) > .hub-btn,
.hub-session-row .hub-row-actions .hub-btn {
  flex: 0 0 auto;  /* 縮めない。長い名前（全部を原本の順に解く など）は行の幅で折る */
  max-width: 100%;
}
.hub-session-row .hub-btn > span:first-child {
  min-width: 0;
  text-align: left;
}
.hub-session-row .hub-btn > .hub-muted {
  flex: none;
  margin-left: 0.75rem;
  white-space: nowrap;
}
.hub-btn--primary .hub-muted {
  color: rgba(255, 255, 255, 0.85);
}
[data-testid="freq-row"] > :first-child {
  flex-basis: 12rem !important;
}

/* 表の見出しと短い値（あり・なし など）は 1 字ずつ折らない。表は横に流れる箱の中にある。 */
.hub-table th,
.hub-nowrap {
  white-space: nowrap;
}

/* ---- 細かく設定する：下に浮く「N問で始める」帯 ------------------------------
   320×568 では画面の半分近く（258px）を覆い、選んでいる条件が見えなかった。スマホでは詰め、
   背の低い画面ではまとめの説明を帯から外す（件数と「今回 N 問」は残る）。帯のあるページは、
   ページの終わりのリンクが帯に隠れないようフッターの下を空ける。 */
.hub-sticky-bar > .hub-sticky-bar__count {
  flex: 1 1 20rem;  /* タブレットではボタンを同じ行に置く（説明があると 2 段になっていた） */
  /* 横並びの帯だけに適用。縦並びの条件ダイアログでは320pxの高さになる。 */
  min-width: 0;
}
@media (max-width: 575px) {
  .hub-sticky-bar {
    gap: 0.4rem 0.75rem;
    width: calc(100% - 1rem);
    padding: 0.55rem 0.75rem;
  }
  .hub-sticky-bar__count {
    font-size: 0.9rem;
    line-height: 1.45;
  }
  .hub-sticky-bar .hub-note {
    margin-top: 0.25rem !important;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.45;
  }
}
@media (max-width: 575px) and (max-height: 700px) {
  .hub-sticky-bar .hub-note {
    display: none !important;
  }
}
body:has(.app-main .hub-sticky-bar) .app-footer {
  padding-bottom: 11rem !important;
}

/* ---- 横向きのスマホ（高さ 500px 以下） ----------------------------------
   上の帯と下のタブで高さの 3 分の 1 を使っていた。帯を細くし、タブは絵と名前を横に並べる。 */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --footer-h: 48px;
    --bl-head: 53px;
  }
  .hub-topbar__main,
  .app-header,
  body.is-quiz .hub-topbar__main {
    min-height: 52px;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
  }
  .hub-brand__tag {
    display: none;
  }
  .hub-brand__name {
    font-size: 20px;
  }
  .hub-brand {
    justify-content: center;
    min-height: 44px;
  }
  .app-tabs a {
    flex-direction: row;
    gap: 0.4rem;
    font-size: 0.8rem;
  }
}

/* ---- 画面の端（ノッチ・角） --------------------------------------------
   viewport-fit=cover なので、横向きの iPhone では左右の切り欠きを自分で避ける。 */
@media (max-width: 991px) {
  :is(.hub-topbar, .app-header, .app-main, .app-footer, .pwa-bar, .demo-banner) {
    margin-left: env(safe-area-inset-left, 0px);
    margin-right: env(safe-area-inset-right, 0px);
  }
  .app-tabs {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}

/* ---- ホーム画面のアプリとして開いたとき（html.is-standalone は base.html が付ける） ---- */
html.is-standalone #pwa-install {
  display: none !important;
}
html.is-standalone body {
  -webkit-tap-highlight-color: transparent;
}
html.is-standalone :is(.app-tabs, .hub-topbar, .hub-topnav) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---- 更新・追加の案内（pwa.js が出す） ---------------------------------- */
.pwa-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem 1rem;
  margin: 0;
  padding: 0.55rem 16px;
  border-bottom: 1px solid var(--hub-line);
  background: var(--bl-pale);
  color: var(--fg);
  font-size: 0.875rem;
  text-align: center;
}
.pwa-bar[hidden] {
  display: none;
}
.pwa-bar--update {
  border-bottom: 0;
  background: #00468c;
  color: #fff;
  font-weight: 600;
}
.pwa-bar__btn {
  min-height: 44px;
  padding: 0 1.1rem;
  border: 1px solid #fff;
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 700;
}
@media (hover: hover) {
  .pwa-bar__btn:hover {
    background: #fff;
    color: #00468c;
  }
}

/* オフラインの画面（templates/offline.html）。 */
.offline-state {
  max-width: 520px;
  margin: 2rem auto 1.25rem;
  padding: 2rem 1.25rem;
  border: 1px solid var(--hub-line);
  background: var(--hub-surface);
  text-align: center;
}
.offline-state[hidden] {
  display: none;
}
.offline-state__icon {
  color: var(--hub-blue);
}
.offline-state__title {
  margin: 0.75rem 0 0.5rem;
  color: var(--hub-blue);
  font-size: 1.35rem;
  font-weight: 700;
}
.offline-state__lead {
  color: var(--muted);
}
.offline-packs {
  display: grid;
  gap: 0.5rem;
  max-width: 520px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}
.offline-home {
  max-width: 520px;
  margin: 1rem auto;
  text-align: center;
}

.me-install {
  margin: 0 0 1rem;
  padding: 1rem;
  border: 1px solid var(--hub-line);
  background: var(--bl-pale);
}
.me-install .me-section__note:last-child {
  margin-bottom: 0;
}
.me-install__done {
  margin: 0;
  color: var(--hub-blue);
  font-weight: 700;
}
