/*
  YELL 教材ページのレイアウト（front matter に type があるページだけ）。
  .yell-page-header の有無で判定する（overrides/partials/yell-page-header.html）。
  色・余白は tokens.css の変数を使う。カードは「教材を選ぶ」ところだけに使う。
*/

.yell-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.yell-subject--math { --yell-subject: var(--yell-subject-math); }
.yell-subject--english { --yell-subject: var(--yell-subject-english); }
.yell-subject--science { --yell-subject: var(--yell-subject-science); }
.yell-subject--social { --yell-subject: var(--yell-subject-social); }
.yell-subject--japanese { --yell-subject: var(--yell-subject-japanese); }

/* ── 外枠：ドキュメントサイトらしさを減らす ───────────────── */

body:has(.yell-page-header) .md-tabs,
body:has(.yell-page-header) .print-button-container,
.md-main:has(.yell-page-header) .md-path {
  display: none;
}

/* 文章を読む幅（Visual Lab は広く） */
.md-main:has(.yell-page-header) .md-content {
  max-width: var(--yell-reading-width);
  margin-inline: auto;
}

.md-main:has(.yell-page-header--visual-lab) .md-content {
  max-width: var(--yell-wide-width);
}

/* Lesson の中の操作する部分だけ、本文より広く使う */
.md-main:has(.yell-page-header--lesson) .yell-number-line[data-yell] {
  --wide: min(var(--yell-wide-width), calc(100vw - 2rem));
  width: var(--wide);
  margin-left: calc(50% - var(--wide) / 2);
}

.md-main:has(.yell-page-header) .md-typeset h1 {
  margin-bottom: var(--yell-space-3);
  color: var(--yell-color-text);
  font-weight: var(--yell-font-weight-bold);
}

/* ── ページ上部 ───────────────────────────────────────── */

.yell-page-header {
  margin: 0 0 var(--yell-space-3);
}

.md-typeset ol.yell-page-header__path {
  display: flex;
  flex-wrap: wrap;
  gap: var(--yell-space-1) var(--yell-space-2);
  margin: 0;
  padding: 0;
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
  list-style: none;
}

.md-typeset .yell-page-header__path li {
  margin: 0;
}

.yell-page-header__path li + li::before {
  content: ">";
  margin-right: var(--yell-space-2);
  color: var(--yell-color-text-muted);
}

.yell-page-header__path li:first-child {
  color: var(--yell-subject, var(--yell-color-primary));
  font-weight: var(--yell-font-weight-bold);
}

.yell-page-header__path a {
  color: inherit;
}

.yell-page-header__position {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--yell-space-3);
  margin-top: var(--yell-space-3);
}

.yell-page-header__kind {
  margin: var(--yell-space-2) 0 0;
  color: var(--yell-color-secondary);
  font-size: var(--yell-font-size-sm);
  font-weight: var(--yell-font-weight-bold);
  letter-spacing: 0.08em;
}

.yell-page-header__position .yell-page-header__kind {
  margin: 0;
}

.yell-page-header__back {
  margin: var(--yell-space-3) 0 0;
  font-size: var(--yell-font-size-md);
}

/* Lesson の進み具合（● 終えた・◐ 学習中・○ まだ）。色だけでなく形でも区別する */
.md-typeset ol.yell-lesson-dots {
  display: flex;
  gap: var(--yell-space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Material の [dir=ltr] .md-typeset ol li の左余白（1.25em）を打ち消す。残すと Lesson が7つの単元でスマホの幅をこえる */
[dir] .md-typeset ol.yell-lesson-dots li,
.md-typeset ol.yell-lesson-dots li {
  margin: 0;
}

.yell-lesson-dots a {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
}

.yell-lesson-dots a::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid var(--yell-color-primary);
  border-radius: 50%;
  box-sizing: border-box;
}

.yell-lesson-dots li[data-state="visited"] a::before {
  background: linear-gradient(90deg, var(--yell-color-primary) 50%, transparent 50%);
}

.yell-lesson-dots li[data-state="completed"] a::before {
  background: var(--yell-color-primary);
}

.yell-lesson-dots li[aria-current="page"] a::before {
  outline: 2px solid var(--yell-color-secondary);
  outline-offset: 2px;
}

.yell-page-header__print {
  margin-left: auto;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--yell-color-border);
  border-radius: var(--yell-radius-sm);
  background: none;
  color: var(--yell-color-text-muted);
  font: inherit;
  font-size: var(--yell-font-size-sm);
  cursor: pointer;
}

