/* =========================================================================
   初めて開いたときの «使い方の案内» (resources/views/components/guide/coach.blade.php・public/assets/js/guide/guide.js)

   ⚠ 見本はユーザーが Codex で作った scroll-and-tap.html (画面を暗くして、真ん中に絵つきのカード)。
     色は速報サイト・受付票と同じ stone / purple。平らな面 (グラデーション・影の重ねを使わない)
   ⚠ 暗いところをスクロールするとページが動く (見本と同じ。速報ではそれで閉じる)。押すと案内を閉じるだけ (後ろのボタンは押されない)
   ⚠ 動きは 2 回だけ (ずっと動かさない)。動きを減らす設定の端末では止める。印刷には出さない
   ========================================================================= */

.nl-guide {
  --guide-text: #1c1917;
  --guide-text-subtle: #57534e;
  --guide-surface: #ffffff;
  --guide-scene: #faf5ff;
  --guide-line: #e7e5e4;
  --guide-line-strong: #d6d3d1;
  --guide-ink: #44403c;
  --guide-accent: #7e22ce;
  --guide-accent-strong: #6b21a8;
  --guide-accent-soft: #f3e8ff;
  --guide-accent-border: #e3cff7;
  --guide-focus: #8a51aa;
  --guide-shade: rgba(28, 25, 23, .62);
  /* 絵の動きの 1 回の長さ (見本と同じ)。2 回くり返して止める */
  --guide-period: 2.2s;

  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
  font-family: inherit;
  color: var(--guide-text);
  -webkit-text-size-adjust: 100%;
}

.nl-guide[hidden] { display: none; }

.nl-guide__shade {
  position: absolute;
  inset: 0;
  background: var(--guide-shade);
  transition: opacity 260ms ease;
  /* ⚠ 押したのを受け止めて閉じる (後ろへ通さない)。スクロールは固定の面を通り抜けてページが動く */
  pointer-events: auto;
}

.nl-guide__card {
  position: relative;
  box-sizing: border-box;
  width: min(100%, 320px);
  /* ⚠ 横向き・拡大で高さが足りないときはカードの中でスクロールしてボタンまで届く */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  pointer-events: auto;
  padding: 14px 14px 16px;
  border-radius: 20px;
  background: var(--guide-surface);
  text-align: center;
  transition: opacity 220ms ease, transform 220ms ease;
}

.nl-guide__title {
  margin: 14px 0 6px;
  color: inherit;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: .02em;
}

.nl-guide__message {
  margin: 0;
  color: var(--guide-text-subtle);
  font-size: 14px;
  line-height: 1.7;
  word-break: auto-phrase;
}

/* 2 つめのこつ (小さな絵 + 見出し + 文) */
.nl-guide__tip {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--guide-line);
  border-radius: 12px;
  text-align: left;
}

.nl-guide__tip-title {
  margin: 0 0 3px;
  color: inherit;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.35;
}

.nl-guide__tip-message {
  margin: 0;
  color: var(--guide-text-subtle);
  font-size: 12.5px;
  line-height: 1.6;
  word-break: auto-phrase;
}

.nl-guide__cta {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--guide-accent);
  color: #ffffff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

@media (hover: hover) {
  .nl-guide__cta:hover { background: var(--guide-accent-strong); }
}

.nl-guide__cta:focus-visible,
.nl-guide-replay:focus-visible {
  outline: 2px solid var(--guide-focus);
  outline-offset: 3px;
}

/* 読み上げに «案内を出した» と知らせる所 (目には見せない) */
.nl-guide__status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 閉じるとき (JS が付けて、終わったら hidden にする) */
.nl-guide--leaving .nl-guide__shade,
.nl-guide--leaving .nl-guide__card { opacity: 0; }
.nl-guide--leaving .nl-guide__card { transform: translateY(-8px); }
/* ⚠ 暗いところは消えきるまで押したのを受け止める (消えかけの間に後ろのボタンが押されないように) */
.nl-guide--leaving .nl-guide__card { pointer-events: none; }

/* -------------------------------------------------------------------------
   絵の部品
   ------------------------------------------------------------------------- */

/* 大きな絵の台 */
.nl-guide__scene {
  display: grid;
  justify-items: center;
  overflow: hidden;
  border-radius: 12px;
  background: var(--guide-scene);
}

.nl-guide-stage {
  position: relative;
  width: 200px;
  height: 160px;
}

/* 高さが足りない画面 (スマホの横向きなど) では大きな絵を出さない。⚠ 上の .nl-guide__scene より後ろに置く */
@media (max-height: 560px) {
  .nl-guide__scene { display: none; }
  .nl-guide__title { margin-top: 2px; }
}

