/* User Provided Stylesheet */

/*
 * UTAF curriculum layout
 *
 * The desktop composition follows the JSK exercise-text pattern:
 * project navigation and a large identity mark on the left, reading content in
 * the centre, and the current page outline on the right.
 */

:root {
  --utaf-border: #e2e8f0;
  --utaf-ink: #172033;
  --utaf-muted: #5c687c;
  --utaf-accent: #ef7d32;
}

html {
  scroll-behavior: smooth;
}

body {
  color: var(--utaf-ink);
}

/*
 * Keep downloads contextual: the complete PDF is linked explicitly from the
 * landing page, so the stock per-page download menu is intentionally absent.
 */
.myst-fm-downloads-dropdown {
  display: none !important;
}

.article .utaf-pdf-download {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.625rem 1rem;
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  text-decoration: none;
  background: #0f5960;
  border: 1px solid #0f5960;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgb(15 23 42 / 12%);
}

.article .utaf-pdf-download:hover {
  color: #fff;
  background: #0b464c;
  border-color: #0b464c;
}

.article .utaf-pdf-download:focus-visible {
  outline: 3px solid rgb(239 125 50 / 45%);
  outline-offset: 3px;
}

/*
 * The landing page title and subtitle are synchronized from myst.yml. The
 * native subtitle therefore sits between the title and this credits block.
 * Contributors come first and the supervisor is the final entry.
 */
body:has(.utaf-project-toc) .myst-fm-block-subtitle {
  max-width: 48rem;
  margin-top: 0.75rem !important;
  font-size: clamp(1.1rem, 1.5vw, 1.3rem);
  line-height: 1.65;
  color: var(--utaf-muted);
}

body:has(.utaf-project-toc) .myst-fm-authors-affiliations {
  margin-top: 1.5rem;
}

body:has(.utaf-project-toc) .myst-fm-authors-list {
  display: grid;
  width: fit-content;
  max-width: 100%;
  row-gap: 0.35rem;
}

body:has(.utaf-project-toc) .myst-fm-author-item {
  display: grid !important;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  column-gap: 1rem;
  align-items: baseline;
}

body:has(.utaf-project-toc) .myst-fm-author-item::before {
  grid-column: 1;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--utaf-muted);
  text-align: right;
  content: "";
}

body:has(.utaf-project-toc) .myst-fm-author-item:first-child::before {
  content: "執筆";
}

body:has(.utaf-project-toc) .myst-fm-author-item:last-child::before {
  content: "監修";
}

body:has(.utaf-project-toc) .myst-fm-author-popover {
  grid-column: 2;
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.6;
  text-align: left;
}

body:has(.utaf-project-toc) .myst-fm-author-comma::after {
  display: none;
  content: none;
}

/* The project TOC already sits on the landing page, so omit its self-link. */
.article .utaf-project-toc > ul > li:first-child {
  display: none;
}

/* Use spacing and indentation—not faint bullets—to express TOC hierarchy. */
.article .utaf-project-toc ul {
  list-style: none;
}

.article .utaf-project-toc > ul {
  padding-left: 0;
}

.article .utaf-project-toc > ul > li {
  margin-block: 1.25rem;
}

.article .utaf-project-toc > ul > li > ul {
  margin-top: 0.5rem;
  padding-left: 1.5rem;
}

.article .utaf-project-toc > ul > li > ul > li {
  margin-block: 0.375rem;
}

/*
 * The brand is supplied through MyST's primary-sidebar footer part, then moved
 * visually before the navigation. The pointer—not the navigation alone—is the
 * scroll container, so the logo scrolls away together with the table of
 * contents instead of floating above it.
 */
.myst-primary-sidebar-pointer {
  overflow-x: hidden;
  overflow-y: auto;
}

.myst-primary-sidebar-nav {
  flex: 0 0 auto;
  overflow: visible;
}

.myst-primary-sidebar-pointer > .myst-primary-sidebar-footer {
  order: -1;
  display: block;
  flex: none;
  max-width: none;
  margin: 0;
  padding: 1rem 1.25rem 1.25rem;
  opacity: 1 !important;
  transform: none !important;
  border-bottom: 1px solid var(--utaf-border);
}

.myst-primary-sidebar-footer .myst-primary-sidebar-footer {
  max-width: none;
  margin: 0;
  padding: 0;
}

.myst-primary-sidebar-footer p,
.myst-primary-sidebar-footer a,
.myst-primary-sidebar-footer img {
  margin: 0;
}

.myst-primary-sidebar-footer a {
  display: block;
}