.yell-page-header__print:hover,
.yell-page-header__print:focus-visible {
  border-color: var(--yell-color-primary);
  color: var(--yell-color-primary);
}

.yell-page-header__meta {
  display: flex;
  gap: var(--yell-space-5);
  margin: var(--yell-space-3) 0 0;
}

.yell-page-header__meta dt {
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

.yell-page-header__meta dd {
  margin: 0;
  font-weight: var(--yell-font-weight-bold);
}

.yell-page-header__action .md-button {
  margin: var(--yell-space-3) 0 0;
}

/* ── 節の目次（Lesson。画面上部に固定し、今いる節を強調する） ── */

.yell-lesson-sections {
  position: sticky;
  top: 2.4rem;
  z-index: 20; /* JSXGraph の文字（z-index 10 前後）より手前に出す */
  margin: 0 calc(-1 * var(--yell-space-2)) var(--yell-space-5);
  padding: var(--yell-space-2);
  background: var(--yell-color-surface);
  border-bottom: 1px solid var(--yell-color-border);
}

.md-typeset .yell-lesson-sections ol:not([hidden]) {
  display: flex;
  gap: var(--yell-space-1);
  margin: 0;
  padding: 0;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: thin;
}

.md-typeset .yell-lesson-sections li {
  margin: 0;
  flex: none;
}

.yell-lesson-sections a {
  display: block;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--yell-color-border);
  border-radius: 999px;
  color: var(--yell-color-text);
  font-size: 0.72rem;
  white-space: nowrap;
}

.yell-lesson-sections a:hover,
.yell-lesson-sections a:focus-visible {
  border-color: var(--yell-color-primary);
}

.yell-lesson-sections a[aria-current="true"] {
  border-color: var(--yell-color-primary);
  background: var(--yell-color-primary);
  color: var(--yell-color-on-primary);
}

/* 節の見出し：箱で囲まず、上の線と余白で区切る */
.md-main:has(.yell-page-header--lesson) .md-typeset h2[id] {
  margin-top: var(--yell-space-6);
  padding-top: var(--yell-space-3);
  border-top: 2px solid var(--yell-color-border);
  color: var(--yell-color-secondary);
}

/* ── 次に進もう・関連教材 ──────────────────────────────── */

.yell-lesson-next {
  margin-top: var(--yell-space-6);
}

.md-typeset ul.yell-related {
  margin: var(--yell-space-4) 0 0;
  padding: 0;
  list-style: none;
}

.md-typeset .yell-related li {
  margin: 0;
  border-top: 1px solid var(--yell-color-border);
}

.yell-related a {
  display: block;
  padding: var(--yell-space-3) 0;
  color: var(--yell-color-text);
}

