/* ===================================================================
   はじめてのルール（チュートリアル）。js/pages/tutorial.js
   PC・タブレット: 上にセクションの一覧、左に盤、右に会話（画面の高さに収め、会話だけがスクロールする）。
   スマホ: ヘッダーの右端に今のセクション（押すと一覧）、その下に盤と会話（ページ全体は動かず、会話だけがスクロールする）。
   =================================================================== */
.tutorial-page { padding-top: 20px; padding-bottom: 24px; }

/* ───────── セクションの一覧 ───────── */
.tut-sections { margin-bottom: 16px; position: relative; }
.tut-sections-toggle { display: none; }
.tut-sections-list { list-style: none; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.tut-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%;
  padding: 8px 4px; background: var(--surface); box-shadow: var(--shadow-card);
  color: var(--text-sub); font-size: 12px; line-height: 1.4; text-align: center; text-decoration: none;
}
a.tut-item:hover { background: var(--aqua-pale); }
.tut-no {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border: 1.5px solid var(--line-input); border-radius: 50%; font-size: 12px; font-weight: 700; color: var(--text-sub);
}
.tut-name { font-weight: 700; }
.tut-soon { font-size: 10.5px; color: var(--text-placeholder); }
.is-current .tut-item { background: var(--slate); color: #fff; }
.is-current .tut-no { border-color: #fff; color: #fff; }
.is-done .tut-no { background: var(--aqua); border-color: var(--aqua); color: #fff; }
.is-soon .tut-item { opacity: 0.6; cursor: default; box-shadow: none; }

/* ───────── 2つの場所 ───────── */
.tut-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); gap: var(--gap);
  height: calc(100dvh - var(--header-h) - 148px); min-height: 540px;
}

/* 盤の場所: 盤は残りの高さに収まる正方形 */
.tut-stage { display: flex; flex-direction: column; min-height: 0; }
.tut-hands { display: flex; gap: 14px; }
.tut-hand { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #fff; }
.tut-hand b { font-size: 15px; }
.tut-board-wrap { flex: 1 1 auto; min-height: 0; container-type: size; display: grid; place-items: center; padding: 16px 16px 0; }
.tut-stage #board { width: min(100cqw, 100cqh); }
.tut-stage .ul-board[data-variant="static"] .cell { cursor: default; }
/* 操作中は丸のマスを少し脈打たせる */
.tut-stage .ul-board[data-variant="play"] .ul-ring { animation: tut-ring 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes tut-ring { 50% { transform: scale(0.88); } }
.ul-board .cell.is-focus { background: var(--aqua-pale); box-shadow: inset 0 0 0 3px var(--aqua); }
.tut-caption { padding: 12px 20px 16px; min-height: calc(1.8em + 28px); text-align: center; color: var(--ink); font-weight: 500; }
.tut-caption.is-empty { visibility: hidden; }

/* 会話の場所 */
.tut-chat { display: flex; flex-direction: column; min-height: 0; }
.tut-chat .card-head { justify-content: space-between; }
.tut-log { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 12px; }
.tut-log .talk { margin: 14px 0 0; animation: tut-in 0.22s ease-out both; }
.tut-log .talk.is-cont { margin-top: 6px; }
.tut-log .talk.is-cont .talk-bubble::before { display: none; }
.tut-log .talk-bubble { max-width: calc(100% - 76px); padding: 10px 14px; }
@keyframes tut-in { from { opacity: 0; transform: translateY(6px); } }

.typing-dots { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-placeholder); animation: tut-dot 1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes tut-dot { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.tut-notice { margin: 18px 0 4px; padding: 12px 16px; background: var(--aqua-pale); text-align: center; animation: tut-in 0.22s ease-out both; }
.tut-notice-title { font-weight: 700; color: var(--aqua-text); display: inline-flex; align-items: center; gap: 6px; }
.tut-notice .sub { margin-top: 4px; }
.tut-score { margin-top: 6px; font-size: 18px; font-weight: 700; color: var(--ink); }

/* 返信欄: ジュリの返事（押すと送る）や、セクションの終わりのボタン */
.tut-replies {
  flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  min-height: calc(var(--btn-h) + 25px); padding: 12px 16px; border-top: 1px solid var(--line);
}
.tut-replies .btn { flex: 1 1 0; }
.tut-replies .tut-mode { flex: none; align-self: center; min-width: 176px; }
.tut-replies .tut-mode button { min-height: 44px; }
.tut-reply-hint { align-self: center; margin-right: auto; color: var(--text-sub); font-size: 14px; }
.tut-reply-hint::before { content: "← "; color: var(--aqua); font-weight: 700; }
.tut-reply {
  max-width: 100%; min-height: var(--btn-h); padding: 10px 18px;
  background: var(--surface); border: 2px solid var(--aqua); color: var(--aqua-text);
  font-weight: 700; text-align: left; line-height: 1.6; cursor: pointer;
  animation: tut-in 0.22s ease-out both;
}
.tut-reply::after { content: "送る"; margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--aqua-soft); font-size: 12px; }
.tut-reply:hover, .tut-reply:focus-visible { background: var(--aqua); color: #fff; }
.tut-reply:hover::after, .tut-reply:focus-visible::after { border-left-color: rgba(255, 255, 255, 0.6); }

@media (prefers-reduced-motion: reduce) {
  .tut-log .talk, .tut-notice, .tut-reply, .typing-dots i, .ul-ring { animation: none !important; }
}

/* ───────── タブレット ───────── */
@media (max-width: 1023px) {
  .tut-layout { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: 16px; }
  .tut-item { font-size: 11px; padding: 6px 2px; }
}

/* ───────── 縦長の画面（スマホ・縦向きのタブレット）: 盤の下に会話 ───────── */
@media (max-width: 767px), (max-width: 1023px) and (orientation: portrait) {
  body.no-tabbar .tutorial-page {
    display: flex; flex-direction: column;
    height: calc(100dvh - var(--header-h)); padding: 12px var(--gutter) 0;
    /* body の min-height: 100vh（URL バーが隠れたときの高さ）まで伸びると、送信欄が URL バーの下に入るので伸ばさない */
    flex: none;
  }
  body.no-tabbar:has(.tutorial-page) { min-height: 100dvh; }
  .tut-layout { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; height: auto; min-height: 0; }
  .tut-stage { flex: none; }
  .tut-board-wrap { container-type: normal; display: block; padding: 12px 0 0; }
  .tut-stage #board { width: min(100%, 36dvh); margin: 0 auto; }
  .tut-chat { flex: 1 1 auto; }
  .tut-reply-hint::before { content: "↑ "; }
}

/* ───────── スマホ ───────── */
@media (max-width: 767px) {
  body.no-tabbar .tutorial-page { padding-top: 8px; }

  /* セクションはヘッダーの右端（js/pages/tutorial.js が移す）。今の番号だけを出し、押すと一覧が開く */
  .sp-header:has(.tut-sections) { grid-template-columns: 76px 1fr 76px; }
  .tut-sections { margin: 0; justify-self: end; }
  .tut-sections-toggle {
    display: inline-flex; align-items: center; gap: 2px; height: 36px; margin-right: 4px;
    padding: 0 6px 0 10px; background: var(--aqua-pale); border: 0; white-space: nowrap;
    font-weight: 700; color: var(--aqua-text); cursor: pointer;
  }
  .tut-sections-toggle .tut-current-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; } /* 読み上げには残す */
  .tut-sections-toggle [data-icon] { display: inline-flex; transition: transform 0.15s; }
  .tut-sections.is-open .tut-sections-toggle [data-icon] { transform: rotate(180deg); }
  .tut-sections-list {
    display: none; position: fixed; top: var(--header-h); left: 8px; right: 8px;
    grid-auto-flow: row; grid-template-columns: 1fr; gap: 0; background: var(--surface); box-shadow: var(--shadow-pop);
    max-height: 60dvh; overflow-y: auto;
  }
  .tut-sections.is-open .tut-sections-list { display: grid; }
  .tut-item { flex-direction: row; gap: 10px; padding: 10px 12px; font-size: 14px; box-shadow: none; text-align: left; border-bottom: 1px solid var(--line-light); }
  .tut-soon { margin-left: auto; font-size: 12px; }
  .is-soon .tut-item { opacity: 0.55; }

  .tut-layout { gap: 8px; }

  .tut-stage .card-head.slate { min-height: 36px; padding: 6px 12px; }
  .tut-stage .turn-label { font-size: 14px; }
  .tut-hand { font-size: 12px; }
  .tut-board-wrap { padding: 0; }
  /* 盤はできるだけ大きく。ただし会話などに 500px を残す（小さい画面では 34dvh を下限にする） */
  .tut-stage #board { width: min(100%, max(34dvh, 100dvh - 500px)); margin: 0 auto; }
  .tut-caption { padding: 6px 12px 8px; min-height: calc(1.6em * 2 + 14px); font-size: 13px; line-height: 1.6; display: flex; align-items: center; justify-content: center; }

  /* 会話の見出し（セクション名・最初から）は出さない。名前と選び直しはヘッダーの「1 / 8」から */
  .tut-chat .card-head { display: none; }
  .tut-log { padding: 0 10px 10px; }
  .tut-log .talk { margin-top: 10px; gap: 8px; }
  .tut-log .talk-person { width: 40px; }
  .tut-log .talk-person svg { width: 36px; height: 36px; }
  .tut-log .talk-name { font-size: 10px; }
  .tut-log .talk-bubble { max-width: calc(100% - 52px); padding: 8px 12px; line-height: 1.7; }
  .tut-log .talk-bubble::before { top: 10px; }
  .tut-replies { min-height: calc(48px + 16px + env(safe-area-inset-bottom)); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .tut-reply { width: 100%; min-height: 48px; padding: 8px 14px; }
  /* 切り替えがあるときは横いっぱいに出し、案内文は盤の下の一言に任せる */
  .tut-replies .tut-mode { flex: 1 1 auto; }
  .tut-replies:has(.tut-mode) .tut-reply-hint { display: none; }
  .tut-replies .btn { min-height: 48px; padding: 0 8px; font-size: 14px; white-space: nowrap; }
}
