/* まなびの ちず（/map, /map/:subject_slug）
   タブレット（768〜1180px）を基準に: くねくね道（行ごとに 右→ / ←左）。スマホ幅（〜599px）は たて1列。
   道は .map-cell::after でかく（まっすぐな線と、行の はしの U ターン）。画像は使わない */

/* ---------- 科目えらび（/map） ---------- */
.map-hero { display: flex; align-items: center; gap: 16px; background: linear-gradient(135deg, #ecfdf5, #eff6ff); border: 2px solid #a7f3d0; }
.map-hero-ico { font-size: 3.2rem; line-height: 1; flex: none; }
.map-hero .body { min-width: 0; }

.map-resume {
  display: flex; align-items: center; gap: 14px; color: var(--text); text-decoration: none;
  border: 2px solid #a5b4fc; min-height: 96px;
}
.map-resume:hover { text-decoration: none; transform: translateY(-2px); transition: transform .15s; }
.map-resume-ico { flex: none; width: 72px; height: 72px; border-radius: 20px; background: var(--surface-2); display: grid; place-items: center; font-size: 2.6rem; line-height: 1; overflow: hidden; }
.map-resume-ico .illust-icon { width: 72px; height: 72px; vertical-align: top; }
.map-resume .body { flex: 1; min-width: 0; display: grid; gap: 4px; justify-items: start; }
.map-resume .body .bar { width: 100%; }
.map-resume .nm { font-size: 1.2rem; line-height: 1.6; }
.map-resume .go { flex: none; font-size: 1.8rem; font-weight: 800; color: var(--primary-dark); }
.map-count { font-size: .85rem; font-weight: 700; color: var(--muted); }

.map-index-title { margin: 20px 0 8px; }
.map-group { margin-bottom: 18px; }
.map-group-title { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding-left: 10px; border-left: 6px solid var(--c, var(--primary)); font-size: 1.05rem; }
.map-group-title .ico { font-size: 1.4rem; line-height: 1; }
.map-group-title .ico .illust-icon { width: 36px; height: 36px; vertical-align: middle; }
.map-subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.map-subject {
  display: flex; align-items: center; gap: 12px; min-height: 88px; padding: 10px 12px; color: var(--text); text-decoration: none;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); border: 2px solid transparent;
}
.map-subject:hover { text-decoration: none; border-color: var(--c, var(--primary)); }
.map-subject:active { transform: scale(.98); }
.map-subject.is-complete { background: #fffbeb; border-color: #fcd34d; }
.map-subject .pic { flex: none; width: 64px; height: 64px; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; font-size: 2.2rem; line-height: 1; overflow: hidden; }
.map-subject .pic .illust-icon { width: 64px; height: 64px; vertical-align: top; }
.map-subject .body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.map-subject .nm { font-weight: 800; line-height: 1.5; overflow-wrap: anywhere; }

/* ---------- 1科目の ちず: 上のまとめ ---------- */
.map-head { border-top: 6px solid var(--c, var(--primary)); }
.map-head-top { display: flex; align-items: center; gap: 14px; }
.map-head-ico { flex: none; width: 72px; height: 72px; border-radius: 20px; background: var(--surface-2); display: grid; place-items: center; font-size: 2.6rem; line-height: 1; overflow: hidden; }
.map-head-ico .illust-icon { width: 72px; height: 72px; vertical-align: top; }
.map-head-top .body { min-width: 0; }
.map-summary { margin-top: 12px; display: grid; gap: 8px; }
.map-count-big { font-size: 1.1rem; }
.map-count-big .n { font-size: 1.6rem; color: #b45309; }
.map-cheer { margin-top: 12px; font-weight: 800; font-size: 1.1rem; color: #b45309; }
.map-next { margin-top: 14px; }
.map-next h2 { font-size: 1rem; margin: 0 0 8px; }
.map-next-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.map-next-item {
  display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 8px 12px; color: var(--text); text-decoration: none;
  border-radius: 16px; border: 2px solid #6ee7b7; background: #ecfdf5;
}
.map-next-item:hover { text-decoration: none; background: #d1fae5; }
.map-next-item .num { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 3px solid #10b981; color: #047857; font-weight: 900; }
.map-next-item .body { min-width: 0; display: grid; }
.map-next-item .nm { font-weight: 800; line-height: 1.5; overflow-wrap: anywhere; }
.map-next-item .meta { font-size: .78rem; color: var(--muted); }

/* ---------- ばん面 ---------- */
.map-board {
  --road: #e7d7ae;         /* 道の色 */
  --road-done: #fbbf24;    /* マスターしたマスから先の道 */
  --dot: 68px;             /* マスの大きさ */
  --gap-x: 10px;
  --gap-y: 30px;
  --side: 0px;             /* 左右の よはく（U ターンが はみ出すぶん） */
  --lift: 0px;             /* マスの上の よはく（「いま ここ」の ふきだしのぶん） */
  padding: 16px 14px 24px; border-radius: 24px; overflow: hidden;
  background-color: #f0fdf4;
  background-image: radial-gradient(rgba(16, 185, 129, .13) 2px, transparent 2.5px);
  background-size: 26px 26px;
  border: 2px solid #bbf7d0;
}
.map-legend { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.map-legend li { display: inline-flex; align-items: center; gap: 6px; }
.map-legend .key { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .7rem; line-height: 1; background: #fff; border: 3px solid #c7d2fe; }
.map-legend .key.is-mastered { background: #fde68a; border-color: #f59e0b; }
.map-legend .key.is-learning { border-color: #f59e0b; border-right-color: #fde68a; border-bottom-color: #fde68a; }
.map-legend .key.is-ready { border-color: #10b981; background: #ecfdf5; }
.map-legend .key.is-locked { border-style: dashed; border-color: #9ca3af; background: #e5e7eb; }

.map-path {
  list-style: none; margin: 0; padding: 0 var(--side);
  display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap-y) var(--gap-x);
  position: relative; z-index: 0; /* 道（z-index: -1）を この中に とどめる */
}
.map-cell { position: relative; min-width: 0; padding-top: var(--lift); scroll-margin-top: calc(var(--top-h, 64px) + 80px); }

/* 道: スマホは マスの まん中から 下の マスへ まっすぐ */
.map-cell::after {
  content: ""; position: absolute; z-index: -1; box-sizing: border-box;
  left: calc(var(--dot) / 2 - 6px); top: calc(var(--lift) + var(--dot) / 2);
  width: 12px; height: calc(100% + var(--gap-y));
  background: var(--road); border: 0 solid var(--road); border-radius: 6px;
}
.map-cell:last-child::after { display: none; }
.map-cell.is-mastered, .map-cell.map-grade.is-complete { --road: var(--road-done); }

.map-tile { display: flex; align-items: flex-start; gap: 14px; min-height: var(--dot); color: var(--text); text-decoration: none; }
a.map-tile:hover { text-decoration: none; }
a.map-tile:hover .map-name { text-decoration: underline; }
a.map-tile:active .map-dot { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
a.map-tile:focus-visible { outline: none; }
a.map-tile:focus-visible .map-dot { outline: 4px solid var(--primary); outline-offset: 3px; }

/* マス（丸） */
.map-dot {
  flex: none; position: relative; width: var(--dot); height: var(--dot); border-radius: 50%;
  display: grid; place-items: center; line-height: 1;
  background: #fff; border: 5px solid #c7d2fe; color: var(--primary-dark);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .14);
  font-weight: 900; font-size: 1.5rem; transition: transform .1s;
}
.map-badge {
  position: absolute; right: -6px; top: -6px; min-width: 28px; height: 28px; padding: 0 4px; border-radius: 14px;
  display: grid; place-items: center; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  font-size: .9rem; line-height: 1; color: var(--text);
}
.map-badge.is-number { font-size: .78rem; font-weight: 800; color: #92400e; }

.map-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-top: 4px; }
.map-name { font-weight: 800; line-height: 1.55; overflow-wrap: anywhere; }
.map-state { font-size: .8rem; font-weight: 700; color: var(--muted); line-height: 1.5; }
.map-pct { color: #b45309; font-size: .95rem; }
.map-stars { color: #f59e0b; letter-spacing: 1px; white-space: nowrap; }
.map-stars .off { color: #d6d3d1; }

/* 状態ごとの色 */
.map-stop.is-mastered .map-dot { background: linear-gradient(135deg, #fef3c7, #fbbf24); border-color: #f59e0b; font-size: 2rem; }
.map-stop.is-mastered .map-state { color: #b45309; }
.map-stop.is-learning .map-dot { border-color: #f59e0b; color: #b45309; }
@supports (background: conic-gradient(red, blue)) {
  /* 習熟度の わっか（--pct = 0〜100） */
  .map-stop.is-learning .map-dot {
    border-width: 0;
    background:
      radial-gradient(closest-side, #fff calc(100% - 8px), transparent calc(100% - 7px)),
      conic-gradient(#f59e0b calc(var(--pct, 0) * 1%), #fde68a 0);
  }
}
.map-stop.is-ready .map-dot { border-color: #10b981; background: #ecfdf5; color: #047857; box-shadow: 0 5px 0 rgba(0, 0, 0, .14), 0 0 0 6px rgba(16, 185, 129, .22); }
.map-stop.is-ready .map-state { color: #047857; }
.map-stop.is-locked .map-dot { border: 4px dashed #9ca3af; background: #e5e7eb; color: #6b7280; box-shadow: 0 3px 0 rgba(0, 0, 0, .08); }
.map-stop.is-locked .map-name { color: #4b5563; }

/* 学年の 立てふだ・ゴール */
.map-grade .map-dot { border-radius: 20px; background: linear-gradient(135deg, #818cf8, #4f46e5); border-color: #3730a3; color: #fff; font-size: 1.35rem; }
.map-grade.is-complete .map-dot { background: linear-gradient(135deg, #fbbf24, #d97706); border-color: #b45309; }
.map-grade .map-badge { right: -11px; top: -11px; min-width: 24px; height: 24px; font-size: .72rem; }
.map-grade .map-name { font-size: 1.1rem; color: #3730a3; }
.map-goal .map-dot { border-color: #111827; font-size: 2rem; }
.map-goal.is-complete .map-dot { background: linear-gradient(135deg, #fef3c7, #fbbf24); border-color: #f59e0b; }

/* いま ここ */
.map-now { display: inline-flex; scroll-margin-top: calc(var(--top-h, 64px) + 80px); }
.map-now b {
  position: relative; display: inline-flex; align-items: center; white-space: nowrap;
  padding: 3px 14px; border-radius: 999px; background: var(--primary); color: #fff; font-size: .95rem; line-height: 1.5;
  box-shadow: 0 3px 8px rgba(79, 70, 229, .4); animation: map-hop 1.4s ease-in-out infinite;
}
.map-stop.is-now .map-dot { animation: map-pulse 1.8s ease-out infinite; }
.map-stop.is-now .map-name { font-size: 1.08rem; }
@keyframes map-pulse {
  0% { box-shadow: 0 5px 0 rgba(0, 0, 0, .14), 0 0 0 0 rgba(99, 102, 241, .6); }
  70% { box-shadow: 0 5px 0 rgba(0, 0, 0, .14), 0 0 0 18px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 5px 0 rgba(0, 0, 0, .14), 0 0 0 0 rgba(99, 102, 241, 0); }
}
@keyframes map-hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* ほかの ちずから 来たとき・ページの中で とんだとき */
.map-cell.is-target .map-dot, .map-cell:target .map-dot { outline: 4px solid #ec4899; outline-offset: 4px; }

/* 「さきに: …」のチップ */
.map-pre { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 calc(var(--dot) + 14px); }
/* .chip は inline-flex。ふりがな（ruby）が 1つずつ ばらばらに ならばないよう、ふつうの文として流す */
.map-pre .map-pre-chip {
  display: inline-block; max-width: 100%; min-height: 36px; padding: 6px 12px; border-radius: 18px;
  font-size: .8rem; white-space: normal; text-align: left; line-height: 1.7; overflow-wrap: anywhere;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
}
.map-pre-chip.is-outside { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.map-pre-chip.is-done { background: #d1fae5; color: #047857; border-color: #6ee7b7; }
.map-pre-chip:hover { text-decoration: none; filter: brightness(.97); }

/* ---------- タブレット以上: くねくね道 ---------- */
@media (min-width: 600px) {
  .map-board { --dot: 76px; --gap-x: 12px; --gap-y: 34px; --side: 30px; --lift: 40px; padding: 18px 12px 30px; }
  .map-head-ico, .map-head-ico .illust-icon { width: 96px; height: 96px; }
  .map-head-ico { font-size: 3.4rem; }
  .map-path { grid-auto-flow: row dense; } /* 列を決めたマスを、その列の 空いている いちばん上の行に 入れる */
  .map-tile { flex-direction: column; align-items: center; gap: 10px; text-align: center; }
  .map-text { flex: none; width: 100%; align-items: center; padding-top: 0; }
  .map-name { font-size: .95rem; }
  .map-pre { margin: 8px 0 0; justify-content: center; }
  .map-pre-chip { text-align: center; }

  /* 「いま ここ」は マスの 真上に */
  .map-now { position: absolute; top: 0; left: 0; right: 0; justify-content: center; pointer-events: none; }
  .map-now b::after { content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: var(--primary); }

  /* 道（→ 右の マスへ） */
  .map-cell::after {
    top: calc(var(--lift) + var(--dot) / 2 - 6px); left: 50%; right: auto;
    width: calc(100% + var(--gap-x)); height: 12px;
  }
}

/* 3列（タブレット たて向き）: 1 2 3 / 6 5 4 / 7 8 9 … */
@media (min-width: 600px) and (max-width: 1023.98px) {
  .map-path { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .map-cell:nth-child(6n+1), .map-cell:nth-child(6n) { grid-column: 1; }
  .map-cell:nth-child(6n+2), .map-cell:nth-child(6n+5) { grid-column: 2; }
  .map-cell:nth-child(6n+3), .map-cell:nth-child(6n+4) { grid-column: 3; }
  /* ← 左の マスへ */
  .map-cell:nth-child(6n+4)::after, .map-cell:nth-child(6n+5)::after { left: auto; right: 50%; }
  /* 行の はし: U ターンで 下の行へ */
  .map-cell:nth-child(6n+3)::after, .map-cell:nth-child(6n)::after {
    width: auto; height: calc(100% + var(--gap-y) + 12px); background: none; border-width: 12px;
  }
  .map-cell:nth-child(6n+3)::after { left: 50%; right: calc(10px - var(--side)); border-left-width: 0; border-radius: 0 40px 40px 0; }
  .map-cell:nth-child(6n)::after { right: 50%; left: calc(10px - var(--side)); border-right-width: 0; border-radius: 40px 0 0 40px; }
}

/* 4列（タブレット よこ向き・PC）: 1 2 3 4 / 8 7 6 5 / 9 … */
@media (min-width: 1024px) {
  .map-path { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .map-cell:nth-child(8n+1), .map-cell:nth-child(8n) { grid-column: 1; }
  .map-cell:nth-child(8n+2), .map-cell:nth-child(8n+7) { grid-column: 2; }
  .map-cell:nth-child(8n+3), .map-cell:nth-child(8n+6) { grid-column: 3; }
  .map-cell:nth-child(8n+4), .map-cell:nth-child(8n+5) { grid-column: 4; }
  .map-cell:nth-child(8n+5)::after, .map-cell:nth-child(8n+6)::after, .map-cell:nth-child(8n+7)::after { left: auto; right: 50%; }
  .map-cell:nth-child(8n+4)::after, .map-cell:nth-child(8n)::after {
    width: auto; height: calc(100% + var(--gap-y) + 12px); background: none; border-width: 12px;
  }
  .map-cell:nth-child(8n+4)::after { left: 50%; right: calc(10px - var(--side)); border-left-width: 0; border-radius: 0 40px 40px 0; }
  .map-cell:nth-child(8n)::after { right: 50%; left: calc(10px - var(--side)); border-right-width: 0; border-radius: 40px 0 0 40px; }
}

/* ---------- スマホ ---------- */
@media (max-width: 599.98px) {
  .map-hero-ico { font-size: 2.4rem; }
  .map-subjects { grid-template-columns: minmax(0, 1fr); }
  .map-grade .map-text, .map-goal .map-text { padding-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .map-now b, .map-stop.is-now .map-dot { animation: none; }
  .map-stop.is-now .map-dot { box-shadow: 0 5px 0 rgba(0, 0, 0, .14), 0 0 0 7px rgba(99, 102, 241, .35); }
  .map-dot, .map-resume:hover { transition: none; }
}
