/* Math Derivation Chart 固有スタイル */

.mdc-outer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.2rem;
}

.breadcrumb {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
.breadcrumb a {
  color: var(--color-primary);
  text-decoration: none;
}
.breadcrumb a:hover {
  text-decoration: underline;
}

.mdc-intro {
  font-size: 0.88rem;
  color: var(--color-text-light);
  margin-bottom: 1.2rem;
  line-height: 1.7;
}

/* Filter bar */
.mdc-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.8rem;
  font-size: 0.82rem;
}
.mdc-filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.mdc-filter-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-right: 0.2rem;
}
.mdc-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-light);
  font-size: 0.78rem;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-primary);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.mdc-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.mdc-chip.active {
  background: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}
.mdc-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

/* Action chips (preset buttons - not toggleable) */
.mdc-chip-action {
  font-size: 0.7rem;
  padding: 0.12rem 0.55rem;
  border-style: dashed;
  color: var(--color-text-muted);
}
.mdc-chip-action:hover {
  border-style: solid;
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-bg);
}

/* Layout: graph + panel (panel overlays graph) */
.mdc-layout {
  display: block;
}
.mdc-graph-wrapper {
  position: relative;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  height: 78vh;
  min-height: 540px;
  overflow: hidden;
}
#mdc-graph {
  width: 100%;
  height: 100%;
  overflow: auto;
  background:
    linear-gradient(to bottom, transparent calc(100% - 1px), var(--color-bg-alt) 100%);
}
#mdc-svg {
  display: block;
}

/* SVG: depth 軸 */
.mdc-axis-depth text {
  font-family: var(--font-accent, var(--font-primary));
  font-size: 10px;
  fill: var(--color-text-muted);
  letter-spacing: 0.05em;
}
.mdc-axis-depth line {
  stroke: var(--color-border);
  stroke-dasharray: 2 3;
}

/* SVG: スイムレーン */
.mdc-lane-bg {
  fill: var(--color-bg-alt);
  stroke: var(--color-border);
}
.mdc-lane-cat {
  font-family: var(--font-accent, var(--font-primary));
  font-size: 10px;
  font-weight: 600;
  text-anchor: end;
}
.mdc-lane-topic {
  font-family: var(--font-accent, var(--font-primary));
  font-size: 11px;
  fill: var(--color-text);
  text-anchor: end;
}
.mdc-lane-sep {
  stroke: var(--color-border);
  stroke-dasharray: 2 4;
}

/* SVG: ノード */
.mdc-node {
  cursor: pointer;
}
.mdc-node text {
  font-family: var(--font-primary);
  font-size: 10px;
  fill: var(--color-text);
  pointer-events: none;
  user-select: none;
}
.mdc-node rect {
  transition: filter 0.12s;
}
.mdc-node.faded { opacity: 0.16; }
.mdc-node.selected rect {
  stroke: var(--color-accent) !important;
  stroke-width: 3.5 !important;
  filter: drop-shadow(0 0 4px rgba(192, 76, 56, 0.45));
}

/* 学年で扱いが変わるノードのバッジ（右上隅のアスタリスク） */
.mdc-node-badge {
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 700;
  fill: #d4a373;  /* 補題色と同系の amber、目立ちすぎず */
  pointer-events: none;
  user-select: none;
}
/* 凡例の同バッジ表示 */
.mdc-legend-badge {
  display: inline-block;
  width: 16px;
  text-align: center;
  font-weight: 700;
  color: #d4a373;
}

/* SVG: エッジ */
.mdc-edge-line {
  fill: none;
  stroke: #a8a395;
  stroke-width: 1;
  stroke-opacity: 0.5;
  pointer-events: none;
}
.mdc-edge-label {
  font-size: 9px;
  font-family: var(--font-primary);
  fill: #5a5a5a;
  paint-order: stroke fill;
  stroke: var(--color-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
  opacity: 0;                     /* default: hidden to avoid label clutter */
  transition: opacity 0.15s ease;
}
.mdc-edge.faded .mdc-edge-line { stroke-opacity: 0.05; }
.mdc-edge.highlighted .mdc-edge-line {
  stroke: var(--color-accent);
  stroke-opacity: 0.95;
  stroke-width: 1.8;
}
.mdc-edge.highlighted .mdc-edge-label {
  opacity: 1;                     /* shown only when the edge is highlighted */
  fill: var(--color-accent);
  font-weight: 600;
}

/* Loading overlay */
.mdc-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  background: rgba(248, 246, 241, 0.92);
  z-index: 20;
  font-size: 0.88rem;
  color: var(--color-text-light);
  font-family: var(--font-primary);
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.mdc-loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}
.mdc-loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: mdc-spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes mdc-spin {
  to { transform: rotate(360deg); }
}

/* Legend (overlay) */
.mdc-legend {
  position: absolute;
  bottom: 0.6rem;
  left: 0.6rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.6rem;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  pointer-events: none;
}
.mdc-legend-section-title {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-transform: none;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.1rem;
  margin-bottom: 0.1rem;
}
.mdc-legend-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.mdc-legend-swatch {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  box-sizing: border-box;
}

