@use '../_common';
@use './mixins/media-queries';

html,
body,
app-root,
.app-frame {
  overflow: hidden;
  margin: 0;
  /* stylelint-disable-next-line no-duplicate-selectors */
  height: 100%;
  height: -webkit-fill-available;
  box-sizing: border-box;
  font-optical-sizing: auto;
  font-family: var(--font-primary-stack);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  letter-spacing: var(--letter-spacing-normal);
}

// Tabular figures — opt-in only (avoid applying to non-numeric <time> content)
.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

// Wrapped in :where() so the global rules specificity is (0,0,0) — any
// component or Material typography override wins trivially.
// Excludes Material dialog/card titles explicitly.
:where(h1, h2, h3, h4, h5, h6):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(
    .mat-mdc-card-title
  ) {
  font-family: inherit;
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--text-color-most-intense);
}

:where(h1):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-3xl);
  letter-spacing: var(--letter-spacing-tighter);
  line-height: var(--line-height-tight);
}

:where(h2):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-2xl);
  letter-spacing: var(--letter-spacing-tighter);
}

:where(h3):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-xl);
}

:where(h4):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-lg);
}

:where(h5):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-md);
}

:where(h6):not([mat-dialog-title]):not(.mat-mdc-dialog-title):not(.mat-mdc-card-title) {
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--text-color-muted);
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono-stack);
  font-feature-settings: 'liga' 0;
}

html {
  overflow: hidden !important;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  // Set html background for iOS safe area (home indicator)
  // Uses :has() to match body theme class since --bg is defined on body
  &:has(body.isLightTheme) {
    background: #f8f8f7;
  }

  &:has(body.isDarkTheme) {
    background: #131314;
  }

  button,
  a {
    -webkit-app-region: no-drag !important;
  }

  // scrollbars - apply to html only, properties inherit to scrollable children
  /* Modern browsers with `scrollbar-*` support */
  @supports (scrollbar-width: auto) {
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
  }

  /* Legacy browsers with `::-webkit-scrollbar-*` support */
  @supports selector(::-webkit-scrollbar) {
    ::-webkit-scrollbar-thumb {
      background: var(--scrollbar-thumb);
    }

    ::-webkit-scrollbar-track {
      background: var(--scrollbar-track);
    }

    ::-webkit-scrollbar {
      max-width: 4px;
      max-height: 4px;
    }
  }
}

body {
  // to fix older android web view
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;

  &:before {
    display: none;
    transition: 1s opacity;
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
  }

  // Soft primary-tinted gradient backdrop. Light and dark want different
  // recipes — the same single corner-glow that reads as warm on dark looks
  // smudgy on white, so light gets two larger diffuse glows (primary +
  // accent) for subtle depth without flat-tint feel.
  // Themes that want a different/no backdrop hide body:before (dark-base,
  // arc, nord-snow-storm, dracula, velvet do this).
  &.isLightTheme,
  &.isDarkTheme {
    color: var(--text-color);
    background: var(--bg);

    &.isDisableBackgroundTint {
      background: var(--bg);
      &:before {
        display: none;
        opacity: 0;
      }
    }
  }

  &.isLightTheme:before {
    display: block;
    opacity: 1;
    // Two glows in different primary shades — primary-200 (soft pastel)
    // for the top-left highlight, primary-400 (deeper) for bottom-right
    // depth. Single-hue keeps the light-mode wash calm.
    background:
      radial-gradient(
        ellipse 120% 80% at 0% -10%,
        color-mix(in srgb, var(--palette-primary-200) 40%, transparent) 0%,
        transparent 65%
      ),
      radial-gradient(
        ellipse 80% 60% at 100% 100%,
        color-mix(in srgb, var(--palette-primary-400) 15%, transparent) 0%,
        transparent 60%
      );
  }

  &.isDarkTheme:before {
    display: block;
    opacity: 1;
    background:
      radial-gradient(
        ellipse 80% 60% at 10% -10%,
        color-mix(in srgb, var(--c-primary) 10%, transparent) 0%,
        transparent 55%
      ),
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--c-primary) 4%, transparent) 0%,
        transparent 100%
      );
  }

  // also hide material dialogs while import is in progress
  &.isDataImportInProgress {
    .cdk-overlay-container {
      display: none !important;
    }
  }

  &.isElectron:not(.isFullScreen) {
    border: 1px solid var(--divider-color);
  }
}

.page-wrapper {
  padding: var(--s) var(--s) calc(var(--s) * 9);

  @include media-queries.mq(xs) {
    padding: var(--s) var(--s2) calc(var(--s) * 9);
  }
}

.component-wrapper {
  max-width: var(--component-max-width);
  margin: auto;
}

.task-list-wrapper {
  padding: 0 var(--s) var(--s7);
  // for a little bit of extra space for 800 width
  max-width: calc(var(--component-max-width) - 40px);
  margin: auto;

  @include media-queries.mq(xxs) {
    padding: 0 var(--s) var(--s7);
  }

  @include media-queries.mq(xs) {
    padding: 0 calc(var(--s) * 1.5) var(--s7);
  }

  @include media-queries.mq(sm) {
    padding: 0 var(--s3) var(--s7);
    max-width: var(--component-max-width);
  }

  @include media-queries.mq(lg) {
    padding: 0 var(--s3) var(--s7);
    max-width: calc(var(--component-max-width) + 100px);
  }

  improvement-banner + & {
    padding-top: 0;
  }
}

blockquote {
  border-left: 4px solid rgba(var(--c-accent), 1);
  margin: 20px 0;
  padding: 1px 20px;
}

a[href] {
  color: var(--c-accent);
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

// make images responsive per default
img {
  max-width: 100%;
  height: auto;
  display: block;
}