.myst-primary-sidebar-footer img {
  width: 9rem;
  max-height: none;
  margin-inline: auto;
}

.utaf-sidebar-search-slot {
  height: 2.5rem;
  margin-top: 1rem;
}

@supports (animation-timeline: scroll()) and (timeline-scope: --utaf-sidebar-scroll) {
  body {
    timeline-scope: --utaf-sidebar-scroll;
  }

  .myst-primary-sidebar-pointer {
    scroll-timeline: --utaf-sidebar-scroll block;
  }

  @keyframes utafs-sidebar-search-scroll {
    from {
      transform: translateY(0);
    }

    to {
      transform: translateY(-26.25rem);
    }
  }

  .myst-top-nav .myst-search-bar {
    animation: utafs-sidebar-search-scroll 1ms linear both;
    animation-timeline: --utaf-sidebar-scroll;
    animation-range: 0 26.25rem;
  }
}

/* Keep Japanese text comfortable to scan while retaining the theme's fonts. */
.article {
  line-height: 1.85;
}

/* Keep body-list bullets as legible as the surrounding text. */
.article ul > li::marker {
  color: var(--utaf-ink);
}

.dark .article ul > li::marker {
  color: #fafaf9;
}

.article :where(h1, h2, h3) {
  letter-spacing: -0.025em;
}

.article :where(h2) {
  scroll-margin-top: 1.5rem;
}

.article :where(h2) .heading-anchor,
.article :where(h3) .heading-anchor {
  color: var(--utaf-accent);
}

/* Present code as a flat working area instead of a floating card. */
.article .myst-code,
.article .myst-code:hover {
  overflow: hidden;
  background: #f3f4f6 !important;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  box-shadow: none !important;
}

.article .myst-code-body {
  background: transparent;
}

.dark .article .myst-code,
.dark .article .myst-code:hover {
  background: #20242b !important;
  border-color: #3f4652;
}