/* Detail panel (overlay) */
.mdc-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 340px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  border-left: 1px solid var(--color-border);
  display: none;
  flex-direction: column;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.06);
}
.mdc-panel.is-visible {
  display: flex;
}
.mdc-panel-header {
  display: flex;
  justify-content: flex-end;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.mdc-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  padding: 0.15rem 0.4rem;
  line-height: 1;
  font-family: var(--font-primary);
}
.mdc-panel-close:hover {
  color: var(--color-accent);
}
#mdc-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  font-size: 0.85rem;
  line-height: 1.7;
}
.mdc-panel-empty {
  color: var(--color-text-muted);
  font-style: italic;
}
.mdc-panel-type-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-white);
}
.mdc-panel-grade-badge {
  display: inline-block;
  padding: 0 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--color-white);
  letter-spacing: 0.06em;
}
.mdc-panel-label {
  font-family: var(--font-accent);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--color-primary);
  margin-bottom: 0.3rem;
  line-height: 1.4;
}
.mdc-panel-meta {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-bottom: 0.6rem;
}
.mdc-panel-section {
  margin-top: 0.7rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--color-border);
}
.mdc-panel-section h4 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.3rem;
  letter-spacing: 0.04em;
}
.mdc-panel-proof {
  white-space: pre-wrap;
  font-size: 0.82rem;
  color: var(--color-text);
  background: var(--color-bg);
  padding: 0.5rem 0.6rem;
  border-left: 3px solid var(--color-primary-light);
}
.mdc-panel-refs {
  list-style: none;
  padding: 0;
}
.mdc-panel-refs li {
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}
.mdc-panel-refs a {
  color: var(--color-accent);
  text-decoration: none;
}
.mdc-panel-refs a:hover {
  text-decoration: underline;
}

/* 参考書籍セクション */
.mdc-book-pr {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 2px;
  padding: 0 0.25rem;
  vertical-align: middle;
  margin-left: 0.3rem;
}
.mdc-book-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.mdc-book-item a {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-white);
  transition: background 0.15s;
}
.mdc-book-item a:hover {
  background: var(--color-bg);
}
.mdc-book-cover {
  width: 44px;
  height: auto;
  flex-shrink: 0;
  object-fit: contain;
  border: 1px solid var(--color-border);
}
.mdc-book-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.mdc-book-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.4;
  word-break: break-all;
}
.mdc-book-author {
  font-size: 0.72rem;
  color: var(--color-text-light);
}
.mdc-book-rakuten {
  font-size: 0.7rem;
  color: var(--color-accent);
  margin-top: 0.1rem;
}

.mdc-related-list {
  list-style: none;
  padding: 0;
  font-size: 0.78rem;
}
.mdc-related-list li {
  margin-bottom: 0.15rem;
}
.mdc-related-link {
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-align: left;
}
.mdc-related-link:hover {
  text-decoration: underline;
}
.mdc-related-edge-label {
  color: var(--color-text-muted);
  font-size: 0.72rem;
  margin-left: 0.3rem;
}

/* Guide explainer */
.mdc-guide {
  font-size: 0.92rem;
  line-height: 2;
  color: var(--color-text);
  max-width: 760px;
  margin: 1.6rem auto 0;
}
.mdc-guide h3 {
  font-family: var(--font-accent);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--color-primary);
  margin: 2rem 0 0.6rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--color-border);
}
.mdc-guide h3:first-child {
  margin-top: 0;
}
.mdc-guide p {
  margin: 0 0 1rem;
}
.mdc-guide ul {
  padding-left: 1.4em;
  margin: 0 0 1rem;
}
.mdc-guide li {
  margin-bottom: 0.5rem;
}
.mdc-guide strong {
  color: var(--color-text);
  font-weight: 700;
}

/* Sources note */
.mdc-sources {
  margin-top: 1.6rem;
  padding: 0.9rem 1rem;
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-primary);
  font-size: 0.78rem;
  color: var(--color-text-light);
  line-height: 1.7;
}
.mdc-sources h3 {
  font-family: var(--font-accent);
  font-size: 0.95rem;
  color: var(--color-primary);
  margin-bottom: 0.4rem;
}
.mdc-sources ul {
  padding-left: 1.2rem;
  margin: 0.3rem 0;
}

/* Fullscreen button */
.mdc-btn-fullscreen {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 5;
  font-size: 0.75rem;
  font-family: var(--font-primary);
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-text-light);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.mdc-btn-fullscreen:hover {
  border-color: var(--color-primary);
  background: var(--color-bg);
  color: var(--color-primary);
}

/* Fullscreen mode */
.mdc-graph-wrapper:fullscreen,
.mdc-graph-wrapper:-webkit-full-screen {
  width: 100vw;
  height: 100vh !important;
  min-height: unset;
  border: none;
}

/* Mobile */
@media (max-width: 900px) {
  .mdc-btn-fullscreen {
    display: none;
  }
  .mdc-graph-wrapper {
    height: 60vh;
    min-height: 380px;
  }
  .mdc-panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 55%;
    border-left: none;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  }
  /* パネル展開時は下端の凡例とフルスクリーンボタンが被るので隠す */
  .mdc-graph-wrapper:has(.mdc-panel.is-visible) .mdc-legend {
    display: none;
  }
}
@media (max-width: 600px) {
  .mdc-filters {
    font-size: 0.78rem;
    padding: 0.5rem 0.7rem;
  }
  .mdc-chip {
    padding: 0.18rem 0.5rem;
    font-size: 0.72rem;
  }
  .mdc-legend {
    font-size: 0.68rem;
    padding: 0.3rem 0.5rem;
  }
}
