@import 'base';

$callout-note: #F2CB69;
$callout-hint: desaturate(adjust-hue($p-soft, -20deg), 2%);

$pre-before: $p-soft;
$pre-before-syntax: $p-intermediate;
$pre-before-negative: $callout-note;
$pre-before-specification: $p-soft;

$syntax-placeholder-color: saturate(lighten($p-intermediate, 64%), 25%);

$version-color: $p-soft;

$content-width: 750px;

$toc-color: $p-gray;
$toc-item-color: $p-intermediate;
$toc-current-color: $p-soft;
$toc-hover-color: darken($toc-color, 10%);
$toc-width: 280px;
$toc-margin-right: 36px;

body {
  padding-bottom: 24px;
}

table {
  display: block;
  width: 100%;
  overflow: auto;
  word-break: keep-all;
  border-collapse: collapse;
  border-spacing: 0;

  th {
    font-weight: bold;
  }

  th,
  td {
    padding: 6px 13px;
    border: 1px solid $table-border-color;
  }

  tr {
    background-color: $white;
    border-top: 1px solid $table-row-border-top-color;
  }

  tr:nth-child(2n) {
    background-color: $table-alternative-color;
  }
}


.docs-header {
  @extend %display-font;
  display: flex;
  align-items: center;
  background-color: $p-gray;
  padding: 1.25em;
  font-size: 1.125em;

  a {
    color: $heading-color;
    text-decoration: none;
  }
}

.docs-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;

  a {
    margin-left: 0.4em;

    &.active {
      border-bottom: 3px solid $p-soft;
    }
  }
}

.docs-header-search {
  margin-left: 0.125em;
}

.docs-header-title {
  font-size: 1.25em;
}

.docs-header-version {
  background-color: $p-soft;
  border-radius: $border-radius;
  padding: 0.2em 0.3em;
  color: $white;
  font-size: 1rem;
  line-height: 100%;
}

@media (max-width: $break) {
  .docs-header {
    display: block;
    padding: 1em;
  }

  .docs-header-title {
    font-size: 1.1em;
  }

  .docs-header-right {
    margin-top: 0.5em;
    font-size: 0.8em;

    :first-child {
      margin-left: 0;
    }
  }
}

@media print {
  .content {
    font-size: 14px;
  }

  .book-navigation-bottom,
  .book-improve {
    display: none;
  }

  h1,
  h2,
  h3,
  h4 {
    margin-top: 2rem;
  }
}

@mixin syntax-before($text, $color) {
  text-transform: uppercase;
  font-size: 10.8px;
  margin-top: -0.2rem;
  margin-bottom: 0.7rem;
  display: block;
  color: $color;
  content: $text;
}

.syntax {
  font-size: 0.73em;

  &::before {
    @include syntax-before('Syntax', $pre-before-syntax);
  }
}

.negative-example::before {
  @include syntax-before('Bad Example', $pre-before-negative);
}

.declaration::before {
  @include syntax-before('Declaration', $pre-before-specification);
}

pre:not(.negative-example):not(.syntax):not(.declaration)::before {
  @include syntax-before('Example', $pre-before);
}

.syntax-placeholder {
  display: inline-block;
  border-radius: $border-radius;
  margin: 0.1em 0;
  padding: 0.25em 0.38em;
  background-color: $syntax-placeholder-color;
}

section,
.content {
  max-width: $content-width;
  margin: 0 auto;
  padding: 0 20px;
  padding-bottom: 1em;
}

// ==== SPECIAL ====

.method-emoji {
  font-size: 36px;
}

.link-list {
  a {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.2em;
    margin: 0;
    border: 2px solid $p-gray;
    text-decoration: none;
    margin-top: -2px;

    &:hover {
      background: linear-gradient(to top, darken($p-gray, 0.6%), $p-gray);
      text-decoration: none;
    }

    .name {
      font-size: 1.8em;
      margin: 0.15em 0.25em;
      margin-right: 0.4em;
    }

    &:first-child {
      margin-top: 0;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
    }

    &:last-child {
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
    }
  }
}

