// This file contains the styles for the overall layouting of the documentation
// skeleton, including the responsive changes as well as sidebar toggles.
//
// This is implemented as a mobile-last design, which isn't ideal, but it is
// reasonably good-enough and I got pretty tired by the time I'd finished this
// to move the rules around to fix this. Shouldn't take more than 3-4 hours,
// if you know what you're doing tho.

// HACK: Not all browsers account for the scrollbar width in media queries.
// This results in horizontal scrollbars in the breakpoint where we go
// from displaying everything to hiding the ToC. We accomodate for this by
// adding a bit of padding to the TOC drawer, disabling the horizontal
// scrollbar and allowing the scrollbars to cover the padding.
// https://www.456bereastreet.com/archive/201301/media_query_width_and_vertical_scrollbars/

// HACK: Always having the scrollbar visible, prevents certain browsers from
// causing the content to stutter horizontally between taller-than-viewport and
// not-taller-than-viewport pages.
@use "variables" as *

html
  overflow-x: hidden
  overflow-y: scroll
  scroll-behavior: smooth

.sidebar-scroll, .toc-scroll, article[role=main] *
  scrollbar-width: thin
  scrollbar-color: var(--color-foreground-border) transparent

//
// Overalls
//
html,
body
  height: 100%
  color: var(--color-foreground-primary)
  background: var(--color-background-primary)

.skip-to-content
  position: fixed
  padding: 1rem
  border-radius: 1rem
  left: 0.25rem
  top: 0.25rem
  z-index: 40
  background: var(--color-background-primary)
  color: var(--color-foreground-primary)

  transform: translateY(-200%)
  transition: transform 300ms ease-in-out

  &:focus-within
    transform: translateY(0%)

article
  color: var(--color-content-foreground)
  background: var(--color-content-background)
  overflow-wrap: break-word

.page
  display: flex
  // fill the viewport for pages with little content.
  min-height: 100%

.mobile-header
  width: 100%
  height: var(--header-height)
  background-color: var(--color-header-background)
  color: var(--color-header-text)
  border-bottom: 1px solid var(--color-header-border)

  // Looks like sub-script/super-script have this, and we need this to
  // be "on top" of those.
  z-index: 10

  // We don't show the header on large screens.
  display: none

  // Add shadow when scrolled
  &.scrolled
    border-bottom: none
    box-shadow: 0 0 0.2rem rgba(0, 0, 0, 0.1), 0 0.2rem 0.4rem rgba(0, 0, 0, 0.2)

  .header-center
    a
      color: var(--color-header-text)
      text-decoration: none

.main
  display: flex
  flex: 1