/* 小さな絵の台 */
.nl-guide__tip-scene {
  position: relative;
  height: 60px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--guide-scene);
}

/* 指をさす手 (x-guide.hand) */
.nl-guide-hand {
  position: absolute;
  display: block;
  overflow: visible;
}
.nl-guide-hand__skin {
  fill: #f5c8a6;
  stroke: #584539;
  stroke-width: 1.65;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.nl-guide-hand__crease {
  fill: none;
  stroke: #a8765f;
  stroke-width: 1.2;
  stroke-linecap: round;
}

/* 小さなスマホ */
.nl-guide-phone {
  position: absolute;
  top: 14px;
  left: 62px;
  box-sizing: border-box;
  width: 70px;
  height: 132px;
  border: 2px solid var(--guide-ink);
  border-radius: 14px;
  background: #ffffff;
}
.nl-guide-phone::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 16px;
  height: 3px;
  transform: translateX(-50%);
  border-radius: 3px;
  background: var(--guide-ink);
}
.nl-guide-phone__screen {
  position: absolute;
  inset: 15px 5px 7px;
  overflow: hidden;
  border-radius: 3px 3px 7px 7px;
}

/* 上向きの矢印 (スクロール) */
.nl-guide-arrow {
  position: absolute;
  top: 26px;
  left: 142px;
  display: grid;
  justify-items: center;
  color: var(--guide-accent);
}
.nl-guide-arrow svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nl-guide-arrow::after {
  content: "";
  height: 20px;
  border-left: 1.5px dashed var(--guide-accent-border);
  border-left-color: #c4a3e3;
}

/* 触れたところの輪 */
.nl-guide-touch {
  position: absolute;
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--guide-accent);
  border-radius: 50%;
  background: rgba(243, 232, 255, .8);
}

/* ---- 速報: 順位の一覧をスクロール --------------------------------------- */

.nl-guide-feed {
  display: grid;
  gap: 4px;
  padding: 2px 1px;
}
.nl-guide-feed__row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) 14px;
  gap: 4px;
  align-items: center;
  height: 15px;
  padding: 0 3px;
  border: 1px solid var(--guide-line);
  border-radius: 3px;
}
/* 順位の印・氏名・記録 (線で表す) */
.nl-guide-feed__row i { height: 7px; border-radius: 2px; background: var(--guide-accent-soft); }
.nl-guide-feed__row b { height: 3px; border-radius: 2px; background: var(--guide-line-strong); }
.nl-guide-feed__row em { height: 3px; border-radius: 2px; background: var(--guide-ink); opacity: .55; }
.nl-guide-feed__row:nth-child(-n+3) i { background: var(--guide-accent); opacity: .75; }
.nl-guide-feed__row:nth-child(2n) b { width: 78%; }

.nl-guide-swipe .nl-guide-touch { top: 80px; left: 95px; }
.nl-guide-swipe .nl-guide-hand { top: 65px; left: 92px; width: 96px; height: 92px; }

/* 一覧の 1 行をタップ */
.nl-guide-tap__row {
  position: absolute;
  inset: 12px 8px auto 6px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 6px;
  gap: 5px;
  align-items: center;
  height: 22px;
  padding: 0 5px;
  box-sizing: border-box;
  border: 1px solid var(--guide-accent-border);
  border-radius: 5px;
  background: #ffffff;
}
.nl-guide-tap__row i { height: 9px; border-radius: 2px; background: var(--guide-accent); opacity: .75; }
.nl-guide-tap__row b { display: grid; gap: 3px; }
.nl-guide-tap__row b::before,
.nl-guide-tap__row b::after { content: ""; height: 2px; border-radius: 1px; background: var(--guide-line-strong); }
.nl-guide-tap__row b::after { width: 60%; background: var(--guide-ink); opacity: .5; }
/* 右の «›» */
.nl-guide-tap__row em {
  width: 4px;
  height: 4px;
  border-top: 1.5px solid var(--guide-ink);
  border-right: 1.5px solid var(--guide-ink);
  transform: rotate(45deg);
}
.nl-guide-tap .nl-guide-touch { top: 16px; left: 22px; width: 14px; height: 14px; background: none; }
.nl-guide-tap .nl-guide-hand { top: 15px; left: 23px; width: 36px; height: 35px; }

/* ---- 受付票: QR を見せる ------------------------------------------------ */