@media (min-width: 1280px) {
  /*
   * Re-map MyST's named grid lines into a deliberate three-column curriculum
   * frame. Components supplied by book-theme continue to target their normal
   * named lines, so no generated HTML needs to be patched.
   */
  .article-grid,
  .myst-primary-sidebar {
    grid-template-columns:
      [screen-start page-start]
      clamp(17.5rem, 20vw, 24rem)
      [page-inset-start]
      clamp(2rem, 3vw, 3.5rem)
      [body-outset-start body-start gutter-left-start body-inset-start middle-start]
      minmax(0, 1fr)
      [middle-end body-inset-end body-end gutter-left-end gutter-right-start gutter-right-end body-outset-end]
      clamp(1.75rem, 2.5vw, 3rem)
      [page-inset-end]
      clamp(15rem, 18vw, 21rem)
      [page-end screen-end];
  }

  /*
   * Keep the horizontal header visually absent while reusing its native,
   * functional search control in the sidebar's reserved search slot.
   */
  .myst-top-nav {
    position: fixed !important;
    inset: 0 auto auto 0 !important;
    z-index: 40;
    display: block;
    width: 0;
    height: 0;
    min-height: 0;
    padding: 0;
    overflow: visible;
    pointer-events: none;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .myst-top-nav-bar,
  .myst-top-nav-bar > div:last-child {
    display: contents;
  }

  .myst-top-nav-bar > div:first-child,
  .myst-top-nav-bar > div:last-child > div,
  .myst-top-nav .myst-theme-button {
    display: none;
  }

  .myst-top-nav .myst-search-bar {
    position: fixed;
    top: 21.75rem;
    left: 1.5rem;
    display: flex !important;
    width: calc(
      clamp(17.5rem, 20vw, 24rem) + clamp(2rem, 3vw, 3.5rem) +
        clamp(0.75rem, 0.78vw, 1rem) - 3.0625rem
    ) !important;
    max-width: none;
    pointer-events: auto;
    aspect-ratio: auto;
  }

  .myst-primary-sidebar {
    top: 0 !important;
    height: 100vh;
    overflow: hidden;
  }

  .myst-primary-sidebar-pointer {
    height: 100vh !important;
    background: #fff;
    border-right: 1px solid var(--utaf-border);
  }

  .dark .myst-primary-sidebar-pointer {
    background: #1c1917;
    border-right-color: #44403c;
  }

  .myst-primary-sidebar-nav {
    padding-top: 0;
  }

  .myst-primary-sidebar-pointer > .myst-primary-sidebar-footer {
    padding: 1.75rem 1.5rem 1.5rem;
  }

  .myst-primary-sidebar-footer img {
    width: min(16rem, calc(100% - 1rem));
  }

  .myst-primary-sidebar-toc {
    max-width: none;
    margin-right: 1.35rem;
    margin-left: 1.35rem;
    padding-top: 1rem;
    border-top: 1px solid var(--utaf-border);
  }

  .dark .myst-primary-sidebar-toc {
    border-top-color: #44403c;
  }

  .myst-primary-sidebar-item-link {
    line-height: 1.45;
  }

  .article.content {
    max-width: none;
    font-size: 1.05rem;
  }

  .myst-fm-block {
    padding-top: 4.5rem;
  }

  .myst-fm-block-title {
    max-width: none;
    font-size: clamp(2.5rem, 3vw, 3.2rem) !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    letter-spacing: 0;
    color: var(--utaf-ink);
  }

  .dark .myst-fm-block-title {
    color: #fafaf9;
  }

  /* Convert the stock margin outline into the bordered right-hand contents rail. */
  .article.content > div[class*="col-margin-right"] {
    top: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .dark .article.content > div[class*="col-margin-right"] {
    background: transparent;
  }

  .article.content > div[class*="col-margin-right"] .myst-outline {
    width: 100%;
    height: 100vh;
    max-height: 100vh !important;
    margin: 0;
    padding: 1.5rem 1.25rem 2rem;
    overflow-y: auto;
    background: #fff;
    backdrop-filter: none;
    border-left: 1px solid var(--utaf-border);
    border-radius: 0;
  }

  .dark .article.content > div[class*="col-margin-right"] .myst-outline {
    background: #1c1917;
    border-left-color: #44403c;
  }

  .article.content > div[class*="col-margin-right"] .myst-outline-header {
    align-items: center;
    font-size: 0;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: none;
  }

  .article.content > div[class*="col-margin-right"] .myst-outline-header::before {
    content: "\76ee\6b21";
    font-size: 1rem;
  }

  .article.content > div[class*="col-margin-right"] a {
    color: var(--utaf-muted);
    line-height: 1.45;
  }

  .article.content > div[class*="col-margin-right"] a:hover,
  .article.content > div[class*="col-margin-right"] a[aria-current="true"] {
    color: var(--utaf-accent);
  }
}

@media (max-width: 1279px) {
  /*
   * Mobile uses an icon-only control row: no brand lockup or site-title header.
   * The full brand and cross-page navigation live inside the hamburger drawer.
   */
  .myst-top-nav {
    min-height: 3.75rem;
    padding: 0.625rem 0.75rem;
    pointer-events: none;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .myst-top-nav-menu-button,
  body:has(.myst-primary-sidebar-pointer.flex) .myst-top-nav .myst-search-bar {
    pointer-events: auto;
  }

  .myst-home-link {
    display: none;
  }

  .myst-top-nav-bar > div:first-child {
    min-width: 0;
    margin-right: 0;
  }

  .myst-top-nav-bar > div:last-child {
    display: contents;
  }

  .myst-top-nav-bar > div:last-child > div,
  .myst-top-nav .myst-theme-button,
  .myst-top-nav .myst-search-bar {
    display: none;
  }

  body:has(.myst-primary-sidebar-pointer.flex) .myst-top-nav {
    z-index: 50;
  }

  body:has(.myst-primary-sidebar-pointer.flex) .myst-top-nav-menu-button {
    visibility: hidden;
  }

  body:has(.myst-primary-sidebar-pointer.flex) .myst-top-nav .myst-search-bar {
    position: fixed;
    top: 14rem;
    left: 1.25rem;
    display: flex !important;
    width: calc(min(75vw, 21.875rem) - 2.5rem) !important;
    max-width: none;
    aspect-ratio: auto;
  }

  body:has(.myst-primary-sidebar-pointer.flex)
    .myst-top-nav
    .myst-search-text-placeholder {
    display: block;
  }

  body:has(.myst-primary-sidebar-pointer.flex)
    .myst-top-nav
    .myst-search-shortcut {
    display: flex;
  }

  .myst-fm-block {
    position: relative;
    padding-top: 1rem;
  }

  .myst-fm-block-header {
    position: absolute;
    top: -2.875rem;
    right: 0;
    width: auto;
    margin: 0;
  }

  .myst-primary-sidebar-pointer {
    display: flex;
    flex-direction: column;
  }

  .article.content > div[class*="col-margin-right"] {
    display: none;
  }

  .myst-outline-header {
    align-items: center;
    font-size: 0;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: none;
  }

  .myst-outline-header::before {
    content: "\76ee\6b21";
    font-size: 1rem;
  }
}
