@use 'variables' as *;

html {
  color: var(--color-text-primary);
  background: var(--color-bg-primary);

  &.custom-scrollbars {
    scrollbar-color: var(--color-text-secondary) var(--color-bg-secondary);
  }

  --font-body: mastodon-font-sans-serif, sans-serif;
  --font-heading: Syne, sans-serif;
  --font-monospace: mastodon-font-monospace, monospace;

  &[data-redesign='true'] {
    --font-body: Inter, sans-serif;
  }

  --outline-focus-default: 2px solid var(--color-border-brand);
  --avatar-border-radius: 8px;
  --max-media-height-small: 460px;
  --max-media-height-large: 566px;

  // Variable for easily inverting directional UI elements,
  --text-x-direction: 1;

  &.rtl {
    --text-x-direction: -1;
  }

  // Compensate for column header height when scrolling elements into view
  --column-header-height: 62px;

  scroll-padding-top: var(--column-header-height);

  &:has(.layout-multi-column) {
    --column-header-height: 0;
  }
}

html.has-modal {
  &,
  body {
    touch-action: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    scrollbar-gutter: stable;
  }

  body {
    overflow: hidden !important;
  }
}

body {
  font-family: var(--font-body);
  background: var(--color-bg-primary);
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  color: var(--color-text-primary);
  text-rendering: optimizelegibility;

  // Disable kerning for Japanese text to preserve monospaced alignment for readability
  &:not(:lang(ja)) {
    font-feature-settings: 'kern';
  }

  text-size-adjust: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0%);
  -webkit-tap-highlight-color: transparent;

  .system-font & {
    // system-ui => standard property (Chrome/Android WebView 56+, Opera 43+, Safari 11+)
    // -apple-system => Safari <11 specific
    // BlinkMacSystemFont => Chrome <56 on macOS specific
    // Segoe UI => Windows 7/8/10
    // Oxygen => KDE
    // Ubuntu => Unity/Ubuntu
    // Cantarell => GNOME
    // Fira Sans => Firefox OS
    // Droid Sans => Older Androids (<4.0)
    // Helvetica Neue => Older macOS <10.11
    font-family:
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      'Segoe UI',
      Oxygen,
      Ubuntu,
      Cantarell,
      'Fira Sans',
      'Droid Sans',
      'Helvetica Neue',
      sans-serif;
  }

  &.app-body {
    padding: 0;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;

    &.layout-single-column {
      height: auto;
      min-height: 100vh;
      min-height: 100dvh;
      overflow-y: scroll;
    }

    &.layout-multiple-columns {
      position: absolute;
      width: 100%;
      height: 100%;
      padding-bottom: env(safe-area-inset-bottom);
    }
  }

  &.player {
    padding: 0;
    margin: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;

    & > div {
      height: 100%;
    }

    .video-player video {
      width: 100%;
      height: 100%;
      max-height: 100vh;
    }

    .media-gallery {
      margin-top: 0;
      height: 100% !important;
      border-radius: 0;
    }

    .media-gallery__item {
      border-radius: 0;
    }
  }

  &.embed {
    margin: 0;
    padding-bottom: 0;
    overflow: hidden;
  }

  &.admin {
    padding: 0;
    background: var(--color-bg-primary);
  }

  &.error {
    position: absolute;
    text-align: center;
    width: 100%;
    height: 100%;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;

    .dialog {
      vertical-align: middle;
      margin: 20px;

      &__illustration {
        img {
          display: block;
          max-width: 470px;
          width: 100%;
          height: auto;
          margin-top: -120px;
          margin-bottom: -45px;
        }
      }

      h1 {
        font-size: 20px;
        line-height: 28px;
        font-weight: 400;
      }
    }
  }
}

a {
  &:focus {
    border-radius: 4px;
    outline: var(--outline-focus-default);
  }

  &:focus:not(:focus-visible) {
    outline: none;
  }
}

button {
  font-family: inherit;
  cursor: pointer;

  &:focus:not(:focus-visible) {
    outline: none;
  }
}

.app-holder {
  &,
  & > div,
  & > noscript {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    outline: 0 !important;
  }

  & > noscript {
    min-height: 100vh;
    min-height: 100dvh;
  }
}

.layout-single-column .app-holder {
  &,
  & > div {
    min-height: 100vh;
    min-height: 100dvh;
  }
}

.layout-multiple-columns .app-holder {
  &,
  & > div {
    height: 100%;
  }
}

.error-boundary,
.app-holder noscript {
  flex-direction: column;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.7;
  color: var(--color-text-error);
  text-align: center;

  & > div {
    max-width: 500px;
  }

  p {
    margin-bottom: 0.85em;

    &:last-child {
      margin-bottom: 0;
    }
  }

  a {
    color: var(--color-text-brand);

    &:hover,
    &:focus,
    &:active {
      text-decoration: none;
    }
  }

  &__footer {
    color: var(--color-text-secondary);
    font-size: 13px;

    a {
      color: var(--color-text-secondary);
    }
  }

  button {
    display: inline;
    border: 0;
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    padding: 0;
    margin: 0;
    line-height: inherit;
    cursor: pointer;
    outline: 0;
    transition: color 300ms linear;
    text-decoration: underline;

    &:hover,
    &:focus,
    &:active {
      text-decoration: none;
    }

    &.copied {
      color: var(--mas-status-success-color);
      transition: none;
    }
  }
}

.logo-resources {
  // Not using display: none because of https://bugs.chromium.org/p/chromium/issues/detail?id=258029
  visibility: hidden;
  user-select: none;
  pointer-events: none;
  width: 0;
  height: 0;
  overflow: hidden;
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  z-index: -1000;
}

// NoScript adds a __ns__pop2top class to the full ancestry of blocked elements,
// to set the z-index to a high value, which messes with modals and dropdowns.
// Blocked elements can in theory only be media and frames/embeds, so they
// should only appear in statuses, under divs and articles.
body,
div,
article {
  .__ns__pop2top {
    z-index: unset !important;
  }
}