// Sidebar (left) also covers the entire left portion of screen.
.sidebar-drawer
  box-sizing: border-box

  border-right: 1px solid var(--color-sidebar-background-border)
  background: var(--color-sidebar-background)

  display: flex
  justify-content: flex-end
  // These next two lines took me two days to figure out.
  width: calc((100% - #{$full-width}) / 2 + #{$sidebar-width})
  min-width: $sidebar-width

// Scroll-along sidebars
.sidebar-container,
.toc-drawer
  box-sizing: border-box
  width: $sidebar-width

.toc-drawer
  background: var(--color-toc-background)
  // See HACK described on top of this document
  padding-right: 1rem

.sidebar-sticky,
.toc-sticky
  position: sticky
  top: 0
  height: min(100%, 100vh)
  height: 100vh

  display: flex
  flex-direction: column

.sidebar-scroll,
.toc-scroll
  flex-grow: 1
  flex-shrink: 1

  overflow: auto
  scroll-behavior: smooth

// Central items.
.content
  padding: 0 $content-padding
  width: $content-width

  display: flex
  flex-direction: column
  justify-content: space-between

.icon
  display: inline-block
  height: 1rem
  width: 1rem
  svg
    width: 100%
    height: 100%

//
// Accommodate announcement banner
//
.announcement
  background-color: var(--color-announcement-background)
  color: var(--color-announcement-text)

  height: var(--header-height)
  display: flex
  align-items: center
  overflow-x: auto
  & + .page
    min-height: calc(100% - var(--header-height))

.announcement-content
  box-sizing: border-box
  padding: 0.5rem
  min-width: 100%
  white-space: nowrap
  text-align: center

  a
    color: var(--color-announcement-text)
    text-decoration-color: var(--color-announcement-text)

    &:hover
      color: var(--color-announcement-text)
      text-decoration-color: var(--color-link--hover)

////////////////////////////////////////////////////////////////////////////////
// Toggles for theme
////////////////////////////////////////////////////////////////////////////////
.no-js .theme-toggle-container  // don't show theme toggle if there's no JS
  display: none

.theme-toggle-container
  display: flex

.theme-toggle
  display: flex
  cursor: pointer
  border: none
  padding: 0
  background: transparent

.theme-toggle svg
  height: 1.25rem
  width: 1.25rem
  color: var(--color-foreground-primary)
  display: none

.theme-toggle-header
  display: flex
  align-items: center
  justify-content: center

////////////////////////////////////////////////////////////////////////////////
// Toggles for elements
////////////////////////////////////////////////////////////////////////////////
.toc-overlay-icon, .nav-overlay-icon
  display: none
  cursor: pointer

  .icon
    color: var(--color-foreground-secondary)
    height: 1.5rem
    width: 1.5rem

.toc-header-icon, .nav-overlay-icon
  // for when we set display: flex
  justify-content: center
  align-items: center

.toc-content-icon
  height: 1.5rem
  width: 1.5rem

.content-icon-container
  float: right
  display: flex
  margin-top: 1.5rem
  margin-left: 1rem
  margin-bottom: 1rem
  gap: 0.5rem

  .edit-this-page, .view-this-page
    svg
      color: inherit
      height: 1.25rem
      width: 1.25rem

.sidebar-toggle
  position: absolute
  display: none
// <debugging things>
.sidebar-toggle[name="__toc"]
  left: 20px
.sidebar-toggle:checked
  left: 40px
// </debugging things>

.overlay
  position: fixed
  top: 0
  width: 0
  height: 0

  transition: width 0ms, height 0ms, opacity 250ms ease-out

  opacity: 0
  background-color: rgba(0, 0, 0, 0.54)
.sidebar-overlay
  z-index: 20
.toc-overlay
  z-index: 40

// Keep things on top and smooth.
.sidebar-drawer
  z-index: 30
  transition: left 250ms ease-in-out
.toc-drawer
  z-index: 50
  transition: right 250ms ease-in-out

// Show the Sidebar
#__navigation:checked
  & ~ .sidebar-overlay
    width: 100%
    height: 100%
    opacity: 1
  & ~ .page
    .sidebar-drawer
      top: 0
      left: 0
      // Show the toc sidebar
#__toc:checked
  & ~ .toc-overlay
    width: 100%
    height: 100%
    opacity: 1
  & ~ .page
    .toc-drawer
      top: 0
      right: 0

////////////////////////////////////////////////////////////////////////////////
// Back to top
////////////////////////////////////////////////////////////////////////////////
.back-to-top
  text-decoration: none

  display: none
  position: fixed
  left: 0
  top: 1rem
  padding: 0.5rem
  padding-right: 0.75rem
  border-radius: 1rem
  font-size: 0.8125rem

  background: var(--color-background-primary)
  box-shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.05), #6b728080 0px 0px 1px 0px

  z-index: 10

  margin-left: 50%
  transform: translateX(-50%)
  svg
    height: 1rem
    width: 1rem
    fill: currentColor
    display: inline-block

  span
    margin-left: 0.25rem

  .show-back-to-top &
    display: flex
    align-items: center

////////////////////////////////////////////////////////////////////////////////
// Responsive layouting
////////////////////////////////////////////////////////////////////////////////
// Make things a bit bigger on bigger screens.
@media (min-width: $full-width + $sidebar-width)
  html
    font-size: 110%

@media (max-width: $full-width)
  // Collapse "toc" into the icon.
  .toc-content-icon
    display: flex
  .toc-drawer
    position: fixed
    height: 100vh
    top: 0
    right: -$sidebar-width
    border-left: 1px solid var(--color-background-muted)
  .toc-tree
    border-left: none
    font-size: var(--toc-font-size--mobile)

  // Accomodate for a changed content width.
  .sidebar-drawer
    width: calc((100% - #{$full-width - $sidebar-width}) / 2 + #{$sidebar-width})

@media (max-width: $content-padded-width + $sidebar-width)
  // Center the page
  .content
    margin-left: auto
    margin-right: auto
    padding: 0 $content-padding--small

@media (max-width: $content-padded-width--small + $sidebar-width)
  // Collapse "navigation".
  .nav-overlay-icon
    display: flex
  .sidebar-drawer
    position: fixed
    height: 100vh
    width: $sidebar-width

    top: 0
    left: -$sidebar-width

  // Swap which icon is visible.
  .toc-header-icon, .theme-toggle-header
    display: flex
  .toc-content-icon, .theme-toggle-content
    display: none

  // Show the header.
  .mobile-header
    position: sticky
    top: 0
    display: flex
    justify-content: space-between
    align-items: center

    .header-left,
    .header-right
      display: flex
      height: var(--header-height)
      padding: 0 var(--header-padding)
      label
        height: 100%
        width: 100%
        user-select: none

  .nav-overlay-icon .icon,
  .theme-toggle svg
    height: 1.5rem
    width: 1.5rem

  // Add a scroll margin for the content
  :target
    scroll-margin-top: calc(var(--header-height) + 2.5rem)

  // Show back-to-top below the header
  .back-to-top
    top: calc(var(--header-height) + 0.5rem)

  // Accommodate for the header.
  .page
    flex-direction: column
    justify-content: center

@media (max-width: $content-width + 2* $content-padding--small)
  // Content should respect window limits.
  .content
    width: 100%
    overflow-x: auto

@media (max-width: $content-width)
  article[role=main] aside.sidebar
    float: none
    width: 100%
    margin: 1rem 0
