/* スマホでの操作性に関する調整。
   配色・書体は style.css の既存トークンをそのまま使う（新しい配色は足さない）。
   狙いは3つ：①モード切替をいつでも押せる ②指で押しやすい ③長文が読みやすい。 */

/* ---- 1. タブを上部に固定する ---- */

.top-tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  /* 端まで背景を伸ばして、下の本文が透けないようにする */
  margin-left: -16px;
  margin-right: -16px;
  padding: 8px 16px calc(8px + env(safe-area-inset-top, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--page);
  border-bottom: 1px solid var(--gridline);
}

.tab-btn {
  min-height: 44px;
  font-family: inherit;
}

/* 固定タブの下に隠れないように、スクロール先の余白を確保する */
#lesson-quiz-area,
#lesson-practice-area,
#lesson-finish-area,
.lesson-sec,
.card {
  scroll-margin-top: 80px;
}

/* ---- 2. 指で押しやすくする ---- */

* {
  -webkit-tap-highlight-color: transparent;
}

.choice,
.ox-btn,
.lesson-row,
.mode-btn,
.start-btn,
.next-btn,
.to-lesson-btn,
.finish-actions button,
.exam-actions button,
.retry-row button,
.back-link {
  min-height: 44px;
  touch-action: manipulation;
}

.back-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 0;
}

.nav-cell {
  min-width: 34px;
  min-height: 34px;
}

/* 押した瞬間の手応え */
.choice:active:not(:disabled),
.ox-btn:active:not(:disabled),
.lesson-row:active,
.to-lesson-btn:active {
  background: color-mix(in srgb, var(--seq-450) 8%, var(--surface-1));
}

/* キーボード操作時のフォーカスを見えるようにする */
button:focus-visible,
.lesson-row:focus-visible {
  outline: 2px solid var(--seq-450);
  outline-offset: 2px;
}

/* ---- 3. 長文を読みやすくする ---- */

@media (max-width: 600px) {
  .wrap {
    padding: 0 16px calc(56px + env(safe-area-inset-bottom, 0px));
  }

  header {
    padding-top: 16px;
  }

  header .sub {
    margin-bottom: 12px;
  }

  /* 本文はスマホでひとまわり大きく */
  .lesson-sec p,
  .lesson-sec li,
  .ox-q,
  .q-text {
    font-size: 0.94rem;
    line-height: 1.85;
  }

  .lesson-lead {
    font-size: 0.9rem;
  }

  .ox-explain,
  .trap-d {
    font-size: 0.85rem;
  }

  .lesson-head h2 {
    font-size: 1.2rem;
    text-wrap: balance;
  }

  .lesson-sec {
    padding: 16px 14px;
  }

  .tab-btn {
    font-size: 0.88rem;
    padding: 10px 4px;
  }

  /* カウントダウンは場所を取らない横並びに */
  .countdown {
    width: 100%;
  }
}

/* 表は横スクロールできることを示す。端に薄い影を出す */
.lesson-sec table.cmp {
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, var(--surface-1) 30%, transparent) left / 24px 100% no-repeat,
    linear-gradient(to left, var(--surface-1) 30%, transparent) right / 24px 100% no-repeat,
    linear-gradient(to right, rgba(0, 0, 0, 0.09), transparent) left / 10px 100% no-repeat,
    linear-gradient(to left, rgba(0, 0, 0, 0.09), transparent) right / 10px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}

@media (max-width: 600px) {
  table.cmp {
    font-size: 0.82rem;
  }

  table.cmp th,
  table.cmp td {
    padding: 8px 10px;
  }
}

/* 数字が並ぶところは桁を揃える */
.stat-tile .value,
.timer,
.finish-score,
.learn-hero .big-num {
  font-variant-numeric: tabular-nums;
}

/* ---- 4. 動きを減らす設定への対応 ---- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