/* 受付票の小さな写し (ゼッケンの面 + QR) */
.nl-guide-ticket {
  display: grid;
  gap: 5px;
  justify-items: center;
  padding-top: 2px;
}
.nl-guide-ticket__bib {
  width: 100%;
  height: 16px;
  border-radius: 3px;
  background: var(--guide-accent-soft);
  position: relative;
}
.nl-guide-ticket__bib::after {
  content: "";
  position: absolute;
  inset: 6px 30% 6px 30%;
  border-radius: 2px;
  background: var(--guide-accent);
  opacity: .8;
}
.nl-guide-ticket__lines { display: grid; gap: 3px; width: 100%; }
.nl-guide-ticket__lines::before,
.nl-guide-ticket__lines::after { content: ""; height: 2px; border-radius: 1px; background: var(--guide-line-strong); }
.nl-guide-ticket__lines::after { width: 64%; }

/* QR (3 隅の印 + 点) */
.nl-guide-qr {
  position: relative;
  width: 44px;
  height: 44px;
  background:
    radial-gradient(circle, var(--guide-text) 0 1.2px, transparent 1.4px) 0 0 / 5px 5px;
}
.nl-guide-qr i {
  position: absolute;
  width: 11px;
  height: 11px;
  box-sizing: border-box;
  border: 3px solid var(--guide-text);
  background: #ffffff;
  box-shadow: 0 0 0 2px #ffffff;
}
.nl-guide-qr i:nth-child(1) { top: 0; left: 0; }
.nl-guide-qr i:nth-child(2) { top: 0; right: 0; }
.nl-guide-qr i:nth-child(3) { bottom: 0; left: 0; }

/* 受付端末の読み取りの光 */
.nl-guide-scan {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 47px;
  height: 2px;
  border-radius: 2px;
  background: var(--guide-accent);
  box-shadow: 0 0 6px 1px rgba(126, 34, 206, .45);
  opacity: 0;
}
/* 読み取り機の先から QR へ届く光 (読み取っているのは受付端末だと分かるように) */
.nl-guide-beam {
  /* 読み取り機の先 (右の細い所) から QR の上下いっぱい (左の太い所) へ */
  position: absolute;
  top: 46px;
  left: 75px;
  width: 67px;
  height: 64px;
  background: rgba(126, 34, 206, .2);
  clip-path: polygon(100% 0, 100% 12.5%, 0 100%, 0 31%);
  opacity: 0;
}
/* 受付端末 (読み取り機) */
.nl-guide-reader {
  position: absolute;
  top: 40px;
  left: 142px;
  width: 38px;
  height: 60px;
}
.nl-guide-reader__head {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  width: 38px;
  height: 24px;
  border: 2px solid var(--guide-ink);
  border-radius: 6px 6px 4px 4px;
  background: #ffffff;
}
.nl-guide-reader__head::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 6px;
  width: 4px;
  height: 8px;
  border-radius: 2px 0 0 2px;
  background: var(--guide-accent);
}
.nl-guide-reader__grip {
  position: absolute;
  top: 20px;
  left: 18px;
  box-sizing: border-box;
  width: 14px;
  height: 36px;
  border: 2px solid var(--guide-ink);
  border-top: 0;
  border-radius: 0 0 5px 5px;
  background: #ffffff;
  transform: rotate(-12deg);
  transform-origin: top center;
}
/* 読めた印 */
.nl-guide-ok {
  position: absolute;
  top: 18px;
  left: 120px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--guide-accent);
  opacity: 0;
}
.nl-guide-ok svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- 受付票: スクリーンショットで保存 ----------------------------------- */

.nl-guide-shot__phone {
  position: absolute;
  top: 7px;
  left: 19px;
  box-sizing: border-box;
  width: 26px;
  height: 46px;
  border: 1.5px solid var(--guide-ink);
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
}
.nl-guide-shot__phone::before {
  content: "";
  position: absolute;
  inset: 5px 4px auto;
  height: 5px;
  border-radius: 1px;
  background: var(--guide-accent-soft);
}
.nl-guide-shot__phone::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 50%;
  width: 12px;
  height: 12px;
  transform: translateX(-50%);
  background: radial-gradient(circle, var(--guide-text) 0 .8px, transparent 1px) 0 0 / 3px 3px;
}
/* 撮った範囲の四隅の印 */
.nl-guide-shot__frame {
  --corner: var(--guide-accent);
  position: absolute;
  top: 3px;
  left: 14px;
  width: 36px;
  height: 54px;
  background:
    linear-gradient(var(--corner), var(--corner)) top left / 8px 2px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top left / 2px 8px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top right / 8px 2px no-repeat,
    linear-gradient(var(--corner), var(--corner)) top right / 2px 8px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom left / 8px 2px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom left / 2px 8px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom right / 8px 2px no-repeat,
    linear-gradient(var(--corner), var(--corner)) bottom right / 2px 8px no-repeat;
}
/* 撮ったときの白い光 */
.nl-guide-shot__flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
}
/* 横のボタン (押すところ) */
.nl-guide-shot__button {
  position: absolute;
  top: 16px;
  left: 46px;
  width: 3px;
  height: 9px;
  border-radius: 0 2px 2px 0;
  background: var(--guide-accent);
}
/* 保存できた印 */
.nl-guide-shot__saved {
  position: absolute;
  top: 36px;
  left: 40px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--guide-accent);
  opacity: 0;
}
.nl-guide-shot__saved svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* -------------------------------------------------------------------------
   動き (JS が `nl-guide--play` を付けたときだけ。2 回で止める)
   ------------------------------------------------------------------------- */