.toc {
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  font-size: 16px;
  z-index: 100;
  background-color: $toc-color;
  max-height: calc(100vh - #{$menu-height + 73px} - 4.9rem);
  position: fixed;
  width: $toc-width;

  h2,
  h3 {
    margin: 0.8em;
  }

  ul,
  ol {
    padding: 0;
    list-style: none;
  }
}

.toc-wrapper {
  position: absolute;
  left: 0;
  top: 0;
}

.toc-toggle {
  display: none;
}

.content {
  margin-top: 2rem;
  position: relative;
  padding-left: $toc-width + $toc-margin-right;
  max-width: $content-width + $toc-width + $toc-margin-right;
}

.section-link,
.chapter-link {
  color: $toc-item-color;
  display: block;
  padding: 0.35em 0.75em;
  border-left: 6px solid transparent;

  &:hover {
    background-color: $toc-hover-color;
    text-decoration: none;
  }

  &.current {
    border-left-color: $toc-current-color;
  }
}

.section-link {
  padding-left: 2rem;
  font-size: 0.875em;
}

@media (max-width: $break), print {
  .toc-wrapper {
    position: static;
  }

  .toc {
    margin-top: 0;
    position: static;
    overflow-y: auto;
    max-height: none;
    width: auto;
  }

  .toc-content {
    display: none;

    &:target {
      display: block;
    }
  }

  .toc-toggle {
    display: block;
    padding: 0.35rem 1rem;

    &::before {
      content: 'Show Table of Contents';
    }
  }

  .content {
    max-width: none;
  }

  section,
  .content {
    padding: 0 12px;
  }
}

// ===== CALLOUTS =====

@mixin callout($color) {
  overflow: hidden;
  margin: 1.25rem 0;
  padding: 1.4rem 1.8rem;
  background-color: lighten($color, 29%);

  a, & {
    color: saturate(darken($color, 40%), 10%);
  }

  a {
    font-weight: bold;
  }

  .title {
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.33px;
    margin-bottom: 0.45rem;
    display: block;
    color: saturate(darken($color, 40%), 1%);
  }

  p {
    margin-top: 0;
    margin-bottom: 0;
  }
}

.callout-caution {
  @include callout($callout-note);
}

.callout-hint {
  @include callout($callout-hint);
}

.book-navigation-bottom {
  display: flex;

  .right {
    text-align: right;
    flex: 1;
  }
}

.book-improve {
  text-align: center;
  font-size: 0.875em;
  margin: 0.875rem 0;
  border-radius: $border-radius;

  a, & {
    color: lighten($p-intermediate, 45%);
  }

  a {
    font-weight: bold;
  }
}

.pre-release-warning {
  margin-top: 2rem;
  padding: 0.75rem;
  background-color: lighten($callout-note, 29%);

  a, & {
    color: saturate(darken($callout-note, 40%), 10%);
  }

  a {
    font-weight: bold;
  }
}

// ==== MAGIC INSTALL ====

.magic-install-sw {
  display: flex;
}

.magic-install-sw-box {
  width: 33.33333%;

  select {
    width: 100%;
  }

  &.center {
    padding: 0 0.75em;
  }
}

.magic-install-sw-label {
  color: $heading-color;
  display: block;
  margin-bottom: 0.18em;
}

.magic-install-sw-help {
  color: $heading-color;
  font-size: 0.66667em;
  margin-top: 0.15em;
}

// ==== CARBON ADS =====

#carbonads {
  float: right;
  display: block;
  overflow: hidden;
  margin-bottom: 20px;
  max-width: 180px;
  background-color: $p-gray;
  padding: 0.8rem;
  margin-left: 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.75rem;
}

.carbon-text {
  color: inherit;
  text-decoration: none;

  &:hover {
    text-decoration: none;
  }
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

.carbon-img {
  display: block;
  margin-bottom: 8px;
  line-height: 1;
}

.carbon-img img {
  display: block;
  height: auto;
}

.carbon-text {
  display: block;
  margin-bottom: 0.25rem;
}

.carbon-poweredby {
  display: block;
  font-size: 0.6rem;
  color: darken(desaturate($p-gray, 30%), 36%);
}

@media (max-width: $break) {
  #carbonads {
    float: none;
    margin: 1.25rem 0;
  }
}