.yell-related__kind {
  display: block;
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

/* ── 単元ページ ───────────────────────────────────────── */

.yell-hub__group {
  margin-top: var(--yell-space-6);
}

.md-typeset .yell-hub__group h2 {
  margin: 0 0 var(--yell-space-3);
  font-size: var(--yell-font-size-lg);
  font-weight: var(--yell-font-weight-bold);
}

.md-typeset ol.yell-hub__lessons {
  margin: 0;
  padding: 0;
  list-style: none;
}

.md-typeset .yell-hub__lessons li {
  margin: 0;
  border-bottom: 1px solid var(--yell-color-border);
}

.yell-hub__lessons a {
  display: flex;
  align-items: center;
  gap: var(--yell-space-3);
  min-height: 48px;
  color: var(--yell-color-text);
}

.yell-hub__number {
  color: var(--yell-color-text-muted);
  font-variant-numeric: tabular-nums;
}

.yell-hub__lessons .yell-hub__title {
  flex: 1;
}

.yell-hub__state {
  color: var(--yell-color-primary);
  font-size: var(--yell-font-size-sm);
  font-weight: var(--yell-font-weight-bold);
  white-space: nowrap;
}

.md-typeset ul.yell-hub__items {
  display: grid;
  gap: var(--yell-space-3);
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.md-typeset .yell-hub__items li {
  margin: 0;
}

.yell-hub__items a {
  display: flex;
  flex-direction: column;
  gap: var(--yell-space-1);
  height: 100%;
  padding: var(--yell-space-4);
  border: 1px solid var(--yell-color-border);
  border-radius: var(--yell-radius-md);
  color: var(--yell-color-text);
}

.yell-hub__items a:hover,
.yell-hub__items a:focus-visible,
.yell-hub__lessons a:focus-visible {
  border-color: var(--yell-color-primary);
}

.yell-hub__items .yell-hub__title {
  font-weight: var(--yell-font-weight-bold);
}

.yell-hub__description,
.yell-hub__meta {
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

.yell-hub__meta {
  display: flex;
  gap: var(--yell-space-3);
}

/* ── Visual Lab ──────────────────────────────────────── */

.yell-lab__readout {
  display: flex;
  justify-content: center;
  gap: var(--yell-space-6);
  margin: 0 0 var(--yell-space-3);
  text-align: center;
}

.yell-lab__readout dt {
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

.yell-lab__readout dd {
  margin: 0;
  font-size: var(--yell-font-size-xl);
  font-weight: var(--yell-font-weight-bold);
  font-variant-numeric: tabular-nums;
}

.yell-number-line .yell-lab__controls {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.yell-lab__controls .md-button {
  min-height: 44px;
  margin: 0;
}

.yell-lab__challenge {
  margin-top: var(--yell-space-4);
  padding: var(--yell-space-4);
  border-left: 4px solid var(--yell-brand-green);
  background: var(--yell-color-primary-soft);
}

.yell-lab__challenge p {
  margin: 0 0 var(--yell-space-2);
}

.yell-lab__challenge-label {
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
  font-weight: var(--yell-font-weight-bold);
}

.yell-lab__challenge-text {
  font-size: var(--yell-font-size-lg);
}

.yell-lab__message {
  color: var(--yell-feedback-correct);
  font-weight: var(--yell-font-weight-bold);
}

.yell-lab__challenge .md-button {
  margin: var(--yell-space-2) 0 0;
}

.md-main:has(.yell-page-header--visual-lab) .yell-explorer__board {
  max-width: none;
  height: 220px;
}

/* ── プリント ─────────────────────────────────────────── */

.yell-worksheet__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--yell-space-3);
  padding-bottom: var(--yell-space-2);
  border-bottom: 2px solid var(--yell-color-text);
}

.yell-worksheet__header p {
  margin: 0;
}

.yell-worksheet__title {
  font-weight: var(--yell-font-weight-bold);
}

.yell-worksheet__name span {
  display: inline-block;
  width: min(7rem, 22vw);
  margin: 0 var(--yell-space-3) 0 var(--yell-space-1);
  border-bottom: 1px solid var(--yell-color-text);
}

.yell-worksheet__questions li {
  margin-bottom: var(--yell-space-5);
}

.yell-worksheet__blank {
  display: inline-block;
  width: 8rem;
  height: 1.4em;
  margin-left: var(--yell-space-4);
  border-bottom: 1px solid var(--yell-color-text);
  vertical-align: bottom;
}

.yell-worksheet__part {
  display: block;
  margin-top: var(--yell-space-1);
}

.yell-worksheet__choices {
  display: block;
  margin-top: var(--yell-space-1);
}

.yell-worksheet__answers {
  margin-top: var(--yell-space-6);
}

/* 作図・説明の問題：問題図のまわりに作図するスペース（紙にかく）。説明は罫線の欄 */
.yell-worksheet__space {
  margin-top: var(--yell-space-2);
  padding: var(--yell-space-3);
  border: 1px solid var(--yell-color-border, #bbb);
  border-radius: 4px;
}

.yell-worksheet__space--draw {
  display: flex;
  min-height: 15rem;
  align-items: center;
  justify-content: center;
}

.yell-worksheet__space--draw svg {
  width: 100%;
  max-width: calc(var(--yell-svg-width, 320) * 1.15px);
  height: auto;
}

.yell-worksheet__space--write {
  min-height: 9rem;
  background: repeating-linear-gradient(transparent 0 1.9rem, var(--yell-color-border, #ccc) 1.9rem 2rem);
}

.yell-worksheet__answers .yell-visual svg {
  max-width: calc(var(--yell-svg-width, 320) * 1px);
}

/* ── テスト ───────────────────────────────────────────── */

.yell-test {
  padding: var(--yell-space-4) 0;
}

.yell-test__meta {
  font-size: var(--yell-font-size-lg);
  font-weight: var(--yell-font-weight-bold);
}

.yell-test__note {
  color: var(--yell-color-text-muted);
}

.yell-test__progress p {
  margin: 0 0 var(--yell-space-1);
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

.yell-test__question {
  margin: var(--yell-space-4) 0;
  font-size: var(--yell-font-size-lg);
}

.yell-test__label {
  margin: 0;
  color: var(--yell-color-secondary);
  font-size: var(--yell-font-size-sm);
  font-weight: var(--yell-font-weight-bold);
  letter-spacing: 0.12em;
}

.yell-test__score {
  margin: 0;
  font-size: var(--yell-font-size-lg);
}

.yell-test__score-note {
  margin-left: var(--yell-space-2);
  font-size: var(--yell-font-size-sm);
  color: var(--yell-color-text-muted);
}

.yell-test__self-note {
  font-size: var(--yell-font-size-sm);
  color: var(--yell-color-text-muted);
}

.yell-test__score strong {
  font-size: 2.4rem;
}

.yell-test__message {
  font-weight: var(--yell-font-weight-bold);
}

.yell-test__skills-result th {
  font-weight: normal;
}

.yell-test__skills-result td span[aria-hidden] {
  color: var(--yell-color-primary);
  letter-spacing: 0.15em;
}

.yell-test__count {
  margin-left: var(--yell-space-2);
  color: var(--yell-color-text-muted);
  font-size: var(--yell-font-size-sm);
}

.yell-test__review li.is-wrong .yell-test__mark {
  color: var(--yell-feedback-retry);
}

.yell-test__explanation {
  color: var(--yell-color-text-muted);
}

/* テスト中は、余計なナビゲーションを隠して問題に集中する */
.yell-test-running .md-header__inner .md-search,
.yell-test-running .yell-page-header,
.yell-test-running .md-footer,
.yell-test-running .md-source-file,
.yell-test-running .md-content__inner > h1 ~ :not(.yell-test) {
  display: none !important;
}

/* ── 印刷 ─────────────────────────────────────────────── */

@media print {
  .yell-lesson-sections,
  .yell-page-header__action,
  .yell-lesson-dots,
  .yell-page-header__back,
  .yell-hub .md-button {
    display: none !important;
  }

  .md-main:has(.yell-page-header) .md-content,
  .md-main:has(.yell-page-header--visual-lab) .md-content {
    max-width: none;
  }

  .md-main:has(.yell-page-header--lesson) .yell-number-line[data-yell] {
    width: auto;
    margin-left: 0;
  }

  .yell-worksheet__answers {
    break-before: page;
  }

  .yell-worksheet__questions > li,
  .yell-worksheet__answers li {
    break-inside: avoid;
  }

  .yell-worksheet__space {
    border-color: #999;
  }

  .md-typeset .yell-worksheet__answers {
    border: 0;
    box-shadow: none;
  }

  .yell-worksheet__answers > summary {
    display: none;
  }

  .yell-page-header__print {
    display: none;
  }
}

.md-typeset .yell-lab__readout dd {
  margin: 0;
}

.md-typeset .yell-test__skills-result th {
  text-align: left;
}

/* 結果に移ったとき、読み上げのためにフォーカスを移すが、大きな枠は出さない */
.yell-test__stage:focus {
  outline: none;
}

/* 間違えやすいポイント：箱で囲まず、✗ と ○ の行で示す（色だけでなく記号と言葉でも区別する） */
.md-typeset p.yell-mistake-wrong,
.md-typeset p.yell-mistake-right {
  margin: var(--yell-space-1) 0;
  padding-left: var(--yell-space-3);
  border-left: 3px solid;
}

.md-typeset p.yell-mistake-wrong {
  border-color: var(--yell-feedback-retry);
  color: var(--yell-color-text-muted);
}

.md-typeset p.yell-mistake-right {
  border-color: var(--yell-feedback-correct);
  font-weight: var(--yell-font-weight-bold);
}

.md-typeset .yell-page-header__meta dd {
  margin: 0;
}

/* スマホ：スライダーを1行目、左右のボタンを2行目に並べる */
@media (max-width: 599px) {
  .yell-number-line .yell-lab__controls {
    grid-template-columns: 1fr 1fr;
  }

  .yell-lab__controls .yell-explorer__control {
    grid-column: 1 / -1;
    order: -1;
  }
}

.yell-worksheet__answers-title {
  font-weight: var(--yell-font-weight-bold);
}