.nl-guide--play .nl-guide-swipe .nl-guide-hand,
.nl-guide--play .nl-guide-swipe .nl-guide-touch,
.nl-guide--play .nl-guide-feed {
  animation: nl-guide-swipe var(--guide-period) ease-in-out 2;
}
@keyframes nl-guide-swipe {
  0%, 17%, 100% { transform: translateY(0); }
  49%, 65% { transform: translateY(-31px); }
}

.nl-guide--play .nl-guide-tap .nl-guide-hand {
  animation: nl-guide-tap-hand var(--guide-period) ease-in-out 2;
}
.nl-guide--play .nl-guide-tap .nl-guide-touch {
  animation: nl-guide-tap-ring var(--guide-period) ease-out 2;
}
.nl-guide--play .nl-guide-tap__row {
  animation: nl-guide-tap-row var(--guide-period) ease-out 2;
}
@keyframes nl-guide-tap-hand {
  0%, 47%, 100% { transform: translate(3px, 4px); }
  61%, 69% { transform: translate(0, 0); }
}
@keyframes nl-guide-tap-ring {
  0%, 55%, 100% { opacity: .45; transform: scale(.72); }
  67% { opacity: 1; transform: scale(1); }
  83% { opacity: 0; transform: scale(1.48); }
}
@keyframes nl-guide-tap-row {
  0%, 58%, 90%, 100% { background: #ffffff; }
  66%, 80% { background: var(--guide-accent-soft); }
}

.nl-guide--play .nl-guide-scan {
  animation: nl-guide-scan var(--guide-period) ease-in-out 2;
}
.nl-guide--play .nl-guide-beam {
  animation: nl-guide-beam var(--guide-period) ease-in-out 2;
}
@keyframes nl-guide-beam {
  0%, 12%, 58%, 100% { opacity: 0; }
  18%, 52% { opacity: 1; }
}
/* ⚠ 読めた印・保存した印は、動きが終わったあとも出したままにする (forwards) */
.nl-guide--play .nl-guide-ok {
  animation: nl-guide-ok var(--guide-period) ease-out 2 forwards;
}
@keyframes nl-guide-scan {
  0%, 12% { opacity: 0; transform: translateY(0); }
  18% { opacity: 1; transform: translateY(0); }
  52% { opacity: 1; transform: translateY(46px); }
  58%, 100% { opacity: 0; transform: translateY(46px); }
}
@keyframes nl-guide-ok {
  0%, 56% { opacity: 0; transform: scale(.6); }
  64% { opacity: 1; transform: scale(1.08); }
  70%, 100% { opacity: 1; transform: scale(1); }
}

.nl-guide--play .nl-guide-shot__flash {
  animation: nl-guide-flash var(--guide-period) ease-out 2;
}
.nl-guide--play .nl-guide-shot__button {
  animation: nl-guide-press var(--guide-period) ease-in-out 2;
}
.nl-guide--play .nl-guide-shot__saved {
  animation: nl-guide-ok var(--guide-period) ease-out 2 forwards;
}
@keyframes nl-guide-flash {
  0%, 40%, 70%, 100% { opacity: 0; }
  46% { opacity: .95; }
}
@keyframes nl-guide-press {
  0%, 30%, 52%, 100% { transform: translateX(0); }
  38%, 46% { transform: translateX(-1.5px); }
}

/* 動きを止めたとき・動きを減らす設定: 絵は «終わった形» で止める */
@media (prefers-reduced-motion: reduce) {
  .nl-guide *,
  .nl-guide--play * { animation: none !important; }
  .nl-guide__shade,
  .nl-guide__card { transition: none; }
  .nl-guide-ok,
  .nl-guide-shot__saved { opacity: 1; }
}

/* -------------------------------------------------------------------------
   出し直すボタン (JS が動くときだけ hidden を外す)
   ------------------------------------------------------------------------- */

.nl-guide-replay {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #d6d3d1;
  border-radius: 999px;
  background: #ffffff;
  color: #44403c;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.nl-guide-replay[hidden] { display: none; }
.nl-guide-replay svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (hover: hover) {
  .nl-guide-replay:hover { border-color: #c4a3e3; color: #6b21a8; }
}

@media print {
  .nl-guide,
  .nl-guide-replay { display: none !important; }
}
